Hello, you are not logged in.  Login or sign up
Toad on Twitter Follow Toad Search Toad World Search
Blogger List   

All Recent Blog Entries
 

Johannes Ahrends
Unicode and Toad

Ben Boise
Toad SC Discussions

Kevin Dalton
Benchmark Factory

Steven Feuerstein
Oracle PL/SQL

Devin Gallagher
Toad SC discussions

Stuart Hodgins
JProbe Discussions

  Henrik "Mauritz" Johnson
Toad Tips & Tricks on the "other" Toads
  Mark Kurtz
Toad SC discussions
  Michael Lumbard
Toad SC discussions
Daniel Norwood
Toad for Data Analysts
Debbie Peabody
Toad for Data Analysts
Gary Piper
Toad Reports Manager
John Pocknell
Toad for Oracle, JProbe
Kuljit Sangha
Toad SC discussions
Bert Scalzo Indicates Oracle ACE status
Toad for Oracle, Data Modeling, Benchmarking
Jeff Smith
Toad product family
Richard To
SQL Optimization
Jim Wankowski
DB2 - LUW and z/OS
John Weathington
  Toad World Editor
Toad World issues

  Toad Data Modeler Opens in a new window
Data Modeling
 
  Real Automated Code Testing for Oracle
Quest Code Tester blog

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.  Have some views of your own to share?  Post your comments!  Note:  Comments are restricted to registered Toad World users.

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.

Toad “Explains” It Best
 
Location: Blogs Bert Scalzo's Blog    
 Bert Wednesday, January 14, 2009 7:31 AM

Oracle explain plans – they are considered by many as critical when optimizing or tuning SQL statements (I however prefer to look at trace data in conjunction with explain plans). For those who prefer primarily to rely on explain plan interpretation, comprehension and improvement – Toad offers numerous capabilities to make the entire process simpler and more productive. Because let’s face it, explain plans are like much proofs in mathematics. Some people are naturally good at proofs, while the rest of us struggle with them. That’s where Toad comes in – Toad makes explain plan work trivial. In this blog I’ll just focus on how the base edition of Toad can help. For even more, Toad offers the SQL Optimizer add-on product that’s the key enabling component of the Toad for Oracle Xpert Edition.

Let’s start with a fairly simple query that’s based off the SCOTT/TIGER demo tables, specifically the EMP table. So, we have a single table query – that should not be too tough, right? Look at the code below – it contains both “AND” and “OR” operations, two similar non-correlated sub-queries, and one correlated sub-query. The explain plan should not therefore be trivial. But Toad can make working with it just that. J

select *
from emp aaa
where
( active = 'Y'
 and job <> 'PRESIDENT'
)
and
(
 (
 sal+nvl(comm,0) > ( select avg(sal+nvl(comm,0))
                      from emp
                      where active = 'Y'
                        and job <> 'PRESIDENT'
                        and hiredate < sysdate-90)
 and
 sysdate-hiredate < ( select avg(sysdate-hiredate)
                       from emp
                      where active = 'Y'
                        and job <> 'PRESIDENT'
                        and hiredate < sysdate-90)
 )
or
 (
  sal+nvl(comm,0) > ( select sal+nvl(comm,0)
                      from emp bbb
                      where bbb.active = 'Y'
                        and bbb.job <> 'PRESIDENT'
                        and bbb.empno = aaa.mgr)
 )
);

So let’s look at the query in the Toad Editor – and what we see by default when we press the ambulance toolbar icon to generate the explain plan for the editor content. Most users know about or have done this numerous times – but please read on, because there’s more!

OK – the cost of just 14 looks good (for those who focus on cost – which may not always be the best metric in isolation). But look at that tree-view of the explain plan statements. So has Toad offered anything unique or special (so far)?  No (look at the same function performed in Oracle’s (SQL Developer below). Yes, Toad also displays the explain plan’s step numbers in the order to read them – but that’s still not too easy to read in this “tree-view” format.

So just how should one read the explain plan – and is there an easier/better way? Of course the answer is an emphatic “yes” – and Toad makes explain plan usage both the easiest and best possible experience, if you know where to look. So let’s dig deeper…
 
First, let’s examine how one should read the explain plan for either of the prior product’s screen snapshots. Look for the most indented operations.  They are performed first.  Then for those that are at the same level.  They execute in their hierarchical order. Another way to say that is to read the explain plan backwards using a “rightmost uppermost” order. Of course that was somewhat easier to read in Toad, because it displayed the line numbers.
 

But that’s just too difficult and too much work for this lazy guy. What I really want is a graphical display that communicates all that information without the line numbers even being really needed – i.e. my brain “just sees it correctly”. There has to be an easier way. Of course there is – it’s called Toad. Simply “right-mouse” click anywhere on your Toad explain plan area to display the following options:

The “Adjust Content” choice permits you to pick what output Toad will display in your explain plan – such as which “explain plan table” columns to display or not. But it’s the “Display Mode” options that are going to make your day – because both the “Graphic” and “MS Graphic” options make reading explain plans a snap. And for those of you who also do Microsoft SQL Server development, the “MS Graphic” option means the exact same display style of execution plans as Microsoft SQL Server does! Here they are:
 


 
 
I personally find both these styles much easier to read, and thus I can focus on making the query better – rather than spending far too much energy just reading them. Thanks Toad!
Permalink |  Trackback

Comments (1)  
By hillbillyToad on Wednesday, January 14, 2009 8:22 AM
We've just put up a White Paper on Oracle Execution plans, if you'd like to learn more about them in general and how Toad can help, here's the link:

http://www.toadworld.com/Knowledge/ToadKnowledge/ToadPapersandPodcasts/tabid/82/TID/257/cid/49/Default.aspx

Search Blog Entries
 
Copyright 2010 by Quest Software  | Terms Of Use | Privacy Statement | Contact Us