﻿<?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>Richard To's Blog</title>
    <description>Solving problems in your SQL code, tune queries, and share new tips, tricks, and techniques</description>
    <link>http://www.toadworld.com/Community/Blogs/tabid/67/BlogId/15/Default.aspx</link>
    <language>en-US</language>
    <managingEditor>Richard To</managingEditor>
    <webMaster>webmaster@toadworld.com</webMaster>
    <pubDate>Tue, 02 Dec 2008 07:26:05 GMT</pubDate>
    <lastBuildDate>Tue, 02 Dec 2008 07:26:05 GMT</lastBuildDate>
    <docs>http://backend.userland.com/rss</docs>
    <generator>Blog RSS Generator Version 3.2.0.15477</generator>
    <item>
      <title>Optimizing SQL Part 4 – Optimizing SQL statements with a VIEW</title>
      <description>&lt;div&gt;
&lt;p&gt;&lt;font size="1"&gt;Written by Rene Woody&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;This blog is a &lt;a href="http://www.toadworld.com/Default.aspx?tabid=67&amp;EntryID=309"&gt;continuation of a series&lt;/a&gt; about the SQL optimization process in the Batch Optimizer and the Tuning Lab modules of Quest SQL Optimizer &lt;em&gt;for Oracle&lt;/em&gt;. It covers optimizing SQL statements that use VIEWs.&lt;/p&gt;
&lt;/div&gt;
&lt;div&gt;In early versions of the Oracle database, a VIEW was handled like a temporary table that stores the temporary data from the VIEW’s SELECT statement. Then the temporary table was joined with the main portion of the SQL statement, so the tuning of a SQL statement that contained a VIEW could be separated into the VIEW’s SQL statement and main SQL statement. In more recent versions of Oracle, the SQL optimizer in Oracle can merge these two SQL statements together before it does further SQL optimization, so, it is now more complicated for you to tune a VIEW SQL statement by hand than before. Quest SQL Optimizer has a “View to Inline View transformation” technique to solve this problem.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;The optimization process in Quest SQL Optimizer includes this technique of rewriting the VIEW’s SQL statement when it transforms the syntax of the original SQL statement. So it will automatically do all the work for you.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;For example, with this simple SQL statement &lt;/div&gt;
&lt;blockquote dir="ltr" style="margin-right: 0px"&gt;
&lt;pre&gt;&lt;font size="2"&gt;SELECT * FROM VIEW_DEPT&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;WHERE DPT_AVG_SALARY &gt; 40000&lt;/font&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;div&gt;that uses the following VIEW.&lt;/div&gt;
&lt;blockquote dir="ltr" style="margin-right: 0px"&gt;
&lt;pre&gt;&lt;font size="2"&gt;CREATE OR REPLACE VIEW VIEW_DEPT&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;    (DPT_ID,&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;     DPT_NAME,&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;     DPT_MANAGER,&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;     DPT_AVG_SALARY)&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;AS&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;SELECT "DPT_ID", &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;       "DPT_NAME", &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;       "DPT_MANAGER", &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;       "DPT_AVG_SALARY" &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;  FROM DEPARTMENT &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt; WHERE DPT_ID IN (SELECT EMP_DEPT &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;                    FROM EMPLOYEE &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;                   WHERE EMP_ID &gt; 50)&lt;/font&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;div&gt;When the VIEW’s SELECT statement is inserted into the original SQL statement, the SQL statement looks like this:&lt;/div&gt;
&lt;blockquote dir="ltr" style="margin-right: 0px"&gt;
&lt;pre&gt;&lt;font size="2"&gt;SELECT *&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt; FROM (SELECT "DPT_ID", &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;               "DPT_NAME", &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;               "DPT_MANAGER", &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;               "DPT_AVG_SALARY" &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;          FROM DEPARTMENT &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;            WHERE DPT_ID IN (SELECT EMP_DEPT &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;                               FROM EMPLOYEE &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;                              WHERE EMP_ID &gt; 50))&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt; WHERE DPT_AVG_SALARY &gt; 40000&lt;/font&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;div&gt;
&lt;p&gt;The original SQL statement and the SQL statement with the VIEW inserted will both be rewritten by the Quest SQL Optimizer to generate all the possible SQL statements which produce the same results as the original SQL statement. Some of the SQL alternatives will not include the VIEW’s SQL and others will have the VIEW’s SQL rewritten.&lt;/p&gt;
&lt;p&gt;An example of one of the SQL alternatives is:&lt;/p&gt;
&lt;/div&gt;
&lt;blockquote dir="ltr" style="margin-right: 0px"&gt;
&lt;pre&gt;&lt;font size="2"&gt;SELECT * &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;  FROM (SELECT DPT_ID,&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;               DPT_NAME,&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;               DPT_MANAGER,&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;               DPT_AVG_SALARY&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;          FROM DEPARTMENT &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;         WHERE EXISTS (SELECT 'X' &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;                         FROM EMPLOYEE &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;                        WHERE EMP_ID &gt; 50 &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;                          AND EMP_DEPT = DEPARTMENT.DPT_ID))&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt; WHERE DPT_AVG_SALARY &gt; 40000&lt;/font&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;div&gt;You can control whether the VIEW’s SQL is rewritten along with the original SQL statement with the &lt;strong&gt;Transform view to inline view&lt;/strong&gt; setting in the Options. Quest SQL Optimizer will also transform a VIEW that is being used by another VIEW. You control how many levels (VIEWs within VIEWs) are included when the original SQL is rewritten by specifying the &lt;strong&gt;Transformation levels&lt;/strong&gt; setting.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;em&gt;If you would like to learn more about Quest SQL Optimizer for Oracle, please visit the &lt;/em&gt;&lt;a href="http://sqloptimizeroracle.inside.quest.com/index.jspa"&gt;Inside SQL Optimizer for Oracle community&lt;/a&gt;.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;</description>
      <link>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/314/Default.aspx</link>
      <author>Richard To</author>
      <comments>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/314/Default.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.toadworld.com/Default.aspx?tabid=67&amp;EntryID=314</guid>
      <pubDate>Fri, 21 Nov 2008 13:54:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.toadworld.com/DesktopModules/Blog/Trackback.aspx?id=314</trackback:ping>
    </item>
    <item>
      <title>Optimizing SQL Part 3– Generating more SQL alternatives for simple SQL statements</title>
      <description>&lt;div&gt;
