How I Approach Tuning a SQL Statement

Comments
-
a very good outline. we know tuning a SQL can be a very big topic.
but, can you be a little more detail and speak out your most 'exciting experience' and the most useful ref./doc. to be read ??
thanks a lot.
0 -
a very good outline. we know tuning a SQL can be a very big topic.
Thats right, Really its nice outline,but, can you be a little more detail and speak out your most 'exciting experience' and the most useful ref./doc. to be read ??
thanks a lot.
That will be a great for us to understand the basis of tuning methods. Please share the details about your tuning experience where we can learn more from you.
Best,
Mohammed Yousuf
Sr.Oracle DBA ( Team Lead)
IBM, Bangalore.
India,
0 -
Thats right, Really its nice outline,
Tuning should ALWAYS be performed in a top down approach. This will give you the biggest bang for the buck.That will be a great for us to understand the basis of tuning methods. Please share the details about your tuning experience where we can learn more from you.
Best,
Mohammed Yousuf
Sr.Oracle DBA ( Team Lead)
IBM, Bangalore.
India,
Start with the hardware. Are drives fast enough, do you have enough memory, etc.
After hardware, tune the OS. Do you have sufficient swap space, have you turned OFF disk cache, do you have enough processes, files, etc. set for the Oracle user
Next tune Oracle, tune your init file, looking at things like cursor sharing, index_cost_ parameters, and anything else in the init file that has a direct effect on the optimizer. Do not forget to look at things like sufficient buffers, etc.
Finally, tune the sql statements. To make sure you are tuning the correct statements, use statspak or AWR to give you a list of the top 5 statements and top 5 wait events. Don't waste time trying to tune something that will only give you a marginal return, be sure of what needs to be tuned.
HTH
Peter
0 -
trying to outsmart the optimizer is not a good use of your time.
tuning by cardinality feedback is much simpler and more productive, IMO, and it ensures that if there is a problem with stats, you'll know what it is, and fixing that problem, will fix many queries, not necessarily just the one you are looking at.
https://portal.hotsos.com/events/SYM06/speakers/abstracts/tuning-by-cardinality-feedback-method-and-examples
The presentation discusses a method of tuning which is based on the premise that whenever the CBO chooses a bad plan it can be traced back to an error in the estimation of the cardinality of one or more row sources. Tuning by cardinality feedback thus looks at discrepancies between estimated and real row source cardinalities of an execution plan and attempts to find ways to correct the CBO’s error in estimation, ultimately trusting it to find a better plan based on the corrected, more accurate estimates.
----
nowadays with gather_plan_statistics it is quite easy to see where the optimizer is going astray on the occasions that it does. if you fix/correct it with better stats or a sql profile, the best plan will be found without you trying every combination out for yourself.
http://kerryosborne.oracle-guy.com/2010/02/gather_plan_statistics/
0 -
Tuning should ALWAYS be performed in a top down approach. This will give you the biggest bang for the buck.
Though a top down approach is receommended by some practitioners, it never ever gives you the biggest bang.Start with the hardware. Are drives fast enough, do you have enough memory, etc.
After hardware, tune the OS. Do you have sufficient swap space, have you turned OFF disk cache, do you have enough processes, files, etc. set for the Oracle user
Next tune Oracle, tune your init file, looking at things like cursor sharing, index_cost_ parameters, and anything else in the init file that has a direct effect on the optimizer. Do not forget to look at things like sufficient buffers, etc.
Finally, tune the sql statements. To make sure you are tuning the correct statements, use statspak or AWR to give you a list of the top 5 statements and top 5 wait events. Don't waste time trying to tune something that will only give you a marginal return, be sure of what needs to be tuned.
HTH
Peter
Most production systems over a period of time are most optimised in terms of hardware/cache etct etc...
Tuning init usually results in upping parameter values which in turns needs more resources and this causes a loop.
The biggest bang comes from tuning your SQl's- with SP /AWR it is easy to isolate the most costly SQL's/ AWR also gives you an impact assesment for each SQL.
Once you have isolated your expensive SQL - then it would make sense you plan it / index / statistics / histograms et al to arrive at a reaonable cost.
But an top SQL from the AWR normally would not lead you to the right SQL for an particular instance - because the busninees group who is complaining about performance might be using a different one. Talk to them first, see their business rules, see if you can isolate their problem SQL and then try to tune it
If you are not tuning the right SQl then any benefits you derieve are useless.
hotsos profiling helps. Extended tracing is crucial; but the trick is to isolate the problem SQL first.
Nizar
0 -
trying to outsmart the optimizer is not a good use of your time.
Newbie User95935 is right. If you find the best statistics for your objects, (which sometimes means no statistics at all), you will improve times for the all the sql and not only one sql... In my experience, I get better performance with less estimate percent when using DBMS_STATS in 9i and 10g (sometimes I generate stats with estimate of 5 and get better times), and surprisingly in 11g too, starting with 20 - 25 estimate percent... now I am testing to generate histograms only in columns that are part of an equijoin...
tuning by cardinality feedback is much simpler and more productive, IMO, and it ensures that if there is a problem with stats, you'll know what it is, and fixing that problem, will fix many queries, not necessarily just the one you are looking at.
https://portal.hotsos.com/events/SYM06/speakers/abstracts/tuning-by-cardinality-feedback-method-and-examples
The presentation discusses a method of tuning which is based on the premise that whenever the CBO chooses a bad plan it can be traced back to an error in the estimation of the cardinality of one or more row sources. Tuning by cardinality feedback thus looks at discrepancies between estimated and real row source cardinalities of an execution plan and attempts to find ways to correct the CBO’s error in estimation, ultimately trusting it to find a better plan based on the corrected, more accurate estimates.
----
nowadays with gather_plan_statistics it is quite easy to see where the optimizer is going astray on the occasions that it does. if you fix/correct it with better stats or a sql profile, the best plan will be found without you trying every combination out for yourself.
http://kerryosborne.oracle-guy.com/2010/02/gather_plan_statistics/I don't like profiles, I think oracle by itself is enough smart to find out the best execution plan and some dba's are too scared from full scan tables, you just give oracle the right stats...
Regards.
0 -
Newbie User95935 is right. If you find the best statistics for your objects, (which sometimes means no statistics at all), you will improve times for the all the sql and not only one sql... In my experience, I get better performance with less estimate percent when using DBMS_STATS in 9i and 10g (sometimes I generate stats with estimate of 5 and get better times), and surprisingly in 11g too, starting with 20 - 25 estimate percent... now I am testing to generate histograms only in columns that are part of an equijoin...
Thanks for sharing your 'experienced' knowledge.I don't like profiles, I think oracle by itself is enough smart to find out the best execution plan and some dba's are too scared from full scan tables, you just give oracle the right stats...
Regards.
0