Buy Quest Products Buy Guy'S Book Buy Quest Products: Top Tips For Oracle SQL Tuning
Buy Quest Products Buy Guy'S Book Buy Quest Products: Top Tips For Oracle SQL Tuning
BUY GUY’S
tuning
BUY
BUY QUEST
QUEST
PRODUCTS
Guy Harrison
PRODUCTS
BOOK
Senior Software Architect,
Quest Software
Top 10 Oracle SQL tuning tips
QUERY_PLAN
--------------------------------------------
SELECT STATEMENT
SORT AGGREGATE
TABLE ACCESS FULL SALES
Interpreting EXPLAIN PLAN
– SQLab can also retrieve the execution statistics that are otherwise only
available through tkprof
Hint #3: Index wisely
Merge 3 indexes 40
Index on 6
Surname+f irstname+DOB
Index on 4
Surname+f irstname+dob+phoneo
Logical IO
Bit-map indexes
– Contrary to widespread belief, can be effective when there
are many distinct column values
– Not suitable for OLTP however
100
10
E la p s e d tim e ( s )
0.1
0.01
1 10 100 1,000 10,000 100,000 1,000,000
Distinct values
Bitmap index B*-Tree index Full table scan
Hint #4: Reduce parsing
– Missing Index
– Using “!=“, “<>” or NOT
• Use inclusive range conditions or IN lists
– Looking for values that are NULL
• Use NOT NULL values with a default value
– Using functions on indexed columns
• Use “functional” indexes in Oracle8i
Hint #7: Optimize necessary table
scans
There are many occasions where a table scan is the only option.
If so:
– Consider parallel query option
– Try to reduce size of the table
• Adjust PCTFREE and PCTUSED
• Relocate infrequently used long columns or BLOBs
• Rebuild when necessary to reduce the high water mark
– Improve the caching of the table
• Use the CACHE hint or table property
• Implement KEEP and RECYCLE pools
– Partition the table (if you really seek a large subset of data)
– Consider the fast full index scan
Fast full index scan performance
– Use when you must read every row, but not every column
– Counting the rows in a table is a perfect example
0 5 10 15 20
31.01
EXISTS no semi-join but with index
6.83
EXISTS - merge semi-join
6.69
IN-based subquery
Star_transformation
Star
0.24
Concatenated index
0.01
0 1 2 3 4 5 6 7 8 9 10
60
50
40
Elaps ed tim e
30
20
10
0
0 20 40 60 80 100 120 140 160 180 200 220 240 260 280 300
Array size
Hint #10: Consider PL/SQL for
“tricky” SQL
With SQL you specify the data you want, not how to
get it. Sometime you need to specifically dictate your
retrieval algorithms.
For example:
– Getting the second highest value
– Doing lookups on a low-high lookup table
– Correlated updates
– SQL with multiple complex correlated subqueries
– SQL that seems to hard to optimize unless it is broken into
multiple queries linked in PL/SQL
Oracle8i PL/SQL Improvements
– Array processing
– NOCOPY
– Temporary tables
– The profiler
– Dynamic SQL
Bonus hint: When your SQL is
tuned, look to your Oracle
configuration
When SQL is inefficient there is limited benefit in investing in
Oracle server or operating system tuning.