&lt;p&gt;&lt;font size="1"&gt;Written by Rene Woody&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;This blog is a &lt;a href="http://www.toadworld.com/Default.aspx?tabid=67&amp;EntryID=300"&gt;continuation&lt;/a&gt; of a series about the SQL optimization process in the Batch Optimizer and the Tuning Lab modules of &lt;a href="http://www.toadworld.com/LinkClick.aspx?link=434&amp;tabid=67"&gt;Quest SQL Optimizer &lt;em&gt;for Oracle&lt;/em&gt;&lt;/a&gt;. It covers how to generate more SQL alternatives.&lt;/p&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;p&gt;When you optimize a simple SQL statement, Quest SQL Optimizer may only generate a few SQL alternatives using the default settings in the Optimizer options. It is very likely that many more alternatives can be generated, but they did not get generated because of the way the options were set.&lt;/p&gt;
&lt;p&gt;The options settings in Quest SQL Optimizer &lt;em&gt;for Oracle&lt;/em&gt; enable you to select which Oracle optimization hints are applied, include or exclude a few of the syntax transformation rules that are used, select how many driving paths will be tried, and increase or decrease the number of SQL alternatives generated.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;We’ll take a look at how you can do this using the Optimizer options. These options apply to the optimization process in both the Tuning Lab and the Batch Optimizer.&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;To open the Options window, click &lt;strong&gt;Options&lt;/strong&gt; &lt;img height="26" alt="" width="64" src="http://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.com/Portals/0/blogimages/Richard To/RichadToBlog10242008-1.gif" /&gt;&lt;span&gt;.&lt;/span&gt; &lt;br /&gt;
     &lt;/li&gt;
    &lt;li&gt;Select &lt;strong&gt;Tuning Lab | Optimizer | Intelligence&lt;/strong&gt;. &lt;br /&gt;
     &lt;/li&gt;
    &lt;li&gt;By default, the “intelligence level” of the optimization process is set to &lt;strong&gt;&lt;span&gt;Predefined Settings&lt;/span&gt;&lt;/strong&gt; with &lt;strong&gt;level 4&lt;/strong&gt;. Change the intelligence level to 10. &lt;br /&gt;
     &lt;br /&gt;
    &lt;img height="510" alt="" width="678" src="http://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.com/Portals/0/blogimages/Richard To/RichadToBlog11062008-1.gif" /&gt;&lt;br /&gt;
     &lt;/li&gt;
    &lt;li&gt;Level 10 selects all of the Optimization options, all of the Oracle optimization hints, and sets the quotas for the number of SQL statements that will be generated very high.&lt;br /&gt;
     &lt;br /&gt;
    &lt;img height="510" alt="" width="678" src="http://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.com/Portals/0/blogimages/Richard To/RichadToBlog11062008-2.gif" /&gt;&lt;br /&gt;
    &lt;br /&gt;
    Applying Level 10 to your original SQL statement maximizes the possibility of finding a better alternative for you.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;&lt;em&gt;If you would like to learn more about Quest SQL Optimizer for Oracle, please visit the &lt;/em&gt;&lt;strong&gt;&lt;a href="http://sqloptimizeroracle.inside.quest.com/index.jspa"&gt;Inside SQL Optimizer for Oracle community&lt;/a&gt;.&lt;br /&gt;
 &lt;/strong&gt;&lt;/div&gt;</description>
      <link>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/309/Default.aspx</link>
      <author>Richard To</author>
      <comments>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/309/Default.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.toadworld.com/Default.aspx?tabid=67&amp;EntryID=309</guid>
      <pubDate>Thu, 06 Nov 2008 16:10:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.toadworld.com/DesktopModules/Blog/Trackback.aspx?id=309</trackback:ping>
    </item>
    <item>
      <title>Optimizing SQL Part 2 – Generating fewer alternative SQL statements</title>
      <description>&lt;div&gt;
