45
1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

Embed Size (px)

Citation preview

Page 1: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

1Jonathan LewisEOUG Jun 2000

Execution Plans

Explain Plan - part 2

Parallel - Partitions - Problems

Page 2: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

2Jonathan LewisEOUG Jun 2000

Execution Plans

Parallel - Partitions - Problems

• Execution Plans - reprise

• Interpreting Parallel Queries

• Interpreting Partition table queries

• New mysteries

Page 3: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

3Jonathan LewisEOUG Jun 2000

Execution Plans

Execution Plans - reprise

select ep1.v1, count(ep2.v2)

from ep2, ep1

where ep2.v1 = 'Tyne Tees'

and ep1.n1 = ep2.n1

group by ep1.v1

order by count(ep2.v2) desc ;

Page 4: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

4Jonathan LewisEOUG Jun 2000

Execution Plans

Execution Plans - reprise

SELECT STATEMENT (choose)

SORT (order by)

SORT (group by)

HASH JOIN

TABLE ACCESS (analyzed) EP1 (full)

TABLE ACCESS (analyzed) EP2 (full)

Page 5: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

5Jonathan LewisEOUG Jun 2000

Execution Plans

Parallel Execution

Slave P003 Slave P004 Slave P005

Slave P000 Slave P001 Slave P002

Co-ordinator

Page 6: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

6Jonathan LewisEOUG Jun 2000

Execution Plans

Parallel Execution

SORT (order by) PARA_2_SERIAL :Q819004

SORT (group by) PARA_2_PARA :Q819003

HASH JOIN PARA_2_PARA :Q819002

TABLE ACCESS EP2(full) P_2_P :Q819000

TABLE ACCESS EP1(full) P_2_P :Q819001

Page 7: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

7Jonathan LewisEOUG Jun 2000

Execution Plans

Parallel Execution

Co-ordinator

Slave P003 Slave P004 Slave P005

Slave P000 Slave P001 Slave P002

Slave P003 Slave P004 Slave P005

Slave P000 Slave P001 Slave P002

Select x 2

Hash

Group

Order

Q0, Q1

Q2

Q3

Q4

Page 8: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

8Jonathan LewisEOUG Jun 2000

Execution Plans

Parallel Execution

:Q819000 SELECT /*+ NO_EXPAND ROWID(A1) */

A1."N1" C0,A1."V2" C1

FROM "EP2" A1

WHERE ROWID BETWEEN :B1 AND :B2

AND A1."V1"='Tyne Tees'

:Q819001 SELECT /*+ NO_EXPAND ROWID(A1) */

A1."N1" C0,A1."V1" C1

FROM "EP1" A1

WHERE ROWID BETWEEN :B1 AND :B2

Page 9: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

9Jonathan LewisEOUG Jun 2000

Execution Plans

Parallel Execution

:Q819004 SELECT A1.C0 C0,A1.C1 C1 FROM :Q819003 A1 ORDER BY A1.C0 DESC

:Q819003 SELECT COUNT(A1.C1) C0,A1.C0 C1 FROM :Q819002 A1 GROUP BY A1.C0

:Q819002 SELECT/*+ ORDERED NO_EXPAND USE_HASH(A2) */ A2.C1 C0,A1.C1 C1 FROM :Q819000 A1, :Q819001 A2 WHERE A2.C0=A1.C0

Page 10: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

10Jonathan LewisEOUG Jun 2000

Execution Plans

Parallel Execution

select

tq_id, server_type, process,

num_rows, bytes, waits

from

v$pq_tqstat

order by

tq_id,

server_type desc;

Page 11: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

11Jonathan LewisEOUG Jun 2000

Execution Plans

Parallel Execution

ID SERVER_TYP PROCESS ROWS BYTES WAITS 0 Producer P005 67 1135 10 P004 67 1127 10 P003 66 1109 10 Consumer P002 80 1343 4 P000 58 982 4 P001 62 1046 4

1 Producer P005 78 16287 14 P004 66 13788 12 P003 56 11703 10 Consumer P002 80 16703 10 P000 57 11909 8 P001 63 13166 9

Page 12: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

12Jonathan LewisEOUG Jun 2000

Execution Plans

Parallel Execution

Co-ordinator

