SlideShare a Scribd company logo
1 of 148
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Ask TOM Mini-Lesson
SQL Tuning with Connor McDonald
Confidential – Oracle Internal/Restricted/Highly Restricted
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Connor McDonald
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
3
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
4
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Stuff
youtube bit.ly/youtube-connor
blog bit.ly/blog-connor
twitter bit.ly/twitter-connor
400+ posts mainly on database & development
250 technical videos, new uploads every week
rants and raves on tech and the world :-)
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
6
Dump of memory from 0x07246400 to 0x07248400
1064B4C00 06A20000 08C0000A 0A07C47E 00020506 [...........~....]
1064B4C10 34BC0000 01000000 00030CBF 0A07C47C [4..............|]
1064B4C20 0002EC28 00020300 00000000 0004001D [...(............]
...
1064B6BF0 C10B02C1 0B06436F 6E6E6F72 C47E0605 [......Connor.~..]
table or index
block size
database version created in
relative block address
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
https://asktom.oracle.com
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
8https://asktom.oracle.com/officehours
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
150 hours of free access (so far)
9
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
10
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
11
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
if you are tuning SQL ...
12
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
13
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
why ?
14
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
real example
15
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
16
CUSTOMER_ACCOUNTS
CUSTOMER_TRANSACTIONS
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
17
"last transaction for all customers"
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
18
SQL> select ACCOUNT_NUM,
2 max(TXN_TS) LAST_TS
3 from CUSTOMER_TRANS t
4 group by ACCOUNT_NUM
5 order by 1;
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
19
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
20
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
make it faster ...
21
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
we tried ...
22
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
23
SQL> select /*+ PARALLEL(t 16) */
2 ACCOUNT_NUM, max(TXN_TS) LAST_TS
3 from CUSTOMER_TRANS t
4 group by ACCOUNT_NUM
5 order by 1;
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
24
SQL> create index CUSTOMER_TRANS_IX
2 on CUSTOMER_TRANS( account_num, txn_ts )
SQL> select ACCOUNT_NUM, max(TXN_TS) LAST_TS
2 from CUSTOMER_TRANS t
3 group by ACCOUNT_NUM
4 order by 1;
--------------------------------------------------
| Id | Operation | Name |
--------------------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | INDEX FAST FULL SCAN| CUSTOMER_TRANS_IX |
--------------------------------------------------
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
25
CREATE TABLE CUSTOMER_TRANS
(
...
)
PARTITION BY RANGE (TXN_TS)
INTERVAL( NUMTOYMINTERVAL(1,'MONTH'))
(
PARTITION P1 VALUES LESS THAN (TIMESTAMP' 2018-01-01 00:00:00')
PARTITION P2 VALUES LESS THAN (TIMESTAMP' 2018-06-01 00:00:00')
...
);
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
26
SQL> select ACCOUNT_NUM, max(TXN_TS) LAST_TS
2 from CUSTOMER_TRANS t
3 where TXN_TS > add_months(sysdate,-12)
4 group by ACCOUNT_NUM
5 order by 1;
-------------------------------------------------------------------
| Id | Operation | Name |Pstart| Pstop |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| 1 | PARTITION RANGE ITERATOR | | 127 | 138 |
|* 2 | TABLE ACCESS FULL | CUSTOMER_TRANS | 127 | 138 |
-------------------------------------------------------------------
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
¯_(ツ)_/¯
27
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
the requirement
28
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
29
"we have an interest in recent
activity for customers"
"last transaction for all customers"
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
promotional material
30
"we haven't seen you in a while,
here's a discount on ...."
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
the solution ?
31
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
32
SQL> desc CUSTOMER_ACCOUNTS
Name Null? Type
----------------------------------- -------- ---------------
ACCOUNT_NUM NOT NULL NUMBER(8)
CURRENT_BALANCE NOT NULL NUMBER(14,2)
...
...
...
LAST_LOGIN_TIME NOT NULL TIMESTAMP(6)
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
don't focus on the SQL
33
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
don't tune SQL ...
34
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
... tune this instead
35
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
36
HERE
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
UX
37
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
sql tuning is ...
38
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
39
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
stop the bleeding...
40
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
...until find a cure
41
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
</end of rant>
42
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
TREAT
43
FIND
CURE
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
45
SQL> select sql_fulltext
2 from v$sql
3 where module = 'PAYROLL'
4 and action = 'Process Bonus'
5 and ( buffer_gets > 1000000 or
6 executions > 10000 or
7 disk_reads > 100000
8 );
SQL_FULLTEXT
-----------------------------------------------
SELECT ...
FROM ...
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
46
latching
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
47
crappy metaphor
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
48
crappy metaphorcrap-py
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
51
same with memory
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
SGA
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
SGA
protected by
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
SGA
protected by
1) get latch
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
SGA
protected by
2) access memory
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
SGA
protected by
3) release latch
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
back to V$SQL
57
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
it is the database's SQL
58
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
hunting for bad SQL ...
59
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
... with a bad SQL
60
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
you can do better
61
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
62
SQL> select sql_fulltext
2 from v$sqlstats
3 where module = 'PAYROLL'
4 and action = 'Process Bonus'
5 and ( buffer_gets > 1000000 or
6 executions > 10000 or
7 disk_reads > 100000
8 );
SQL_FULLTEXT
-----------------------------------------------
SELECT ...
FROM ...
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
"The column definitions for columns in V$SQLSTATS are
identical to those in the V$SQL and V$SQLAREA views.
However, the V$SQLSTATS view differs from V$SQL and
V$SQLAREA in that it is faster, more scalable, and has a
greater data retention (the statistics may still appear in
this view, even after the cursor has been aged out of the
shared pool)."
63
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
its not the (real) shared pool
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
65
found your sql...
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
SQL> select count(*)
2 from VEHICLES
3 where MAKE = 'HONDA'
4 and MODEL = 'CIVIC';
67
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
1) what is the real query
68
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
69
SQL> set autotrace traceonly stat
SQL> select *
2 from LOOKS_SO_INNOCENT
3 where CREATED > sysdate
Statistics
------------------------------------------
651 recursive calls
0 db block gets
23243 consistent gets
24 physical reads
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
70
SQL> variable c clob
SQL> begin
2 dbms_utility.expand_sql_text
3 ( 'select * from LOOKS_SO_INNOCENT '||
4 'where created > sysdate',:c);
5 end;
6 /
PL/SQL procedure successfully completed.
SQL> print c
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
71
SQL> create or replace
2 view LOOK_SO_INNOCENT as
3 select
4 o.owner,
5 o.created,
6 s.bytes,
7 s.tablespace_name
8 from
9 dba_segments s,
10 all_objects o
11 where o.owner = s.owner
12 and o.object_name = s.segment_name;
View created.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
72
SELECT "A1"."OWNER" "OWNER",
"A1"."NAME" "NAME",
"A1"."CREATED" "CREATED",
"A1"."BYTES" "BYTES",
"A1"."TABLESPACE_NAME" "TABLESPACE_NAME"
FROM (SELECT "A2"."OWNER" "OWNER",
"A2"."OBJECT_NAME" "NAME",
"A2"."CREATED" "CREATED",
"A3"."BYTES" "BYTES",
"A3"."TABLESPACE_NAME" "TABLESPACE_NAME" FROM (SELECT "A4"
."OWNER" "OWNER",
"A4"."SEGMENT_NAME" "SEGMENT_NAME",
"A4"."PARTITION_NAME" "PARTITION_NAME",
"A4"."SEGMENT_TYPE" "SEGMENT_TYPE",
"A4"."SEGMENT_SUBTYPE" "SEGMENT_SUBTYPE",
"A4"."TABLESPACE_NAME" "TABLESPACE_NAME",
"A4"."HEADER_FILE" "HEADER_FILE",
"A4"."HEADER_BLOCK" "HEADER_BLOCK",
DECODE(BITAND("A4"."SEGMENT_FLAGS",131072),131072,
"A4"."BLOCKS",DECODE(BITAND("A4"."SEGMENT_FLAGS",1),1,
"SYS"."DBMS_SPACE_ADMIN"."SEGMENT_NUMBER_BLOCKS"("A4"."TABLESPACE_ID",
"A4"."RELATIVE_FNO",
"A4"."HEADER_BLOCK",
"A4"."SEGMENT_TYPE_ID",
"A4"."BUFFER_POOL_ID",
"A4"."SEGMENT_FLAGS",
"A4"."SEGMENT_OBJD",
"A4"."BLOCKS"),
"A4"."BLOCKS"))*"A4"."BLOCKSIZE" "BYTES",
DECODE(BITAND("A4"."SEGMENT_FLAGS",131072),131072,
"A4"."BLOCKS",DECODE(BITAND("A4"."SEGMENT_FLAGS",1),1,
"SYS"."DBMS_SPACE_ADMIN"."SEGMENT_NUMBER_BLOCKS"("A4"."TABLESPACE_ID",
"A4"."RELATIVE_FNO",
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
73
"A4"."HEADER_BLOCK",
"A4"."SEGMENT_TYPE_ID",
"A4"."BUFFER_POOL_ID",
"A4"."SEGMENT_FLAGS",
"A4"."SEGMENT_OBJD",
"A4"."BLOCKS"),
"A4"."BLOCKS")) "BLOCKS",DECODE(BITAND("A4"."SEGMENT_FLAGS",131072),131072,
"A4"."EXTENTS",DECODE(BITAND("A4"."SEGMENT_FLAGS",1),1,
"SYS"."DBMS_SPACE_ADMIN"."SEGMENT_NUMBER_EXTENTS"("A4"."TABLESPACE_ID",
"A4"."RELATIVE_FNO",
"A4"."HEADER_BLOCK",
"A4"."SEGMENT_TYPE_ID",
"A4"."BUFFER_POOL_ID",
"A4"."SEGMENT_FLAGS",
"A4"."SEGMENT_OBJD",
"A4"."EXTENTS"),
"A4"."EXTENTS")) "EXTENTS",
"A4"."INITIAL_EXTENT" "INITIAL_EXTENT",
"A4"."NEXT_EXTENT" "NEXT_EXTENT",
"A4"."MIN_EXTENTS" "MIN_EXTENTS",
"A4"."MAX_EXTENTS" "MAX_EXTENTS",
"A4"."MAX_SIZE" "MAX_SIZE",
"A4"."RETENTION" "RETENTION",
"A4"."MINRETENTION" "MINRETENTION",
"A4"."PCT_INCREASE" "PCT_INCREASE",
"A4"."FREELISTS" "FREELISTS",
"A4"."FREELIST_GROUPS" "FREELIST_GROUPS",
"A4"."RELATIVE_FNO" "RELATIVE_FNO",
DECODE("A4"."BUFFER_POOL_ID",1,'KEEP',2,'RECYCLE','DEFAULT') "BUFFER_POOL",
DECODE("A4"."FLASH_CACHE",1,'KEEP',2,
'NONE','DEFAULT') "FLASH_CACHE",DECODE("A4"."CELL_FLASH_CACHE",1,'KEEP',2,'NONE','DEFAULT')
"CELL_FLASH_CACHE"
FROM ( (SELECT NVL("A199"."NAME",'SYS') "OWNER",
"A198"."NAME" "SEGMENT_NAME",
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
74
"A198"."SUBNAME" "PARTITION_NAME",
"A196"."OBJECT_TYPE" "SEGMENT_TYPE",
"A195"."TYPE#" "SEGMENT_TYPE_ID",DECODE(BIT
AND("A195"."SPARE1",2097408),2097152,'SECUREFILE',256,'ASSM','MSSM') "SEGMENT_SUBTYPE",
"A197"."TS#" "TABLESPACE_ID",
"A197"."NAME" "TABLESPACE_NAME",
"A197"."BLOCKSIZE" "BLOCKSIZE",
"A194"."FILE#" "HEADER_FILE",
"A195"."BLOCK#" "HEADER_BLOCK",
"A195"."BLOCKS"*"A197"."BLOCKSIZE" "BYTES",
"A195"."BLOCKS" "BLOCKS",
"A195"."EXTENTS" "EXTENTS",
"A195"."INIEXTS"*"A197"."BLOCKSIZE" "INITIAL_EXTENT",
"A195"."EXTSIZE"*"A197"."BLOCKSIZE" "NEXT_EXTENT",
"A195"."MINEXTS" "MIN_EXTENTS",
"A195"."MAXEXTS" "MAX_EXTENTS",DECODE(BITAND("A195"."SPARE1",4194304),4194304,
"A195"."BITMAPRANGES",NULL) "MAX_SIZE",TO_CHAR(DECODE(
BITAND("A195"."SPARE1",2097152),2097152,
DECODE("A195"."LISTS",0,'NONE',1,'AUTO',2,'MIN',3,'MAX',4,'DEFAULT','INVALID'),NULL))
"RETENTION",DECODE(BITAND("A195"."SPARE1",2097152),2097152,
"A195"."GROUPS",NULL) "MINRETENTION",DECODE(BITAND("A197"."FLAGS",3),1,TO_NUMBER(NULL),
"A195"."EXTPCT") "PCT_INCREASE",DECODE(BITAND("A197"."FLAGS",32),32,
TO_NUMBER(NULL),DECODE("A195"."LISTS",0,1,
"A195"."LISTS"))
"FREELISTS",DECODE(BITAND("A197"."FLAGS",32),32,TO_NUMBER(NULL),DECODE("A195"."GROUPS",0,1,
"A195"."GROUPS")) "FREELIST_GROUPS",
"A195"."FILE#" "RELATIVE_FNO",BITAND("A195"."CACHEHINT",3) "BUFFER_POOL_ID",
BITAND("A195"."CACHEHINT",12)/4 "FLASH_CACHE",BITAND("A195"."CACHEHINT",48)/16 "CELL_FLASH_CACHE",
NVL("A195"."SPARE1",0)
"SEGMENT_FLAGS",DECODE(BITAND("A195"."SPARE1",1),1,
"A195"."HWMINCR",
"A198"."DATAOBJ#") "SEGMENT_OBJD" FROM "SYS"."USER$" "A199",
"SYS"."OBJ$" "A198",
"SYS"."TS$" "A197", ( (SELECT
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
75
DECODE(BITAND("A209"."PROPERTY",8192),8192,'NESTED TABLE','TABLE') "OBJECT_TYPE",
2 "OBJECT_TYPE_ID",5 "SEGMENT_TYPE_ID",
"A209"."OBJ#" "OBJECT_ID",
"A209"."FILE#" "HEADER_FILE",
"A209"."BLOCK#" "HEADER_BLOCK",
"A209"."TS#" "TS_NUMBER" FROM "SYS"."TAB$" "A209" WHERE BITAND("A209"."PROPERTY",1024)=0) UNI
ON ALL (SELECT 'TABLE PARTITION' "OBJECT_TYPE",19 "OBJECT_TYPE_ID",5 "SEGMENT_TYPE_ID",
"A208"."OBJ#" "OBJECT_ID",
"A208"."FILE#" "HEADER_FILE",
"A208"."BLOCK#" "HEADER_BLOCK",
"A208"."TS#" "TS_NUMBER" FROM "SYS"."TABPART$" "A208") UNION ALL
(SELECT 'CLUSTER' "OBJECT_TYPE",3 "OBJECT_TYPE_ID",5 "SEGMENT_TYPE_ID",
"A207"."OBJ#" "OBJECT_ID",
"A207"."FILE#" "HEADER_FILE",
"A207"."BLOCK#" "HEADER_BLOCK",
"A207"."TS#" "TS_NUMBER" FROM "SYS"."CLU$" "A207") UNION ALL
(SELECT DECODE("A206"."TYPE#",8,'LOBINDEX','INDEX') "OBJECT_TYPE",1 "OBJECT_TYPE_ID",6
"SEGMENT_TYPE_ID",
"A206"."OBJ#" "OBJECT_ID",
"A206"."FILE#" "HEADER_FILE",
"A206"."BLOCK#" "HEADER_BLOCK",
"A206"."TS#" "TS_NUMBER" FROM "SYS"."IND$" "A206" WHERE "A206"."TYPE#"=1 OR
"A206"."TYPE#"=2 OR
"A206"."TYPE#"=3 OR
"A206"."TYPE#"=4 OR
"A206"."TYPE#"=6 OR
"A206"."TYPE#"=7 OR
"A206"."TYPE#"=8 OR
"A206"."TYPE#"=9) UNION ALL
(SELECT 'INDEX PARTITION'
"OBJECT_TYPE",20 "OBJECT_TYPE_ID",6 "SEGMENT_TYPE_ID",
"A205"."OBJ#" "OBJECT_ID",
"A205"."FILE#" "HEADER_FILE",
"A205"."BLOCK#" "HEADER_BLOCK",
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
76
"A205"."TS#" "TS_NUMBER" FROM "SYS"."INDPART$" "A205") UNION ALL
(SELECT 'LOBSEGMENT' "OBJECT_TYPE",21 "OBJECT_TYPE_ID",8 "SEGMENT_TYPE_ID",
"A204"."LOBJ#" "OBJECT_ID",
"A204"."FILE#" "HEADER_FILE",
"A204"."BLOCK#" "HEADER_BLOCK",
"A204"."TS#" "TS_NUMBER" FROM "SYS"."LOB$" "A204" WHERE BITAND("A204"."PROPERTY",64)=0 OR
BITAND("A204"."PROPERTY",128)=128) UNION ALL
(SELECT 'TABLE SUBPARTITION' "OBJECT_TYPE",34 "OBJECT_TYPE_ID",5 "SEGMENT_TYPE_ID",
"A203"."OBJ#" "OBJECT_ID",
"A203"."FILE#" "HEADER_FILE",
"A203"."BLOCK#" "HEADER_BLOCK",
"A203"."TS#" "TS_NUMBER" FROM "SYS"."TABSUBPART$" "A203") UNION ALL
(SELECT 'INDEX SUBPARTITION' "OBJECT_TYPE",35 "OBJECT_TYPE_ID",6 "SEGMENT_TYPE_ID",
"A202"."OBJ#" "OBJECT_ID",
"A202"."FILE#" "HEADER_FILE",
"A202"."BLOCK#" "HEADER_BLOCK",
"A202"."TS#" "TS_NUMBER" FROM "SYS"."INDSUBPART$" "A202") UNION ALL
(SELECT DECODE("A201"."FRAGTYPE$",'P','LOB PARTITION','LOB SUBPARTITION')
"OBJECT_TYPE",DECODE("A201"."FRAGTYPE$",'P',40,41) "OBJECT_TYPE_ID",8 "SEGMENT_TYPE_ID",
"A201"."FRAGOBJ#" "OBJECT_ID",
"A201"."FILE#" "HEADER_FILE",
"A201"."BLOCK#" "HEADER_BLOCK",
"A201"."TS#" "TS_NUMBER" FROM "SYS"."LOBFRAG$" "A201")) "A196",
"SYS"."SEG$" "A195",
"SYS"."FILE$" "A194" WHERE "A195"."FILE#"="A196"."HEADER_FILE" AND
"A195"."BLOCK#"="A196"."HEADER_BLOCK" AND
"A195"."TS#"="A196"."TS_NUMBER" AND
"A195"."TS#"="A197"."TS#" AND
"A198"."OBJ#"="A196"."OBJECT_ID" AND
"A198"."OWNER#"="A199"."USER#"(+) AND
"A195"."TYPE#"="A196"."SEGMENT_TYPE_ID" AND
"A198"."TYPE#"="A196"."OBJECT_TYPE_ID" AND
"A195"."TS#"="A194"."TS#" AND
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
77
"A195"."FILE#"="A194"."RELFILE#") UNION ALL
(SELECT NVL("A193"."NAME",'SYS') "OWNER",
"A191"."NAME" "SEGMENT_NAME",NULL "PARTITION_NAME",
DECODE("A190"."TYPE#",1,'ROLLBACK',10,'TYPE2 UNDO') "SEGMENT_TYPE",
"A190"."TYPE#" "SEGMENT_TYPE_ID",NULL "SEGMENT_SUBTYPE",
"A192"."TS#" "TABLESPACE_ID",
"A192"."NAME" "TABLESPACE_NAME",
"A192"."BLOCKSIZE" "BLOCKSIZE",
"A189"."FILE#" "HEADER_FILE",
"A190"."BLOCK#" "HEADER_BLOCK",
"A190"."BLOCKS"*"A192"."BLOCKSIZE" "BYTES",
"A190"."BLOCKS" "BLOCKS",
"A190"."EXTENTS" "EXTENTS",
"A190"."INIEXTS"*"A192"."BLOCKSIZE" "INITIAL_EXTENT",
"A190"."EXTSIZE"*"A192"."BLOCKSIZE" "NEXT_EXTENT",
"A190"."MINEXTS" "MIN_EXTENTS",
"A190"."MAXEXTS" "MAX_EXTENTS",DECODE(BITAND("A190"."SPARE1",4194304),4194304,
"A190"."BITMAPRANGES",NULL) "MAX_SIZE",NULL "RETENTION",NULL "MINRETENTION",
"A190"."EXTPCT"
"PCT_INCREASE",DECODE(BITAND("A192"."FLAGS",32),32,TO_NUMBER(NULL),DECODE("A190"."LISTS",0,1,
"A190"."LISTS")) "FREELISTS",DECODE(BITAND("A192"."FLAGS",32),32,TO_NUMBER(NULL),
DECODE("A190"."GROUPS",0,1,"A190"."GROUPS")) "FREELIST_GROUPS",
"A190"."FILE#" "RELATIVE_FNO",BITAND("A190"."CACHEHINT",3)
"BUFFER_POOL_ID",BITAND("A190"."CACHEHINT",12)/4 "FLASH_CACHE",
BITAND("A190"."CACHEHINT",48)/16 "CELL_FLASH_CACHE",NVL("A190"."SPARE1",0) "SEGMENT_FLAGS",
"A191"."US#" "SEGMENT_OBJD" FROM "SYS"."USER$" "A193","SYS"."TS$" "A192",
"SYS"."UNDO$" "A191",
"SYS"."SEG$" "A190",
"SYS"."FILE$" "A189" WHERE "A190"."FILE#"="A191"."FILE#" AND
"A190"."BLOCK#"="A191"."BLOCK#" AND
"A190"."TS#"="A191"."TS#" AND
"A190"."TS#"="A192"."TS#" AND
"A190"."USER#"="A193"."USER#"(+) AND
("A190"."TYPE#"=1 OR
"A190"."TYPE#"=10) AND
"A191"."STATUS$"<>1 AND
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
78
"A191"."TS#"="A189"."TS#" AND
"A191"."FILE#"="A189"."RELFILE#") UNION ALL
(SELECT NVL("A188"."NAME",'SYS') "OWNER",
TO_CHAR("A185"."FILE#")||'.'||TO_CHAR("A186"."BLOCK#") "SEGMENT_NAME",NULL "PARTITION_NAME",
DECODE("A186"."TYPE#",2,'DEFERRED ROLLBACK',3,
'TEMPORARY',4,'CACHE',9,'SPACE HEADER','UNDEFINED') "SEGMENT_TYPE",
"A186"."TYPE#" "SEGMENT_TYPE_ID",NULL "SEGMENT_SUBTYPE",
"A187"."TS#" "TABLESPACE_ID",
"A187"."NAME" "TABLESPACE_NAME",
"A187"."BLOCKSIZE" "BLOCKSIZE",
"A185"."FILE#" "HEADER_FILE",
"A186"."BLOCK#" "HEADER_BLOCK",
"A186"."BLOCKS"*"A187"."BLOCKSIZE" "BYTES",
"A186"."BLOCKS" "BLOCKS",
"A186"."EXTENTS" "EXTENTS",
"A186"."INIEXTS"*"A187"."BLOCKSIZE" "INITIAL_EXTENT",
"A186"."EXTSIZE"*"A187"."BLOCKSIZE" "NEXT_EXTENT",
"A186"."MINEXTS" "MIN_EXTENTS",
"A186"."MAXEXTS" "MAX_EXTENTS",DECODE(BITAND("A186"."SPARE1",4194304),4194304,
"A186"."BITMAPRANGES",NULL) "MAX_SIZE",NULL
"RETENTION",NULL "MINRETENTION",DECODE(BITAND("A187"."FLAGS",3),1,TO_NUMBER(NULL),
"A186"."EXTPCT")
"PCT_INCREASE",DECODE(BITAND("A187"."FLAGS",32),32,TO_NUMBER(NULL),DECODE("A186"."LISTS",0,1,
"A186"."LISTS"))
"FREELISTS",DECODE(BITAND("A187"."FLAGS",32),32,TO_NUMBER(NULL),DECODE("A186"."GROUPS",0,1,
"A186"."GROUPS")) "FREELIST_GROUPS",
"A186"."FILE#" "RELATIVE_FNO",BITAND("A186"."CACHEHINT",3)
"BUFFER_POOL_ID",BITAND("A186"."CACHEHINT",12)/4 "FLASH_CACHE",BITAND("A186"."CACHEHINT",48)/16
"CELL_FLASH_CACHE",NVL("A186"."SPARE1",0) "SEGMENT_FLAGS",
"A186"."HWMINCR" "SEGMENT_OBJD" FROM "SYS"."USER$"
"A188",
"SYS"."TS$" "A187",
"SYS"."SEG$" "A186",
"SYS"."FILE$" "A185" WHERE "A186"."TS#"="A187"."TS#" AND
"A186"."USER#"="A188"."USER#"(+) AND
"A186"."TYPE#"<>1 AND
"A186"."TYPE#"<>5 AND
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
79
"A186"."TYPE#"<>6 AND
"A186"."TYPE#"<>8 AND
"A186"."TYPE#"<>10 AND
"A186"."TYPE#"<>11 AND
"A186"."TS#"="A185"."TS#"
AND
"A186"."FILE#"="A185"."RELFILE#") UNION ALL
(SELECT NVL("A184"."NAME",'SYS') "OWNER",'HEATMAP' "SEGMENT_NAME",
NULL "PARTITION_NAME",'SYSTEM STATISTICS' "SEGMENT_TYPE",
"A182"."TYPE#" "SEGMENT_TYPE_ID",NULL "SEGMENT_SUBTYPE",
"A183"."TS#" "TABLESPACE_ID",
"A183"."NAME" "TABLESPACE_NAME",
"A183"."BLO
CKSIZE" "BLOCKSIZE",
"A181"."FILE#" "HEADER_FILE",
"A182"."BLOCK#" "HEADER_BLOCK",
"A182"."BLOCKS"*"A183"."BLOCKSIZE" "BYTES",
"A182"."BLOCKS" "BLOCKS",
"A182"."EXTENTS" "EXTENTS",
"A182"."INIEXTS"*"A183"."BLOCKSIZE" "INITIAL_EXTENT",
"A182"."EXTSIZE"*"A183"."BLOCKSIZE" "NEXT_EXTENT",
"A182"."MINEXTS" "MIN_EXTENTS",
"A182"."MAXEXTS" "MAX_EXTENTS",DECODE(BITAND("A182"."SPARE1",4194304),4194304,
"A182"."BITMAPRANGES",NULL) "MAX_SIZE",NULL "RETENTION",NULL
"MINRETENTION",DECODE(BITAND("A183"."FLAGS",3),1,TO_NUMBER(NULL),
"A182"."EXTPCT") "PCT_INCREASE",DECODE(BITAND("A183"."FLAGS",32),32,TO_NUMBER(NULL),DEC
ODE("A182"."LISTS",0,1,
"A182"."LISTS"))
"FREELISTS",DECODE(BITAND("A183"."FLAGS",32),32,TO_NUMBER(NULL),DECODE("A182"."GROUPS",0,1,
"A182"."GROUPS")) "FREELIST_GROUPS",
"A182"."FILE#" "RELATIVE_FNO",BITAND("A182"."CACHEHINT",3) "BUFFER_POOL_ID",
BITAND("A182"."CACHEHINT",12)/4 "FLASH_CACHE",BITAND("A18
2"."CACHEHINT",48)/16 "CELL_FLASH_CACHE",NVL("A182"."SPARE1",0) "SEGMENT_FLAGS",
"A182"."HWMINCR" "SEGMENT_OBJD" FROM "SYS"."USER$" "A184",
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
80
"SYS"."TS$" "A183",
"SYS"."SEG$" "A182",
"SYS"."FILE$" "A181" WHERE "A182"."TS#"="A183"."TS#" AND
"A182"."USER#"="A184"."USER#"(+) AND
"A182"."TYPE#"=11 AND
"A182"."TS#"="A181"."TS#" AND
"A182"."FILE#"="A181"."RELFILE#")) "A4") "A3", (SELECT "A5"."NAME" "OWNER",
"A6"."NAME" "OBJECT_NAME",
"A6"."SUBNAME" "SUBOBJECT_NAME",
"A6"."OBJ#" "OBJECT_ID",
"A6"."DATAOBJ#" "DATA_OBJECT_ID",DECODE("A6"."TYPE#",0,'NEXT OBJECT',1,'INDEX',
2,'TABLE',3,'CLUSTER',4,'VIEW',5,'SYNONYM
',6,'SEQUENCE',7,'PROCEDURE',8,'FUNCTION',9,'PACKAGE',11,'PACKAGE BODY',12,
'TRIGGER',13,'TYPE',14,'TYPE BODY',19,'TABLE PARTITION',20,'INDEX PARTITION',
21,'LOB',22,'LIBRARY',23,'DIRECTORY',24,'QUEUE',28,'JAVA SOURCE',29,'JAVA CLASS',30,
'JAVA RESOURCE',32,'INDEXTYPE',33,'OPERATOR',34,
'TABLE SUBPARTITION',35,'INDEX SUBPARTITION',40,'LOB PARTITION',41,'LOB SUBPARTITION',42
,NVL( (SELECT 'REWRITE EQUIVALENCE' "'REWRITEEQUIVALENCE'" FROM SYS."SUM$" "A52" WHERE "A52"."OBJ#"="A6"."OBJ#" AND
BITAND("A52"."XPFLAGS",8388608)=8388608),'MATERIALIZED VIEW'),43,'DIMENSION',
44,'CONTEXT',46,'RULE SET',47,'RESOURCE PLAN',48,'CONSUMER GROUP',55,'XML SCHEMA',56,'JAVA
DATA',57,'EDITION',59,'RULE',
60,'CAPTURE',61,'APPLY',62,'EVALUATION CONTEXT',66,'JOB',67,'PROGRAM',68,'JOB CLASS',69,
'WINDOW',72,'SCHEDULER GROUP',74,'SCHEDULE',79,'CHAIN',81,'FILE GROUP',82,'MINING
MODEL',87,'ASSEMBLY',90,'CREDENTIAL',92,'CUBE
DIMENSION',93,'CUBE',94,'MEASURE FOLDER',95,'CUBE BUILD PROCESS',100,'FILE WATCHER',
101,'DESTINATION',114,'SQL TRANSLATION PROFILE',115,'UNIFIED AUDIT POLICY','UNDEFINED') "OBJECT_TYPE",
"A6"."CTIME" "CREATED",
"A6"."MTIME" "LAST_DDL_TIME",TO_CHAR("A6"."STIME",'YYYY-MM-DD:HH24:MI:SS') "TIMESTAMP",DEC
ODE("A6"."STATUS",0,'N/A',1,'VALID','INVALID') "STATUS",DECODE(BITAND("A6"."FLAGS",2),0,'N',2,'Y','N')
"TEMPORARY",DECODE(BITAND("A6"."FLAGS",4),0,'N',4,'Y','N') "GENERATED",DECODE(BITAND("A6"."FLAGS",16),0,'N',16,'Y','N')
"SECONDARY",
"A6"."NAMESPACE" "NAMESPACE",
"A6"."DEFINING_EDITION" "EDITION_NAM
E",DECODE(BITAND("A6"."FLAGS",196608),65536,'METADATA LINK',131072,'OBJECT LINK','NONE') "SHARING",
CASE WHEN ("A6"."TYPE#"=4 OR
"A6"."TYPE#"=5 OR
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
16 ...
81
more ...
pages !
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
82
back to our problem SQL
SQL> select count(*)
2 from VEHICLES
3 where MAKE = 'HONDA'
4 and MODEL = 'CIVIC';
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
83
2) is it sensible/correct ?
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 84
SQL> select ...
2 from EMP e,
3 DEPT d
4 where e.JOB = 'SALES'
5 and d.LOC = 'NORTH';
DISTINCT ...
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 85
SQL> select REGION, min(AMOUNT)
2 from EMP e,
3 SALES_TRANSACTIONS s
4 where e.JOB = 'SALES'
5 and s.EMPNO = e.EMPNO
6 and s.REGION = 'CA'
7 and s.TAX_AMT > 10
8 or s.SUBSIDY > 0
9 group by REGION
7 and s.TAX_AMT > 10
8 or s.SUBSIDY > 0
9 group by REGION
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
86
3) check the plan
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
optimizer got it wrong...
87
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
or
88
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
... it cannot run better
89
legitimate response
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
90
v$sql_plan
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
91
dbms_xplan.display_cursor
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
92
not EXPLAIN PLAN
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1| 5|
| 1 | SORT AGGREGATE | | 1| 5|
| 2 | TABLE ACCESS BY INDEX ROWID | VEHICLES | 20K| 2687K|
| 3 | INDEX RANGE SCAN | MAKE_IX | 45K| 4592K|
------------------------------------------------------------------
93
SQL> select count(*)
2 from VEHICLES
3 where MAKE = 'HONDA'
4 and MODEL = 'CIVIC';
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
94
now what ?
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
"where does it hurt ?"
95
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
96
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
97
where in the plan ?
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
98
for human beings ...
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 99
... cardinality is important
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
100
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 102
same with the optimizer
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 103
actual versus estimate
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 104
SQL> select /*+ GATHER_PLAN_STATISTICS */ count(*)
2 from VEHICLES
3 where MAKE = 'HONDA'
4 and MODEL = 'CIVIC';
COUNT(*)
----------
114468
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 105
SQL> SELECT *
2 FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(
3 NULL, NULL, 'ALLSTATS LAST'));
----------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows |
----------------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 | 1 |
| 2 | TABLE ACCESS BY INDEX | VEHICLES| 1 | 20K| 114K|
| 3 | INDEX RANGE SCAN | MAKE_IX | 1 | 45K| 182K|
----------------------------------------------------------------------
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 106
for quick fixes
remember...triage
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 107
SQL> select /*+ FULL */ count(*)
2 from VEHICLES
3 where MAKE = 'HONDA'
4 and MODEL = 'CIVIC';
COUNT(*)
----------
114468
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
I'm not saying ...
108
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
... hints are the solution
109
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
110
"optimizer hints should only be
used with extreme care"
Maria Colgan, Oct 2012
Optimizer product manager
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
cool hints
111
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
112
first_rows_n
all_rows
leading
cardinality
statement_queueing
opt_param
dynamic_sampling
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
assisting optimizer
113
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
dangerous hints ...
114
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
... everything else !
115
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
116
full
index
use_hash
use_nl
etc
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
suppressing the optimizer
117
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
a nifty triage trick
118
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
119
SQL> SELECT *
2 from table(dbms_xplan.display(.... ,
format=>'typical +OUTLINE))
/*+ BEGIN_OUTLINE_DATA
USE_HASH(@"SEL$1" "B"@"SEL$1")
USE_HASH(@"SEL$1" "D"@"SEL$1")
LEADING(@"SEL$1" "E"@"SEL$1" "D"@"SEL$1" "B"@"SEL$1")
FULL(@"SEL$1" "B"@"SEL$1")
FULL(@"SEL$1" "D"@"SEL$1")
FULL(@"SEL$1" "E"@"SEL$1")
OUTLINE_LEAF(@"SEL$1")
ALL_ROWS
DB_VERSION('11.2.0.2')
OPTIMIZER_FEATURES_ENABLE('11.2.0.2')
IGNORE_OPTIM_EMBEDDED_HINTS
END_OUTLINE_DATA
*/
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
120
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
heading from triage into ...
121
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
1) fix the periphery
123
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
add / remove indexes safely
124
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
125
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
adding / improving statistics
126
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
back to our example
127
SQL> select ...
2 from VEHICLES
3 where MAKE = 'HONDA'
4 and MODEL = 'CIVIC';
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
extended statistics
128
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
129
SQL> select
2 dbms_stats.create_extended_stats('','VEHICLE',
3 '(MAKE,MODEL)') ext
2 from dual;
EXT
-------------------------------------------------------------
SYS_STUF3GLKIOP5F4B0BTTCFTMX0W
SQL> begin
2 dbms_stats.gather_table_stats('','VEHICLE'
3 ,method_opt=>'for all columns size auto');
4 end;
5 /
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 130
SQL> select /*+ GATHER_PLAN_STATISTICS */ count(*)
2 from VEHICLES
3 where MAKE = 'HONDA'
4 and MODEL = 'CIVIC';
COUNT(*)
----------
114468
-----------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows |
-----------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 | 1 |
|* 2 | TABLE ACCESS FULL| VEHICLES| 1 | 114K| 114K|
-----------------------------------------------------------------
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
2) force the plan you want
131
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
sql plan baselines
132
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
mea culpa
133
evolve
accepted
repeatable
unaccepted
capture
signature
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
very simple, very cool
134
"This plan is good, keep it!"
"This new plan looks bad, don't touch it"
"Actually, it might be OK. Use it!"
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
135
-----------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-----------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| 1 | NESTED LOOPS | | 25 | 425 |
| 2 | NESTED LOOPS | | 25 | 425 |
|* 3 | TABLE ACCESS FULL | TAB1 | 1 | 11 |
|* 4 | INDEX RANGE SCAN | TAB2_TAB1_FKI | 25 | |
| 5 | TABLE ACCESS BY INDEX ROWID| TAB2 | 25 | 150 |
-----------------------------------------------------------------------
select a.data, b.data
from tab1 a, tab2
where b.tab1_id = a.id
and a.code = :1
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
"accepted" plan
136
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
137
-----------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-----------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| 1 | NESTED LOOPS | | 25 | 425 |
| 2 | NESTED LOOPS | | 25 | 425 |
|* 3 | TABLE ACCESS FULL | TAB1 | 1 | 11 |
|* 4 | INDEX RANGE SCAN | TAB2_TAB1_FKI | 25 | |
| 5 | TABLE ACCESS BY INDEX ROWID| TAB2 | 25 | 150 |
-----------------------------------------------------------------------
select a.data, b.data
from tab1 a, tab2
where b.tab1_id = a.id
and a.code = :1
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
138
-----------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-----------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| 1 | NESTED LOOPS | | 25 | 425 |
| 2 | NESTED LOOPS | | 25 | 425 |
|* 3 | TABLE ACCESS FULL | TAB1 | 1 | 11 |
|* 4 | INDEX RANGE SCAN | TAB2_TAB1_FKI | 25 | |
| 5 | TABLE ACCESS BY INDEX ROWID| TAB2 | 25 | 150 |
-----------------------------------------------------------------------
select a.data, b.data
from tab1 a, tab2
where b.tab1_id = a.id
and a.code = :1
-----------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-----------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| * 1 | HASH JOIN | | 25 | 425 |
| * 5 | TABLE ACCESS FULL | TAB1 | 1 | 11 |
| 8 | TABLE ACCESS FULL | TAB2 | 25 | 150 |
-----------------------------------------------------------------------
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
but we saved this !
139
-----------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-----------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| * 1 | HASH JOIN | | 25 | 425 |
| * 5 | TABLE ACCESS FULL | TAB1 | 1 | 11 |
| 8 | TABLE ACCESS FULL | TAB2 | 25 | 150 |
-----------------------------------------------------------------------
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
maybe it is better
140
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
"evolve" a plan
141
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
142
-----------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-----------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| 1 | NESTED LOOPS | | 25 | 425 |
| 2 | NESTED LOOPS | | 25 | 425 |
|* 3 | TABLE ACCESS FULL | TAB1 | 1 | 11 |
|* 4 | INDEX RANGE SCAN | TAB2_TAB1_FKI | 25 | |
| 5 | TABLE ACCESS BY INDEX ROWID| TAB2 | 25 | 150 |
-----------------------------------------------------------------------
select a.data, b.data
from tab1 a, tab2
where b.tab1_id = a.id
and a.code = :1
-----------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-----------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| * 1 | HASH JOIN | | 25 | 425 |
| * 5 | TABLE ACCESS FULL | TAB1 | 1 | 11 |
| 8 | TABLE ACCESS FULL | TAB2 | 25 | 150 |
-----------------------------------------------------------------------
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
wrap up
143
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
if you are tuning SQL ...
144
... you are probably failing
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
tune the user experience
145
I love your feedback!
Rate your trip with Connor
Coming up!
Follow and Subscribe!
youtube bit.ly/youtube-connor
blog bit.ly/blog-connor
twitter bit.ly/twitter-connor

More Related Content

Similar to OpenWorld 2018 - SQL Tuning in 20 mins

Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c OptimizerWellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c OptimizerConnor McDonald
 
Hyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cHyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cConnor McDonald
 
Hyderabad Mar 2019 - Autonomous Database
Hyderabad Mar 2019 - Autonomous DatabaseHyderabad Mar 2019 - Autonomous Database
Hyderabad Mar 2019 - Autonomous DatabaseConnor McDonald
 
Perth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c featuresPerth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c featuresConnor McDonald
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAsConnor McDonald
 
Perth APAC Groundbreakers tour - The Autonomous Database
Perth APAC Groundbreakers tour - The Autonomous DatabasePerth APAC Groundbreakers tour - The Autonomous Database
Perth APAC Groundbreakers tour - The Autonomous DatabaseConnor McDonald
 
OpenWorld 2018 - 20 years of hints and tips
OpenWorld 2018 - 20 years of hints and tipsOpenWorld 2018 - 20 years of hints and tips
OpenWorld 2018 - 20 years of hints and tipsConnor McDonald
 
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019   - 18c and 19c featuesLatin America Tour 2019   - 18c and 19c featues
Latin America Tour 2019 - 18c and 19c featuesConnor McDonald
 
Melbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and TipsMelbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and TipsConnor McDonald
 
Melbourne Groundbreakers Tour - Upgrading without risk
Melbourne Groundbreakers Tour - Upgrading without riskMelbourne Groundbreakers Tour - Upgrading without risk
Melbourne Groundbreakers Tour - Upgrading without riskConnor McDonald
 
Sangam 18 - The New Optimizer in Oracle 12c
Sangam 18 - The New Optimizer in Oracle 12cSangam 18 - The New Optimizer in Oracle 12c
Sangam 18 - The New Optimizer in Oracle 12cConnor McDonald
 
OpenWorld 2018 - Pagination
OpenWorld 2018 - PaginationOpenWorld 2018 - Pagination
OpenWorld 2018 - PaginationConnor McDonald
 
APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101Connor McDonald
 
APEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentAPEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentConnor McDonald
 
Latin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matchingLatin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matchingConnor McDonald
 
How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0Norvald Ryeng
 
Five more things about Oracle SQL and PLSQL
Five more things about Oracle SQL and PLSQLFive more things about Oracle SQL and PLSQL
Five more things about Oracle SQL and PLSQLConnor McDonald
 
ILOUG 2019 - Autonomous, what does it mean for DBAs
ILOUG 2019 - Autonomous, what does it mean for DBAsILOUG 2019 - Autonomous, what does it mean for DBAs
ILOUG 2019 - Autonomous, what does it mean for DBAsConnor McDonald
 
MySQL 8 High Availability with InnoDB Clusters
MySQL 8 High Availability with InnoDB ClustersMySQL 8 High Availability with InnoDB Clusters
MySQL 8 High Availability with InnoDB ClustersMiguel Araújo
 

Similar to OpenWorld 2018 - SQL Tuning in 20 mins (20)

Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c OptimizerWellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
 
Hyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cHyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19c
 
Hyderabad Mar 2019 - Autonomous Database
Hyderabad Mar 2019 - Autonomous DatabaseHyderabad Mar 2019 - Autonomous Database
Hyderabad Mar 2019 - Autonomous Database
 
Perth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c featuresPerth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c features
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAs
 
Perth APAC Groundbreakers tour - The Autonomous Database
Perth APAC Groundbreakers tour - The Autonomous DatabasePerth APAC Groundbreakers tour - The Autonomous Database
Perth APAC Groundbreakers tour - The Autonomous Database
 
OpenWorld 2018 - 20 years of hints and tips
OpenWorld 2018 - 20 years of hints and tipsOpenWorld 2018 - 20 years of hints and tips
OpenWorld 2018 - 20 years of hints and tips
 
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019   - 18c and 19c featuesLatin America Tour 2019   - 18c and 19c featues
Latin America Tour 2019 - 18c and 19c featues
 
Melbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and TipsMelbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and Tips
 
Melbourne Groundbreakers Tour - Upgrading without risk
Melbourne Groundbreakers Tour - Upgrading without riskMelbourne Groundbreakers Tour - Upgrading without risk
Melbourne Groundbreakers Tour - Upgrading without risk
 
Sangam 18 - The New Optimizer in Oracle 12c
Sangam 18 - The New Optimizer in Oracle 12cSangam 18 - The New Optimizer in Oracle 12c
Sangam 18 - The New Optimizer in Oracle 12c
 
OpenWorld 2018 - Pagination
OpenWorld 2018 - PaginationOpenWorld 2018 - Pagination
OpenWorld 2018 - Pagination
 
APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101
 
APEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentAPEX Connect 2019 - successful application development
APEX Connect 2019 - successful application development
 
Latin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matchingLatin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matching
 
Partitioning 101
Partitioning 101Partitioning 101
Partitioning 101
 
How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0
 
Five more things about Oracle SQL and PLSQL
Five more things about Oracle SQL and PLSQLFive more things about Oracle SQL and PLSQL
Five more things about Oracle SQL and PLSQL
 
ILOUG 2019 - Autonomous, what does it mean for DBAs
ILOUG 2019 - Autonomous, what does it mean for DBAsILOUG 2019 - Autonomous, what does it mean for DBAs
ILOUG 2019 - Autonomous, what does it mean for DBAs
 
MySQL 8 High Availability with InnoDB Clusters
MySQL 8 High Availability with InnoDB ClustersMySQL 8 High Availability with InnoDB Clusters
MySQL 8 High Availability with InnoDB Clusters
 

More from Connor McDonald

Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestConnor McDonald
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQLConnor McDonald
 
UKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsUKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsConnor McDonald
 
Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousConnor McDonald
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesConnor McDonald
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresConnor McDonald
 
APEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomousAPEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomousConnor McDonald
 
APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne Connor McDonald
 
OOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAsOOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAsConnor McDonald
 
OOW19 - Read consistency
OOW19 - Read consistencyOOW19 - Read consistency
OOW19 - Read consistencyConnor McDonald
 
OOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsOOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsConnor McDonald
 
OOW19 - Killing database sessions
OOW19 - Killing database sessionsOOW19 - Killing database sessions
OOW19 - Killing database sessionsConnor McDonald
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresConnor McDonald
 
Latin America tour 2019 - Flashback
Latin America tour 2019 -  FlashbackLatin America tour 2019 -  Flashback
Latin America tour 2019 - FlashbackConnor McDonald
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql featuresConnor McDonald
 
Latin America Tour 2019 - slow data and sql processing
Latin America Tour 2019  - slow data and sql processingLatin America Tour 2019  - slow data and sql processing
Latin America Tour 2019 - slow data and sql processingConnor McDonald
 
OG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizerOG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizerConnor McDonald
 
OG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsOG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsConnor McDonald
 

More from Connor McDonald (20)

Flashback ITOUG
Flashback ITOUGFlashback ITOUG
Flashback ITOUG
 
Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolest
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQL
 
UKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsUKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tips
 
Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on Autonomous
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest Features
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL features
 
APEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomousAPEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomous
 
APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne
 
OOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAsOOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAs
 
OOW19 - Read consistency
OOW19 - Read consistencyOOW19 - Read consistency
OOW19 - Read consistency
 
OOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsOOW19 - Slower and less secure applications
OOW19 - Slower and less secure applications
 
OOW19 - Killing database sessions
OOW19 - Killing database sessionsOOW19 - Killing database sessions
OOW19 - Killing database sessions
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL features
 
Latin America tour 2019 - Flashback
Latin America tour 2019 -  FlashbackLatin America tour 2019 -  Flashback
Latin America tour 2019 - Flashback
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql features
 
Latin America Tour 2019 - slow data and sql processing
Latin America Tour 2019  - slow data and sql processingLatin America Tour 2019  - slow data and sql processing
Latin America Tour 2019 - slow data and sql processing
 
ANSI vs Oracle language
ANSI vs Oracle languageANSI vs Oracle language
ANSI vs Oracle language
 
OG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizerOG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizer
 
OG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsOG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tips
 

Recently uploaded

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Recently uploaded (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

OpenWorld 2018 - SQL Tuning in 20 mins

  • 1. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Ask TOM Mini-Lesson SQL Tuning with Connor McDonald Confidential – Oracle Internal/Restricted/Highly Restricted
  • 2. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Connor McDonald
  • 3. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 3
  • 4. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 4
  • 5. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Stuff youtube bit.ly/youtube-connor blog bit.ly/blog-connor twitter bit.ly/twitter-connor 400+ posts mainly on database & development 250 technical videos, new uploads every week rants and raves on tech and the world :-)
  • 6. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 6 Dump of memory from 0x07246400 to 0x07248400 1064B4C00 06A20000 08C0000A 0A07C47E 00020506 [...........~....] 1064B4C10 34BC0000 01000000 00030CBF 0A07C47C [4..............|] 1064B4C20 0002EC28 00020300 00000000 0004001D [...(............] ... 1064B6BF0 C10B02C1 0B06436F 6E6E6F72 C47E0605 [......Connor.~..] table or index block size database version created in relative block address
  • 7. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | https://asktom.oracle.com
  • 8. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 8https://asktom.oracle.com/officehours
  • 9. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 150 hours of free access (so far) 9
  • 10. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 10
  • 11. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 11
  • 12. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | if you are tuning SQL ... 12
  • 13. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 13
  • 14. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | why ? 14
  • 15. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | real example 15
  • 16. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 16 CUSTOMER_ACCOUNTS CUSTOMER_TRANSACTIONS
  • 17. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 17 "last transaction for all customers"
  • 18. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 18 SQL> select ACCOUNT_NUM, 2 max(TXN_TS) LAST_TS 3 from CUSTOMER_TRANS t 4 group by ACCOUNT_NUM 5 order by 1;
  • 19. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 19
  • 20. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 20
  • 21. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | make it faster ... 21
  • 22. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | we tried ... 22
  • 23. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 23 SQL> select /*+ PARALLEL(t 16) */ 2 ACCOUNT_NUM, max(TXN_TS) LAST_TS 3 from CUSTOMER_TRANS t 4 group by ACCOUNT_NUM 5 order by 1;
  • 24. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 24 SQL> create index CUSTOMER_TRANS_IX 2 on CUSTOMER_TRANS( account_num, txn_ts ) SQL> select ACCOUNT_NUM, max(TXN_TS) LAST_TS 2 from CUSTOMER_TRANS t 3 group by ACCOUNT_NUM 4 order by 1; -------------------------------------------------- | Id | Operation | Name | -------------------------------------------------- | 0 | SELECT STATEMENT | | | 1 | INDEX FAST FULL SCAN| CUSTOMER_TRANS_IX | --------------------------------------------------
  • 25. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 25 CREATE TABLE CUSTOMER_TRANS ( ... ) PARTITION BY RANGE (TXN_TS) INTERVAL( NUMTOYMINTERVAL(1,'MONTH')) ( PARTITION P1 VALUES LESS THAN (TIMESTAMP' 2018-01-01 00:00:00') PARTITION P2 VALUES LESS THAN (TIMESTAMP' 2018-06-01 00:00:00') ... );
  • 26. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 26 SQL> select ACCOUNT_NUM, max(TXN_TS) LAST_TS 2 from CUSTOMER_TRANS t 3 where TXN_TS > add_months(sysdate,-12) 4 group by ACCOUNT_NUM 5 order by 1; ------------------------------------------------------------------- | Id | Operation | Name |Pstart| Pstop | ------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | | 1 | PARTITION RANGE ITERATOR | | 127 | 138 | |* 2 | TABLE ACCESS FULL | CUSTOMER_TRANS | 127 | 138 | -------------------------------------------------------------------
  • 27. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | ¯_(ツ)_/¯ 27
  • 28. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | the requirement 28
  • 29. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 29 "we have an interest in recent activity for customers" "last transaction for all customers"
  • 30. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | promotional material 30 "we haven't seen you in a while, here's a discount on ...."
  • 31. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | the solution ? 31
  • 32. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 32 SQL> desc CUSTOMER_ACCOUNTS Name Null? Type ----------------------------------- -------- --------------- ACCOUNT_NUM NOT NULL NUMBER(8) CURRENT_BALANCE NOT NULL NUMBER(14,2) ... ... ... LAST_LOGIN_TIME NOT NULL TIMESTAMP(6)
  • 33. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | don't focus on the SQL 33
  • 34. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | don't tune SQL ... 34
  • 35. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | ... tune this instead 35
  • 36. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 36 HERE
  • 37. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | UX 37
  • 38. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | sql tuning is ... 38
  • 39. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 39
  • 40. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | stop the bleeding... 40
  • 41. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | ...until find a cure 41
  • 42. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | </end of rant> 42
  • 43. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | TREAT 43 FIND CURE
  • 44. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
  • 45. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 45 SQL> select sql_fulltext 2 from v$sql 3 where module = 'PAYROLL' 4 and action = 'Process Bonus' 5 and ( buffer_gets > 1000000 or 6 executions > 10000 or 7 disk_reads > 100000 8 ); SQL_FULLTEXT ----------------------------------------------- SELECT ... FROM ...
  • 46. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 46 latching
  • 47. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 47 crappy metaphor
  • 48. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 48 crappy metaphorcrap-py
  • 49. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
  • 50. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
  • 51. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 51 same with memory
  • 52. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | SGA
  • 53. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | SGA protected by
  • 54. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | SGA protected by 1) get latch
  • 55. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | SGA protected by 2) access memory
  • 56. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | SGA protected by 3) release latch
  • 57. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | back to V$SQL 57
  • 58. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | it is the database's SQL 58
  • 59. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | hunting for bad SQL ... 59
  • 60. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | ... with a bad SQL 60
  • 61. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | you can do better 61
  • 62. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 62 SQL> select sql_fulltext 2 from v$sqlstats 3 where module = 'PAYROLL' 4 and action = 'Process Bonus' 5 and ( buffer_gets > 1000000 or 6 executions > 10000 or 7 disk_reads > 100000 8 ); SQL_FULLTEXT ----------------------------------------------- SELECT ... FROM ...
  • 63. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | "The column definitions for columns in V$SQLSTATS are identical to those in the V$SQL and V$SQLAREA views. However, the V$SQLSTATS view differs from V$SQL and V$SQLAREA in that it is faster, more scalable, and has a greater data retention (the statistics may still appear in this view, even after the cursor has been aged out of the shared pool)." 63
  • 64. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | its not the (real) shared pool
  • 65. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 65 found your sql...
  • 66. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
  • 67. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | SQL> select count(*) 2 from VEHICLES 3 where MAKE = 'HONDA' 4 and MODEL = 'CIVIC'; 67
  • 68. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 1) what is the real query 68
  • 69. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 69 SQL> set autotrace traceonly stat SQL> select * 2 from LOOKS_SO_INNOCENT 3 where CREATED > sysdate Statistics ------------------------------------------ 651 recursive calls 0 db block gets 23243 consistent gets 24 physical reads
  • 70. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 70 SQL> variable c clob SQL> begin 2 dbms_utility.expand_sql_text 3 ( 'select * from LOOKS_SO_INNOCENT '|| 4 'where created > sysdate',:c); 5 end; 6 / PL/SQL procedure successfully completed. SQL> print c
  • 71. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 71 SQL> create or replace 2 view LOOK_SO_INNOCENT as 3 select 4 o.owner, 5 o.created, 6 s.bytes, 7 s.tablespace_name 8 from 9 dba_segments s, 10 all_objects o 11 where o.owner = s.owner 12 and o.object_name = s.segment_name; View created.
  • 72. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 72 SELECT "A1"."OWNER" "OWNER", "A1"."NAME" "NAME", "A1"."CREATED" "CREATED", "A1"."BYTES" "BYTES", "A1"."TABLESPACE_NAME" "TABLESPACE_NAME" FROM (SELECT "A2"."OWNER" "OWNER", "A2"."OBJECT_NAME" "NAME", "A2"."CREATED" "CREATED", "A3"."BYTES" "BYTES", "A3"."TABLESPACE_NAME" "TABLESPACE_NAME" FROM (SELECT "A4" ."OWNER" "OWNER", "A4"."SEGMENT_NAME" "SEGMENT_NAME", "A4"."PARTITION_NAME" "PARTITION_NAME", "A4"."SEGMENT_TYPE" "SEGMENT_TYPE", "A4"."SEGMENT_SUBTYPE" "SEGMENT_SUBTYPE", "A4"."TABLESPACE_NAME" "TABLESPACE_NAME", "A4"."HEADER_FILE" "HEADER_FILE", "A4"."HEADER_BLOCK" "HEADER_BLOCK", DECODE(BITAND("A4"."SEGMENT_FLAGS",131072),131072, "A4"."BLOCKS",DECODE(BITAND("A4"."SEGMENT_FLAGS",1),1, "SYS"."DBMS_SPACE_ADMIN"."SEGMENT_NUMBER_BLOCKS"("A4"."TABLESPACE_ID", "A4"."RELATIVE_FNO", "A4"."HEADER_BLOCK", "A4"."SEGMENT_TYPE_ID", "A4"."BUFFER_POOL_ID", "A4"."SEGMENT_FLAGS", "A4"."SEGMENT_OBJD", "A4"."BLOCKS"), "A4"."BLOCKS"))*"A4"."BLOCKSIZE" "BYTES", DECODE(BITAND("A4"."SEGMENT_FLAGS",131072),131072, "A4"."BLOCKS",DECODE(BITAND("A4"."SEGMENT_FLAGS",1),1, "SYS"."DBMS_SPACE_ADMIN"."SEGMENT_NUMBER_BLOCKS"("A4"."TABLESPACE_ID", "A4"."RELATIVE_FNO",
  • 73. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 73 "A4"."HEADER_BLOCK", "A4"."SEGMENT_TYPE_ID", "A4"."BUFFER_POOL_ID", "A4"."SEGMENT_FLAGS", "A4"."SEGMENT_OBJD", "A4"."BLOCKS"), "A4"."BLOCKS")) "BLOCKS",DECODE(BITAND("A4"."SEGMENT_FLAGS",131072),131072, "A4"."EXTENTS",DECODE(BITAND("A4"."SEGMENT_FLAGS",1),1, "SYS"."DBMS_SPACE_ADMIN"."SEGMENT_NUMBER_EXTENTS"("A4"."TABLESPACE_ID", "A4"."RELATIVE_FNO", "A4"."HEADER_BLOCK", "A4"."SEGMENT_TYPE_ID", "A4"."BUFFER_POOL_ID", "A4"."SEGMENT_FLAGS", "A4"."SEGMENT_OBJD", "A4"."EXTENTS"), "A4"."EXTENTS")) "EXTENTS", "A4"."INITIAL_EXTENT" "INITIAL_EXTENT", "A4"."NEXT_EXTENT" "NEXT_EXTENT", "A4"."MIN_EXTENTS" "MIN_EXTENTS", "A4"."MAX_EXTENTS" "MAX_EXTENTS", "A4"."MAX_SIZE" "MAX_SIZE", "A4"."RETENTION" "RETENTION", "A4"."MINRETENTION" "MINRETENTION", "A4"."PCT_INCREASE" "PCT_INCREASE", "A4"."FREELISTS" "FREELISTS", "A4"."FREELIST_GROUPS" "FREELIST_GROUPS", "A4"."RELATIVE_FNO" "RELATIVE_FNO", DECODE("A4"."BUFFER_POOL_ID",1,'KEEP',2,'RECYCLE','DEFAULT') "BUFFER_POOL", DECODE("A4"."FLASH_CACHE",1,'KEEP',2, 'NONE','DEFAULT') "FLASH_CACHE",DECODE("A4"."CELL_FLASH_CACHE",1,'KEEP',2,'NONE','DEFAULT') "CELL_FLASH_CACHE" FROM ( (SELECT NVL("A199"."NAME",'SYS') "OWNER", "A198"."NAME" "SEGMENT_NAME",
  • 74. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 74 "A198"."SUBNAME" "PARTITION_NAME", "A196"."OBJECT_TYPE" "SEGMENT_TYPE", "A195"."TYPE#" "SEGMENT_TYPE_ID",DECODE(BIT AND("A195"."SPARE1",2097408),2097152,'SECUREFILE',256,'ASSM','MSSM') "SEGMENT_SUBTYPE", "A197"."TS#" "TABLESPACE_ID", "A197"."NAME" "TABLESPACE_NAME", "A197"."BLOCKSIZE" "BLOCKSIZE", "A194"."FILE#" "HEADER_FILE", "A195"."BLOCK#" "HEADER_BLOCK", "A195"."BLOCKS"*"A197"."BLOCKSIZE" "BYTES", "A195"."BLOCKS" "BLOCKS", "A195"."EXTENTS" "EXTENTS", "A195"."INIEXTS"*"A197"."BLOCKSIZE" "INITIAL_EXTENT", "A195"."EXTSIZE"*"A197"."BLOCKSIZE" "NEXT_EXTENT", "A195"."MINEXTS" "MIN_EXTENTS", "A195"."MAXEXTS" "MAX_EXTENTS",DECODE(BITAND("A195"."SPARE1",4194304),4194304, "A195"."BITMAPRANGES",NULL) "MAX_SIZE",TO_CHAR(DECODE( BITAND("A195"."SPARE1",2097152),2097152, DECODE("A195"."LISTS",0,'NONE',1,'AUTO',2,'MIN',3,'MAX',4,'DEFAULT','INVALID'),NULL)) "RETENTION",DECODE(BITAND("A195"."SPARE1",2097152),2097152, "A195"."GROUPS",NULL) "MINRETENTION",DECODE(BITAND("A197"."FLAGS",3),1,TO_NUMBER(NULL), "A195"."EXTPCT") "PCT_INCREASE",DECODE(BITAND("A197"."FLAGS",32),32, TO_NUMBER(NULL),DECODE("A195"."LISTS",0,1, "A195"."LISTS")) "FREELISTS",DECODE(BITAND("A197"."FLAGS",32),32,TO_NUMBER(NULL),DECODE("A195"."GROUPS",0,1, "A195"."GROUPS")) "FREELIST_GROUPS", "A195"."FILE#" "RELATIVE_FNO",BITAND("A195"."CACHEHINT",3) "BUFFER_POOL_ID", BITAND("A195"."CACHEHINT",12)/4 "FLASH_CACHE",BITAND("A195"."CACHEHINT",48)/16 "CELL_FLASH_CACHE", NVL("A195"."SPARE1",0) "SEGMENT_FLAGS",DECODE(BITAND("A195"."SPARE1",1),1, "A195"."HWMINCR", "A198"."DATAOBJ#") "SEGMENT_OBJD" FROM "SYS"."USER$" "A199", "SYS"."OBJ$" "A198", "SYS"."TS$" "A197", ( (SELECT
  • 75. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 75 DECODE(BITAND("A209"."PROPERTY",8192),8192,'NESTED TABLE','TABLE') "OBJECT_TYPE", 2 "OBJECT_TYPE_ID",5 "SEGMENT_TYPE_ID", "A209"."OBJ#" "OBJECT_ID", "A209"."FILE#" "HEADER_FILE", "A209"."BLOCK#" "HEADER_BLOCK", "A209"."TS#" "TS_NUMBER" FROM "SYS"."TAB$" "A209" WHERE BITAND("A209"."PROPERTY",1024)=0) UNI ON ALL (SELECT 'TABLE PARTITION' "OBJECT_TYPE",19 "OBJECT_TYPE_ID",5 "SEGMENT_TYPE_ID", "A208"."OBJ#" "OBJECT_ID", "A208"."FILE#" "HEADER_FILE", "A208"."BLOCK#" "HEADER_BLOCK", "A208"."TS#" "TS_NUMBER" FROM "SYS"."TABPART$" "A208") UNION ALL (SELECT 'CLUSTER' "OBJECT_TYPE",3 "OBJECT_TYPE_ID",5 "SEGMENT_TYPE_ID", "A207"."OBJ#" "OBJECT_ID", "A207"."FILE#" "HEADER_FILE", "A207"."BLOCK#" "HEADER_BLOCK", "A207"."TS#" "TS_NUMBER" FROM "SYS"."CLU$" "A207") UNION ALL (SELECT DECODE("A206"."TYPE#",8,'LOBINDEX','INDEX') "OBJECT_TYPE",1 "OBJECT_TYPE_ID",6 "SEGMENT_TYPE_ID", "A206"."OBJ#" "OBJECT_ID", "A206"."FILE#" "HEADER_FILE", "A206"."BLOCK#" "HEADER_BLOCK", "A206"."TS#" "TS_NUMBER" FROM "SYS"."IND$" "A206" WHERE "A206"."TYPE#"=1 OR "A206"."TYPE#"=2 OR "A206"."TYPE#"=3 OR "A206"."TYPE#"=4 OR "A206"."TYPE#"=6 OR "A206"."TYPE#"=7 OR "A206"."TYPE#"=8 OR "A206"."TYPE#"=9) UNION ALL (SELECT 'INDEX PARTITION' "OBJECT_TYPE",20 "OBJECT_TYPE_ID",6 "SEGMENT_TYPE_ID", "A205"."OBJ#" "OBJECT_ID", "A205"."FILE#" "HEADER_FILE", "A205"."BLOCK#" "HEADER_BLOCK",
  • 76. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 76 "A205"."TS#" "TS_NUMBER" FROM "SYS"."INDPART$" "A205") UNION ALL (SELECT 'LOBSEGMENT' "OBJECT_TYPE",21 "OBJECT_TYPE_ID",8 "SEGMENT_TYPE_ID", "A204"."LOBJ#" "OBJECT_ID", "A204"."FILE#" "HEADER_FILE", "A204"."BLOCK#" "HEADER_BLOCK", "A204"."TS#" "TS_NUMBER" FROM "SYS"."LOB$" "A204" WHERE BITAND("A204"."PROPERTY",64)=0 OR BITAND("A204"."PROPERTY",128)=128) UNION ALL (SELECT 'TABLE SUBPARTITION' "OBJECT_TYPE",34 "OBJECT_TYPE_ID",5 "SEGMENT_TYPE_ID", "A203"."OBJ#" "OBJECT_ID", "A203"."FILE#" "HEADER_FILE", "A203"."BLOCK#" "HEADER_BLOCK", "A203"."TS#" "TS_NUMBER" FROM "SYS"."TABSUBPART$" "A203") UNION ALL (SELECT 'INDEX SUBPARTITION' "OBJECT_TYPE",35 "OBJECT_TYPE_ID",6 "SEGMENT_TYPE_ID", "A202"."OBJ#" "OBJECT_ID", "A202"."FILE#" "HEADER_FILE", "A202"."BLOCK#" "HEADER_BLOCK", "A202"."TS#" "TS_NUMBER" FROM "SYS"."INDSUBPART$" "A202") UNION ALL (SELECT DECODE("A201"."FRAGTYPE$",'P','LOB PARTITION','LOB SUBPARTITION') "OBJECT_TYPE",DECODE("A201"."FRAGTYPE$",'P',40,41) "OBJECT_TYPE_ID",8 "SEGMENT_TYPE_ID", "A201"."FRAGOBJ#" "OBJECT_ID", "A201"."FILE#" "HEADER_FILE", "A201"."BLOCK#" "HEADER_BLOCK", "A201"."TS#" "TS_NUMBER" FROM "SYS"."LOBFRAG$" "A201")) "A196", "SYS"."SEG$" "A195", "SYS"."FILE$" "A194" WHERE "A195"."FILE#"="A196"."HEADER_FILE" AND "A195"."BLOCK#"="A196"."HEADER_BLOCK" AND "A195"."TS#"="A196"."TS_NUMBER" AND "A195"."TS#"="A197"."TS#" AND "A198"."OBJ#"="A196"."OBJECT_ID" AND "A198"."OWNER#"="A199"."USER#"(+) AND "A195"."TYPE#"="A196"."SEGMENT_TYPE_ID" AND "A198"."TYPE#"="A196"."OBJECT_TYPE_ID" AND "A195"."TS#"="A194"."TS#" AND
  • 77. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 77 "A195"."FILE#"="A194"."RELFILE#") UNION ALL (SELECT NVL("A193"."NAME",'SYS') "OWNER", "A191"."NAME" "SEGMENT_NAME",NULL "PARTITION_NAME", DECODE("A190"."TYPE#",1,'ROLLBACK',10,'TYPE2 UNDO') "SEGMENT_TYPE", "A190"."TYPE#" "SEGMENT_TYPE_ID",NULL "SEGMENT_SUBTYPE", "A192"."TS#" "TABLESPACE_ID", "A192"."NAME" "TABLESPACE_NAME", "A192"."BLOCKSIZE" "BLOCKSIZE", "A189"."FILE#" "HEADER_FILE", "A190"."BLOCK#" "HEADER_BLOCK", "A190"."BLOCKS"*"A192"."BLOCKSIZE" "BYTES", "A190"."BLOCKS" "BLOCKS", "A190"."EXTENTS" "EXTENTS", "A190"."INIEXTS"*"A192"."BLOCKSIZE" "INITIAL_EXTENT", "A190"."EXTSIZE"*"A192"."BLOCKSIZE" "NEXT_EXTENT", "A190"."MINEXTS" "MIN_EXTENTS", "A190"."MAXEXTS" "MAX_EXTENTS",DECODE(BITAND("A190"."SPARE1",4194304),4194304, "A190"."BITMAPRANGES",NULL) "MAX_SIZE",NULL "RETENTION",NULL "MINRETENTION", "A190"."EXTPCT" "PCT_INCREASE",DECODE(BITAND("A192"."FLAGS",32),32,TO_NUMBER(NULL),DECODE("A190"."LISTS",0,1, "A190"."LISTS")) "FREELISTS",DECODE(BITAND("A192"."FLAGS",32),32,TO_NUMBER(NULL), DECODE("A190"."GROUPS",0,1,"A190"."GROUPS")) "FREELIST_GROUPS", "A190"."FILE#" "RELATIVE_FNO",BITAND("A190"."CACHEHINT",3) "BUFFER_POOL_ID",BITAND("A190"."CACHEHINT",12)/4 "FLASH_CACHE", BITAND("A190"."CACHEHINT",48)/16 "CELL_FLASH_CACHE",NVL("A190"."SPARE1",0) "SEGMENT_FLAGS", "A191"."US#" "SEGMENT_OBJD" FROM "SYS"."USER$" "A193","SYS"."TS$" "A192", "SYS"."UNDO$" "A191", "SYS"."SEG$" "A190", "SYS"."FILE$" "A189" WHERE "A190"."FILE#"="A191"."FILE#" AND "A190"."BLOCK#"="A191"."BLOCK#" AND "A190"."TS#"="A191"."TS#" AND "A190"."TS#"="A192"."TS#" AND "A190"."USER#"="A193"."USER#"(+) AND ("A190"."TYPE#"=1 OR "A190"."TYPE#"=10) AND "A191"."STATUS$"<>1 AND
  • 78. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 78 "A191"."TS#"="A189"."TS#" AND "A191"."FILE#"="A189"."RELFILE#") UNION ALL (SELECT NVL("A188"."NAME",'SYS') "OWNER", TO_CHAR("A185"."FILE#")||'.'||TO_CHAR("A186"."BLOCK#") "SEGMENT_NAME",NULL "PARTITION_NAME", DECODE("A186"."TYPE#",2,'DEFERRED ROLLBACK',3, 'TEMPORARY',4,'CACHE',9,'SPACE HEADER','UNDEFINED') "SEGMENT_TYPE", "A186"."TYPE#" "SEGMENT_TYPE_ID",NULL "SEGMENT_SUBTYPE", "A187"."TS#" "TABLESPACE_ID", "A187"."NAME" "TABLESPACE_NAME", "A187"."BLOCKSIZE" "BLOCKSIZE", "A185"."FILE#" "HEADER_FILE", "A186"."BLOCK#" "HEADER_BLOCK", "A186"."BLOCKS"*"A187"."BLOCKSIZE" "BYTES", "A186"."BLOCKS" "BLOCKS", "A186"."EXTENTS" "EXTENTS", "A186"."INIEXTS"*"A187"."BLOCKSIZE" "INITIAL_EXTENT", "A186"."EXTSIZE"*"A187"."BLOCKSIZE" "NEXT_EXTENT", "A186"."MINEXTS" "MIN_EXTENTS", "A186"."MAXEXTS" "MAX_EXTENTS",DECODE(BITAND("A186"."SPARE1",4194304),4194304, "A186"."BITMAPRANGES",NULL) "MAX_SIZE",NULL "RETENTION",NULL "MINRETENTION",DECODE(BITAND("A187"."FLAGS",3),1,TO_NUMBER(NULL), "A186"."EXTPCT") "PCT_INCREASE",DECODE(BITAND("A187"."FLAGS",32),32,TO_NUMBER(NULL),DECODE("A186"."LISTS",0,1, "A186"."LISTS")) "FREELISTS",DECODE(BITAND("A187"."FLAGS",32),32,TO_NUMBER(NULL),DECODE("A186"."GROUPS",0,1, "A186"."GROUPS")) "FREELIST_GROUPS", "A186"."FILE#" "RELATIVE_FNO",BITAND("A186"."CACHEHINT",3) "BUFFER_POOL_ID",BITAND("A186"."CACHEHINT",12)/4 "FLASH_CACHE",BITAND("A186"."CACHEHINT",48)/16 "CELL_FLASH_CACHE",NVL("A186"."SPARE1",0) "SEGMENT_FLAGS", "A186"."HWMINCR" "SEGMENT_OBJD" FROM "SYS"."USER$" "A188", "SYS"."TS$" "A187", "SYS"."SEG$" "A186", "SYS"."FILE$" "A185" WHERE "A186"."TS#"="A187"."TS#" AND "A186"."USER#"="A188"."USER#"(+) AND "A186"."TYPE#"<>1 AND "A186"."TYPE#"<>5 AND
  • 79. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 79 "A186"."TYPE#"<>6 AND "A186"."TYPE#"<>8 AND "A186"."TYPE#"<>10 AND "A186"."TYPE#"<>11 AND "A186"."TS#"="A185"."TS#" AND "A186"."FILE#"="A185"."RELFILE#") UNION ALL (SELECT NVL("A184"."NAME",'SYS') "OWNER",'HEATMAP' "SEGMENT_NAME", NULL "PARTITION_NAME",'SYSTEM STATISTICS' "SEGMENT_TYPE", "A182"."TYPE#" "SEGMENT_TYPE_ID",NULL "SEGMENT_SUBTYPE", "A183"."TS#" "TABLESPACE_ID", "A183"."NAME" "TABLESPACE_NAME", "A183"."BLO CKSIZE" "BLOCKSIZE", "A181"."FILE#" "HEADER_FILE", "A182"."BLOCK#" "HEADER_BLOCK", "A182"."BLOCKS"*"A183"."BLOCKSIZE" "BYTES", "A182"."BLOCKS" "BLOCKS", "A182"."EXTENTS" "EXTENTS", "A182"."INIEXTS"*"A183"."BLOCKSIZE" "INITIAL_EXTENT", "A182"."EXTSIZE"*"A183"."BLOCKSIZE" "NEXT_EXTENT", "A182"."MINEXTS" "MIN_EXTENTS", "A182"."MAXEXTS" "MAX_EXTENTS",DECODE(BITAND("A182"."SPARE1",4194304),4194304, "A182"."BITMAPRANGES",NULL) "MAX_SIZE",NULL "RETENTION",NULL "MINRETENTION",DECODE(BITAND("A183"."FLAGS",3),1,TO_NUMBER(NULL), "A182"."EXTPCT") "PCT_INCREASE",DECODE(BITAND("A183"."FLAGS",32),32,TO_NUMBER(NULL),DEC ODE("A182"."LISTS",0,1, "A182"."LISTS")) "FREELISTS",DECODE(BITAND("A183"."FLAGS",32),32,TO_NUMBER(NULL),DECODE("A182"."GROUPS",0,1, "A182"."GROUPS")) "FREELIST_GROUPS", "A182"."FILE#" "RELATIVE_FNO",BITAND("A182"."CACHEHINT",3) "BUFFER_POOL_ID", BITAND("A182"."CACHEHINT",12)/4 "FLASH_CACHE",BITAND("A18 2"."CACHEHINT",48)/16 "CELL_FLASH_CACHE",NVL("A182"."SPARE1",0) "SEGMENT_FLAGS", "A182"."HWMINCR" "SEGMENT_OBJD" FROM "SYS"."USER$" "A184",
  • 80. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 80 "SYS"."TS$" "A183", "SYS"."SEG$" "A182", "SYS"."FILE$" "A181" WHERE "A182"."TS#"="A183"."TS#" AND "A182"."USER#"="A184"."USER#"(+) AND "A182"."TYPE#"=11 AND "A182"."TS#"="A181"."TS#" AND "A182"."FILE#"="A181"."RELFILE#")) "A4") "A3", (SELECT "A5"."NAME" "OWNER", "A6"."NAME" "OBJECT_NAME", "A6"."SUBNAME" "SUBOBJECT_NAME", "A6"."OBJ#" "OBJECT_ID", "A6"."DATAOBJ#" "DATA_OBJECT_ID",DECODE("A6"."TYPE#",0,'NEXT OBJECT',1,'INDEX', 2,'TABLE',3,'CLUSTER',4,'VIEW',5,'SYNONYM ',6,'SEQUENCE',7,'PROCEDURE',8,'FUNCTION',9,'PACKAGE',11,'PACKAGE BODY',12, 'TRIGGER',13,'TYPE',14,'TYPE BODY',19,'TABLE PARTITION',20,'INDEX PARTITION', 21,'LOB',22,'LIBRARY',23,'DIRECTORY',24,'QUEUE',28,'JAVA SOURCE',29,'JAVA CLASS',30, 'JAVA RESOURCE',32,'INDEXTYPE',33,'OPERATOR',34, 'TABLE SUBPARTITION',35,'INDEX SUBPARTITION',40,'LOB PARTITION',41,'LOB SUBPARTITION',42 ,NVL( (SELECT 'REWRITE EQUIVALENCE' "'REWRITEEQUIVALENCE'" FROM SYS."SUM$" "A52" WHERE "A52"."OBJ#"="A6"."OBJ#" AND BITAND("A52"."XPFLAGS",8388608)=8388608),'MATERIALIZED VIEW'),43,'DIMENSION', 44,'CONTEXT',46,'RULE SET',47,'RESOURCE PLAN',48,'CONSUMER GROUP',55,'XML SCHEMA',56,'JAVA DATA',57,'EDITION',59,'RULE', 60,'CAPTURE',61,'APPLY',62,'EVALUATION CONTEXT',66,'JOB',67,'PROGRAM',68,'JOB CLASS',69, 'WINDOW',72,'SCHEDULER GROUP',74,'SCHEDULE',79,'CHAIN',81,'FILE GROUP',82,'MINING MODEL',87,'ASSEMBLY',90,'CREDENTIAL',92,'CUBE DIMENSION',93,'CUBE',94,'MEASURE FOLDER',95,'CUBE BUILD PROCESS',100,'FILE WATCHER', 101,'DESTINATION',114,'SQL TRANSLATION PROFILE',115,'UNIFIED AUDIT POLICY','UNDEFINED') "OBJECT_TYPE", "A6"."CTIME" "CREATED", "A6"."MTIME" "LAST_DDL_TIME",TO_CHAR("A6"."STIME",'YYYY-MM-DD:HH24:MI:SS') "TIMESTAMP",DEC ODE("A6"."STATUS",0,'N/A',1,'VALID','INVALID') "STATUS",DECODE(BITAND("A6"."FLAGS",2),0,'N',2,'Y','N') "TEMPORARY",DECODE(BITAND("A6"."FLAGS",4),0,'N',4,'Y','N') "GENERATED",DECODE(BITAND("A6"."FLAGS",16),0,'N',16,'Y','N') "SECONDARY", "A6"."NAMESPACE" "NAMESPACE", "A6"."DEFINING_EDITION" "EDITION_NAM E",DECODE(BITAND("A6"."FLAGS",196608),65536,'METADATA LINK',131072,'OBJECT LINK','NONE') "SHARING", CASE WHEN ("A6"."TYPE#"=4 OR "A6"."TYPE#"=5 OR
  • 81. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 16 ... 81 more ... pages !
  • 82. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 82 back to our problem SQL SQL> select count(*) 2 from VEHICLES 3 where MAKE = 'HONDA' 4 and MODEL = 'CIVIC';
  • 83. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 83 2) is it sensible/correct ?
  • 84. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 84 SQL> select ... 2 from EMP e, 3 DEPT d 4 where e.JOB = 'SALES' 5 and d.LOC = 'NORTH'; DISTINCT ...
  • 85. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 85 SQL> select REGION, min(AMOUNT) 2 from EMP e, 3 SALES_TRANSACTIONS s 4 where e.JOB = 'SALES' 5 and s.EMPNO = e.EMPNO 6 and s.REGION = 'CA' 7 and s.TAX_AMT > 10 8 or s.SUBSIDY > 0 9 group by REGION 7 and s.TAX_AMT > 10 8 or s.SUBSIDY > 0 9 group by REGION
  • 86. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 86 3) check the plan
  • 87. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | optimizer got it wrong... 87
  • 88. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | or 88
  • 89. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | ... it cannot run better 89 legitimate response
  • 90. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 90 v$sql_plan
  • 91. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 91 dbms_xplan.display_cursor
  • 92. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 92 not EXPLAIN PLAN
  • 93. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | ------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | ------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 1| 5| | 1 | SORT AGGREGATE | | 1| 5| | 2 | TABLE ACCESS BY INDEX ROWID | VEHICLES | 20K| 2687K| | 3 | INDEX RANGE SCAN | MAKE_IX | 45K| 4592K| ------------------------------------------------------------------ 93 SQL> select count(*) 2 from VEHICLES 3 where MAKE = 'HONDA' 4 and MODEL = 'CIVIC';
  • 94. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 94 now what ?
  • 95. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | "where does it hurt ?" 95
  • 96. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 96
  • 97. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 97 where in the plan ?
  • 98. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 98 for human beings ...
  • 99. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 99 ... cardinality is important
  • 100. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 100
  • 101. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
  • 102. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 102 same with the optimizer
  • 103. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 103 actual versus estimate
  • 104. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 104 SQL> select /*+ GATHER_PLAN_STATISTICS */ count(*) 2 from VEHICLES 3 where MAKE = 'HONDA' 4 and MODEL = 'CIVIC'; COUNT(*) ---------- 114468
  • 105. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 105 SQL> SELECT * 2 FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR( 3 NULL, NULL, 'ALLSTATS LAST')); ---------------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows | A-Rows | ---------------------------------------------------------------------- | 1 | SORT AGGREGATE | | 1 | 1 | 1 | | 2 | TABLE ACCESS BY INDEX | VEHICLES| 1 | 20K| 114K| | 3 | INDEX RANGE SCAN | MAKE_IX | 1 | 45K| 182K| ----------------------------------------------------------------------
  • 106. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 106 for quick fixes remember...triage
  • 107. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 107 SQL> select /*+ FULL */ count(*) 2 from VEHICLES 3 where MAKE = 'HONDA' 4 and MODEL = 'CIVIC'; COUNT(*) ---------- 114468
  • 108. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | I'm not saying ... 108
  • 109. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | ... hints are the solution 109
  • 110. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 110 "optimizer hints should only be used with extreme care" Maria Colgan, Oct 2012 Optimizer product manager
  • 111. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | cool hints 111
  • 112. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 112 first_rows_n all_rows leading cardinality statement_queueing opt_param dynamic_sampling
  • 113. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | assisting optimizer 113
  • 114. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | dangerous hints ... 114
  • 115. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | ... everything else ! 115
  • 116. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 116 full index use_hash use_nl etc
  • 117. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | suppressing the optimizer 117
  • 118. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | a nifty triage trick 118
  • 119. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 119 SQL> SELECT * 2 from table(dbms_xplan.display(.... , format=>'typical +OUTLINE)) /*+ BEGIN_OUTLINE_DATA USE_HASH(@"SEL$1" "B"@"SEL$1") USE_HASH(@"SEL$1" "D"@"SEL$1") LEADING(@"SEL$1" "E"@"SEL$1" "D"@"SEL$1" "B"@"SEL$1") FULL(@"SEL$1" "B"@"SEL$1") FULL(@"SEL$1" "D"@"SEL$1") FULL(@"SEL$1" "E"@"SEL$1") OUTLINE_LEAF(@"SEL$1") ALL_ROWS DB_VERSION('11.2.0.2') OPTIMIZER_FEATURES_ENABLE('11.2.0.2') IGNORE_OPTIM_EMBEDDED_HINTS END_OUTLINE_DATA */
  • 120. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 120
  • 121. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | heading from triage into ... 121
  • 122. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
  • 123. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 1) fix the periphery 123
  • 124. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | add / remove indexes safely 124
  • 125. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 125
  • 126. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | adding / improving statistics 126
  • 127. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | back to our example 127 SQL> select ... 2 from VEHICLES 3 where MAKE = 'HONDA' 4 and MODEL = 'CIVIC';
  • 128. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | extended statistics 128
  • 129. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 129 SQL> select 2 dbms_stats.create_extended_stats('','VEHICLE', 3 '(MAKE,MODEL)') ext 2 from dual; EXT ------------------------------------------------------------- SYS_STUF3GLKIOP5F4B0BTTCFTMX0W SQL> begin 2 dbms_stats.gather_table_stats('','VEHICLE' 3 ,method_opt=>'for all columns size auto'); 4 end; 5 /
  • 130. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 130 SQL> select /*+ GATHER_PLAN_STATISTICS */ count(*) 2 from VEHICLES 3 where MAKE = 'HONDA' 4 and MODEL = 'CIVIC'; COUNT(*) ---------- 114468 ----------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows | A-Rows | ----------------------------------------------------------------- | 1 | SORT AGGREGATE | | 1 | 1 | 1 | |* 2 | TABLE ACCESS FULL| VEHICLES| 1 | 114K| 114K| -----------------------------------------------------------------
  • 131. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 2) force the plan you want 131
  • 132. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | sql plan baselines 132
  • 133. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | mea culpa 133 evolve accepted repeatable unaccepted capture signature
  • 134. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | very simple, very cool 134 "This plan is good, keep it!" "This new plan looks bad, don't touch it" "Actually, it might be OK. Use it!"
  • 135. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 135 ----------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ----------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | | 1 | NESTED LOOPS | | 25 | 425 | | 2 | NESTED LOOPS | | 25 | 425 | |* 3 | TABLE ACCESS FULL | TAB1 | 1 | 11 | |* 4 | INDEX RANGE SCAN | TAB2_TAB1_FKI | 25 | | | 5 | TABLE ACCESS BY INDEX ROWID| TAB2 | 25 | 150 | ----------------------------------------------------------------------- select a.data, b.data from tab1 a, tab2 where b.tab1_id = a.id and a.code = :1
  • 136. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | "accepted" plan 136
  • 137. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 137 ----------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ----------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | | 1 | NESTED LOOPS | | 25 | 425 | | 2 | NESTED LOOPS | | 25 | 425 | |* 3 | TABLE ACCESS FULL | TAB1 | 1 | 11 | |* 4 | INDEX RANGE SCAN | TAB2_TAB1_FKI | 25 | | | 5 | TABLE ACCESS BY INDEX ROWID| TAB2 | 25 | 150 | ----------------------------------------------------------------------- select a.data, b.data from tab1 a, tab2 where b.tab1_id = a.id and a.code = :1
  • 138. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 138 ----------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ----------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | | 1 | NESTED LOOPS | | 25 | 425 | | 2 | NESTED LOOPS | | 25 | 425 | |* 3 | TABLE ACCESS FULL | TAB1 | 1 | 11 | |* 4 | INDEX RANGE SCAN | TAB2_TAB1_FKI | 25 | | | 5 | TABLE ACCESS BY INDEX ROWID| TAB2 | 25 | 150 | ----------------------------------------------------------------------- select a.data, b.data from tab1 a, tab2 where b.tab1_id = a.id and a.code = :1 ----------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ----------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | | * 1 | HASH JOIN | | 25 | 425 | | * 5 | TABLE ACCESS FULL | TAB1 | 1 | 11 | | 8 | TABLE ACCESS FULL | TAB2 | 25 | 150 | -----------------------------------------------------------------------
  • 139. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | but we saved this ! 139 ----------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ----------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | | * 1 | HASH JOIN | | 25 | 425 | | * 5 | TABLE ACCESS FULL | TAB1 | 1 | 11 | | 8 | TABLE ACCESS FULL | TAB2 | 25 | 150 | -----------------------------------------------------------------------
  • 140. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | maybe it is better 140
  • 141. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | "evolve" a plan 141
  • 142. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 142 ----------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ----------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | | 1 | NESTED LOOPS | | 25 | 425 | | 2 | NESTED LOOPS | | 25 | 425 | |* 3 | TABLE ACCESS FULL | TAB1 | 1 | 11 | |* 4 | INDEX RANGE SCAN | TAB2_TAB1_FKI | 25 | | | 5 | TABLE ACCESS BY INDEX ROWID| TAB2 | 25 | 150 | ----------------------------------------------------------------------- select a.data, b.data from tab1 a, tab2 where b.tab1_id = a.id and a.code = :1 ----------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ----------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | | * 1 | HASH JOIN | | 25 | 425 | | * 5 | TABLE ACCESS FULL | TAB1 | 1 | 11 | | 8 | TABLE ACCESS FULL | TAB2 | 25 | 150 | -----------------------------------------------------------------------
  • 143. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | wrap up 143
  • 144. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | if you are tuning SQL ... 144 ... you are probably failing
  • 145. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | tune the user experience 145
  • 146. I love your feedback! Rate your trip with Connor
  • 148. Follow and Subscribe! youtube bit.ly/youtube-connor blog bit.ly/blog-connor twitter bit.ly/twitter-connor