&lt;p&gt;&lt;font size="1"&gt;Written by Rene Woody&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;This blog is a continuation of a series (&lt;a href="http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/287/Default.aspx"&gt;view last blog on the Optimization Process&lt;/a&gt;) about the SQL optimization process in the Batch Optimizer and the Tuning Lab modules of &lt;a href="http://www.toadworld.com/LinkClick.aspx?link=434&amp;tabid=67"&gt;Quest SQL Optimizer &lt;em&gt;for Oracle&lt;/em&gt;&lt;/a&gt;. It covers how to limit the number of SQL alternatives generated by the optimization process.&lt;/p&gt;
&lt;/div&gt;
&lt;div&gt;When you are optimizing a complicated SQL statement, Quest SQL Optimizer is capable of generating hundreds to even thousands of SQL alternatives. While theoretically this may be nice, it is not practical to review, select, and test hundreds of SQL statements, especially if it is a long running SQL statement.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;The options settings in Quest SQL Optimizer &lt;em&gt;for Oracle&lt;/em&gt; enable you to control the maximum number of SQL alternatives generated, select which Oracle optimization hints are applied, exclude a few of the transformation rules that are used, and limit the maximum number of SQL statements generated.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;We’ll take a look at how you can do this using the Optimizer options. These options apply to the optimization process in both the Tuning Lab and the Batch Optimizer.&lt;/div&gt;
&lt;ol&gt;
    &lt;li&gt;To open the Options window, click &lt;strong&gt;Options&lt;/strong&gt; &lt;img height="26" alt="" width="64" src="http://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.comhttp://www.toadworld.com/Portals/0/blogimages/Richard To/RichadToBlog10242008-1.gif" /&gt;.&lt;br /&gt;
     &lt;/li&gt;
    &lt;li&gt;Select &lt;strong&gt;Tuning Lab | Optimizer | Intelligence&lt;/strong&gt;.&lt;br /&gt;
     &lt;/li&gt;
    &lt;li&gt;By default, the “intelligence level” of the optimization process is set to &lt;strong&gt;Predefined Settings&lt;/strong&gt; with &lt;strong&gt;level 4&lt;/strong&gt; selected. In order to customize the number of alternative statements that are generated and other options, set the intelligence level to &lt;strong&gt;Custom Settings&lt;/strong&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/Richard To/RichadToBlog10242008-2.gif" /&gt;&lt;br /&gt;
      &lt;/li&gt;
    &lt;li&gt;Select &lt;strong&gt;Tuning Lab | Optimizer | Optimization&lt;/strong&gt;.&lt;br /&gt;
     &lt;/li&gt;
    &lt;li&gt;If the &lt;strong&gt;Transform view to inline view&lt;/strong&gt; or&lt;strong&gt; &lt;span&gt;Transform query to inline view &lt;/span&gt;&lt;/strong&gt;&lt;span&gt;apply to your SQL statement, fewer SQL alternatives will be generated if you unselect these options. &lt;br /&gt;
     &lt;/span&gt;
    &lt;ol&gt;
        &lt;li&gt;The &lt;strong&gt;Transform view to inline view&lt;/strong&gt; option inserts the SELECT statement from each VIEW used in the SQL statement and then transforms the syntax of the original SQL statement and the SQL statements from the VIEWs.&lt;br /&gt;
         &lt;/li&gt;
        &lt;li&gt;The &lt;span&gt;&lt;strong&gt;Transform query to inline view&lt;/strong&gt;&lt;/span&gt;&lt;span&gt; option &lt;/span&gt;transforms the subquery to an inline view (a subquery used as a table in a FROM clause).&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/Richard To/RichadToBlog10242008-3.gif" /&gt;&lt;br /&gt;
          &lt;/li&gt;
    &lt;/ol&gt;
    &lt;/li&gt;
    &lt;li&gt;Select &lt;strong&gt;Tuning Lab | Optimizer | Hints&lt;/strong&gt;.&lt;br /&gt;
     &lt;/li&gt;
    &lt;li&gt;The Oracle optimization hints are displayed on six pages. Select the hints you want to use for optimizing your SQL statements. The fewer hints selected the fewer alternative SQL statements will be generated by the SQL Optimizer.&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/Richard To/RichadToBlog10242008-4.gif" /&gt;&lt;br /&gt;
     &lt;/li&gt;
    &lt;li&gt;Select &lt;strong&gt;Tuning Lab | Optimizer | Quota&lt;/strong&gt;.&lt;br /&gt;
     &lt;/li&gt;
    &lt;li&gt;Set the quotas to reduce the number of SQL statements generated during the optimization process.&lt;br /&gt;
     
    &lt;ol&gt;
        &lt;li&gt;The &lt;strong&gt;Syntax transformation quota&lt;/strong&gt; limits the number of SQL alternatives generated during the SQL syntax transformation phase of the optimization process. What this means is that the SQL Optimizer will stop finding syntactically different SQL statements after the quota has been reached.&lt;br /&gt;
         &lt;br /&gt;
        &lt;strong&gt;Note&lt;/strong&gt;: Although the SQL statements are syntactically different, they still produce the same result.&lt;br /&gt;
         &lt;/li&gt;
        &lt;li&gt;The &lt;strong&gt;Table join permutation quota&lt;/strong&gt; limits the number of ways the order of the tables is rearranged. This table order rearrangement is actually one of the many rules that comprise the syntax transformation rules. The &lt;strong&gt;Table join permutation quota&lt;/strong&gt; is used to control how many SQL syntax transformations are created using only this one rule.&lt;br /&gt;
         &lt;/li&gt;
        &lt;li&gt;The &lt;strong&gt;Hints quota &lt;/strong&gt;is the number of SQL alternatives that are generated by applying the Oracle optimization hints to the original SQL statement and the SQL alternatives that were created by transforming the SQL syntax.&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/Richard To/RichadToBlog10242008-5.gif" /&gt;&lt;/li&gt;
    &lt;/ol&gt;
    &lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;By changing the options above, fewer or more SQL alternatives can be generated for your original SQL statement.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;em&gt;If you would like to learn more about Quest SQL Optimizer for Oracle, please visit the &lt;/em&gt;&lt;strong&gt;&lt;a href="http://sqloptimizeroracle.inside.quest.com/index.jspa"&gt;Inside SQL Optimizer for Oracle community&lt;/a&gt;.&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;</description>
      <link>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/300/Default.aspx</link>
      <author>Richard To</author>
      <comments>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/300/Default.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.toadworld.com/Default.aspx?tabid=67&amp;EntryID=300</guid>
      <pubDate>Fri, 24 Oct 2008 12:53:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.toadworld.com/DesktopModules/Blog/Trackback.aspx?id=300</trackback:ping>
    </item>
    <item>
      <title>Optimizing SQL Part 1 – The Optimization Process</title>
      <description>&lt;div&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;font size="1"&gt;Written by Rene Woody&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