Slave P003 Slave P004 Slave P005

Slave P000 Slave P001 Slave P002

Slave P003 Slave P004 Slave P005

Slave P000 Slave P001 Slave P002

Select x 2

Hash

Group

Order

Q0, Q1

Q2

Q3

Q4

Page 13: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

13Jonathan LewisEOUG Jun 2000

Execution Plans

Parallel Execution

SORT (order by) PARA_2_SERIAL :Q819002

SORT (group by) PARA_2_PARA :Q819001

NESTED LOOPS PARA_2_PARA :Q819000

TABLE ACCESS EP2(full) P_WITH_Parent

TABLE ACCESS EP1(by index rowid) P_W_P

INDEX UNIQUE EP1_PK (unique) P_W_P

Page 14: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

14Jonathan LewisEOUG Jun 2000

Execution Plans

Parallel Execution

SELECT /*+ ORDERED NO_EXPAND

USE_NL(A2) INDEX(A2 "EP1_PK") */

A2."V1" C0, A1.C1 C1

FROM ( SELECT /*+ NO_EXPAND ROWID(A3) */

A3."N1" C0,A3."V2" C1

FROM "EP2" A3

WHERE ROWID BETWEEN :B1 AND :B2

AND A3."V1"='Tyne Tees'

) A1,

"EP1" A2

WHERE A2."N1" = A1.C0

Page 15: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

15Jonathan LewisEOUG Jun 2000

Execution Plans

PQ Summary

• Node, Other, Other_tag

• V$PQ_TQSTAT

• Messages can be the main cost

Page 16: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

16Jonathan LewisEOUG Jun 2000

Execution Plans

Parallel - Partitions - Problems

Partitioned tables

Page 17: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

17Jonathan LewisEOUG Jun 2000

Execution Plans

Partitioned Tables

create table ep1 (n1, v1, v2)

partition by range (n1) (

partition p1 values less than (50),

partition p2 values less than (100),

partition p3 values less than (150)

)

as

select . . .

Page 18: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

18Jonathan LewisEOUG Jun 2000

Execution Plans

Partitioned Tables

select max(v1)

from ep1

where n1 = 45

SORT (AGGREGATE)

TABLE ACCESS (BY LOCAL INDEX ROWID) OF EP1

INDEX (UNIQUE SCAN) OF 'EP1_PK' (UNIQUE)

Page 19: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

19Jonathan LewisEOUG Jun 2000

Execution Plans

Partitioned Tables

select max(v1)

from ep1

where n1 between 45 and 60;

SORT (AGGREGATE)

PARTITION RANGE (ITERATOR)

TABLE ACCESS (FULL) OF 'EP1'

Page 20: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

20Jonathan LewisEOUG Jun 2000

Execution Plans

Partitioned Tables

create table ref_n1 (r1 number, c1 varchar2(10));

select c1, max(n1)

from ref_n1, ep1

where ref_n1.c1 like 'S%'

and ep1.n1 = ref_n1.r1

group by

ref_n1.c1;

Page 21: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

21Jonathan LewisEOUG Jun 2000

Execution Plans

Partitioned Tables

SORT (GROUP BY)

NESTED LOOPS

TABLE ACCESS (FULL) OF 'REF_N1'

PARTITION RANGE (ITERATOR)

INDEX (UNIQUE SCAN) OF 'EP1_PK' (UNIQUE)

Page 22: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

22Jonathan LewisEOUG Jun 2000

Execution Plans

Partitioned Tables

SORT (AGGREGATE)

TABLE ACCESS (BY LOCAL INDEX ROWID) OF EP1

INDEX (UNIQUE SCAN) OF 'EP1_PK' (UNIQUE)

SORT (aggregate)

TABLE ACCESS (ana) JPL1 EP1 (by local index rowid)

Pt id: 2 Pt Range: 1 - 1

INDEX (ana) UNIQUE JPL1 EP1_PK (range scan)

Pt id: 2 Pt Range: 1 - 1

Page 23: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

23Jonathan LewisEOUG Jun 2000

Execution Plans

Partitioned Tables

SORT (AGGREGATE)

PARTITION RANGE (ITERATOR)

TABLE ACCESS (FULL) OF 'EP1'

