Oracle SQL High Performance Tuning: Guy Harrison Director, R&D Melbourne
Oracle SQL High Performance Tuning: Guy Harrison Director, R&D Melbourne
Guy Harrison
Director, R&D Melbourne
www.guyharrison.net
Guy.harrison@quest.com
@guyharrison
Introductions
Agenda
Optimizer inputs
Table and index
Cardinality
Structure
Estimates
DB parameters
IO and CPU
And config
Estimates
Object Statistics
System Statistics
Cost estimate
System statistics
DBMS_STATS.gather_system_stats
Histograms
20,000
18,000
16,000
14,000
12,000
10,000
8,000
Number of rows
6,000
4,000
2,000
0
Boys
Girls
And name=Sue
10
Histogram limitations
Height balanced histograms dont have
the granularity we might want or
expect.
13
SQL Trace/Tkprof
Best drilldown at the session level
14
Mining V$SQL
15
DBMS_XPLAN
SQL> SELECT *
'TYPICAL -BYTES'));
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------SQL_ID
------------------------------------SELECT
-------------------------------------------------------------------------------------| Id
| Operation
| Name
| Rows
-------------------------------------------------------------------------------------|
0 | SELECT STATEMENT
1 |
SORT ORDER BY
106 |
26
(8)| 00:00:01 |
2 |
NESTED LOOPS
106 |
25
(4)| 00:00:01 |
3 |
MERGE JOIN
107 |
24
(5)| 00:00:01 |
4 |
107 |
20
(0)| 00:00:01 |
5 |
| EMP_JOB_IX
107 |
12
(0)| 00:00:01 |
|*
6 |
19 |
(25)| 00:00:01 |
7 |
| JOBS
19 |
(0)| 00:00:01 |
8 |
1 |
(0)| 00:00:01 |
|*
9 |
1 |
(0)|
| DEPT_ID_PK
26 (100)|
16
17
19
20
22
23
24
25
1000
Full Scan no caching
Index sorted data, no caching
Index unsorted, cached data
Full Table scan, cached data
100
Elaspe d Tim e (s )
10
1
0
10
20
30
40
50
60
70
80
90
100
last,first,birthyear,id
3
SELECT cust_id
FROM sh.customers c
WHERE cust_first_name = 'Connor'
last,first,BirthYear
last+first name
last name
63
None
1459
200
400
600
800
Logical IO
1000
1200
1400
1600
Bitmap indexes
28
Bitmap indexes
100
10
0.1
0.01
1
10
100
1000
10000
100000
1000000
B*-Tree index
29
Vertical partitioning
30
Joins
31
Optimizing joins
Best join order
Eliminate rows as early as possible
Join Type:
Nested loops
Optimize the join index
Sort merge
Avoid, esp. if memory scarce
Hash join
Avoid multi-pass executions
32
2.2
time_id
Indexing
3.14
prod_id,channel_id
23.43
prod_id
48.36
No Index
546.55
100
200
Elapsed time (s)
300
400
500
600
200
Disk Sort
150
50
In Memory
0
1
10
100
Workarea Memory (MB)
Hash Join
1000
13,480
Bitmap index
Access Path
1,524
2000
4000
6000
8000
10000
12000
14000
Logical IO
36
Sorting
37
Multi-pass
Disk Sort
Time
Single Pass
Disk Sort
Memory Sort
Table/Index IO
CPU Time
Temp Segment IO
38
3500
3000
Multi-pass
2500
Disk Sort
2000
1500
1000
Single Pass
Disk Sort
500
0
300
250
200
150
100
50
39
400
350
300
250
Size Limit (MB)
200
150
100
50
0
0
200
400
600
800
1000
1200
PGA_AGGREGATE_TARGET (MB)
Max process PGA
1400
1600
1800
2000
41
Grouping
42
42
Hash Group by
hint
1000
2000
3000
4000
5000
6000
7000
8000
9000
Self Join
Table IO
temp IO
CPU
Partition by
5000
10000
15000
20000
25000
Pivot vs CASE
CASE
IO Time
CPU Time
PIVOT
2000
4000
6000
8000
10000
12000
14000
16000
45
18000
DML
46
16,316
14,285
Number of indexes
12,727
10,719
8,691
6,671
1 (PK only)
1,191
2,000
4,000
6,000
8,000
10,000
12,000
14,000
16,000
47
18,000
Multi-table insert
Multi-table insert
Multi-table insert
Insert both
Insert EMEA
Insert US
Two Inserts
10
49
Merge
MERGE
Merge
Insert
Update
INSERT + UPDATE
3.89
3.71
6
Elapsed Time (s)
3.32
10
12
Merge optimization
7.96
4.23
Array insert
Direct path
NOLOGGING
Commit frequency
NOWAIT and BATCH redo logging
53
Other topics
Database logical design
Clustering and exotic physical options
PL/SQL
Parallel SQL
Application optimization (Arrays, bind variables)
54
Conclusion
Maximizing optimizer accuracy provides the best return on
investment
Sub-optimal optimizations are unfortunately inevitable
Key SQL tuning skills are therefore:
Configuring Oracle to maximize optimizer effectiveness
Detection of sub-optimal SQLs
Techniques for coercing SQLs to acceptable performance
55
Thank You
Danke Schn
Gracias
Merci
Obrigado