This blog is the beginning of a series that will cover the optimization process in the Batch Optimizer and the Tuning Lab modules of &lt;a href="http://www.toadworld.com/LinkClick.aspx?link=434&amp;tabid=67"&gt;Quest SQL Optimizer &lt;em&gt;for Oracle&lt;/em&gt;&lt;/a&gt;. &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;When writing a SQL statement, it is easy to be satisfied when you have figured out how to get the correct results. This is especially true when you are writing a complicated SQL statement. But in order to have good database performance, you need to find the best execution plan that retrieves the desired results.&lt;/font&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;Quest SQL Optimizer has a unique optimization process for finding the best performing SQL statements for each unique database environment. It generates SQL alternatives for a given SQL statement in order to find alternative execution plans for that SQL statement.&lt;br /&gt;
 &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;font size="2"&gt;SQL Syntax Transformation&lt;br /&gt;
 &lt;/font&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;The optimization process first transforms the syntax of a SQL statement to generate alternative SQL statements through a proprietary and unique artificial intelligence algorithm. It applies SQL syntax transformation rules to rewrite a SQL statement in a multitude of different ways that still produces the same result. The knowledge base in the optimization engine has more than 60 SQL transformation rules, which can theoretically generate up to 60! alternatives. (60! = 8.3209871127413901442763411832e+81)&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;This optimization process is a recursive process that rewrites a SQL statement until there are no more possible alternatives. Then it will rewrite each of the alternatives. It will stop when it can no longer generate any more SQL alternatives or when it has reached a user-defined quota for the maximum number of SQL alternatives it should generate while transforming the syntax.&lt;br /&gt;
 &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;font size="2"&gt;Database Optimization Techniques&lt;br /&gt;
 &lt;/font&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;After it has finished rewriting the SQL statement using the SQL syntax transformation rules, it will generate more SQL statements by applying techniques that are unique to the database platform. For Oracle, it applies the Oracle optimization hints. For SQL Server, it applies hints. For DB2 LUW, it applies SQL Options. And for Sybase, it applies forces, optimization goals and optimization criteria. For all database platforms, it applies these techniques to original SQL statement and the SQL alternatives. You can control which specific items are applied to the SQL statements through the settings in the Optimization options.&lt;br /&gt;
 &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;font size="2"&gt;Looking for unique execution plans&lt;br /&gt;
 &lt;/font&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;After the optimization process has finished generating the SQL alternatives, it will retrieve the execution plan for each alternative SQL. It compares the execution plans so that it can eliminate the SQL alternatives that have duplicate execution plans. &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;The final result of this optimization process is one SQL alternative for each unique execution plan. &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;Using Quest SQL Optimizer, you can be sure that you will have tried most of possible alternative execution plans for your original SQL statement, which can be mathematically proved to generate the same results. The next step is then to test the alternatives to findthe one that performs the best in your database environment.&lt;br /&gt;
&lt;/font&gt;&lt;font size="2"&gt;  &lt;/font&gt;&lt;/div&gt;
&lt;p align="center"&gt;&lt;img height="306" alt="" width="620" src="http://www.toadworld.com/Portals/0/blogimages/Richard To/RichadToBlog10102008-1.gif" /&gt;&lt;/p&gt;
&lt;div&gt;&lt;em&gt;&lt;font size="2"&gt;If you would like to learn more about Quest SQL Optimizer for Oracle, please visit the &lt;/font&gt;&lt;/em&gt;&lt;a href="http://sqloptimizeroracle.inside.quest.com/index.jspa"&gt;&lt;font size="2"&gt;Inside SQL Optimizer for Oracle community&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt;.&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/div&gt;</description>
      <link>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/287/Default.aspx</link>
      <author>Richard To</author>
      <comments>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/287/Default.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.toadworld.com/Default.aspx?tabid=67&amp;EntryID=287</guid>
      <pubDate>Fri, 10 Oct 2008 13:48:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.toadworld.com/DesktopModules/Blog/Trackback.aspx?id=287</trackback:ping>
    </item>
    <item>
      <title>A Question from our Quest SQL Optimizer User</title>
      <description>&lt;div&gt;