SORT (AGGREGATE)

PARTITION RANGE (ITERATOR)

Pt id: 2 Pt Range: 1 - 2

TABLE ACCESS (FULL) OF 'EP1'

Pt id: 2 Pt Range: 1 - 2

Page 24: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

24Jonathan LewisEOUG Jun 2000

Execution Plans

Partitioned Tables

SORT (group by)

NESTED LOOPS

TABLE ACCESS REF_N1 (full)

PARTITION RANGE (iterator)

Pt id: 4 Pt Range: KEY - KEY

INDEX (analyzed) UNIQUE EP1_PK (unique scan)

Pt id: 4 Pt Range: KEY - KEY

Page 25: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

25Jonathan LewisEOUG Jun 2000

Execution Plans

Partitioned Tables

select max(v1)

from ep1

where n1 = to_number(:b1)

Page 26: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

26Jonathan LewisEOUG Jun 2000

Execution Plans

Partitioned Tables

SORT (aggregate)

PARTITION RANGE (single)

Pt id: 2 Pt Range: KEY - KEY

TABLE ACCESS (ana) JPL1 EP1 (by local index rowid)

Pt id: 2 Pt Range: KEY - KEY

INDEX (analyzed) UNIQUE JPL1 EP1_PK (range scan)

Pt id: 2 Pt Range: KEY - KEY

Page 27: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

27Jonathan LewisEOUG Jun 2000

Execution Plans

Partitioned Tables

select ep1.v1, count(ep2.v2)

from ep2, ep1

where ep2.v1 = 'Tyne Tees'

and ep2.n1 between 80 and 120

and ep1.n1 = ep2.n1

group by

ep1.v1

Page 28: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

28Jonathan LewisEOUG Jun 2000

Execution Plans

Partitioned Table

SORT (GROUP BY) PARTITION RANGE (ITERATOR) HASH JOIN TABLE ACCESS (FULL) OF 'EP1' TABLE ACCESS (FULL) OF 'EP2'

SORT (GROUP BY) HASH JOIN PARTITION RANGE (ITERATOR) TABLE ACCESS (FULL) OF 'EP1' PARTITION RANGE (ITERATOR) TABLE ACCESS (FULL) OF 'EP2'

Page 29: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

29Jonathan LewisEOUG Jun 2000

Execution Plans

Partitioned Tables

create table ep1 (n1, v1, v2)

partition by range (n1) (

partition p1 values less than (50),

partition p2 values less than (100),

partition p3 values less than (150),

partition p4 values less than (250)

)

as

select . . .

Page 30: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

30Jonathan LewisEOUG Jun 2000

Execution Plans

Partitioned Tables

create table ep2 (n1, n2, v1, v2)

partition by range (n1) (

partition p1 values less than (51),

partition p2 values less than (101),

partition p3 values less than (151),

partition p4 values less than (251)

)

as

select . . .

Page 31: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

31Jonathan LewisEOUG Jun 2000

Execution Plans

Partitioned Tables

SORT (group by) PARTITION RANGE(iterator) Ptid: 2 Pt Rng: 2-3 HASH JOIN TABLE ACCESS EP1(full)Ptid: 2 Pt Rng: 2-3 TABLE ACCESS EP2(full)Ptid: 2 Pt Rng: 2-3

SORT(group by) HASH JOIN PARTITION RANGE(iterator)Ptid: 3 Pt Rng: 2-3 TABLE ACCESS EP1(full)Ptid: 3 Pt Rng: 2-3 PARTITION RANGE(iterator)Ptid: 5 Pt Rng: 2-3 TABLE ACCESS EP2(full)Ptid: 5 Pt Rng: 2-3

Page 32: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

32Jonathan LewisEOUG Jun 2000

Execution Plans

Partitioned Tables

SELECT /*+ ORDERED NO_EXPAND USE_HASH(A2) SWAP_JOIN_INPUTS(A2)

*/ A2.C1 C0,A1.C1C1

FROM (SELECT /*+ NO_EXPAND FULL(A3) */ A3."N1" C0,A3."V2" C1

FROM "EP2" PARTITION(:B1) A3 WHERE A3."V1"='Tyne Tees' AND A3."N1">=80 AND A3."N1"<=120) A1,(SELECT /*+ NO_EXPAND FULL(A4) */

A4."N1" C0,A4."V1" C1 FROM "EP1" PARTITION(:B1)A4 WHERE A4."N1">=80 AND A4."N1"<=120) A2

