﻿<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Bert Scalzo's Blog</title>
    <description>&lt;table&gt;
        &lt;tr&gt;
            &lt;td valign="top"&gt;&lt;img height="183" alt="" width="139" src="/Portals/0/Blog/blog-bert-scalzo.png" /&gt;&lt;/td&gt;
            &lt;td valign="top"&gt;Bert Scalzo is a product architect for Quest Software,&amp;#160;a member of the Toad team and an &lt;a href="http://www.oracle.com/technology/community/oracle_ace/index.html"&gt;Oracle ACE&lt;/a&gt;. He has worked with Oracle databases for over two decades; his key areas of interest are data modeling, database benchmarking, tuning and optimization, "Star Schema" data warehouses and Linux. Bert is the author of several books and has written articles for many online outlets and publications,&amp;#160;and has presented at numerous Oracle conferences and user groups.
            &lt;p&gt;Bert's blog provides useful Toad “how to” and “tips and tricks” covering topics on database admin and benchmarking.&lt;/p&gt;
            &lt;p&gt;&lt;font color="#003366" size="3"&gt;&lt;strong&gt;Recent postings:&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
&lt;/table&gt;</description>
    <link>http://www.toadworld.com/BLOGS/tabid/67/BlogId/14/Default.aspx</link>
    <language>en-US</language>
    <managingEditor>Bert Scalzo</managingEditor>
    <webMaster>webmaster@toadworld.com</webMaster>
    <pubDate>Wed, 10 Mar 2010 21:38:42 GMT</pubDate>
    <lastBuildDate>Wed, 10 Mar 2010 21:38:42 GMT</lastBuildDate>
    <docs>http://backend.userland.com/rss</docs>
    <generator>Blog RSS Generator Version 3.2.0.15477</generator>
    <item>
      <title>Toad “Explains” It Best</title>
      <description>&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;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. &lt;font face="Wingdings"&gt;J&lt;/font&gt;&lt;/p&gt;
&lt;blockquote dir="ltr" style="margin-right: 0px"&gt;
&lt;pre&gt;select *&lt;br /&gt;from emp aaa&lt;br /&gt;where&lt;br /&gt;( active = 'Y'&lt;br /&gt; and job &lt;&gt; 'PRESIDENT'&lt;br /&gt;)&lt;br /&gt;and&lt;/pre&gt;
&lt;pre&gt;(&lt;br /&gt; (&lt;br /&gt; sal+nvl(comm,0) &gt; ( select avg(sal+nvl(comm,0))&lt;br /&gt;&lt;span&gt;                      &lt;/span&gt;from emp &lt;br /&gt;&lt;span&gt;                      &lt;/span&gt;where active = 'Y'&lt;br /&gt;&lt;span&gt;                        &lt;/span&gt;and job &lt;&gt; 'PRESIDENT'&lt;br /&gt;&lt;span&gt;                        &lt;/span&gt;and hiredate &lt; sysdate-90)&lt;br /&gt; and&lt;br /&gt; sysdate-hiredate &lt; ( select avg(sysdate-hiredate)&lt;br /&gt;&lt;span&gt;                       &lt;/span&gt;from emp&lt;br /&gt;&lt;span&gt;                      &lt;/span&gt;where active = 'Y'&lt;br /&gt;&lt;span&gt;                        &lt;/span&gt;and job &lt;&gt; 'PRESIDENT'&lt;br /&gt;&lt;span&gt;                        &lt;/span&gt;and hiredate &lt; sysdate-90)&lt;br /&gt; )&lt;br /&gt;or&lt;br /&gt; (&lt;br /&gt;  sal+nvl(comm,0) &gt; ( select sal+nvl(comm,0)&lt;br /&gt;&lt;span&gt;                      &lt;/span&gt;from emp bbb&lt;br /&gt;&lt;span&gt;                      &lt;/span&gt;where bbb.active = 'Y'&lt;br /&gt;&lt;span&gt;                        &lt;/span&gt;and bbb.job &lt;&gt; 'PRESIDENT'&lt;br /&gt;&lt;span&gt;                        &lt;/span&gt;and bbb.empno = aaa.mgr)&lt;br /&gt; )&lt;br /&gt;);&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;p&gt;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!&lt;/p&gt;
&lt;p&gt;&lt;img height="943" alt="" width="705" src="http://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.com/Portals/0/blogimages/Bert Scalzo/BertBlog011409-1.gif" /&gt;&lt;/p&gt;
&lt;div&gt;
&lt;p&gt;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 “&lt;em&gt;tree-view&lt;/em&gt;” format.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.com/Portals/0/blogimages/Bert Scalzo/BertBlog011409-2.gif" /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div&gt;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…&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;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 “&lt;em&gt;rightmost uppermost&lt;/em&gt;” order. Of course that was somewhat easier to read in Toad, because it displayed the line numbers.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;
&lt;p&gt;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:&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.com/Portals/0/blogimages/Bert Scalzo/BertBlog011409-3.gif" /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div&gt;The “&lt;strong&gt;Adjust Content&lt;/strong&gt;” choice permits you to pick what output Toad will display in your explain plan – such as which “&lt;em&gt;explain plan table&lt;/em&gt;” columns to display or not. But it’s the “&lt;strong&gt;Display Mode&lt;/strong&gt;” options that are going to make your day – because both the “&lt;strong&gt;Graphic&lt;/strong&gt;” and “&lt;strong&gt;MS Graphic&lt;/strong&gt;” options make reading explain plans a snap. And for those of you who also do Microsoft SQL Server development, the “&lt;strong&gt;MS Graphic&lt;/strong&gt;” option means the exact same display style of execution plans as Microsoft SQL Server does! Here they are:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;img alt="" src="http://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.com/Portals/0/blogimages/Bert Scalzo/BertBlog011409-4.gif" /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;img alt="" src="http://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.com/Portals/0/blogimages/Bert Scalzo/BertBlog011409-5.gif" /&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;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!&lt;/div&gt;</description>
      <link>http://www.toadworld.com/BLOGS/tabid/67/EntryID/333/Default.aspx</link>
      <author>Bert Scalzo</author>
      <comments>http://www.toadworld.com/BLOGS/tabid/67/EntryID/333/Default.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.toadworld.com/Default.aspx?tabid=67&amp;EntryID=333</guid>
      <pubDate>Wed, 14 Jan 2009 15:31:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.toadworld.com/DesktopModules/Blog/Trackback.aspx?id=333</trackback:ping>
    </item>
  </channel>
</rss>