&lt;div&gt;Recently, we got a question from a customer:&lt;/div&gt;
&lt;/div&gt;
&lt;blockquote style="margin-right: 0px"&gt;
&lt;div&gt;&lt;em&gt;“Why does adding a ||'' to the end of a key value improve performance... in this case significantly, this query runs in 187 milliseconds regularly where without the ||'' it takes minutes to run... This is the only modification in the result set from SQL Optimizer that was made to this code block. I got this code from a developer, so I know there are other methods to improve upon here, but this one change did everything performance wise that I needed to happen and I want to understand what the ||'' does to the query.”&lt;/em&gt;&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div&gt;Let me explain the question using a simple SQL like the following:&lt;/div&gt;
&lt;div&gt;&lt;strong&gt; &lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;u&gt;SQL A&lt;/u&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;blockquote dir="ltr" style="margin-right: 0px"&gt;
&lt;pre&gt;select *&lt;br /&gt; from employee&lt;br /&gt; where emp_dept in (select dpt_id&lt;br /&gt;&lt;span&gt;                      from department &lt;br /&gt;&lt;/span&gt;&lt;span&gt;                     where dpt_name like 'D%')&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;div&gt;Our SQL Optimizer rewrites it like this:&lt;/div&gt;
&lt;div&gt;&lt;strong&gt; &lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;u&gt;SQL B&lt;/u&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;blockquote dir="ltr" style="margin-right: 0px"&gt;
&lt;pre&gt;select *&lt;br /&gt; from employee&lt;br /&gt; where emp_dept in (select dpt_id &lt;span&gt;|| ’’&lt;br /&gt;&lt;/span&gt;&lt;span&gt;                      from department &lt;br /&gt;&lt;/span&gt;&lt;span&gt;                     where dpt_name like 'D%')&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;div&gt;Most SQL tuning books or SQL tuning experts will tell you how to use or enable indexes to improve the performance of a SQL statement. Most of them will only tell you that using indexes is the way to improve SQL speed. Seldom will they tell you how to change or control the execution plan that Oracle will generate for the SQL statement. In the SQL B above, you will find that we added an empty string to the dpt_id column in the select list of the subquery. It looks like this dummy operation, dpt_id || ’’, is stupid and meaningless since it is concatenating nothing to the dpt_id column in the select list.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;To explain this dummy operation, let’s have a look at the following SQL statement which is semantically equivalent to SQL A:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;u&gt;SQL C&lt;/u&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;blockquote dir="ltr" style="margin-right: 0px"&gt;
&lt;pre&gt;select *&lt;br /&gt; from employee&lt;br /&gt; where exists (select ‘x’&lt;br /&gt;&lt;span&gt;                       from department &lt;br /&gt;&lt;/span&gt;&lt;span&gt;                       where dpt_name like 'D%'&lt;br /&gt;&lt;/span&gt;&lt;span&gt;                         and emp_dept=dpt_id)&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;div&gt;If we change the SQL syntax in SQL C to the following, do you think that the execution plan of this SQL will remain the same or not?&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;u&gt;SQL D&lt;/u&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;blockquote dir="ltr" style="margin-right: 0px"&gt;
&lt;pre&gt;select *&lt;br /&gt; from employee&lt;br /&gt; where exists (select ‘x’&lt;br /&gt;&lt;span&gt;                       from department &lt;br /&gt;&lt;/span&gt;&lt;span&gt;                       where dpt_name like 'D%'&lt;br /&gt;&lt;/span&gt;&lt;span&gt;                         and emp_dept=dpt_id || ’’)&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;div&gt;I think most everyone would expect that the new syntax would generate a different plan since the dpt_id index is disabled by the addition of || ’’. The driving path in SQL C which would do a full table scan on the employee table and an index search of the department table using the dpt_id column can no longer be used (assuming that it was used in the original plan) in SQL D. Therefore when you add || ’’ to a character field or + 0 to a number field, Oracle will try other plans in place of the original plan. Sometimes the new plan will be better in your database environment, and therefore your SQL will be faster. &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Now, let’s take a look at both SQL A and SQL C. SQL A uses an IN clause and SQL C has been rewritten to use the EXIST clause. The Oracle internal SQL optimizer like most of commercial databases has a built-in SQL transformation algorithm. When the SQL is executed, the internal optimizer will transformed the SQL syntax to a better syntax which is known to perform better or can be more easily optimized in next stage of plan generation. Therefore, SQL A and SQL C can be treated as the same SQL when you do SQL tuning by rewriting the syntax because the internal SQL optimizer in the database will perform this transformation during its limited optimization process which takes place before the SQL statement is executed.  Actually, most database internal optimizers will transform an EXIST or IN statement to a Join SQL statement internally, but to simplify our discussion, I used the EXIST example instead of using a Join SQL.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;I would like to emphasize that there is no computer algorithm that can 100% predict which execution plan is the best in your database. Therefore, to test run all alternative SQL which have unique execution plans is the only way to make sure you are using the best SQL alternative, no matter whether you are tuning your SQL statements manually or using our Quest SQL Optimizer.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;</description>
      <link>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/271/Default.aspx</link>
      <author>Richard To</author>
      <comments>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/271/Default.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.toadworld.com/Default.aspx?tabid=67&amp;EntryID=271</guid>
      <pubDate>Thu, 04 Sep 2008 09:50:00 GMT</pubDate>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://www.toadworld.com/DesktopModules/Blog/Trackback.aspx?id=271</trackback:ping>
    </item>
    <item>
      <title>Batch Optimizer Part 6 - Using Batch Optimization with Rule Based Optimizer</title>
      <description>&lt;div&gt;
&lt;p&gt;&lt;em&gt;Written by Rene Woody&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This blog is a continuation of a series about the Batch Optimizer in Quest SQL Optimizer &lt;em&gt;for Oracle&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div&gt;In the Batch Optimizer in Quest SQL Optimizer &lt;em&gt;for Oracle&lt;/em&gt; you may notice that the options for selecting which SQL alternatives to execute by the batch process are all based on the Oracle cost estimation. Although it is not a good idea to trust Oracle cost estimation for problematic SQL statements, in order to save time when testing the SQL alternatives, it is an acceptable way to reduce the test run time.  &lt;/div&gt;
&lt;div&gt;&lt;strong&gt; &lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you really want the best SQL optimization results from the testing, you will not limit the number of alternatives that are tested but will test them all by selecting&lt;strong&gt; All alternatives&lt;/strong&gt;.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;When you have the Oracle Optimizer Mode parameter set to Rule Based in your Oracle database, there is no cost estimation in the execution plan of the SQL statements. So, that prompts the question, “Which &lt;strong&gt;Auto Select SQL Rewrites for Execution &lt;/strong&gt;option should be used to limit the number of SQL alternatives that are executed when the Optimizer Mode is set to Rule Based?”&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;In reviewing the Batch Optimizer option &lt;strong&gt;Auto Select SQL Rewrites for Execution&lt;/strong&gt;, you can see that one option includes a setting for the minimum number of SQL statements to be executed. The &lt;strong&gt;% of alternatives with lowest cost&lt;/strong&gt; option includes the &lt;strong&gt;Minimum alternatives executed&lt;/strong&gt;. This setting takes the first 10 (default setting) alternatives and executes them. When there is no cost estimation, it simply takes the first 10 alternatives that were generated and executes them. Therefore, this is the setting that should be selected when the Optimizer Mode parameter is set to Rule Based and you want to limit the number of SQL alternatives executed.&lt;br /&gt;
 &lt;/div&gt;
&lt;div&gt;  &lt;img height="280" alt="" width="654" src="http://www.toadworld.com/Portals/0/blogimages/RichadToBlog08122008-1.gif" /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;p&gt;&lt;em&gt;If you would like to learn more about Quest SQL Optimizer for Oracle, please visit the &lt;/em&gt;&lt;a href="http://sqloptimizeroracle.inside.quest.com/index.jspa"&gt;&lt;font color="#800080"&gt;Inside SQL Optimizer for Oracle community&lt;/font&gt;&lt;/a&gt;.&lt;br /&gt;
 &lt;/p&gt;
&lt;/div&gt;</description>
      <link>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/262/Default.aspx</link>
      <author>Richard To</author>
      <comments>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/262/Default.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.toadworld.com/Default.aspx?tabid=67&amp;EntryID=262</guid>
      <pubDate>Tue, 12 Aug 2008 14:32:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.toadworld.com/DesktopModules/Blog/Trackback.aspx?id=262</trackback:ping>
    </item>
    <item>
      <title>A New Intelligent Test Run Function is under Research</title>
      <description>&lt;div&gt;  &lt;/div&gt;
