database performance, sql tuning and data visualization
Tuesday, November 17, 2009
Explain Plan vs Real Plan on Oracle
A good part of my presentation Friday at NoCOUG was on explain plan command being an estimate of the actual execution plan. Now on the Oracle-L forum list, I see the same question being asked "Under what conditions, could the plan I get out of ‘explain plan’ differ from what I get from running the sql statement?" and Tanel Poder giving a succinct clear list of reasons:
main reasons: 1) The optimizer statistics the EXPLAIN PLAN ends up using are different from the statistics the other session ended up using 2) Explain plan does not use bind variable peeking thus will not optimize for current bind variable values 3) Explain plan treats all bind variables as VARCHAR2, thus you ma have implicit datatype conversion happening during the plan execution, (meaning to_char,to_number functions are added around variables/columns) and this for example may make optimizer to ignore some indexes if you get unlucky.
with the caveat:
Little correction to point number 3 - of course explain plan doesn't really execute the plan so the implicit datatype conversion you see is in the explained plan only, but if you actually execute the statement (with correct bind datatypes) then there's no implicit datatype conversion. And that's where the difference comes from...
Before working at Embarcadero I redesigned the performance pages in Oracles OEM 10g (see a before and after example). I am on the patent from the team for our tuning methodology (Patents: 20060059205) . I freely provide graphical monitoring tools such as ASHMON (TCL/TK) as well as scripts to profile database load such as S-ASH ie Simulated ASH (PLSQL). S-ASH, ASHMON and more are available at my old site http://ashmasters.com/ . I have made available C code to directly read profiling data out of Oracle's memory structures, called Direct Memory Access. I speak at conferences and give classes around the world.This blog has some of my new ideas on Visual SQL Tuning (VST), work on DB Optimizer, possibly some past material on DB performance monitoring as well as lots of references and pointers to other information on the web that I find important and worth emphasizing.