Lately I’ve been busy on projects and research so I’m putting more and more stuff on my wiki/braindump… and really I need to catch up on blogging.
I have a longer draft post about SQLTXPLAIN.. but I haven’t finished it yet so I’ll just go with the quick post for now.
I’ve been using SQLTXPLAIN for quite a while, and I can say I’m a really big fan. It’s a cool tool to use for systematic SQL Tuning so I got them all neatly documented here http://karlarao.tiddlyspot.com/#SQLTXPLAIN.
BTW, Carlos Sierra, the author of the tool will present at Hotsos 2012 http://www.hotsos.com/sym12/sym_speakers_sierra.html so I may drop by the conference and say hello :)
The wiki link will probably show you all the things you need to know about SQLTXPLAIN. My personal use case favorites would be the following:
- Mining 10053 output
- On the execution plan view of the main HTML report whenever you hover on each step of the plan it will pop up an info about the Query Block (QB) details which you can mine on the raw 10053 text file that is also on the zip file. This is helpful when troubleshooting the specific part of the SQL where it has gone wrong.
- Instant SQL Monitor output
- The HTML and text versions of SQL Monitor is readily available for the particular SQL_ID you are troubleshooting ;)
- Compare good/bad plan of SQLs
- This is pretty handy because the output report of the SQLT-compare highlights the difference in red text. So instead of chasing some delta numbers, you can just go straight to the red text!
- Fix bad stats
- Let’s say you have a prod and dev that have completely different run times. And you found out that the problem is the stats, you can do a SQLT on the good plan and transfer the stats to the other environment. You will be using the sqltimp.sql for this
- Transfer stored outline/profiles
- This makes use of exp/imp to transfer and outline + DBMS_SQLTUNE for the SQL Profile
- Manual SQL Profile is readily available as sqlt_<sqlt_id>_sqlprof.sql or can be created using sqlt/utl/coe_xfr_sql_profile.sql
- Reproducing an execution plan from one system to another and Creating test cases
- I usually pull SQLT from the server I’m troubleshooting and load it on my laptop. And from there I can have the same optimizer environment then I can do anything I want with it. (well you can also do this from prod then load the SQLT to dev/QA environment)
- I mainly use the SQLT-tc (test case builder) and that is totally different from the TCB (test case builder) which uses the DBMS_SQLDIAG.. wait, am I confusing you with the TCB terms? :)
- Let me give you a little background
Each SQLTXPLAIN run (START sqltxtract.sql SQL_ID) packages everything in one zip file
[oracle@karl sqlt_s54491-good]$ du -sm sqlt_s54491.zip 47 sqlt_s54491.zip
and inside that zip file includes the test case zip file that has a *_tc.zip extension (sqlt_s54491_tc.zip)
Note that this is different from the *_tcb.zip extension (sqlt_s54491_tcb.zip) which is using the DBMS_SQLDIAG TCB (test case builder) package
[oracle@karl sqlt_s54491-good]$ unzip -l sqlt_s54491.zip Archive: sqlt_s54491.zip Length Date Time Name --------- ---------- ----- ---- 104557695 11-27-2011 02:36 sqlt_s54491_10053_explain.trc 2587 11-27-2011 09:18 sqlt_s54491_driver.zip 660035 11-27-2011 02:35 sqlt_s54491_lite.html 28711 11-27-2011 09:18 sqlt_s54491_log.zip 34589692 11-27-2011 02:35 sqlt_s54491_main.html 316568 11-27-2011 09:18 sqlt_s54491_opatch.zip 40487 11-27-2011 02:35 sqlt_s54491_p73080644_sqlprof.sql 21526 11-27-2011 02:35 sqlt_s54491_readme.html 461504 11-27-2011 02:35 sqlt_s54491_sql_detail_active.html 385239 11-27-2011 02:35 sqlt_s54491_sql_monitor_active.html 424680 11-27-2011 02:35 sqlt_s54491_sql_monitor.html 57213 11-27-2011 02:35 sqlt_s54491_sql_monitor.txt 333117 11-27-2011 02:35 sqlt_s54491_sta_report_mem.txt 1488 11-27-2011 02:35 sqlt_s54491_sta_script_mem.sql 616556 11-27-2011 02:36 sqlt_s54491_tcb.zip <-- ''DBMS_SQLDIAG TCB'' (test case builder) package zip file 8659 11-27-2011 09:18 sqlt_s54491_tc_script.sql 7793 11-27-2011 09:18 sqlt_s54491_tc_sql.sql 4254816 11-27-2011 09:18 sqlt_s54491_tc.zip <-- ''SQLT-tc test case'' zip file 33308174 11-27-2011 09:18 sqlt_s54491_trc.zip --------- ------- 180076540 19 files
- And from the wiki, you will see the related wiki topics that starts with “testcase -”. Actually, you can generate test cases using the following methods:
- And last but not the least, the most awesome part is 1) using the generated SQLT zip file, 2) building the testcase using SQLT-tc, and 3) then generating a DB Optimizer VST on the SQL_ID!
- Right after the DB Optimizer http://dboptimizer.com/db-optimizer was released last 2010, and right after I got the tool for $99! http://www.freelists.org/post/oracle-l/Special-Offer-for-readers-of-OracleL :) I was chatting with Kyle Hailey about the possibilities of making a VST out of SQLTXPLAIN.. and all along I was right ;)
Below you will see that the highlighted table name starts with the schema TC<sqlt_id>, that means it was generated from SQLT-tc and I was also able to reproduce underlying objects of the SQL_ID and the optimizer environment on my laptop.
The cool thing about DB Optimizer is that it automates a lot of tedious tasks for you. It takes away the pain of manual diagramming just like what I’m doing here http://goo.gl/VZFB that turns out just look like this http://goo.gl/ttrh
I’m a very visual guy, and I can have a better understanding of the problem and solve things quickly (and creatively) by making use of visualization.
The highlighted table on the diagram below shows a missing join condition. This version of the SQL takes FOREVER!… here with DB Optimizer, right after it prints the VST diagram and correlating it with the “merge join cartesian” on the SQLT.. it’s pretty easy to identify the missing join (see highlighted SQL on the left) which is the root cause of the performance problem.
and a quick modification on the SQL made it run for just 10 seconds! that’s the power of SQLTXPLAIN and DB Optimizer VST ;)
You may also want to check out this ultimate SQL tune off by Kyle Hailey and Jonathan Lewis to know more about DB Optimizer http://dboptimizer.com/2010/06/14/jonathan-lewis-kyle-hailey-webinar-replay/
And my example usage of the tool on a high load SAP OLTP environment – DB Optimizer example – 3mins to 10secs
That’s it for now, hope I’ve shared you some good stuff :)
I attended the 2nd day of Hotsos and I was able to meet Carlos, he’s a really nice guy. Randy Johnson, Carlos, and I had a great discussion about the tools we are working on and currently developing… we were like kids on a table with a laptop showing off each others work & that includes Jamey Johnston showing his performance monitoring tool from his server at home… I was able to show Carlos how the VST of DB Optimizer works and he was impressed by the power of easily slicing and dicing on the query visually. Of course we shared a couple of SQLTXPLAIN tips and tricks and war stories where the tool was really useful. And all of these stuff over beer and good food :) that was a fun Hotsos party :)