&lt;div&gt;A problem in the area of SQL optimization that has been around for a long time is the inaccuracy of the cost estimation of a SQL statement. A lot of people have the wrong conception that inaccurate cost estimations generated for a SQL statement by the database optimizer are caused by outdated statistics; whereas in fact, outdated or incorrect statistics is only one of many reasons that cause the database to generate an inaccurate SQL cost estimation. This means that even if you have 100% accurate statistics on your tables and indexes, you will not necessarily have 100% accurate cost estimation for your SQL statements.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Most of the poorly performing SQL statements found in production databases are caused by the wrong SQL cost estimation. For a more detailed discussion on this topic, see my previous blog &lt;a href="http://www.toadworld.com/Community/QuestExpertsBlogs/tabid/67/EntryID/33/Default.aspx"&gt;&lt;strong&gt;Why SQL Tuning?&lt;/strong&gt;&lt;/a&gt;. &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;In Quest SQL Optimizer, we use an Artificial Intelligence technique to generate syntactically different, but semantically equivalent SQL rewrites. This provides several alterative SQL statements for the original SQL. But, since we cannot rely on the database SQL cost estimation to identify the best SQL alternative, we still have to test run those alternatives in a production database or similar environment to pick out the best alternative SQL statement. A close look at the testing results of several different SQL statements will show you that the best alternative SQL statement is not normally the one with the lowest cost in most of cases.  This is why Quest SQL Optimizer provides a test run function to help users to pick out the best alternative SQL statement. But a physical test run for all alternative SQL statements is time consuming, so some users may select only those SQL with relatively lower cost to test run without going through all the alternatives. This approach can save time, but it may miss some potentially better alternatives whose estimated costs have been wrongly estimated high. &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;It has been on my mind for many years to try to find a way to quickly identify the best SQL alterative from all the alternatives generated by Quest SQL Optimizer. There is no easy solution to this problem. Since each database environment is unique and the cost estimation is not reliable, I knew that what was needed was an algorithm which could save users time when test running the alternatives while not missing any potentially good alternatives. Recently, I have been involved in a research project that uses an AI cluster technique to improve the traditional Fuzzy Self-learning algorithm. One of the benefits that have come out of this research is that I found a better way to automatically select which SQL alternatives to test. It is to use an AI cluster technique that we have developed which provides a simple and useful solution to this long standing problem in our Quest SQL Optimizer&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Let me illustrate this using the following SQL statement:&lt;/div&gt;
&lt;blockquote dir="ltr" style="MARGIN-RIGHT: 0px"&gt;
&lt;pre&gt;select * from employee&lt;br /&gt;where emp_dept in (select dpt_id from department&lt;br /&gt;                   where dpt_name LIKE 'D%')&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;div&gt;I put this SQL statement into Quest SQL Optimizer so that it could be rewritten by our optimization process using an AI engine. At the intelligence level 4, in less than 10 seconds, 15 alternatives were generated:&lt;br /&gt;
 &lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;img height="332" alt="" width="600" src="http://www.toadworld.com/Portals/0/blogimages/RichadToBlog06132008-1.gif" /&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Let’s have a closer look at the cost of all the SQL alternatives and the cost distribution chart for the SQL statement and the 15 alternative SQL statements generated by Quest SQL Optimizer &lt;strong&gt;&lt;em&gt;for Oracle&lt;/em&gt;&lt;/strong&gt;:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;img alt="" src="http://www.toadworld.com/Portals/0/blogimages/RichadToBlog06132008-2.gif" /&gt; &lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;As you can see in the chart, the cost distributions of all SQL alternatives are grouped into multiple regions. SQL statements with similar cost normally have similar execution plans which results in similar performance. &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Executing the original and alternative SQL statements produced the following run times.&lt;br /&gt;
 &lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;img alt="" src="http://www.toadworld.com/Portals/0/blogimages/RichadToBlog06132008-3.gif" /&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;In reviewing the run times, you can look at the Plan Cost and see that the Total Elapsed Time and Total CPU time for each of the alternatives with a similar cost are very close. Sometimes, because of how long it takes to execute a SQL statement, testing all of the alternatives is not practical. So, to save time when testing the alternatives, instead of testing only the SQL statements with the lowest cost, it is best to test one SQL statement from each group of SQL with a similar cost.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;For this example, Alt #12 is the fastest SQL statement even though the estimated cost from Oracle is among the highest. The fastest SQL statement would have been missed if only the SQL statements with the lowest cost were selected for testing.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;The behavior we see in this example, that SQL statements with similar cost have similar run time, is common across the broad whether the syntax of the SQL statement is simple or very complex.&lt;/div&gt;
&lt;div&gt;&lt;strong&gt; &lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;A new Algorithm for select SQL to test&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;It is an easy task for a person to look at a group of SQL statements sorted by the cost value and pick one SQL statement from each group of SQL statements that have a similar cost. But it is not so easy to develop an algorithm that can correctly do the same thing, which is to start with a fixed number of points (in this case the Plan Cost values) that have a wide range with an indeterminate granularity of numbers and then group them so that one can be selected. In the field of Artificial Intelligence, this issue would be classified as a clustering problem. &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;The next generation of test running the SQL statements in Quest SQL Optimizer will have an Intelligent Test Run function. This function will be based on an algorithm, developed in the Fuzzy Self-learning project, which will simplify the clustering process (the process of grouping the SQL statements with similar costs) so that Quest SQL Optimizer will be able to select one SQL statement from a group of SQL with similar cost.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;The algorithm is too technical and complex to describe here, but for sure, you will enjoy a faster and better SQL optimization product soon. &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;</description>
      <link>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/233/Default.aspx</link>
      <author>Richard To</author>
      <comments>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/233/Default.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.toadworld.com/Default.aspx?tabid=67&amp;EntryID=233</guid>
      <pubDate>Fri, 13 Jun 2008 11:20:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.toadworld.com/DesktopModules/Blog/Trackback.aspx?id=233</trackback:ping>
    </item>
    <item>
      <title>Batch Optimizer Part 5 – Viewing the SQL alternatives and execution run time statistics</title>
      <description>&lt;div&gt;&lt;em&gt;Written by Rene Woody&lt;br /&gt;
 &lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;After a SQL statement has been optimized in the Batch Optimizer in Quest SQL Optimizer &lt;em&gt;for Oracle&lt;/em&gt;, you can view the text of the SQL alternatives and the execution plans in the Tuning Lab module. If the original SQL statement and alternatives have been executed, you can view the run time statistics as well.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;1.&lt;span&gt;      &lt;/span&gt;In the &lt;strong&gt;SQL in Selected Job&lt;/strong&gt; window in the Batch Optimizer, click the SQL statement to highlight it.&lt;/div&gt;