WHERE A2.C0=A1.C0

Page 33: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

33Jonathan LewisEOUG Jun 2000

Execution Plans

Partitioned Tables

SELECT /*+ ORDERED NO_EXPAND USE_HASH(A2) SWAP_JOIN_INPUTS(A2) */

A2.C1 C0,A1.C1 C1 FROM (SELECT /*+ NO_EXPAND FULL(A3) */

A3."N1" C0,A3."V2" C1 FROM "EP2" PARTITION_SET(1) A3 WHERE A3."V1"='Tyne Tees' AND A3."N1">=80 AND A3."N1"<=120) A1,:Q849000 A2

WHERE A2.C0=A1.C0

SELECT /*+ NO_EXPAND ROWID(A1) */ A1."N1" C0,A1."V1" C1

FROM "EP1" PARTITION(:B1) A1 WHERE ROWID BETWEEN :B2 AND :B3 AND A1."N1">=80 AND A1."N1"<=120

Page 34: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

34Jonathan LewisEOUG Jun 2000

Execution Plans

Partition Summary

• Partition ID

• Partition Start / Partition Stop

• KEY - KEY vs strictly numbered

• Iterator / Single

Page 35: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

35Jonathan LewisEOUG Jun 2000

Execution Plans

Parallel - Partitions - Problems

Problems

Page 36: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

36Jonathan LewisEOUG Jun 2000

Execution Plans

Problems

select sum(sales_value) from rls_demo;

SORT (AGGREGATE)

TABLE ACCESS (FULL) OF 'RLS_DEMO'

Page 37: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

37Jonathan LewisEOUG Jun 2000

Execution Plans

Problems

SORT (AGGREGATE)

NESTED LOOPS

VIEW

SORT (UNIQUE)

TABLE ACCESS (FULL) OF 'RLS_CONTROL'

TABLE ACCESS (FULL) OF 'RLS_DEMO'

Page 38: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

38Jonathan LewisEOUG Jun 2000

Execution Plans

Problems

'owner in (

select t.owner

from rls_control t

where manager =

sys_context(''rls_demo'',''role'')

)'

Page 39: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

39Jonathan LewisEOUG Jun 2000

Execution Plans

Problems

create type jpl_item as object (n1 number, v1 varchar2(32));

/

create type jpl_tab_type as table of jpl_item;

/

create table demo_nest (

id number,

nest jpl_tab_type

)

nested table nest store as t_nested;

Page 40: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

40Jonathan LewisEOUG Jun 2000

Execution Plans

Problems

select

sum(n.n1)

from

demo_nest t,

table(t.nest) n

where

n.v1 = 'asdf';

Page 41: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

41Jonathan LewisEOUG Jun 2000

Execution Plans

Problems

SORT (AGGREGATE)

TABLE ACCESS (BY INDEX ROWID) OF 'T_NESTED'

INDEX (RANGE SCAN) OF 'TN_V1' (NON-UNIQUE)

Where has the parent table DEMO_NEST gone ?

Page 42: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

42Jonathan LewisEOUG Jun 2000

Execution Plans

Problems

select it1.location, it1.sales,

(

select sum(sales)

from inline_test ita

where ita.area = it1.area

and ita.location_type = it1.location_type

) area_sales

from inline_test it1

where it1.location_type != 'WAREHOUSE';

Page 43: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

43Jonathan LewisEOUG Jun 2000

Execution Plans

Problems

SELECT STATEMENT Optimizer=CHOOSE

TABLE ACCESS (FULL) OF 'INLINE_TEST'

Where is the in-line table ?

Page 44: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

44Jonathan LewisEOUG Jun 2000

Execution Plans

Problem Summary

alter session

set events

‘10046 trace name context forever, level 12’

Page 45: 1Jonathan Lewis EOUG Jun 2000 Execution Plans Explain Plan - part 2 Parallel - Partitions - Problems

45Jonathan LewisEOUG Jun 2000

Execution Plans

Conclusion

? ? ? ?