<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Do SQL Plan Baselines Use Hints? - Take 2</title>
	<atom:link href="http://kerryosborne.oracle-guy.com/2009/04/do-sql-plan-baselines-use-hints-take-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://kerryosborne.oracle-guy.com/2009/04/do-sql-plan-baselines-use-hints-take-2/</link>
	<description>Just another Oracle blog</description>
	<pubDate>Thu, 09 Sep 2010 23:24:28 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: osborne</title>
		<link>http://kerryosborne.oracle-guy.com/2009/04/do-sql-plan-baselines-use-hints-take-2/#comment-5425</link>
		<dc:creator>osborne</dc:creator>
		<pubDate>Tue, 20 Oct 2009 20:13:04 +0000</pubDate>
		<guid isPermaLink="false">http://kerryosborne.oracle-guy.com/?p=1226#comment-5425</guid>
		<description>Thanks for the comment Larry. 

You're exactly correct. It all comes down to whether a hint can be used or not. The format of many of the hints specify an object in a query block like the INDEX hint in our example above:

INDEX_RS_ASC(@"SEL$1" "A"@"SEL$1" ("LITTLE_SKEW"."COL1") 

As you pointed out, if you use an alias (in this case we used A), then the original statement can apply that hint because it doesn't have an object ("A") in the specified query block ("SEL$1").

Kerry</description>
		<content:encoded><![CDATA[<p>Thanks for the comment Larry. </p>
<p>You&#8217;re exactly correct. It all comes down to whether a hint can be used or not. The format of many of the hints specify an object in a query block like the INDEX hint in our example above:</p>
<p>INDEX_RS_ASC(@&#8221;SEL$1&#8243; &#8220;A&#8221;@&#8221;SEL$1&#8243; (&#8221;LITTLE_SKEW&#8221;.&#8221;COL1&#8243;) </p>
<p>As you pointed out, if you use an alias (in this case we used A), then the original statement can apply that hint because it doesn&#8217;t have an object (&#8221;A&#8221;) in the specified query block (&#8221;SEL$1&#8243;).</p>
<p>Kerry</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Larry Thomas</title>
		<link>http://kerryosborne.oracle-guy.com/2009/04/do-sql-plan-baselines-use-hints-take-2/#comment-5423</link>
		<dc:creator>Larry Thomas</dc:creator>
		<pubDate>Tue, 20 Oct 2009 17:02:58 +0000</pubDate>
		<guid isPermaLink="false">http://kerryosborne.oracle-guy.com/?p=1226#comment-5423</guid>
		<description>We have also noticed cases in which fixed plans are not being used. In each case the scenario was identical to your test case. A baseline was created by auto-capturing or manually inserting a plan in a baseline. A hinted statement was then run to create the desired plan and that was added to the baseline as the fixed plan. In each case where we had problems, we found that we had aliased a table in the hinted statement (as you did in the example above) and had not had a corresponding alias in the original statement. Removing the alias from the hinted plan solved the problem.

In your test case above removing the alias and using the table name in the hint seems to allow the unhinted statement to use the fixed baseline plan.

Larry Thomas</description>
		<content:encoded><![CDATA[<p>We have also noticed cases in which fixed plans are not being used. In each case the scenario was identical to your test case. A baseline was created by auto-capturing or manually inserting a plan in a baseline. A hinted statement was then run to create the desired plan and that was added to the baseline as the fixed plan. In each case where we had problems, we found that we had aliased a table in the hinted statement (as you did in the example above) and had not had a corresponding alias in the original statement. Removing the alias from the hinted plan solved the problem.</p>
<p>In your test case above removing the alias and using the table name in the hint seems to allow the unhinted statement to use the fixed baseline plan.</p>
<p>Larry Thomas</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: osborne</title>
		<link>http://kerryosborne.oracle-guy.com/2009/04/do-sql-plan-baselines-use-hints-take-2/#comment-4059</link>
		<dc:creator>osborne</dc:creator>
		<pubDate>Wed, 12 Aug 2009 21:45:10 +0000</pubDate>
		<guid isPermaLink="false">http://kerryosborne.oracle-guy.com/?p=1226#comment-4059</guid>
		<description>Mike,

  DBA_SQL_PLAN_BALSELINES is based in part on sqlobj$ which has a column (not exposed in DBA_SQL_PLAN_BASELINES) called plan_id. It does not match the actual plan_hash_value column from v$sql but I believe it is basically the same thing but possibly with additional columns from the v$sql_plan table included the hash calculation. I have not found any cross reference unfortunately. If you Wolfgang a statement that uses a Baseline you will see a line in the trace file something like this:

planId in plan baseline = 2333352146, planId of reproduced plan = 2333352146

This line let's you know whether the plan reproduced using the Baseline hints matched or whether it fell back to re-optimizing the plan from scratch.

Here's the definition of the DBA_SQL_PLAN_BASELINES view and a describe on sqlobj$:

&lt;pre&gt;

SQL&gt; @view_def
Enter value for view_name: DBA_SQL_PLAN_BASELINES

VIEW_NAME                      TEXT
------------------------------ --------------------------------------------------------------------------------
DBA_SQL_PLAN_BASELINES         SELECT /*+ dynamic_sampling(3) */
                                   so.signature,
                                   st.sql_handle,
                                   st.sql_text,
                                   so.name,
                                   ad.creator,
                                   DECODE(ad.origin, 1, 'MANUAL-LOAD',
                                                     2, 'AUTO-CAPTURE',
                                                     3, 'MANUAL-SQLTUNE',
                                                     4, 'AUTO-SQLTUNE',
                                                        'UNKNOWN'),
                                   ad.parsing_schema_name,
                                   ad.description,
                                   ad.version,
                                   ad.created,
                                   ad.last_modified,
                                   so.last_executed,
                                   ad.last_verified,
                                   DECODE(BITAND(so.flags, 1), 1, 'YES', 'NO'),
                                   DECODE(BITAND(so.flags, 2), 2, 'YES', 'NO'),
                                   DECODE(BITAND(so.flags, 4), 4, 'YES', 'NO'),
                                   DECODE(BITAND(so.flags, 8), 8, 'YES', 'NO'),
                                   ad.optimizer_cost,
                                   ad.module,
                                   ad.action,
                                   ad.executions,
                                   ad.elapsed_time,
                                   ad.cpu_time,
                                   ad.buffer_gets,
                                   ad.disk_reads,
                                   ad.direct_writes,
                                   ad.rows_processed,
                                   ad.fetches,
                                   ad.end_of_fetch_count
                               FROM
                                   sqlobj$        so,
                                   sqlobj$auxdata ad,
                                   sql$text       st
                               WHERE
                                   so.signature = st.signature AND
                                   ad.signature = st.signature AND
                                   so.signature = ad.signature AND
                                   so.plan_id = ad.plan_id AND
                                   so.obj_type = 2 AND
                                   ad.obj_type = 2


SQL&gt; desc sqlobj$
 Name                                                                                   Null?    Type
 -------------------------------------------------------------------------------------- -------- ----------------------------------------------------------
 SIGNATURE                                                                              NOT NULL NUMBER
 CATEGORY                                                                               NOT NULL VARCHAR2(30)
 OBJ_TYPE                                                                               NOT NULL NUMBER
 PLAN_ID                                                                                NOT NULL NUMBER
 NAME                                                                                   NOT NULL VARCHAR2(30)
 FLAGS                                                                                  NOT NULL NUMBER
 LAST_EXECUTED                                                                                   TIMESTAMP(6)
 SPARE1                                                                                          NUMBER
 SPARE2                                                                                          CLOB
&lt;/pre&gt;

Hope that helps.

Kerry</description>
		<content:encoded><![CDATA[<p>Mike,</p>
<p>  DBA_SQL_PLAN_BALSELINES is based in part on sqlobj$ which has a column (not exposed in DBA_SQL_PLAN_BASELINES) called plan_id. It does not match the actual plan_hash_value column from v$sql but I believe it is basically the same thing but possibly with additional columns from the v$sql_plan table included the hash calculation. I have not found any cross reference unfortunately. If you Wolfgang a statement that uses a Baseline you will see a line in the trace file something like this:</p>
<p>planId in plan baseline = 2333352146, planId of reproduced plan = 2333352146</p>
<p>This line let&#8217;s you know whether the plan reproduced using the Baseline hints matched or whether it fell back to re-optimizing the plan from scratch.</p>
<p>Here&#8217;s the definition of the DBA_SQL_PLAN_BASELINES view and a describe on sqlobj$:</p>
<pre>

SQL> @view_def
Enter value for view_name: DBA_SQL_PLAN_BASELINES

VIEW_NAME                      TEXT
------------------------------ --------------------------------------------------------------------------------
DBA_SQL_PLAN_BASELINES         SELECT /*+ dynamic_sampling(3) */
                                   so.signature,
                                   st.sql_handle,
                                   st.sql_text,
                                   so.name,
                                   ad.creator,
                                   DECODE(ad.origin, 1, 'MANUAL-LOAD',
                                                     2, 'AUTO-CAPTURE',
                                                     3, 'MANUAL-SQLTUNE',
                                                     4, 'AUTO-SQLTUNE',
                                                        'UNKNOWN'),
                                   ad.parsing_schema_name,
                                   ad.description,
                                   ad.version,
                                   ad.created,
                                   ad.last_modified,
                                   so.last_executed,
                                   ad.last_verified,
                                   DECODE(BITAND(so.flags, 1), 1, 'YES', 'NO'),
                                   DECODE(BITAND(so.flags, 2), 2, 'YES', 'NO'),
                                   DECODE(BITAND(so.flags, 4), 4, 'YES', 'NO'),
                                   DECODE(BITAND(so.flags, 8), 8, 'YES', 'NO'),
                                   ad.optimizer_cost,
                                   ad.module,
                                   ad.action,
                                   ad.executions,
                                   ad.elapsed_time,
                                   ad.cpu_time,
                                   ad.buffer_gets,
                                   ad.disk_reads,
                                   ad.direct_writes,
                                   ad.rows_processed,
                                   ad.fetches,
                                   ad.end_of_fetch_count
                               FROM
                                   sqlobj$        so,
                                   sqlobj$auxdata ad,
                                   sql$text       st
                               WHERE
                                   so.signature = st.signature AND
                                   ad.signature = st.signature AND
                                   so.signature = ad.signature AND
                                   so.plan_id = ad.plan_id AND
                                   so.obj_type = 2 AND
                                   ad.obj_type = 2

SQL> desc sqlobj$
 Name                                                                                   Null?    Type
 -------------------------------------------------------------------------------------- -------- ----------------------------------------------------------
 SIGNATURE                                                                              NOT NULL NUMBER
 CATEGORY                                                                               NOT NULL VARCHAR2(30)
 OBJ_TYPE                                                                               NOT NULL NUMBER
 PLAN_ID                                                                                NOT NULL NUMBER
 NAME                                                                                   NOT NULL VARCHAR2(30)
 FLAGS                                                                                  NOT NULL NUMBER
 LAST_EXECUTED                                                                                   TIMESTAMP(6)
 SPARE1                                                                                          NUMBER
 SPARE2                                                                                          CLOB
</pre>
<p>Hope that helps.</p>
<p>Kerry</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Tefft</title>
		<link>http://kerryosborne.oracle-guy.com/2009/04/do-sql-plan-baselines-use-hints-take-2/#comment-4044</link>
		<dc:creator>Mike Tefft</dc:creator>
		<pubDate>Wed, 12 Aug 2009 11:51:20 +0000</pubDate>
		<guid isPermaLink="false">http://kerryosborne.oracle-guy.com/?p=1226#comment-4044</guid>
		<description>You say 'I never could find a place where the plan data was stored (only the plan_hash_value).' Where did you find it? 

I can see the plan_hash_value in the output from dbms_xplan.display_sql_plan_baseline but view dba_sql_plan_baselines does not have a plan_hash_value. It has a plan_name but it does not look anything like a plan_hash_value and I do not know where any cross-reference is.

Thanks,
Mike</description>
		<content:encoded><![CDATA[<p>You say &#8216;I never could find a place where the plan data was stored (only the plan_hash_value).&#8217; Where did you find it? </p>
<p>I can see the plan_hash_value in the output from dbms_xplan.display_sql_plan_baseline but view dba_sql_plan_baselines does not have a plan_hash_value. It has a plan_name but it does not look anything like a plan_hash_value and I do not know where any cross-reference is.</p>
<p>Thanks,<br />
Mike</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://kerryosborne.oracle-guy.com/2009/04/do-sql-plan-baselines-use-hints-take-2/#comment-2488</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Mon, 15 Jun 2009 05:41:15 +0000</pubDate>
		<guid isPermaLink="false">http://kerryosborne.oracle-guy.com/?p=1226#comment-2488</guid>
		<description>Interesting. It appears there can be an SMB "statement match", but an attempt to "reproduce accepted plan" failed with "SPM: generated non-matching plan". The important bit for me was seeing the 10053 and two types of "matches", e.g. statement match and matching/non-matching plan.

In the documentation, it says "non-match" might happen if you remove an index from all accepted plans. E.g. "if a change in the system (such as a dropped index) causes all accepted plans to become non-reproducible, the optimizer will select the best-cost plan". I think you created the opposite case with same effect using a hint, e.g. forcing an index with hint. Another test case might limit using a variable from the plan history such as bind variables, etc. E.g. "plan history will include relevant information used by the optimizer to reproduce an execution plan, such as the SQL text, outline, bind variables, and compilation environment".

Good luck.</description>
		<content:encoded><![CDATA[<p>Interesting. It appears there can be an SMB &#8220;statement match&#8221;, but an attempt to &#8220;reproduce accepted plan&#8221; failed with &#8220;SPM: generated non-matching plan&#8221;. The important bit for me was seeing the 10053 and two types of &#8220;matches&#8221;, e.g. statement match and matching/non-matching plan.</p>
<p>In the documentation, it says &#8220;non-match&#8221; might happen if you remove an index from all accepted plans. E.g. &#8220;if a change in the system (such as a dropped index) causes all accepted plans to become non-reproducible, the optimizer will select the best-cost plan&#8221;. I think you created the opposite case with same effect using a hint, e.g. forcing an index with hint. Another test case might limit using a variable from the plan history such as bind variables, etc. E.g. &#8220;plan history will include relevant information used by the optimizer to reproduce an execution plan, such as the SQL text, outline, bind variables, and compilation environment&#8221;.</p>
<p>Good luck.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