&lt;div&gt;2.&lt;span&gt;      &lt;/span&gt;Click &lt;strong&gt;Open in Tuning Lab&lt;/strong&gt;  &lt;img height="21" alt="" width="23" src="http://www.toadworld.com/Portals/0/blogimages/RichadToBlog05232008-2.gif" /&gt;.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;img alt="" src="http://www.toadworld.com/Portals/0/blogimages/RichadToBlog05232008-1.gif" /&gt;&lt;/div&gt;
&lt;div&gt;  &lt;/div&gt;
&lt;div&gt;&lt;font color="#000080" size="2"&gt;&lt;strong&gt;Functions Available in the Tuning Lab&lt;/strong&gt;&lt;/font&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Since the Batch Optimizer limits the number of SQL alternatives that are executed automatically, in the Tuning Lab you can execute the alternatives that were not executed in the Batch Optimizer to see if you can find a faster alternative.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;When you are viewing the details of a SQL statement that was optimized in the Batch Optimizer, in addition to the Execute function, you may also use the Test for Scalability, Store Session, Reports, Retrieve Results, and Alter Session Parameters functions.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;font color="#000080" size="2"&gt;&lt;strong&gt;Select the Best SQL Alternative&lt;/strong&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;In the Tuning Lab as you view the SQL alternatives and the run time statistics from the execution of the SQL statements, you can change the alternative that is the “best” alternative based on your own review of all of the run time statistics. &lt;/div&gt;
&lt;ul&gt;
    &lt;li&gt;In the &lt;strong&gt;Tuning Lab | SQL Details Layout | Scenario Explorer&lt;/strong&gt; window, right-click the SQL statement and select &lt;strong&gt;Mark as Best in Batch Optimizer&lt;/strong&gt;. &lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;This changes the SQL alternative that is selected as the “Best Alternative” in the Batch Optimizer. When you generate the optimized script, this “Best Alternative” will be used to replace the original SQL statement.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;em&gt;If you would like to learn more about Quest SQL Optimizer for Oracle, please visit the &lt;/em&gt;&lt;a href="http://sqloptimizeroracle.inside.quest.com/index.jspa"&gt;&lt;font color="#800080"&gt;Inside SQL Optimizer for Oracle community&lt;/font&gt;&lt;/a&gt;. &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;</description>
      <link>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/224/Default.aspx</link>
      <author>Richard To</author>
      <comments>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/224/Default.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.toadworld.com/Default.aspx?tabid=67&amp;EntryID=224</guid>
      <pubDate>Fri, 23 May 2008 12:07:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.toadworld.com/DesktopModules/Blog/Trackback.aspx?id=224</trackback:ping>
    </item>
    <item>
      <title>Batch Optimizer Part 4 – Options Settings for the Batch Optimizer</title>
      <description>&lt;div&gt;&lt;em&gt;Written by Rene Woody&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;This blog is a continuation of a series about the Batch Optimizer in Quest SQL Optimizer &lt;em&gt;for Oracle&lt;/em&gt;. It covers the execution options settings for determining the criteria for selecting the best alternative, for terminating longer running SQL, and eliminating the effect of caching on the comparison run times. &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;font color="#000080" size="2"&gt;&lt;strong&gt;Selecting the Best Alternative&lt;/strong&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;The best alternative is selected based on the setting selected in the&lt;strong&gt; Best alternative selected based on lowest&lt;/strong&gt; option. This is either the fastest &lt;strong&gt;Total elapsed time&lt;/strong&gt; or the fastest &lt;strong&gt;First row elapsed time. &lt;/strong&gt;The &lt;strong&gt;Total elapsed time&lt;/strong&gt; is how long it takes to retrieve or process all the records. The First row elapsed time is how long it takes to retrieve or process the first record. &lt;br /&gt;
 &lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;img height="135" alt="" width="473" src="http://www.toadworld.com/Portals/0/blogimages/RichadToBlog05092008-1.gif" /&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;font color="#000080"&gt;Termination Criteria&lt;/font&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;In testing of the SQL alternatives, the goal is to find a SQL statement that runs faster than the original. So as soon as it is determined that a SQL alternative is not the best alternative, it should be terminated to minimize the time it takes for testing. &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;The &lt;strong&gt;Terminate execution of SQL alternative if it runs longer than&lt;/strong&gt; option provides three settings for determining when to terminate the execution of a SQL statement.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;strong&gt;Run time of fastest SQL&lt;/strong&gt; is the default setting. With this option, the original SQL statement is executed first and the time from that statement is used as the termination time for the next SQL statement. When a SQL statement runs faster than this termination time, the faster time is used as the new termination time. So you are always using the fastest run time as the termination time for the next SQL statement.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;strong&gt;Run time of original SQL&lt;/strong&gt; terminates a SQL alternative if it runs longer than the original SQL statement.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;strong&gt;User defined time&lt;/strong&gt; lets you set your own termination time. It first retrieves the run time of the original SQL statement. When the SQL alternatives are executed, they are terminated if they reach the specified time.&lt;br /&gt;
 &lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;img alt="" src="http://www.toadworld.com/Portals/0/blogimages/RichadToBlog05092008-2.gif" /&gt; &lt;/div&gt;
