 |
Blogs Toad and Database Commentaries |
Toad World blogs are a mix of insightful how-tos from Quest experts as well as their commentary on experiences with new database technologies.
Do you have a topic that you'd like discussed? We'd love to hear from you. Send us your idea for a blog topic.

 |
 |
|
|
 |
 |
Location: Blogs
Mike Ault's Blog
|
|
| MikeA |
Wednesday, October 18, 2006 4:54 PM |
|
When I started working with Oracle in 1990 there weren’t many SQL tuning tools available. At most you had the Oracle supplied tools which allowed you to capture an explain plan and minimal tracing. Most SQL tuning consisted of either encouraging the use to a particular index by making sure the column in the index was on the leading edge of the index or, defeating the use of the index through null concatenation to character values or adding zero or multiplying by one for numeric values. I can’t recall what access paths were actually available but not much more than full table scan or nested loops I am sure.
Gradually Oracle and other database providers added additional methods of optimization by way of additional access paths such as sort-merge-join, hash-joins, and various new types of indexes. Perhaps it is just my personal bias but Oracle seems to be one of the first to come out with the new features, then the others follow. As an example, bitmap indexes and bitmap-join indexes where added to Oracle and in some cases still aren’t available in other systems. Of course the number of tools for tuning databases has also increased, both those provided by the vendors and those provided by third-party vendors such as Quest.
Now tuning has become a fairly complex process where you need to figure out the best index types, the best access paths and the best table order in which to perform joins. Most databases provide a form of cost-based optimization where a numeric cost is associated with each possible path and the one with the lowest cost is utilized automatically. Most of these cost models utilize IO cost (as a function of time required) as the predominate contributor to the time required to resolve a query and return results. Now, with larger and larger memories and faster CPUs some are moving to a more CPU/memory based costing model.
In Oracle by simply taking system statistics (IO timings for single and multi-block reads and CPU speed values) the optimizer will calculate both IO and CPU/memory based costs and utilize the path with gives the lowest overall cost. However, using cost-based optimization means that the various statistics required for the cost calculations must be kept up-to-date; row counts, block sizes, index width and depth and many other statistics will determine the cost of a particular SQL statement. Without accurate values for these parameters Oracle will make bad choices for access paths and indexes as will other database systems that utilize a cost based optimizer.
The DBA and developer must work together to ensure that proper indexes and SQL techniques are utilized to guarantee optimal application performance. Any tools utilized to perform development and tuning operations must work together seamlessly allowing not only monitoring of SQL performance but analysis of tuning alternatives and the ability to test alternatives in a database safe manner.
|
| Copyright ©2006 Quest Software Inc. |
| Permalink |
Trackback |
Comments (8)
|
By Mike on
Tuesday, October 24, 2006 7:48 AM |
| Complex process? Huh? CBO automates 80% plus is not complex. |
|
|
By mikerault on
Tuesday, October 24, 2006 7:49 PM |
Mike,
Try tuning a query that the optimizer has "failed" to tune. It can be a fairly complex and time consuming process. Of course some times it is as easy as adding an index, other times it is much more complex.
If you want to see what the optimizer goes through on your behalf try a 10053 trace, even for a two table join the number of steps is incredible.
The number of join paths, indexes used, possible hints to be utilized makes SQL tuning more complex as the number of tables and indexes increases. You say that the optimizer gets you to 80 percent, even it if gets you to 80 percent (assuming all statistics it used and choices it makes are correct) That is still 20 percent of the tuning effort that will require DBA action.
Mike |
|
|
By Mike on
Wednesday, October 25, 2006 2:48 PM |
| I agree |
|
|
By KobieTau on
Thursday, October 26, 2006 12:26 PM |
Mike,
Hi. I'll bite - what is a 10053 trace?
How do I run one? What packages need to be loaded first (catproc, spcpkg )??
What versions is it good on? 9i, 8i, 10g?
Thanks in advance, Allen |
|
|
By mikerault on
Thursday, October 26, 2006 6:58 PM |
As far as I know it is good on all versions, at least I first started hearing about it in verison 8. It is actually quite simple to use:
1. Connect to Oracle using SQL*Plus as the appropriate user 2. Issue the following series of commands: SQL> ALTER SESSION SET EVENTS '10053 trace name context forever, level 1'; Session altered. 3. SQL> EXPLAIN PLAN FOR --SQL STATEMENT--; Explained. SQL> exit 4. Look in the udump directory for the trace (may be easier if you clean out the udump before hand.
Watch out! For a simple 2 table trace this is several pages, it grows exponentially with the number of tables in the join.
Mike |
|
|
By KobieTau on
Friday, October 27, 2006 11:47 AM |
Mike,
Hi. Thanks. Yes it worked as posted, just needt to add my own -- SQL STATEMENT --.
Interesting to note that:
1) the trace file was created on the remote server holding the Oracle instance where it ran - not where I ran TOAD from.
2) I could run a trace on the table the user owned and had access to like the view user_tables and DUAL but not on V$SESSION. V$session I get an Ora-01039 Isufficiant privledges for underlying objects of the view. As a DBA I could connect as SYS/SYSDBA and try it but "Life gives you the test before the lesson".
3) Multiple explains go in the same trace file - is that from the ".. trace name context forever" part of the syntax. Is there a way to turn tracing off once started?
Is level 1 the most detailed?
In short, thank you. Trace stuff is not something I have tried from TOAD before.
Allen "The best things in life are not things" |
|
|
By mikerault on
Sunday, October 29, 2006 6:05 PM |
From my research I have only found reference to level 1, you can try other levels if you wish, they will:
1. Do nothing 2. Cause a syntax error 3. Bring tons of wonderful information that no one knows about yet
Have fun!
Mike |
|
|
By Norm on
Wednesday, November 08, 2006 3:11 AM |
Hi Mike,
from Julian Dyk'e web site (http://julian.dyke.users.btopenworld.com/Oracle/Diagnostics/Events/EventReference.html#10053) :
Event 10053 - Dump Optimizer Decisions
This event can be used to dump the decisions made by the optimizer when parsing a statement. Level 1 is the most detailed
For example
ALTER SESSION SET EVENTS '10053 trace name context forever, level 1';
Levels are
Level Action 1 Print statistics and computations 2 Print computations only
Cheers, Norm. [TeamT] |
|
|
 |
 |
|
 |
|
 |
|
|