Editor's Notes

  1. These are just some slides I ripped out of existing decks, obviously they would be cleaned up and formatted as we see fit but really just to touch on some of the things in 12c whether it be release 1 or release 2
  2. So when it comes to running stuff well, the two elements we would focus on are - better statistics so the chances of getting a good plan are better - and a recognition that no matter how good the statistics are there will always be challenges for the optimizer so it needs the ability to change course mid-stride
  3. These are just some slides I ripped out of existing decks, obviously they would be cleaned up and formatted as we see fit but really just to touch on some of the things in 12c whether it be release 1 or release 2
  4. These are just some slides I ripped out of existing decks, obviously they would be cleaned up and formatted as we see fit but really just to touch on some of the things in 12c whether it be release 1 or release 2
  5. So when it comes to running stuff well, the two elements we would focus on are - better statistics so the chances of getting a good plan are better - and a recognition that no matter how good the statistics are there will always be challenges for the optimizer so it needs the ability to change course mid-stride
  6. So when it comes to running stuff well, the two elements we would focus on are - better statistics so the chances of getting a good plan are better - and a recognition that no matter how good the statistics are there will always be challenges for the optimizer so it needs the ability to change course mid-stride
  7. So when it comes to running stuff well, the two elements we would focus on are - better statistics so the chances of getting a good plan are better - and a recognition that no matter how good the statistics are there will always be challenges for the optimizer so it needs the ability to change course mid-stride
  8. These are just some slides I ripped out of existing decks, obviously they would be cleaned up and formatted as we see fit but really just to touch on some of the things in 12c whether it be release 1 or release 2