&lt;div&gt;  &lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;font color="#000080"&gt;Accounting for Caching&lt;/font&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Caching the data, the indexes, and the SQL statement can affect the comparison times if one SQL statement has to do some caching and others do not. Therefore, options are available so that you can select the one that provides you with the most accurate comparison of the run times in your environment.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;The &lt;strong&gt;Retrieving run time executing&lt;/strong&gt; optionhas these settings:&lt;br /&gt;
 &lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;img alt="" src="http://www.toadworld.com/Portals/0/blogimages/RichadToBlog05092008-3.gif" /&gt;&lt;/div&gt;
&lt;div&gt;  &lt;/div&gt;
&lt;div&gt;&lt;strong&gt;Original SQL twice using second run time and all others once&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;The first time you access data from a table, the data is cached into memory. This process takes a few moments. The next time you access that data, it is already in memory. Therefore, the first SQL statement executed will have the additional time it takes to cache the data included in the run time. Whereas, the SQL statements that follow do not have the additional time included in their run time. So to have a comparable test, the first SQL is run twice and the time from the second run is compared to the time from the other statements which are run once. In this case, all SQL statements are executed with the data cached.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;strong&gt;All SQL twice using the second run time&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;For fast running SQL statements, executing all SQL statements twice and using only the second run time enables you to eliminate two additional caching factors that can affect the accuracy of the comparison results: caching the SQL statement and caching the indexes. If some SQL statements have been recently executed, then the SQL information for those statements is likely to be resident in the cache and the statements may execute faster because the SQL statement does not need to be cached. Also, if some of the SQL statements use different indexes, one index may be resident in the cache and the other may not be in the cache. So running all the SQL statements twice ensures that each index is cached.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;strong&gt;All SQL once&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;For long running SQL statements, there is no need to run any statement twice since the effect from caching is diminished over time.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;em&gt;If you would like to learn more about Quest SQL Optimizer for Oracle, please visit the &lt;/em&gt;&lt;a href="http://sqloptimizeroracle.inside.quest.com/index.jspa"&gt;Inside SQL Optimizer for Oracle community&lt;/a&gt;. &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;</description>
      <link>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/217/Default.aspx</link>
      <author>Richard To</author>
      <comments>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/217/Default.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.toadworld.com/Default.aspx?tabid=67&amp;EntryID=217</guid>
      <pubDate>Fri, 09 May 2008 13:53:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.toadworld.com/DesktopModules/Blog/Trackback.aspx?id=217</trackback:ping>
    </item>
    <item>
      <title>Batch Optimizer Part 3 – Options Settings for the Batch Optimizer</title>
      <description>&lt;div&gt;&lt;em&gt;Written by Rene Woody&lt;br /&gt;
 &lt;/em&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div&gt;This blog is a continuation of a series about the Batch Optimizer in Quest SQL Optimizer &lt;em&gt;for Oracle&lt;/em&gt;. It covers the execution options settings that determine which SQL statements will be automatically executed by the Batch Optimizer process and the method used for their execution.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;strong&gt;Executing Options&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;When the optimization process is finished, the execution of the original SQL statement and the selected alternatives is automatically started if the &lt;strong&gt;Automatically execute SQL rewrites after optimization &lt;/strong&gt;setting is selected.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;The specific type of SQL statements which are executed automatically is determined by the SQL types selected under the &lt;strong&gt;Execute only these SQL statement types: SELECT&lt;/strong&gt;,&lt;strong&gt; INSERT&lt;/strong&gt;, &lt;strong&gt;UPDATE&lt;/strong&gt;, or&lt;strong&gt; DELETE&lt;/strong&gt;. By default, only the &lt;strong&gt;SELECT&lt;/strong&gt; SQL statements are executed automatically.&lt;br /&gt;
 &lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;img height="155" alt="" width="474" src="http://www.toadworld.com/Portals/0/blogimages/RichardToBlog04252008-1.png" /&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Note: INSERT, UPDATE, and DELETE SQL statements are run in a transaction that is rolled back after each execution so that the data in the database is not changed by the execution process.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;The &lt;strong&gt;Execute only these SQL alternatives&lt;/strong&gt; setting also determines which SQL alternatives are executed. All of the options under this setting are based on the Oracle cost estimation for each SQL alternative in comparison to the Oracle cost of the original SQL statement. By default, only the ten SQL statements with the lowest Oracle cost are executed.&lt;br /&gt;
 &lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;img alt="" src="http://www.toadworld.com/Portals/0/blogimages/RichardToBlog04252008-2.png" /&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;When executing the SQL statements in the Batch Optimizer, the default execution method is &lt;strong&gt;Run on server&lt;/strong&gt;. This means that all SQL statements are executed on the server and do not return the data from the SELECT statements to the client. Executing the SQL statements with this method provides you with the time it takes the SQL statement to execute on the Server. It does not cause extra network traffic by sending the data to the client. When using this method, your logon account must have the privilege to use the SYS.DBMS_SQL package to execute SQL statements on the server.&lt;br /&gt;
 &lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;img alt="" src="http://www.toadworld.com/Portals/0/blogimages/RichardToBlog04252008-3.png" /&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;em&gt;If you would like to learn more about Quest SQL Optimizer for Oracle, please visit the &lt;/em&gt;&lt;a href="http://sqloptimizeroracle.inside.quest.com/index.jspa"&gt;Inside SQL Optimizer for Oracle community&lt;/a&gt;.</description>
      <link>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/210/Default.aspx</link>
      <author>Richard To</author>
      <comments>http://www.toadworld.com/Community/Blogs/tabid/67/EntryID/210/Default.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.toadworld.com/Default.aspx?tabid=67&amp;EntryID=210</guid>
      <pubDate>Fri, 25 Apr 2008 14:44:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.toadworld.com/DesktopModules/Blog/Trackback.aspx?id=210</trackback:ping>
    </item>
  </channel>
</rss>