SlideShare a Scribd company logo
29/01/2019
1
The Fast Lane the Database Success
aka, hints, tips and tricks from an old dude
Connor McDonald
Developer Advocate for Database
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
Connor McDonald
1
2
29/01/2019
2
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
3
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
4
3
4
29/01/2019
3
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.
etc...
facebook bit.ly/facebook-connor
linkedin bit.ly/linkedin-connor
instagram bit.ly/instagram-connor
slideshare bit.ly/slideshare-connor
5
6
29/01/2019
4
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
7https://asktom.oracle.com
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
8
https://asktom.oracle.com/officehours
7
8
29/01/2019
5
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
150 hours of free access (so far)
9
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
why tips and techniques ?
9
10
29/01/2019
6
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SO...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
HERE
11
12
29/01/2019
7
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
IS
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
WHAT
13
14
29/01/2019
8
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
15
16
29/01/2019
9
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
17
18
29/01/2019
10
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
19
20
29/01/2019
11
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
maybe they were right ?
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
I hope not :-)
21
22
29/01/2019
12
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
it's not about manuals
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
it's not about re-invention
23
24
29/01/2019
13
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
it's about sharing
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
it's about community
25
26
29/01/2019
14
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
that’s why
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor Statement
The following is intended to outline our general product direction. It is intended for
information purposes only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality, and should not be relied
upon in making purchasing decisions. The development, release, and timing of any
features or functionality described for Oracle’s products remains at the sole discretion
of Oracle.
26
27
28
29/01/2019
15
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 27
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 27
29
30
29/01/2019
16
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
if it's not in the documentation
- contact Support
- clarify usage before proceeding
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
31
32
29/01/2019
17
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
rogue session
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> select sid, last_call_et, status,
3 from v$session s;
SID LAST_CALL_ET STATUS
---------- ------------ ----------
39 7376 ACTIVE
40 412 INACTIVE
44 421 INACTIVE
46 12 ACTIVE
51 9 ACTIVE
53 15 ACTIVE
58 8 ACTIVE
69 22 ACTIVE
...
80 453 INACTIVE
33
34
29/01/2019
18
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> select sid, last_call_et, status,
3 from v$session s;
SID LAST_CALL_ET STATUS
---------- ------------ ----------
39 7376 ACTIVE
40 412 INACTIVE
44 421 INACTIVE
46 12 ACTIVE
51 9 ACTIVE
53 15 ACTIVE
58 8 ACTIVE
69 22 ACTIVE
...
80 453 INACTIVE
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
old days
35
36
29/01/2019
19
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
idiot in database
37
38
29/01/2019
20
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
much more modern...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
idiot in database
39
40
29/01/2019
21
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> alter system kill session ...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
# kill -9 pid
41
42
29/01/2019
22
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
38
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SID LAST_CALL_ET STATUS
---------- ------------ ----------
39 7376 ACTIVE
40 412 INACTIVE
41 412 INACTIVE
44 421 INACTIVE
46 12 ACTIVE
51 9 ACTIVE
53 15 ACTIVE
58 8 ACTIVE
43
44
29/01/2019
23
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> oradebug setorapid nnn
SQL> oradebug suspend
SID LAST_CALL_ET STATUS
---------- ------------ ----------
39 7376 ACTIVE
40 412 INACTIVE
41 412 INACTIVE
44 421 INACTIVE
46 12 ACTIVE
51 9 ACTIVE
53 15 ACTIVE
58 8 ACTIVE
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> oradebug setorapid nnn
SQL> oradebug suspend
SID LAST_CALL_ET STATUS
---------- ------------ ----------
39 7376 ACTIVE
40 412 INACTIVE
41 412 INACTIVE
44 421 INACTIVE
45
46
29/01/2019
24
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> oradebug setorapid nnn
SQL> oradebug suspend
SID LAST_CALL_ET STATUS
---------- ------------ ----------
39 7376 ACTIVE
40 412 INACTIVE
41 412 INACTIVE
44 421 INACTIVE
SQL> oradebug resume
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
47
48
29/01/2019
25
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
maybe ...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
... you don't want to resume
49
50
29/01/2019
26
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
rogue session
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
44
51
52
29/01/2019
27
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> alter system kill session ...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
46
53
54
29/01/2019
28
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
18c
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> alter system cancel sql '123,456';
55
56
29/01/2019
29
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
bonus tip!
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
maybe...
57
58
29/01/2019
30
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> select sid,
2 last_call_et,
3 status,
4 from v$session s;
SID LAST_CALL_ET STATUS
---------- ------------ ----------
39 7376 ACTIVE
40 412 INACTIVE
44 421 INACTIVE
...
...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> select sid,
2 last_call_et,
3 nvl2(lockwait,'BLOCKED',status) status,
4 from v$session s;
SID LAST_CALL_ET STATUS
---------- ------------ ----------
39 7376 BLOCKED
40 412 INACTIVE
44 421 INACTIVE
...
...
59
60
29/01/2019
31
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> select sid, last_call_et,
2 nvl2(lockwait,'BLOCKED',status) status,
3 blocking_session,
4 ( select sql_text
5 from v$sql
6 where sql_id = s.sql_id ) sql_text
7 from v$session s;
SID LAST_CALL_ET STATUS BLOCKING_SESSION SQL_TEXT
---------- ------------ ---------- ---------------- --------------
46 7376 BLOCKED 39 select *
from T
for update
49 4 ACTIVE
50 453 INACTIVE
51 453 INACTIVE
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
select for update wait 60
61
62
29/01/2019
32
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> select * from T for update wait 60;
(60 seconds pass)
select * from T for update wait 60
*
ERROR at line 1:
ORA-30006: resource busy; acquire with WAIT timeout expired
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
what’s the difference
63
64
29/01/2019
33
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
forever is a long time
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SID LAST_CALL_ET STATUS BLOCKING_SESSION
---------- ------------ ---------- ----------------
39 376 INACTIVE
40 412 ACTIVE
41 412 ACTIVE
44 421 ACTIVE
46 340 BLOCKED 39
49 42 ACTIVE
50 453 ACTIVE
51 453 ACTIVE
56 462 BLOCKED 39
58 436 BLOCKED 39
62 278 BLOCKED 46
63 254 BLOCKED 46
67 292 BLOCKED 46
71 301 BLOCKED 46
76 145 BLOCKED 62
78 132 BLOCKED 62
...
...
65
66
29/01/2019
34
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> create or replace trigger lock_expiry
2 after servererror on database
3 declare
4 l_user varchar2(30);
5 begin
6 if ( is_servererror(30006) ) then
...
... <look up session details>
...
28 raise_application_error(-20000,
29 'User '||l_user||' is causing you grief');
30 end if;
31 end;
32 /
Trigger created.
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> select * from T for update wait 60;
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-20000: User CONNOR (ext.1234) is causing you grief
ORA-06512: at line 6
ORA-30006: resource busy; acquire with WAIT timeout expired
67
68
29/01/2019
35
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
"empowering the users"
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
69
70
29/01/2019
36
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
/*+ GATHER_PLAN_STATISTICS */
71
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
64
64
for the optimizer
71
72
29/01/2019
37
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
65
65
cardinality is everything
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
66
73
74
29/01/2019
38
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
66
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
75
76
29/01/2019
39
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> explain plan for
2 select count(*)
3 from VEHICLE
4 where MAKE = 'HYUNDAI' and MODEL = 'IONIC';
77
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> explain plan for
2 select count(*)
3 from VEHICLE
4 where MAKE = 'HYUNDAI' and MODEL = 'IONIC';
SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_PLAN);
--------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
--------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 |
|* 2 | TABLE ACCESS FULL| VEHICLE | 20K | 270K |
--------------------------------------------------------
78
77
78
29/01/2019
40
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
? 69
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
actual versus estimate
80
79
80
29/01/2019
41
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> select /*+ GATHER_PLAN_STATISTICS */ count(*)
2 from VEHICLE
3 where MAKE = 'HYUNDAI' and MODEL = 'IONIC';
COUNT(*)
----------
114468
81
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> select /*+ GATHER_PLAN_STATISTICS */ count(*)
2 from VEHICLE
3 where MAKE = 'HYUNDAI' and MODEL = 'IONIC';
COUNT(*)
----------
114468
SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(
2 NULL, NULL, 'ALLSTATS LAST'));
-----------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows |
-----------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 | 1 |
|* 2 | TABLE ACCESS FULL| VEHICLE | 1 | 20K| 114K|
-----------------------------------------------------------------
82
81
82
29/01/2019
42
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
tracing
83
84
29/01/2019
43
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
alter session set sql_trace = true
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
C:oraclediagrdbmsdb122db122trace>dir *.trc
Volume in drive C is OS
Volume Serial Number is 9CB0-0212
Directory of C:oraclediagrdbmsdb122db122trace
27/09/2018 09:18 PM 1,314 db122_ora_10020.trc
20/10/2018 06:21 PM 2,691 db122_ora_10048.trc
30/09/2018 12:21 AM 1,345 db122_ora_10104.trc
29/09/2018 03:18 PM 1,314 db122_ora_10144.trc
21/10/2018 06:21 AM 1,346 db122_ora_10156.trc
11/10/2018 05:18 PM 1,312 db122_ora_1016.trc
02/10/2018 08:49 PM 1,346 db122_ora_10192.trc
29/09/2018 12:21 PM 1,345 db122_ora_10320.trc
12/10/2018 12:21 AM 1,501 db122_ora_10348.trc
15/10/2018 12:18 AM 1,314 db122_ora_10352.trc
13/10/2018 11:21 AM 1,499 db122_ora_1036.trc
28/09/2018 05:18 AM 1,315 db122_ora_10368.trc
18/10/2018 05:18 PM 1,824 db122_ora_10384.trc
05/10/2018 05:18 AM 1,178 db122_ora_10388.trc
28/09/2018 11:21 PM 1,346 db122_ora_10400.trc
14/10/2018 11:21 PM 1,501 db122_ora_10404.trc
30/09/2018 06:25 AM 1,346 db122_ora_10440.trc
04/10/2018 01:18 PM 1,313 db122_ora_10460.trc
04/10/2018 12:18 PM 1,313 db122_ora_10464.trc
08/10/2018 09:18 AM 1,314 db122_ora_10484.trc
27/09/2018 10:21 PM 1,344 db122_ora_10492.trc
85
86
29/01/2019
44
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
09/10/2018 12:18 PM 3,138 db122_ora_11280.trc
15/10/2018 01:18 PM 1,314 db122_ora_11300.trc
16/10/2018 04:21 AM 1,501 db122_ora_11312.trc
06/10/2018 03:21 AM 1,346 db122_ora_11320.trc
15/10/2018 02:22 PM 1,501 db122_ora_11348.trc
18/10/2018 03:21 PM 1,347 db122_ora_11388.trc
16/10/2018 01:21 AM 1,501 db122_ora_11460.trc
06/10/2018 05:21 AM 1,346 db122_ora_11464.trc
18/10/2018 02:21 PM 1,347 db122_ora_11476.trc
15/10/2018 03:21 AM 1,501 db122_ora_11480.trc
29/09/2018 11:21 AM 1,343 db122_ora_1152.trc
04/10/2018 07:21 AM 1,346 db122_ora_11524.trc
07/10/2018 03:21 AM 1,345 db122_ora_11532.trc
28/09/2018 09:18 AM 1,178 db122_ora_11548.trc
02/10/2018 04:21 AM 1,346 db122_ora_11556.trc
20/10/2018 04:18 PM 1,313 db122_ora_11568.trc
05/10/2018 06:21 AM 1,346 db122_ora_11588.trc
28/09/2018 02:18 PM 1,315 db122_ora_11616.trc
16/10/2018 07:21 PM 2,813 db122_ora_11620.trc
30/09/2018 09:21 PM 1,346 db122_ora_11624.trc
15/10/2018 03:18 PM 2,658 db122_ora_11636.trc
01/10/2018 09:21 PM 1,346 db122_ora_11644.trc
18/10/2018 01:21 PM 1,345 db122_ora_11688.trc
07/10/2018 04:21 PM 1,343 db122_ora_1172.trc
18/10/2018 04:21 PM 1,346 db122_ora_11720.trc
23/10/2018 11:21 PM 1,344 db122_ora_11724.trc
20/10/2018 10:21 AM 1,346 db122_ora_11768.trc
05/10/2018 02:21 PM 1,345 db122_ora_11776.trc
28/09/2018 08:18 AM 1,313 db122_ora_11808.trc
11/10/2018 09:21 AM 1,656 db122_ora_11856.trc
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
too many trace files
87
88
29/01/2019
45
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> alter session
2 set tracefile_identifier = SALESPGM;
Session altered.
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> alter session
2 set tracefile_identifier = SALESPGM;
Session altered.
SQL> host ls *.trc
db10r2_ora_3248.trc
db10r2_ora_3284.trc
db10r2_ora_3356.trc
db10r2_ora_3492.trc
db10r2_ora_3504_SALESPGM.trc
db10r2_ora_3608.trc
db10r2_ora_3620.trc
...
...
89
90
29/01/2019
46
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
bonus tip
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> select name, value from v$diag_info;
91
92
29/01/2019
47
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> select name, value from v$diag_info;
NAME VALUE
------------------------ ------------------------------------------
Diag Enabled TRUE
ADR Base C:ORACLE
ADR Home C:ORACLEdiagrdbmsdb122db122
Diag Trace C:ORACLEdiagrdbmsdb122db122trace
Diag Alert C:ORACLEdiagrdbmsdb122db122alert
Diag Incident C:ORACLEdiagrdbmsdb122db122incident
Diag Cdump c:oraclediagrdbmsdb122db122cdump
Health Monitor C:ORACLEdiagrdbmsdb122db122hm
Default Trace File C:ORACLE...tracedb122_ora_17296.trc
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
93
94
29/01/2019
48
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
too much trace data
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> alter session
2 set events
3 'immediate trace name trace_buffer_on level 1048576';
Session altered.
SQL> host ls –l *.trc
drw------- oracle dba Jun17 15:10 1048576 db10r2_ora_3248.trc
rolling trace window
95
96
29/01/2019
49
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> select PAYLOAD
2 from V$DIAG_TRACE_FILE_CONTENTS
3 where TRACE_FILENAME = 'db122_ora_12484.trc';
PAYLOAD
----------------------------------------------------------------------------
Trace file C:ORACLEdiagrdbmsdb122db122tracedb122_ora_12484.trc
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Build label: RDBMS_12.2.0.1.0WINDBBP_WINDOWS.X64_180202
Windows NT Version V6.2
ORACLE_HOME = c:oracleproduct12.2.0.1
Node name : XPS13
CPU : 4 - type 8664, 2 Physical Cores
Process Affinity : 0x0x0000000000000000
Memory (Avail/Total): Ph:9411M/16235M, Ph+PgF:4292M/20985M
Instance name: db122
Redo thread mounted by this instance: 1
...
...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
97
98
29/01/2019
50
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
19c
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
automatic indexing
99
100
29/01/2019
51
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. |
• The Automatic Indexing
methodology is based on a common
approach to manual SQL tuning
• It identifies candidate indexes and
validates them before implementing
• The entire process is full automatic
• Transparency is equally important as
sophisticated automation
– All tuning activities are auditable via
reporting
87
Automatic Indexing Methodology
Monitor
Online
Validation
Capture
Identify
Verify
Decide
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
until then ...
101
102
29/01/2019
52
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
“I need a new index
on this 6TB table...”
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
“will it speed up things ?”
103
104
29/01/2019
53
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
“I think so”
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
virtual indexes
105
106
29/01/2019
54
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> create index TEST on
2 MYTAB ( SALES_DATE ) NOSEGMENT;
Index created.
data dictionary only
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> begin
2 dbms_stats.generate_stats(
3 'SCOTT',
4 'MYTAB');
5 end;
6 /
107
108
29/01/2019
55
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> alter session
2 set "_use_nosegment_indexes" = true;
SQL> explain plan for
2 select * from MYTAB
3 where sales_date > sysdate-7;
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 950 | 90109 | 962 (34)|
| 1 | TABLE ACCESS BY INDEX ROWID| MYTAB | 950 | 90109 | 962 (34)|
|* 2 | INDEX RANGE SCAN | TEST | 950 | | 962 (50)|
--------------------------------------------------------------------------
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
109
110
29/01/2019
56
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
97
invisible indexes
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
98
SQL> create table T
2 as select * from all_objects;
Table created.
SQL> create index OBJ_IX on T ( OBJECT_ID );
Index created.
SQL> exec dbms_stats.gather_table_stats('','T')
PL/SQL procedure successfully completed.
111
112
29/01/2019
57
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
99
SQL> set autotrace traceonly explain
SQL> select * from T
2 where OWNER = 'SCOTT'
3 and created > sysdate - 1
4 /
---------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------
| 0 | SELECT STATEMENT | | 6 | 546 | 281 (1)|
|* 1 | TABLE ACCESS FULL| T | 6 | 546 | 281 (1)|
---------------------------------------------------------------
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
100
“Can I index OWNER..”
113
114
29/01/2019
58
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
101
“will it speed up things ?”
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
102
“I know so”
115
116
29/01/2019
59
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
103
SQL> create index NEW_IX on T ( OWNER );
Index created.
SQL> select * from T
2 where OWNER = 'SCOTT'
3 and created > sysdate - 1
4 /
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 6 | 546 | 122 (0)|
|* 1 | TABLE ACCESS BY INDEX ROWID| T | 6 | 546 | 122 (0)|
|* 2 | INDEX RANGE SCAN | NEW_IX | 4107 | | 10 (0)|
---------------------------------------------------------------------------
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
104
117
118
29/01/2019
60
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
105
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
106
everyone elses queries
119
120
29/01/2019
61
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
106
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
107
before the new index
121
122
29/01/2019
62
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
108
SQL> set autotrace traceonly explain
SQL> select * from T
2 where OWNER = 'SYS'
3 and OBJECT_ID between 10 and 8000
4 /
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 462 | 42042 | 143 (0)|
|* 1 | TABLE ACCESS BY INDEX ROWID| T | 462 | 42042 | 143 (0)|
|* 2 | INDEX RANGE SCAN | OBJ_IX | 7851 | | 20 (0)|
---------------------------------------------------------------------------
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
109
SQL> set autotrace traceonly stat
SQL> select * from T
2 where owner = 'SYS'
3 and object_id between 10 and 8000;
4967 rows selected.
Statistics
-----------------------------------------------------
0 recursive calls
0 db block gets
784 consistent gets
15 physical reads
0 redo size
123
124
29/01/2019
63
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
110
after the new index
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
111
SQL> select * from T
2 where owner = 'SYS'
3 and object_id between 10 and 8000
4 /
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 462 | 42042 | 122 (0)|
|* 1 | TABLE ACCESS BY INDEX ROWID| T | 462 | 42042 | 122 (0)|
|* 2 | INDEX RANGE SCAN | NEW_IX | 4105 | | 10 (0)|
---------------------------------------------------------------------------
the new index
125
126
29/01/2019
64
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
112
SQL> set autotrace traceonly stat
SQL> select * from T
2 where owner = 'SYS'
3 and object_id between 10 and 8000;
4967 rows selected.
Statistics
------------------------------------------------------
0 recursive calls
0 db block gets
1522 consistent gets
62 physical reads
0 redo size
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
113
127
128
29/01/2019
65
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
114
the solution ?
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
115
invisible indexes
129
130
29/01/2019
66
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
116
SQL> alter index NEW_IX invisible;
Index altered.
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
117
SQL> select * from T
2 where owner = 'SYS'
3 and object_id between 10 and 8000
4 /
----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 462 | 42042 | 143 (0)|
|* 1 | TABLE ACCESS BY INDEX ROWID| T | 462 | 42042 | 143 (0)|
|* 2 | INDEX RANGE SCAN | OBJ_IX | 7851 | | 20 (0)|
----------------------------------------------------------------------------
131
132
29/01/2019
67
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
118
“gee... thanks for nothing”
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
119
SQL> set autotrace traceonly explain
SQL> select * from T
2 where OWNER = 'SCOTT'
3 and created > sysdate - 1
4 /
---------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------
| 0 | SELECT STATEMENT | | 6 | 546 | 281 (1)|
|* 1 | TABLE ACCESS FULL| T | 6 | 546 | 281 (1)|
---------------------------------------------------------------
133
134
29/01/2019
68
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
120
SQL> alter session set
2 optimizer_use_invisible_indexes = true;
Session altered.
SQL> select * from T
2 where OWNER = 'SCOTT'
3 and created > sysdate - 1
4 /
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 462 | 42042 | 122 (0)|
|* 1 | TABLE ACCESS BY INDEX ROWID| T | 462 | 42042 | 122 (0)|
|* 2 | INDEX RANGE SCAN | NEW_IX | 4105 | | 10 (0)|
---------------------------------------------------------------------------
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
121
wrap your SQL to protect others
135
136
29/01/2019
69
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
122
statement level hint
USE_INVISIBLE_INDEXES
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
137
138
29/01/2019
70
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
better data guard use...
...for free
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> ALTER DATABASE CONVERT TO SNAPSHOT STANDBY;
10.2
139
140
29/01/2019
71
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
open standby read/write
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> ALTER DATABASE CONVERT TO PHYSICAL STANDBY;
SQL> ALTER DATABASE RECOVER MANAGED STANDBY
2 DATABASE DISCONNECT;
10.2
141
142
29/01/2019
72
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
flashback to resetlogs
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
resume managed recovery
143
144
29/01/2019
73
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
archives still transmitted
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
145
146
29/01/2019
74
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
faster queries ... no code changes
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
faster queries ... no code changes
147
148
29/01/2019
75
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> create table cust_trans
2 ( txn_id int,
3 txn_date date,
4 cust_id int,
5 amt number(10,2)
6 );
133
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> insert /*+ APPEND */ into cust_trans
2 select rownum,
3 sysdate-1000+rownum/1000 txn_date,
4 trunc(dbms_random.value(1,1000)) cust_id,
5 dbms_random.value(1,100) amount
6 from
7 ( select 1 from dual
8 connect by level <= 10000000 );
10000000 rows created.
SQL> create index cust_trans_ix
2 on cust_trans (cust_id );
Index created.
134
149
150
29/01/2019
76
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> select max(amt)
2 from cust_trans
3 where cust_id = 123;
135
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
136
151
152
29/01/2019
77
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> select max(amt)
2 from cust_trans
3 where cust_id = 123;
------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 8 |
| 1 | SORT AGGREGATE | | 1 | 8 |
| 2 | TABLE ACCESS BY INDEX ROWID BATCHED| CUST_TRANS | 10010 | 80080 |
|* 3 | INDEX RANGE SCAN | CUST_TRANS_IX | 10010 | |
------------------------------------------------------------------------------
137
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> select max(amt)
2 from cust_trans
3 where cust_id = 123;
------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 8 |
| 1 | SORT AGGREGATE | | 1 | 8 |
| 2 | TABLE ACCESS BY INDEX ROWID BATCHED| CUST_TRANS | 10010 | 80080 |
|* 3 | INDEX RANGE SCAN | CUST_TRANS_IX | 10010 | |
------------------------------------------------------------------------------
Statistics
-----------------------------------------------------
0 recursive calls
0 db block gets
8867 consistent gets
8854 physical reads
0 redo size
543 bytes sent via SQL*Net to client
607 bytes received via SQL*Net from client
137
153
154
29/01/2019
78
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
CUST 123 CUST 47 CUST 123 CUST 76 CUST 95 CUST 47 CUST 123
155
156
29/01/2019
79
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> alter table cust_trans
2 add clustering by linear order(cust_id);
Table altered.
SQL> alter table cust_trans move online;
Table altered.
12.1
12.2
139
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> select max(amt)
2 from cust_trans
3 where cust_id = 123;
------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 8 |
| 1 | SORT AGGREGATE | | 1 | 8 |
| 2 | TABLE ACCESS BY INDEX ROWID BATCHED| CUST_TRANS | 10010 | 80080 |
|* 3 | INDEX RANGE SCAN | CUST_TRANS_IX | 10010 | |
------------------------------------------------------------------------------
140
157
158
29/01/2019
80
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> select max(amt)
2 from cust_trans
3 where cust_id = 123;
------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 8 |
| 1 | SORT AGGREGATE | | 1 | 8 |
| 2 | TABLE ACCESS BY INDEX ROWID BATCHED| CUST_TRANS | 10010 | 80080 |
|* 3 | INDEX RANGE SCAN | CUST_TRANS_IX | 10010 | |
------------------------------------------------------------------------------
Statistics
-----------------------------------------------------
0 recursive calls
0 db block gets
62 consistent gets
23 physical reads
0 redo size
543 bytes sent via SQL*Net to client
607 bytes received via SQL*Net from client
140
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
"but I'm not on 12.2"
159
160
29/01/2019
81
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
dbms_redefinition
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
the marketing spin...
161
162
29/01/2019
82
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> desc EMP
Name Null? Type
----------------------- -------- ----------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> desc EMP
Name Null? Type
----------------------- -------- ----------------
EMPNO NOT NULL NUMBER(8)
SAL_PLUS_10PCT NUMBER(7,2)
163
164
29/01/2019
83
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
online
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> create table EMP_NEW_DEFN(
2 larger_empno number(8),
3 salary_plus_10pct number(7,2));
165
166
29/01/2019
84
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> create table EMP_NEW_DEFN(
2 larger_empno number(8),
3 salary_plus_10pct number(7,2));
SQL> begin
2 DBMS_REDEFINITION.START_REDEF_TABLE( -
3 UNAME =>'SCOTT',
4 ORIG_TABLE =>'EMP',
5 INT_TABLE =>'EMP_NEW_DEFN',
6 COL_MAPPING=>
'empno larger_empno, sal*1.1 salary_plus_10pct'
7 end;
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> exec DBMS_REDEFINITION.FINISH_REDEF_TABLE( -
'SCOTT','EMP','EMP_NEW_DEFN');
167
168
29/01/2019
85
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> exec DBMS_REDEFINITION.FINISH_REDEF_TABLE( -
'SCOTT','EMP','EMP_NEW_DEFN');
SQL> desc EMP
Name Null? Type
-------------------------- -------- -------------------
LARGER_EMPNO NUMBER(8)
SALARY_PLUS_10PCT NUMBER(7,2)
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
169
170
29/01/2019
86
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
PL/SQL programs
triggers
ProC
Java
Reports
ADF
adhoc scripts
BI Publisher layer
APEX
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
171
172
29/01/2019
87
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> begin
2 DBMS_REDEFINITION.START_REDEF_TABLE( -
3 UNAME =>'SCOTT',
4 ORIG_TABLE =>'EMP',
5 INT_TABLE =>'EMP_SAME_DEFN',
6
7 end;
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> begin
2 DBMS_REDEFINITION.START_REDEF_TABLE( -
3 UNAME =>'SCOTT',
4 ORIG_TABLE =>'EMP',
5 INT_TABLE =>'EMP_SAME_DEFN',
6
7 end;
ORDERBY_COLS=>'ename');
173
174
29/01/2019
88
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
DBMS_XPLAN
175
176
29/01/2019
89
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
SQL> explain plan for ...
SQL> select * from
2 table(dbms_xplan.display_plan)
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
extensions
177
178
29/01/2019
90
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
... the (in)famous hint ignore issue
157
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
158
SQL> select *
2 from emp e,
3 dept d
4 where e.deptno = d.deptno
5 and d.dname = 'SALES';
--------------------------------------------------------
| Id | Operation | Name | Rows |
--------------------------------------------------------
| 0 | SELECT STATEMENT | | 5 |
| 1 | MERGE JOIN | | 5 |
|* 2 | TABLE ACCESS BY INDEX ROWID| DEPT | 1 |
| 3 | INDEX FULL SCAN | PK_DEPT | 4 |
|* 4 | SORT JOIN | | 14 |
| 5 | TABLE ACCESS FULL | EMP | 14 |
--------------------------------------------------------
179
180
29/01/2019
91
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
159
"I want a hash join"
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
160
SQL> select /*+ use_hash(d) */ *
2 from emp e,
3 dept d
4 where e.deptno = d.deptno
5 and d.dname = 'SALES';
--------------------------------------------------------
| Id | Operation | Name | Rows |
--------------------------------------------------------
| 0 | SELECT STATEMENT | | 5 |
| 1 | MERGE JOIN | | 5 |
|* 2 | TABLE ACCESS BY INDEX ROWID| DEPT | 1 |
| 3 | INDEX FULL SCAN | PK_DEPT | 4 |
|* 4 | SORT JOIN | | 14 |
| 5 | TABLE ACCESS FULL | EMP | 14 |
--------------------------------------------------------
181
182
29/01/2019
92
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
? 161
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
162
/*+ use_hash(d) */
183
184
29/01/2019
93
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
162
/*+ use_hash(d) */
if joining into DEPT...
use a hash join
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
we're not...
163
185
186
29/01/2019
94
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
164
--------------------------------------------------------
| Id | Operation | Name | Rows |
--------------------------------------------------------
| 0 | SELECT STATEMENT | | 5 |
| 1 | MERGE JOIN | | 5 |
|* 2 | TABLE ACCESS BY INDEX ROWID| DEPT | 1 |
| 3 | INDEX FULL SCAN | PK_DEPT | 4 |
|* 4 | SORT JOIN | | 14 |
| 5 | TABLE ACCESS FULL | EMP | 14 |
--------------------------------------------------------
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
165
if we want to join into DEPT...
...we must be starting with EMP
187
188
29/01/2019
95
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
166
SQL> select /*+ leading(e) use_hash(d) */ *
2 from emp e,
3 dept d
4 where e.deptno = d.deptno
5 and d.dname = 'SALES';
---------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
---------------------------------------------------
| 0 | SELECT STATEMENT | | 5 | 285 |
|* 1 | HASH JOIN | | 5 | 285 |
| 2 | TABLE ACCESS FULL| EMP | 14 | 518 |
|* 3 | TABLE ACCESS FULL| DEPT | 1 | 20 |
---------------------------------------------------
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
not enough hints
167
189
190
29/01/2019
96
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
168
"hints are like violence…
if they do not work, use more"
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
back to dbms_xplan
169
191
192
29/01/2019
97
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
170
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')
END_OUTLINE_DATA
*/
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
consider SQL Plan Management
171
193
194
29/01/2019
98
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
bonus tip !
172
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
173
SQL> select /*+ INDEX(accounts_pk) */
2 from ACCOUNTS
3 where ...
SQL> select /*+ INDEX(a) */
2 from ACCOUNTS
3 where ...
SQL> select /*+ INDEX(scott.accounts) */
2 from SCOTT.ACCOUNTS
3 where ...
SQL> select /* INDEX(A) */
2 from SCOTT.ACCOUNTS A
3 where ...
195
196
29/01/2019
99
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
19c
174
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
175
SQL> SELECT *
2 from table(dbms_xplan.display(.... ,
format=>'typical +HINT_REPORT'))
197
198
29/01/2019
100
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
finding bad SQL ...
199
200
29/01/2019
101
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
... is probably bad SQL
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
179
SQL> select sql_fulltext
2 from v$sql
3 where buffer_gets > 1000000 or
4 executions > 10000 or
5 disk_reads > 100000;
SQL_FULLTEXT
-----------------------------------------------
SELECT ...
FROM ...
201
202
29/01/2019
102
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
179
SQL> select sql_fulltext
2 from v$sql
3 where buffer_gets > 1000000 or
4 executions > 10000 or
5 disk_reads > 100000;
SQL_FULLTEXT
-----------------------------------------------
SELECT ...
FROM ...
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
you can do better
180
203
204
29/01/2019
103
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
181
SQL> select sql_fulltext
2 from v$sqlstats
3 where buffer_gets > 1000000 or
4 executions > 10000 or
5 disk_reads > 100000;
SQL_FULLTEXT
-----------------------------------------------
SELECT ...
FROM ...
Copyright © 2019, 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)."
182
205
206
29/01/2019
104
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
184
sqlplus hash tags
207
208
29/01/2019
105
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
185
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
186
SQL> select SAL
2 from EMP
3 where
209
210
29/01/2019
106
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
186
SQL> select SAL
2 from EMP
3 where
"hmmmm....."
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
187
SQL> select SAL
2 from EMP
3 where
211
212
29/01/2019
107
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
187
SQL> select SAL
2 from EMP
3 where
4 #desc EMP
Name Null? Type
----------------------------- -------- -------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
...
4 job = 'CLERK';
SAL
----------
800
1100
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
188
SQL> declare
2 x int;
3 begin
4 select max(sal)
5 into x
6 from emp;
7
8 dbms_output.put_line(x);
213
214
29/01/2019
108
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
188
SQL> declare
2 x int;
3 begin
4 select max(sal)
5 into x
6 from emp;
7
8 dbms_output.put_line(x);
9 #set serverout on
9 end;
10 /
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
188
SQL> declare
2 x int;
3 begin
4 select max(sal)
5 into x
6 from emp;
7
8 dbms_output.put_line(x);
9 #set serverout on
9 end;
10 /
10000
215
216
29/01/2019
109
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
190
sqlplus error logging
217
218
29/01/2019
110
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
191
SQL> set errorlogging on
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
192
SQL> set errorlogging on
SQL> desc SPERRORLOG
Name Type
------------------------------------- ----------------
USERNAME VARCHAR2(256)
TIMESTAMP TIMESTAMP(6)
SCRIPT VARCHAR2(1024)
IDENTIFIER VARCHAR2(256)
MESSAGE CLOB
STATEMENT CLOB
219
220
29/01/2019
111
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
193
SQL> select * from THE_WRONG_NAME;
select * from THE_WRONG_NAME
*
ERROR at line 1:
ORA-00942: table or view does not exist
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
193
SQL> select * from THE_WRONG_NAME;
select * from THE_WRONG_NAME
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> desc THE_WRONG_NAME;
ERROR:
ORA-04043: object THE_WRONG_NAME does not exist
221
222
29/01/2019
112
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
194
SQL> select timestamp, message, statement
2 from SPERRORLOG;
TIMESTAMP
-----------------------------------------------------
MESSAGE
-----------------------------------------------------
STATEMENT
-----------------------------------------------------
01-APR-08 02.29.58.000000 PM
ORA-00942: table or view does not exist
select * from THE_WRONG_NAME
01-APR-08 02.29.58.000000 PM
ORA-04043: object THE_WRONG_NAME does not exist
desc THE_WRONG_NAME;
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
195
installation scripts
SQL> set errorlogging on
SQL> @create_all_objects
223
224
29/01/2019
113
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
197
sqlplus / sqlcl transaction safety
225
226
29/01/2019
114
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
198
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
198
227
228
29/01/2019
115
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
198
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
199
SQL> set exitcommit
229
230
29/01/2019
116
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
wrap up
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
poaching ideas is fine
231
232
29/01/2019
117
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
learn something new
Follow and Subscribe!
youtube bit.ly/youtube-connor
blog bit.ly/blog-connor
twitter bit.ly/twitter-connor
233
234

More Related Content

What's hot

Oracle database 12c application express installation guide
Oracle database 12c application express installation guideOracle database 12c application express installation guide
Oracle database 12c application express installation guide
bupbechanhgmail
 
122qpug
122qpug122qpug
122qpug
Sara62nath
 
Oracle Enterprise Scheduler(ESS Job Scheduling)
Oracle Enterprise Scheduler(ESS Job Scheduling)Oracle Enterprise Scheduler(ESS Job Scheduling)
Oracle Enterprise Scheduler(ESS Job Scheduling)
TUSHAR VARSHNEY
 
Oracle Incentive User Guide 122cnug
Oracle Incentive User Guide 122cnugOracle Incentive User Guide 122cnug
Oracle Incentive User Guide 122cnug
cuong vu
 
Sales userguide121asnug
Sales userguide121asnugSales userguide121asnug
Sales userguide121asnug
G Selvam Guru
 
OpenWorld 2018 - SQL Tuning in 20 mins
OpenWorld 2018 - SQL Tuning in 20 minsOpenWorld 2018 - SQL Tuning in 20 mins
OpenWorld 2018 - SQL Tuning in 20 mins
Connor McDonald
 
Oracle database 12c application express end user's guide
Oracle database 12c application express end user's guideOracle database 12c application express end user's guide
Oracle database 12c application express end user's guide
bupbechanhgmail
 
India localization urm in60106
India localization urm in60106India localization urm in60106
India localization urm in60106
Vikram Reddy
 
Javaee tutorial
Javaee tutorialJavaee tutorial
Javaee tutorial
Luis Miguel
 
Ora db 2 day+ app express dev guide
Ora db 2 day+ app express dev guideOra db 2 day+ app express dev guide
Ora db 2 day+ app express dev guide
Darnette A
 
BOM & WIP
BOM & WIPBOM & WIP
BOM & WIP
rajeev s
 
Oracle@cloud adapter(SFDC integration with SOA Suites12c)
Oracle@cloud adapter(SFDC integration with SOA Suites12c)Oracle@cloud adapter(SFDC integration with SOA Suites12c)
Oracle@cloud adapter(SFDC integration with SOA Suites12c)
TUSHAR VARSHNEY
 

What's hot (12)

Oracle database 12c application express installation guide
Oracle database 12c application express installation guideOracle database 12c application express installation guide
Oracle database 12c application express installation guide
 
122qpug
122qpug122qpug
122qpug
 
Oracle Enterprise Scheduler(ESS Job Scheduling)
Oracle Enterprise Scheduler(ESS Job Scheduling)Oracle Enterprise Scheduler(ESS Job Scheduling)
Oracle Enterprise Scheduler(ESS Job Scheduling)
 
Oracle Incentive User Guide 122cnug
Oracle Incentive User Guide 122cnugOracle Incentive User Guide 122cnug
Oracle Incentive User Guide 122cnug
 
Sales userguide121asnug
Sales userguide121asnugSales userguide121asnug
Sales userguide121asnug
 
OpenWorld 2018 - SQL Tuning in 20 mins
OpenWorld 2018 - SQL Tuning in 20 minsOpenWorld 2018 - SQL Tuning in 20 mins
OpenWorld 2018 - SQL Tuning in 20 mins
 
Oracle database 12c application express end user's guide
Oracle database 12c application express end user's guideOracle database 12c application express end user's guide
Oracle database 12c application express end user's guide
 
India localization urm in60106
India localization urm in60106India localization urm in60106
India localization urm in60106
 
Javaee tutorial
Javaee tutorialJavaee tutorial
Javaee tutorial
 
Ora db 2 day+ app express dev guide
Ora db 2 day+ app express dev guideOra db 2 day+ app express dev guide
Ora db 2 day+ app express dev guide
 
BOM & WIP
BOM & WIPBOM & WIP
BOM & WIP
 
Oracle@cloud adapter(SFDC integration with SOA Suites12c)
Oracle@cloud adapter(SFDC integration with SOA Suites12c)Oracle@cloud adapter(SFDC integration with SOA Suites12c)
Oracle@cloud adapter(SFDC integration with SOA Suites12c)
 

Similar to ILOUG 2019 - 25 years of hints and tips

OG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developersOG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developers
Connor McDonald
 
Kscope19 - Flashback: Good for Developers as well as DBAs
Kscope19 - Flashback: Good for Developers as well as DBAsKscope19 - Flashback: Good for Developers as well as DBAs
Kscope19 - Flashback: Good for Developers as well as DBAs
Connor McDonald
 
ILOUG 2019 - 18c/19c features
ILOUG 2019 - 18c/19c featuresILOUG 2019 - 18c/19c features
ILOUG 2019 - 18c/19c features
Connor 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 tips
Connor McDonald
 
Latin America tour 2019 - Flashback
Latin America tour 2019 -  FlashbackLatin America tour 2019 -  Flashback
Latin America tour 2019 - Flashback
Connor McDonald
 
ITOUG 2019 - 18c, 19c features
ITOUG 2019 - 18c, 19c featuresITOUG 2019 - 18c, 19c features
ITOUG 2019 - 18c, 19c features
Connor McDonald
 
Melbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and TipsMelbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and Tips
Connor McDonald
 
AIOUG - Groundbreakers - Jul 2019 - 19 Troubleshooting Tips and Tricks for Da...
AIOUG - Groundbreakers - Jul 2019 - 19 Troubleshooting Tips and Tricks for Da...AIOUG - Groundbreakers - Jul 2019 - 19 Troubleshooting Tips and Tricks for Da...
AIOUG - Groundbreakers - Jul 2019 - 19 Troubleshooting Tips and Tricks for Da...
Sandesh Rao
 
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
Connor 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+ optimizer
Connor McDonald
 
Kscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processingKscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processing
Connor McDonald
 
GraalVM Native Images by Oleg Selajev @shelajev
GraalVM Native Images by Oleg Selajev @shelajevGraalVM Native Images by Oleg Selajev @shelajev
GraalVM Native Images by Oleg Selajev @shelajev
Oracle Developers
 
MySQL Performance Schema in MySQL 8.0
MySQL Performance Schema in MySQL 8.0MySQL Performance Schema in MySQL 8.0
MySQL Performance Schema in MySQL 8.0
Mayank Prasad
 
Hyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cHyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19c
Connor McDonald
 
OOW19 - Killing database sessions
OOW19 - Killing database sessionsOOW19 - Killing database sessions
OOW19 - Killing database sessions
Connor McDonald
 
AUSOUG - NZOUG - Groundbreakers - Jun 2019 - 19 Troubleshooting Tips and Tric...
AUSOUG - NZOUG - Groundbreakers - Jun 2019 - 19 Troubleshooting Tips and Tric...AUSOUG - NZOUG - Groundbreakers - Jun 2019 - 19 Troubleshooting Tips and Tric...
AUSOUG - NZOUG - Groundbreakers - Jun 2019 - 19 Troubleshooting Tips and Tric...
Sandesh Rao
 
Perth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c featuresPerth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c features
Connor McDonald
 
Oracle APEX 기초 워크샵 - 실습 가이드 문서: Part 2 (2/2)
Oracle APEX 기초 워크샵 - 실습 가이드 문서:  Part 2 (2/2)Oracle APEX 기초 워크샵 - 실습 가이드 문서:  Part 2 (2/2)
Oracle APEX 기초 워크샵 - 실습 가이드 문서: Part 2 (2/2)
Taewan Kim
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAs
Connor McDonald
 
20190220 Oracle Blockchain Day公開資料
20190220 Oracle Blockchain Day公開資料20190220 Oracle Blockchain Day公開資料
20190220 Oracle Blockchain Day公開資料
オラクルエンジニア通信
 

Similar to ILOUG 2019 - 25 years of hints and tips (20)

OG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developersOG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developers
 
Kscope19 - Flashback: Good for Developers as well as DBAs
Kscope19 - Flashback: Good for Developers as well as DBAsKscope19 - Flashback: Good for Developers as well as DBAs
Kscope19 - Flashback: Good for Developers as well as DBAs
 
ILOUG 2019 - 18c/19c features
ILOUG 2019 - 18c/19c featuresILOUG 2019 - 18c/19c features
ILOUG 2019 - 18c/19c features
 
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 - Flashback
Latin America tour 2019 -  FlashbackLatin America tour 2019 -  Flashback
Latin America tour 2019 - Flashback
 
ITOUG 2019 - 18c, 19c features
ITOUG 2019 - 18c, 19c featuresITOUG 2019 - 18c, 19c features
ITOUG 2019 - 18c, 19c features
 
Melbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and TipsMelbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and Tips
 
AIOUG - Groundbreakers - Jul 2019 - 19 Troubleshooting Tips and Tricks for Da...
AIOUG - Groundbreakers - Jul 2019 - 19 Troubleshooting Tips and Tricks for Da...AIOUG - Groundbreakers - Jul 2019 - 19 Troubleshooting Tips and Tricks for Da...
AIOUG - Groundbreakers - Jul 2019 - 19 Troubleshooting Tips and Tricks for Da...
 
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
 
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
 
Kscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processingKscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processing
 
GraalVM Native Images by Oleg Selajev @shelajev
GraalVM Native Images by Oleg Selajev @shelajevGraalVM Native Images by Oleg Selajev @shelajev
GraalVM Native Images by Oleg Selajev @shelajev
 
MySQL Performance Schema in MySQL 8.0
MySQL Performance Schema in MySQL 8.0MySQL Performance Schema in MySQL 8.0
MySQL Performance Schema in MySQL 8.0
 
Hyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cHyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19c
 
OOW19 - Killing database sessions
OOW19 - Killing database sessionsOOW19 - Killing database sessions
OOW19 - Killing database sessions
 
AUSOUG - NZOUG - Groundbreakers - Jun 2019 - 19 Troubleshooting Tips and Tric...
AUSOUG - NZOUG - Groundbreakers - Jun 2019 - 19 Troubleshooting Tips and Tric...AUSOUG - NZOUG - Groundbreakers - Jun 2019 - 19 Troubleshooting Tips and Tric...
AUSOUG - NZOUG - Groundbreakers - Jun 2019 - 19 Troubleshooting Tips and Tric...
 
Perth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c featuresPerth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c features
 
Oracle APEX 기초 워크샵 - 실습 가이드 문서: Part 2 (2/2)
Oracle APEX 기초 워크샵 - 실습 가이드 문서:  Part 2 (2/2)Oracle APEX 기초 워크샵 - 실습 가이드 문서:  Part 2 (2/2)
Oracle APEX 기초 워크샵 - 실습 가이드 문서: Part 2 (2/2)
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAs
 
20190220 Oracle Blockchain Day公開資料
20190220 Oracle Blockchain Day公開資料20190220 Oracle Blockchain Day公開資料
20190220 Oracle Blockchain Day公開資料
 

More from Connor McDonald

Flashback ITOUG
Flashback ITOUGFlashback ITOUG
Flashback ITOUG
Connor McDonald
 
Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolest
Connor McDonald
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQL
Connor 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 tips
Connor McDonald
 
Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on Autonomous
Connor McDonald
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest Features
Connor McDonald
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL features
Connor 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 autonomous
Connor McDonald
 
APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne
Connor McDonald
 
OOW19 - Read consistency
OOW19 - Read consistencyOOW19 - Read consistency
OOW19 - Read consistency
Connor McDonald
 
OOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsOOW19 - Slower and less secure applications
OOW19 - Slower and less secure applications
Connor McDonald
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL features
Connor 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 featues
Connor 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 features
Connor McDonald
 
Latin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matchingLatin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matching
Connor McDonald
 
ANSI vs Oracle language
ANSI vs Oracle languageANSI vs Oracle language
ANSI vs Oracle language
Connor McDonald
 
KScope19 - SQL Features
KScope19 - SQL FeaturesKScope19 - SQL Features
KScope19 - SQL Features
Connor McDonald
 
APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101
Connor McDonald
 
APEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQLAPEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQL
Connor McDonald
 
APEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentAPEX Connect 2019 - successful application development
APEX Connect 2019 - successful application development
Connor 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 - 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 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL features
 
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
 
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 - pattern matching
Latin America Tour 2019 - pattern matchingLatin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matching
 
ANSI vs Oracle language
ANSI vs Oracle languageANSI vs Oracle language
ANSI vs Oracle language
 
KScope19 - SQL Features
KScope19 - SQL FeaturesKScope19 - SQL Features
KScope19 - SQL Features
 
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 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQLAPEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQL
 
APEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentAPEX Connect 2019 - successful application development
APEX Connect 2019 - successful application development
 

Recently uploaded

Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!
Tobias Schneck
 
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin..."$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
Fwdays
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
christinelarrosa
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving
 
Must Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during MigrationMust Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during Migration
Mydbops
 
AWS Certified Solutions Architect Associate (SAA-C03)
AWS Certified Solutions Architect Associate (SAA-C03)AWS Certified Solutions Architect Associate (SAA-C03)
AWS Certified Solutions Architect Associate (SAA-C03)
HarpalGohil4
 
ScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking ReplicationScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking Replication
ScyllaDB
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
DanBrown980551
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
christinelarrosa
 
"What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w..."What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w...
Fwdays
 
From Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMsFrom Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMs
Sease
 
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
AlexanderRichford
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
ScyllaDB
 
What is an RPA CoE? Session 2 – CoE Roles
What is an RPA CoE?  Session 2 – CoE RolesWhat is an RPA CoE?  Session 2 – CoE Roles
What is an RPA CoE? Session 2 – CoE Roles
DianaGray10
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 

Recently uploaded (20)

Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!
 
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin..."$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
 
Must Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during MigrationMust Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during Migration
 
AWS Certified Solutions Architect Associate (SAA-C03)
AWS Certified Solutions Architect Associate (SAA-C03)AWS Certified Solutions Architect Associate (SAA-C03)
AWS Certified Solutions Architect Associate (SAA-C03)
 
ScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking ReplicationScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking Replication
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
 
"What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w..."What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w...
 
From Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMsFrom Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMs
 
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
 
What is an RPA CoE? Session 2 – CoE Roles
What is an RPA CoE?  Session 2 – CoE RolesWhat is an RPA CoE?  Session 2 – CoE Roles
What is an RPA CoE? Session 2 – CoE Roles
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 

ILOUG 2019 - 25 years of hints and tips

  • 1. 29/01/2019 1 The Fast Lane the Database Success aka, hints, tips and tricks from an old dude Connor McDonald Developer Advocate for Database Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Connor McDonald 1 2
  • 2. 29/01/2019 2 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 3 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 4 3 4
  • 3. 29/01/2019 3 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. etc... facebook bit.ly/facebook-connor linkedin bit.ly/linkedin-connor instagram bit.ly/instagram-connor slideshare bit.ly/slideshare-connor 5 6
  • 4. 29/01/2019 4 Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 7https://asktom.oracle.com Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 8 https://asktom.oracle.com/officehours 7 8
  • 5. 29/01/2019 5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 150 hours of free access (so far) 9 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. why tips and techniques ? 9 10
  • 6. 29/01/2019 6 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SO... Copyright © 2019, Oracle and/or its affiliates. All rights reserved. HERE 11 12
  • 7. 29/01/2019 7 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. IS Copyright © 2019, Oracle and/or its affiliates. All rights reserved. WHAT 13 14
  • 8. 29/01/2019 8 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 15 16
  • 9. 29/01/2019 9 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 17 18
  • 10. 29/01/2019 10 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 19 20
  • 11. 29/01/2019 11 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. maybe they were right ? Copyright © 2019, Oracle and/or its affiliates. All rights reserved. I hope not :-) 21 22
  • 12. 29/01/2019 12 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. it's not about manuals Copyright © 2019, Oracle and/or its affiliates. All rights reserved. it's not about re-invention 23 24
  • 13. 29/01/2019 13 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. it's about sharing Copyright © 2019, Oracle and/or its affiliates. All rights reserved. it's about community 25 26
  • 14. 29/01/2019 14 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. that’s why Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 26 27 28
  • 15. 29/01/2019 15 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 27 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 27 29 30
  • 16. 29/01/2019 16 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. if it's not in the documentation - contact Support - clarify usage before proceeding Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 31 32
  • 17. 29/01/2019 17 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. rogue session Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> select sid, last_call_et, status, 3 from v$session s; SID LAST_CALL_ET STATUS ---------- ------------ ---------- 39 7376 ACTIVE 40 412 INACTIVE 44 421 INACTIVE 46 12 ACTIVE 51 9 ACTIVE 53 15 ACTIVE 58 8 ACTIVE 69 22 ACTIVE ... 80 453 INACTIVE 33 34
  • 18. 29/01/2019 18 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> select sid, last_call_et, status, 3 from v$session s; SID LAST_CALL_ET STATUS ---------- ------------ ---------- 39 7376 ACTIVE 40 412 INACTIVE 44 421 INACTIVE 46 12 ACTIVE 51 9 ACTIVE 53 15 ACTIVE 58 8 ACTIVE 69 22 ACTIVE ... 80 453 INACTIVE Copyright © 2019, Oracle and/or its affiliates. All rights reserved. old days 35 36
  • 19. 29/01/2019 19 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. idiot in database 37 38
  • 20. 29/01/2019 20 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. much more modern... Copyright © 2019, Oracle and/or its affiliates. All rights reserved. idiot in database 39 40
  • 21. 29/01/2019 21 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> alter system kill session ... Copyright © 2019, Oracle and/or its affiliates. All rights reserved. # kill -9 pid 41 42
  • 22. 29/01/2019 22 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 38 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SID LAST_CALL_ET STATUS ---------- ------------ ---------- 39 7376 ACTIVE 40 412 INACTIVE 41 412 INACTIVE 44 421 INACTIVE 46 12 ACTIVE 51 9 ACTIVE 53 15 ACTIVE 58 8 ACTIVE 43 44
  • 23. 29/01/2019 23 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> oradebug setorapid nnn SQL> oradebug suspend SID LAST_CALL_ET STATUS ---------- ------------ ---------- 39 7376 ACTIVE 40 412 INACTIVE 41 412 INACTIVE 44 421 INACTIVE 46 12 ACTIVE 51 9 ACTIVE 53 15 ACTIVE 58 8 ACTIVE Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> oradebug setorapid nnn SQL> oradebug suspend SID LAST_CALL_ET STATUS ---------- ------------ ---------- 39 7376 ACTIVE 40 412 INACTIVE 41 412 INACTIVE 44 421 INACTIVE 45 46
  • 24. 29/01/2019 24 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> oradebug setorapid nnn SQL> oradebug suspend SID LAST_CALL_ET STATUS ---------- ------------ ---------- 39 7376 ACTIVE 40 412 INACTIVE 41 412 INACTIVE 44 421 INACTIVE SQL> oradebug resume Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 47 48
  • 25. 29/01/2019 25 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. maybe ... Copyright © 2019, Oracle and/or its affiliates. All rights reserved. ... you don't want to resume 49 50
  • 26. 29/01/2019 26 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. rogue session Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 44 51 52
  • 27. 29/01/2019 27 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> alter system kill session ... Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 46 53 54
  • 28. 29/01/2019 28 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 18c Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> alter system cancel sql '123,456'; 55 56
  • 29. 29/01/2019 29 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. bonus tip! Copyright © 2019, Oracle and/or its affiliates. All rights reserved. maybe... 57 58
  • 30. 29/01/2019 30 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> select sid, 2 last_call_et, 3 status, 4 from v$session s; SID LAST_CALL_ET STATUS ---------- ------------ ---------- 39 7376 ACTIVE 40 412 INACTIVE 44 421 INACTIVE ... ... Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> select sid, 2 last_call_et, 3 nvl2(lockwait,'BLOCKED',status) status, 4 from v$session s; SID LAST_CALL_ET STATUS ---------- ------------ ---------- 39 7376 BLOCKED 40 412 INACTIVE 44 421 INACTIVE ... ... 59 60
  • 31. 29/01/2019 31 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> select sid, last_call_et, 2 nvl2(lockwait,'BLOCKED',status) status, 3 blocking_session, 4 ( select sql_text 5 from v$sql 6 where sql_id = s.sql_id ) sql_text 7 from v$session s; SID LAST_CALL_ET STATUS BLOCKING_SESSION SQL_TEXT ---------- ------------ ---------- ---------------- -------------- 46 7376 BLOCKED 39 select * from T for update 49 4 ACTIVE 50 453 INACTIVE 51 453 INACTIVE Copyright © 2019, Oracle and/or its affiliates. All rights reserved. select for update wait 60 61 62
  • 32. 29/01/2019 32 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> select * from T for update wait 60; (60 seconds pass) select * from T for update wait 60 * ERROR at line 1: ORA-30006: resource busy; acquire with WAIT timeout expired Copyright © 2019, Oracle and/or its affiliates. All rights reserved. what’s the difference 63 64
  • 33. 29/01/2019 33 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. forever is a long time Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SID LAST_CALL_ET STATUS BLOCKING_SESSION ---------- ------------ ---------- ---------------- 39 376 INACTIVE 40 412 ACTIVE 41 412 ACTIVE 44 421 ACTIVE 46 340 BLOCKED 39 49 42 ACTIVE 50 453 ACTIVE 51 453 ACTIVE 56 462 BLOCKED 39 58 436 BLOCKED 39 62 278 BLOCKED 46 63 254 BLOCKED 46 67 292 BLOCKED 46 71 301 BLOCKED 46 76 145 BLOCKED 62 78 132 BLOCKED 62 ... ... 65 66
  • 34. 29/01/2019 34 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> create or replace trigger lock_expiry 2 after servererror on database 3 declare 4 l_user varchar2(30); 5 begin 6 if ( is_servererror(30006) ) then ... ... <look up session details> ... 28 raise_application_error(-20000, 29 'User '||l_user||' is causing you grief'); 30 end if; 31 end; 32 / Trigger created. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> select * from T for update wait 60; ERROR at line 1: ORA-00604: error occurred at recursive SQL level 1 ORA-20000: User CONNOR (ext.1234) is causing you grief ORA-06512: at line 6 ORA-30006: resource busy; acquire with WAIT timeout expired 67 68
  • 35. 29/01/2019 35 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. "empowering the users" Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 69 70
  • 36. 29/01/2019 36 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. /*+ GATHER_PLAN_STATISTICS */ 71 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 64 64 for the optimizer 71 72
  • 37. 29/01/2019 37 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 65 65 cardinality is everything Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 66 73 74
  • 38. 29/01/2019 38 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 66 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 75 76
  • 39. 29/01/2019 39 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> explain plan for 2 select count(*) 3 from VEHICLE 4 where MAKE = 'HYUNDAI' and MODEL = 'IONIC'; 77 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> explain plan for 2 select count(*) 3 from VEHICLE 4 where MAKE = 'HYUNDAI' and MODEL = 'IONIC'; SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_PLAN); -------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | -------------------------------------------------------- | 1 | SORT AGGREGATE | | 1 | 1 | |* 2 | TABLE ACCESS FULL| VEHICLE | 20K | 270K | -------------------------------------------------------- 78 77 78
  • 40. 29/01/2019 40 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. ? 69 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. actual versus estimate 80 79 80
  • 41. 29/01/2019 41 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> select /*+ GATHER_PLAN_STATISTICS */ count(*) 2 from VEHICLE 3 where MAKE = 'HYUNDAI' and MODEL = 'IONIC'; COUNT(*) ---------- 114468 81 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> select /*+ GATHER_PLAN_STATISTICS */ count(*) 2 from VEHICLE 3 where MAKE = 'HYUNDAI' and MODEL = 'IONIC'; COUNT(*) ---------- 114468 SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR( 2 NULL, NULL, 'ALLSTATS LAST')); ----------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows | A-Rows | ----------------------------------------------------------------- | 1 | SORT AGGREGATE | | 1 | 1 | 1 | |* 2 | TABLE ACCESS FULL| VEHICLE | 1 | 20K| 114K| ----------------------------------------------------------------- 82 81 82
  • 42. 29/01/2019 42 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. tracing 83 84
  • 43. 29/01/2019 43 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. alter session set sql_trace = true Copyright © 2019, Oracle and/or its affiliates. All rights reserved. C:oraclediagrdbmsdb122db122trace>dir *.trc Volume in drive C is OS Volume Serial Number is 9CB0-0212 Directory of C:oraclediagrdbmsdb122db122trace 27/09/2018 09:18 PM 1,314 db122_ora_10020.trc 20/10/2018 06:21 PM 2,691 db122_ora_10048.trc 30/09/2018 12:21 AM 1,345 db122_ora_10104.trc 29/09/2018 03:18 PM 1,314 db122_ora_10144.trc 21/10/2018 06:21 AM 1,346 db122_ora_10156.trc 11/10/2018 05:18 PM 1,312 db122_ora_1016.trc 02/10/2018 08:49 PM 1,346 db122_ora_10192.trc 29/09/2018 12:21 PM 1,345 db122_ora_10320.trc 12/10/2018 12:21 AM 1,501 db122_ora_10348.trc 15/10/2018 12:18 AM 1,314 db122_ora_10352.trc 13/10/2018 11:21 AM 1,499 db122_ora_1036.trc 28/09/2018 05:18 AM 1,315 db122_ora_10368.trc 18/10/2018 05:18 PM 1,824 db122_ora_10384.trc 05/10/2018 05:18 AM 1,178 db122_ora_10388.trc 28/09/2018 11:21 PM 1,346 db122_ora_10400.trc 14/10/2018 11:21 PM 1,501 db122_ora_10404.trc 30/09/2018 06:25 AM 1,346 db122_ora_10440.trc 04/10/2018 01:18 PM 1,313 db122_ora_10460.trc 04/10/2018 12:18 PM 1,313 db122_ora_10464.trc 08/10/2018 09:18 AM 1,314 db122_ora_10484.trc 27/09/2018 10:21 PM 1,344 db122_ora_10492.trc 85 86
  • 44. 29/01/2019 44 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 09/10/2018 12:18 PM 3,138 db122_ora_11280.trc 15/10/2018 01:18 PM 1,314 db122_ora_11300.trc 16/10/2018 04:21 AM 1,501 db122_ora_11312.trc 06/10/2018 03:21 AM 1,346 db122_ora_11320.trc 15/10/2018 02:22 PM 1,501 db122_ora_11348.trc 18/10/2018 03:21 PM 1,347 db122_ora_11388.trc 16/10/2018 01:21 AM 1,501 db122_ora_11460.trc 06/10/2018 05:21 AM 1,346 db122_ora_11464.trc 18/10/2018 02:21 PM 1,347 db122_ora_11476.trc 15/10/2018 03:21 AM 1,501 db122_ora_11480.trc 29/09/2018 11:21 AM 1,343 db122_ora_1152.trc 04/10/2018 07:21 AM 1,346 db122_ora_11524.trc 07/10/2018 03:21 AM 1,345 db122_ora_11532.trc 28/09/2018 09:18 AM 1,178 db122_ora_11548.trc 02/10/2018 04:21 AM 1,346 db122_ora_11556.trc 20/10/2018 04:18 PM 1,313 db122_ora_11568.trc 05/10/2018 06:21 AM 1,346 db122_ora_11588.trc 28/09/2018 02:18 PM 1,315 db122_ora_11616.trc 16/10/2018 07:21 PM 2,813 db122_ora_11620.trc 30/09/2018 09:21 PM 1,346 db122_ora_11624.trc 15/10/2018 03:18 PM 2,658 db122_ora_11636.trc 01/10/2018 09:21 PM 1,346 db122_ora_11644.trc 18/10/2018 01:21 PM 1,345 db122_ora_11688.trc 07/10/2018 04:21 PM 1,343 db122_ora_1172.trc 18/10/2018 04:21 PM 1,346 db122_ora_11720.trc 23/10/2018 11:21 PM 1,344 db122_ora_11724.trc 20/10/2018 10:21 AM 1,346 db122_ora_11768.trc 05/10/2018 02:21 PM 1,345 db122_ora_11776.trc 28/09/2018 08:18 AM 1,313 db122_ora_11808.trc 11/10/2018 09:21 AM 1,656 db122_ora_11856.trc Copyright © 2019, Oracle and/or its affiliates. All rights reserved. too many trace files 87 88
  • 45. 29/01/2019 45 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> alter session 2 set tracefile_identifier = SALESPGM; Session altered. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> alter session 2 set tracefile_identifier = SALESPGM; Session altered. SQL> host ls *.trc db10r2_ora_3248.trc db10r2_ora_3284.trc db10r2_ora_3356.trc db10r2_ora_3492.trc db10r2_ora_3504_SALESPGM.trc db10r2_ora_3608.trc db10r2_ora_3620.trc ... ... 89 90
  • 46. 29/01/2019 46 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. bonus tip Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> select name, value from v$diag_info; 91 92
  • 47. 29/01/2019 47 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> select name, value from v$diag_info; NAME VALUE ------------------------ ------------------------------------------ Diag Enabled TRUE ADR Base C:ORACLE ADR Home C:ORACLEdiagrdbmsdb122db122 Diag Trace C:ORACLEdiagrdbmsdb122db122trace Diag Alert C:ORACLEdiagrdbmsdb122db122alert Diag Incident C:ORACLEdiagrdbmsdb122db122incident Diag Cdump c:oraclediagrdbmsdb122db122cdump Health Monitor C:ORACLEdiagrdbmsdb122db122hm Default Trace File C:ORACLE...tracedb122_ora_17296.trc Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 93 94
  • 48. 29/01/2019 48 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. too much trace data Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> alter session 2 set events 3 'immediate trace name trace_buffer_on level 1048576'; Session altered. SQL> host ls –l *.trc drw------- oracle dba Jun17 15:10 1048576 db10r2_ora_3248.trc rolling trace window 95 96
  • 49. 29/01/2019 49 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> select PAYLOAD 2 from V$DIAG_TRACE_FILE_CONTENTS 3 where TRACE_FILENAME = 'db122_ora_12484.trc'; PAYLOAD ---------------------------------------------------------------------------- Trace file C:ORACLEdiagrdbmsdb122db122tracedb122_ora_12484.trc Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production Build label: RDBMS_12.2.0.1.0WINDBBP_WINDOWS.X64_180202 Windows NT Version V6.2 ORACLE_HOME = c:oracleproduct12.2.0.1 Node name : XPS13 CPU : 4 - type 8664, 2 Physical Cores Process Affinity : 0x0x0000000000000000 Memory (Avail/Total): Ph:9411M/16235M, Ph+PgF:4292M/20985M Instance name: db122 Redo thread mounted by this instance: 1 ... ... Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 97 98
  • 50. 29/01/2019 50 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 19c Copyright © 2019, Oracle and/or its affiliates. All rights reserved. automatic indexing 99 100
  • 51. 29/01/2019 51 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | • The Automatic Indexing methodology is based on a common approach to manual SQL tuning • It identifies candidate indexes and validates them before implementing • The entire process is full automatic • Transparency is equally important as sophisticated automation – All tuning activities are auditable via reporting 87 Automatic Indexing Methodology Monitor Online Validation Capture Identify Verify Decide Copyright © 2019, Oracle and/or its affiliates. All rights reserved. until then ... 101 102
  • 52. 29/01/2019 52 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. “I need a new index on this 6TB table...” Copyright © 2019, Oracle and/or its affiliates. All rights reserved. “will it speed up things ?” 103 104
  • 53. 29/01/2019 53 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. “I think so” Copyright © 2019, Oracle and/or its affiliates. All rights reserved. virtual indexes 105 106
  • 54. 29/01/2019 54 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> create index TEST on 2 MYTAB ( SALES_DATE ) NOSEGMENT; Index created. data dictionary only Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> begin 2 dbms_stats.generate_stats( 3 'SCOTT', 4 'MYTAB'); 5 end; 6 / 107 108
  • 55. 29/01/2019 55 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> alter session 2 set "_use_nosegment_indexes" = true; SQL> explain plan for 2 select * from MYTAB 3 where sales_date > sysdate-7; -------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| -------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 950 | 90109 | 962 (34)| | 1 | TABLE ACCESS BY INDEX ROWID| MYTAB | 950 | 90109 | 962 (34)| |* 2 | INDEX RANGE SCAN | TEST | 950 | | 962 (50)| -------------------------------------------------------------------------- Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 109 110
  • 56. 29/01/2019 56 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 97 invisible indexes Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 98 SQL> create table T 2 as select * from all_objects; Table created. SQL> create index OBJ_IX on T ( OBJECT_ID ); Index created. SQL> exec dbms_stats.gather_table_stats('','T') PL/SQL procedure successfully completed. 111 112
  • 57. 29/01/2019 57 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 99 SQL> set autotrace traceonly explain SQL> select * from T 2 where OWNER = 'SCOTT' 3 and created > sysdate - 1 4 / --------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| --------------------------------------------------------------- | 0 | SELECT STATEMENT | | 6 | 546 | 281 (1)| |* 1 | TABLE ACCESS FULL| T | 6 | 546 | 281 (1)| --------------------------------------------------------------- Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 100 “Can I index OWNER..” 113 114
  • 58. 29/01/2019 58 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 101 “will it speed up things ?” Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 102 “I know so” 115 116
  • 59. 29/01/2019 59 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 103 SQL> create index NEW_IX on T ( OWNER ); Index created. SQL> select * from T 2 where OWNER = 'SCOTT' 3 and created > sysdate - 1 4 / --------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 6 | 546 | 122 (0)| |* 1 | TABLE ACCESS BY INDEX ROWID| T | 6 | 546 | 122 (0)| |* 2 | INDEX RANGE SCAN | NEW_IX | 4107 | | 10 (0)| --------------------------------------------------------------------------- Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 104 117 118
  • 60. 29/01/2019 60 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 105 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 106 everyone elses queries 119 120
  • 61. 29/01/2019 61 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 106 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 107 before the new index 121 122
  • 62. 29/01/2019 62 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 108 SQL> set autotrace traceonly explain SQL> select * from T 2 where OWNER = 'SYS' 3 and OBJECT_ID between 10 and 8000 4 / --------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 462 | 42042 | 143 (0)| |* 1 | TABLE ACCESS BY INDEX ROWID| T | 462 | 42042 | 143 (0)| |* 2 | INDEX RANGE SCAN | OBJ_IX | 7851 | | 20 (0)| --------------------------------------------------------------------------- Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 109 SQL> set autotrace traceonly stat SQL> select * from T 2 where owner = 'SYS' 3 and object_id between 10 and 8000; 4967 rows selected. Statistics ----------------------------------------------------- 0 recursive calls 0 db block gets 784 consistent gets 15 physical reads 0 redo size 123 124
  • 63. 29/01/2019 63 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 110 after the new index Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 111 SQL> select * from T 2 where owner = 'SYS' 3 and object_id between 10 and 8000 4 / --------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 462 | 42042 | 122 (0)| |* 1 | TABLE ACCESS BY INDEX ROWID| T | 462 | 42042 | 122 (0)| |* 2 | INDEX RANGE SCAN | NEW_IX | 4105 | | 10 (0)| --------------------------------------------------------------------------- the new index 125 126
  • 64. 29/01/2019 64 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 112 SQL> set autotrace traceonly stat SQL> select * from T 2 where owner = 'SYS' 3 and object_id between 10 and 8000; 4967 rows selected. Statistics ------------------------------------------------------ 0 recursive calls 0 db block gets 1522 consistent gets 62 physical reads 0 redo size Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 113 127 128
  • 65. 29/01/2019 65 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 114 the solution ? Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 115 invisible indexes 129 130
  • 66. 29/01/2019 66 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 116 SQL> alter index NEW_IX invisible; Index altered. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 117 SQL> select * from T 2 where owner = 'SYS' 3 and object_id between 10 and 8000 4 / ---------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| ---------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 462 | 42042 | 143 (0)| |* 1 | TABLE ACCESS BY INDEX ROWID| T | 462 | 42042 | 143 (0)| |* 2 | INDEX RANGE SCAN | OBJ_IX | 7851 | | 20 (0)| ---------------------------------------------------------------------------- 131 132
  • 67. 29/01/2019 67 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 118 “gee... thanks for nothing” Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 119 SQL> set autotrace traceonly explain SQL> select * from T 2 where OWNER = 'SCOTT' 3 and created > sysdate - 1 4 / --------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| --------------------------------------------------------------- | 0 | SELECT STATEMENT | | 6 | 546 | 281 (1)| |* 1 | TABLE ACCESS FULL| T | 6 | 546 | 281 (1)| --------------------------------------------------------------- 133 134
  • 68. 29/01/2019 68 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 120 SQL> alter session set 2 optimizer_use_invisible_indexes = true; Session altered. SQL> select * from T 2 where OWNER = 'SCOTT' 3 and created > sysdate - 1 4 / --------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 462 | 42042 | 122 (0)| |* 1 | TABLE ACCESS BY INDEX ROWID| T | 462 | 42042 | 122 (0)| |* 2 | INDEX RANGE SCAN | NEW_IX | 4105 | | 10 (0)| --------------------------------------------------------------------------- Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 121 wrap your SQL to protect others 135 136
  • 69. 29/01/2019 69 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 122 statement level hint USE_INVISIBLE_INDEXES Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 137 138
  • 70. 29/01/2019 70 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. better data guard use... ...for free Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> ALTER DATABASE CONVERT TO SNAPSHOT STANDBY; 10.2 139 140
  • 71. 29/01/2019 71 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. open standby read/write Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> ALTER DATABASE CONVERT TO PHYSICAL STANDBY; SQL> ALTER DATABASE RECOVER MANAGED STANDBY 2 DATABASE DISCONNECT; 10.2 141 142
  • 72. 29/01/2019 72 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. flashback to resetlogs Copyright © 2019, Oracle and/or its affiliates. All rights reserved. resume managed recovery 143 144
  • 73. 29/01/2019 73 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. archives still transmitted Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 145 146
  • 74. 29/01/2019 74 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. faster queries ... no code changes Copyright © 2019, Oracle and/or its affiliates. All rights reserved. faster queries ... no code changes 147 148
  • 75. 29/01/2019 75 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> create table cust_trans 2 ( txn_id int, 3 txn_date date, 4 cust_id int, 5 amt number(10,2) 6 ); 133 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> insert /*+ APPEND */ into cust_trans 2 select rownum, 3 sysdate-1000+rownum/1000 txn_date, 4 trunc(dbms_random.value(1,1000)) cust_id, 5 dbms_random.value(1,100) amount 6 from 7 ( select 1 from dual 8 connect by level <= 10000000 ); 10000000 rows created. SQL> create index cust_trans_ix 2 on cust_trans (cust_id ); Index created. 134 149 150
  • 76. 29/01/2019 76 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> select max(amt) 2 from cust_trans 3 where cust_id = 123; 135 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 136 151 152
  • 77. 29/01/2019 77 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> select max(amt) 2 from cust_trans 3 where cust_id = 123; ------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | ------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 1 | 8 | | 1 | SORT AGGREGATE | | 1 | 8 | | 2 | TABLE ACCESS BY INDEX ROWID BATCHED| CUST_TRANS | 10010 | 80080 | |* 3 | INDEX RANGE SCAN | CUST_TRANS_IX | 10010 | | ------------------------------------------------------------------------------ 137 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> select max(amt) 2 from cust_trans 3 where cust_id = 123; ------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | ------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 1 | 8 | | 1 | SORT AGGREGATE | | 1 | 8 | | 2 | TABLE ACCESS BY INDEX ROWID BATCHED| CUST_TRANS | 10010 | 80080 | |* 3 | INDEX RANGE SCAN | CUST_TRANS_IX | 10010 | | ------------------------------------------------------------------------------ Statistics ----------------------------------------------------- 0 recursive calls 0 db block gets 8867 consistent gets 8854 physical reads 0 redo size 543 bytes sent via SQL*Net to client 607 bytes received via SQL*Net from client 137 153 154
  • 78. 29/01/2019 78 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. CUST 123 CUST 47 CUST 123 CUST 76 CUST 95 CUST 47 CUST 123 155 156
  • 79. 29/01/2019 79 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> alter table cust_trans 2 add clustering by linear order(cust_id); Table altered. SQL> alter table cust_trans move online; Table altered. 12.1 12.2 139 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> select max(amt) 2 from cust_trans 3 where cust_id = 123; ------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | ------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 1 | 8 | | 1 | SORT AGGREGATE | | 1 | 8 | | 2 | TABLE ACCESS BY INDEX ROWID BATCHED| CUST_TRANS | 10010 | 80080 | |* 3 | INDEX RANGE SCAN | CUST_TRANS_IX | 10010 | | ------------------------------------------------------------------------------ 140 157 158
  • 80. 29/01/2019 80 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> select max(amt) 2 from cust_trans 3 where cust_id = 123; ------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | ------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 1 | 8 | | 1 | SORT AGGREGATE | | 1 | 8 | | 2 | TABLE ACCESS BY INDEX ROWID BATCHED| CUST_TRANS | 10010 | 80080 | |* 3 | INDEX RANGE SCAN | CUST_TRANS_IX | 10010 | | ------------------------------------------------------------------------------ Statistics ----------------------------------------------------- 0 recursive calls 0 db block gets 62 consistent gets 23 physical reads 0 redo size 543 bytes sent via SQL*Net to client 607 bytes received via SQL*Net from client 140 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. "but I'm not on 12.2" 159 160
  • 81. 29/01/2019 81 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. dbms_redefinition Copyright © 2019, Oracle and/or its affiliates. All rights reserved. the marketing spin... 161 162
  • 82. 29/01/2019 82 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> desc EMP Name Null? Type ----------------------- -------- ---------------- EMPNO NOT NULL NUMBER(4) ENAME VARCHAR2(10) JOB VARCHAR2(9) MGR NUMBER(4) HIREDATE DATE SAL NUMBER(7,2) COMM NUMBER(7,2) DEPTNO NUMBER(2) Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> desc EMP Name Null? Type ----------------------- -------- ---------------- EMPNO NOT NULL NUMBER(8) SAL_PLUS_10PCT NUMBER(7,2) 163 164
  • 83. 29/01/2019 83 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. online Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> create table EMP_NEW_DEFN( 2 larger_empno number(8), 3 salary_plus_10pct number(7,2)); 165 166
  • 84. 29/01/2019 84 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> create table EMP_NEW_DEFN( 2 larger_empno number(8), 3 salary_plus_10pct number(7,2)); SQL> begin 2 DBMS_REDEFINITION.START_REDEF_TABLE( - 3 UNAME =>'SCOTT', 4 ORIG_TABLE =>'EMP', 5 INT_TABLE =>'EMP_NEW_DEFN', 6 COL_MAPPING=> 'empno larger_empno, sal*1.1 salary_plus_10pct' 7 end; Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> exec DBMS_REDEFINITION.FINISH_REDEF_TABLE( - 'SCOTT','EMP','EMP_NEW_DEFN'); 167 168
  • 85. 29/01/2019 85 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> exec DBMS_REDEFINITION.FINISH_REDEF_TABLE( - 'SCOTT','EMP','EMP_NEW_DEFN'); SQL> desc EMP Name Null? Type -------------------------- -------- ------------------- LARGER_EMPNO NUMBER(8) SALARY_PLUS_10PCT NUMBER(7,2) Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 169 170
  • 86. 29/01/2019 86 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. PL/SQL programs triggers ProC Java Reports ADF adhoc scripts BI Publisher layer APEX Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 171 172
  • 87. 29/01/2019 87 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> begin 2 DBMS_REDEFINITION.START_REDEF_TABLE( - 3 UNAME =>'SCOTT', 4 ORIG_TABLE =>'EMP', 5 INT_TABLE =>'EMP_SAME_DEFN', 6 7 end; Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> begin 2 DBMS_REDEFINITION.START_REDEF_TABLE( - 3 UNAME =>'SCOTT', 4 ORIG_TABLE =>'EMP', 5 INT_TABLE =>'EMP_SAME_DEFN', 6 7 end; ORDERBY_COLS=>'ename'); 173 174
  • 88. 29/01/2019 88 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. DBMS_XPLAN 175 176
  • 89. 29/01/2019 89 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. SQL> explain plan for ... SQL> select * from 2 table(dbms_xplan.display_plan) Copyright © 2019, Oracle and/or its affiliates. All rights reserved. extensions 177 178
  • 90. 29/01/2019 90 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. ... the (in)famous hint ignore issue 157 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 158 SQL> select * 2 from emp e, 3 dept d 4 where e.deptno = d.deptno 5 and d.dname = 'SALES'; -------------------------------------------------------- | Id | Operation | Name | Rows | -------------------------------------------------------- | 0 | SELECT STATEMENT | | 5 | | 1 | MERGE JOIN | | 5 | |* 2 | TABLE ACCESS BY INDEX ROWID| DEPT | 1 | | 3 | INDEX FULL SCAN | PK_DEPT | 4 | |* 4 | SORT JOIN | | 14 | | 5 | TABLE ACCESS FULL | EMP | 14 | -------------------------------------------------------- 179 180
  • 91. 29/01/2019 91 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 159 "I want a hash join" Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 160 SQL> select /*+ use_hash(d) */ * 2 from emp e, 3 dept d 4 where e.deptno = d.deptno 5 and d.dname = 'SALES'; -------------------------------------------------------- | Id | Operation | Name | Rows | -------------------------------------------------------- | 0 | SELECT STATEMENT | | 5 | | 1 | MERGE JOIN | | 5 | |* 2 | TABLE ACCESS BY INDEX ROWID| DEPT | 1 | | 3 | INDEX FULL SCAN | PK_DEPT | 4 | |* 4 | SORT JOIN | | 14 | | 5 | TABLE ACCESS FULL | EMP | 14 | -------------------------------------------------------- 181 182
  • 92. 29/01/2019 92 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. ? 161 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 162 /*+ use_hash(d) */ 183 184
  • 93. 29/01/2019 93 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 162 /*+ use_hash(d) */ if joining into DEPT... use a hash join Copyright © 2019, Oracle and/or its affiliates. All rights reserved. we're not... 163 185 186
  • 94. 29/01/2019 94 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 164 -------------------------------------------------------- | Id | Operation | Name | Rows | -------------------------------------------------------- | 0 | SELECT STATEMENT | | 5 | | 1 | MERGE JOIN | | 5 | |* 2 | TABLE ACCESS BY INDEX ROWID| DEPT | 1 | | 3 | INDEX FULL SCAN | PK_DEPT | 4 | |* 4 | SORT JOIN | | 14 | | 5 | TABLE ACCESS FULL | EMP | 14 | -------------------------------------------------------- Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 165 if we want to join into DEPT... ...we must be starting with EMP 187 188
  • 95. 29/01/2019 95 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 166 SQL> select /*+ leading(e) use_hash(d) */ * 2 from emp e, 3 dept d 4 where e.deptno = d.deptno 5 and d.dname = 'SALES'; --------------------------------------------------- | Id | Operation | Name | Rows | Bytes | --------------------------------------------------- | 0 | SELECT STATEMENT | | 5 | 285 | |* 1 | HASH JOIN | | 5 | 285 | | 2 | TABLE ACCESS FULL| EMP | 14 | 518 | |* 3 | TABLE ACCESS FULL| DEPT | 1 | 20 | --------------------------------------------------- Copyright © 2019, Oracle and/or its affiliates. All rights reserved. not enough hints 167 189 190
  • 96. 29/01/2019 96 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 168 "hints are like violence… if they do not work, use more" Copyright © 2019, Oracle and/or its affiliates. All rights reserved. back to dbms_xplan 169 191 192
  • 97. 29/01/2019 97 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 170 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') END_OUTLINE_DATA */ Copyright © 2019, Oracle and/or its affiliates. All rights reserved. consider SQL Plan Management 171 193 194
  • 98. 29/01/2019 98 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. bonus tip ! 172 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 173 SQL> select /*+ INDEX(accounts_pk) */ 2 from ACCOUNTS 3 where ... SQL> select /*+ INDEX(a) */ 2 from ACCOUNTS 3 where ... SQL> select /*+ INDEX(scott.accounts) */ 2 from SCOTT.ACCOUNTS 3 where ... SQL> select /* INDEX(A) */ 2 from SCOTT.ACCOUNTS A 3 where ... 195 196
  • 99. 29/01/2019 99 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 19c 174 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 175 SQL> SELECT * 2 from table(dbms_xplan.display(.... , format=>'typical +HINT_REPORT')) 197 198
  • 100. 29/01/2019 100 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. finding bad SQL ... 199 200
  • 101. 29/01/2019 101 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. ... is probably bad SQL Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 179 SQL> select sql_fulltext 2 from v$sql 3 where buffer_gets > 1000000 or 4 executions > 10000 or 5 disk_reads > 100000; SQL_FULLTEXT ----------------------------------------------- SELECT ... FROM ... 201 202
  • 102. 29/01/2019 102 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 179 SQL> select sql_fulltext 2 from v$sql 3 where buffer_gets > 1000000 or 4 executions > 10000 or 5 disk_reads > 100000; SQL_FULLTEXT ----------------------------------------------- SELECT ... FROM ... Copyright © 2019, Oracle and/or its affiliates. All rights reserved. you can do better 180 203 204
  • 103. 29/01/2019 103 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 181 SQL> select sql_fulltext 2 from v$sqlstats 3 where buffer_gets > 1000000 or 4 executions > 10000 or 5 disk_reads > 100000; SQL_FULLTEXT ----------------------------------------------- SELECT ... FROM ... Copyright © 2019, 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)." 182 205 206
  • 104. 29/01/2019 104 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 184 sqlplus hash tags 207 208
  • 105. 29/01/2019 105 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 185 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 186 SQL> select SAL 2 from EMP 3 where 209 210
  • 106. 29/01/2019 106 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 186 SQL> select SAL 2 from EMP 3 where "hmmmm....." Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 187 SQL> select SAL 2 from EMP 3 where 211 212
  • 107. 29/01/2019 107 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 187 SQL> select SAL 2 from EMP 3 where 4 #desc EMP Name Null? Type ----------------------------- -------- ------------- EMPNO NOT NULL NUMBER(4) ENAME VARCHAR2(10) JOB VARCHAR2(9) ... 4 job = 'CLERK'; SAL ---------- 800 1100 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 188 SQL> declare 2 x int; 3 begin 4 select max(sal) 5 into x 6 from emp; 7 8 dbms_output.put_line(x); 213 214
  • 108. 29/01/2019 108 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 188 SQL> declare 2 x int; 3 begin 4 select max(sal) 5 into x 6 from emp; 7 8 dbms_output.put_line(x); 9 #set serverout on 9 end; 10 / Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 188 SQL> declare 2 x int; 3 begin 4 select max(sal) 5 into x 6 from emp; 7 8 dbms_output.put_line(x); 9 #set serverout on 9 end; 10 / 10000 215 216
  • 109. 29/01/2019 109 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 190 sqlplus error logging 217 218
  • 110. 29/01/2019 110 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 191 SQL> set errorlogging on Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 192 SQL> set errorlogging on SQL> desc SPERRORLOG Name Type ------------------------------------- ---------------- USERNAME VARCHAR2(256) TIMESTAMP TIMESTAMP(6) SCRIPT VARCHAR2(1024) IDENTIFIER VARCHAR2(256) MESSAGE CLOB STATEMENT CLOB 219 220
  • 111. 29/01/2019 111 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 193 SQL> select * from THE_WRONG_NAME; select * from THE_WRONG_NAME * ERROR at line 1: ORA-00942: table or view does not exist Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 193 SQL> select * from THE_WRONG_NAME; select * from THE_WRONG_NAME * ERROR at line 1: ORA-00942: table or view does not exist SQL> desc THE_WRONG_NAME; ERROR: ORA-04043: object THE_WRONG_NAME does not exist 221 222
  • 112. 29/01/2019 112 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 194 SQL> select timestamp, message, statement 2 from SPERRORLOG; TIMESTAMP ----------------------------------------------------- MESSAGE ----------------------------------------------------- STATEMENT ----------------------------------------------------- 01-APR-08 02.29.58.000000 PM ORA-00942: table or view does not exist select * from THE_WRONG_NAME 01-APR-08 02.29.58.000000 PM ORA-04043: object THE_WRONG_NAME does not exist desc THE_WRONG_NAME; Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 195 installation scripts SQL> set errorlogging on SQL> @create_all_objects 223 224
  • 113. 29/01/2019 113 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 197 sqlplus / sqlcl transaction safety 225 226
  • 114. 29/01/2019 114 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 198 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 198 227 228
  • 115. 29/01/2019 115 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 198 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 199 SQL> set exitcommit 229 230
  • 116. 29/01/2019 116 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. wrap up Copyright © 2019, Oracle and/or its affiliates. All rights reserved. poaching ideas is fine 231 232
  • 117. 29/01/2019 117 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. learn something new Follow and Subscribe! youtube bit.ly/youtube-connor blog bit.ly/blog-connor twitter bit.ly/twitter-connor 233 234