<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>For DBA</title>
	<atom:link href="http://fordba.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://fordba.wordpress.com</link>
	<description>Oracle Site for DBA</description>
	<lastBuildDate>Sat, 28 Jan 2012 08:09:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='fordba.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/3c92ac6e0ac36cbcc3b75b49ad506ec8?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>For DBA</title>
		<link>http://fordba.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://fordba.wordpress.com/osd.xml" title="For DBA" />
	<atom:link rel='hub' href='http://fordba.wordpress.com/?pushpress=hub'/>
		<item>
		<title>SPM and Profiles &#8211;Part 3</title>
		<link>http://fordba.wordpress.com/2012/01/23/spm-and-profiles-part-3/</link>
		<comments>http://fordba.wordpress.com/2012/01/23/spm-and-profiles-part-3/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 07:43:32 +0000</pubDate>
		<dc:creator>Sumit</dc:creator>
				<category><![CDATA[Baselines]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Difference between explain plan and execution plan]]></category>
		<category><![CDATA[execution plan]]></category>
		<category><![CDATA[explain plan and execution plan]]></category>
		<category><![CDATA[hash value]]></category>
		<category><![CDATA[other_xml]]></category>
		<category><![CDATA[outline data]]></category>
		<category><![CDATA[Outlines]]></category>
		<category><![CDATA[plan_hash2]]></category>
		<category><![CDATA[plan_hash_2]]></category>
		<category><![CDATA[plan_table]]></category>
		<category><![CDATA[profiles]]></category>
		<category><![CDATA[SPM]]></category>
		<category><![CDATA[sql profiles]]></category>

		<guid isPermaLink="false">http://fordba.wordpress.com/?p=511</guid>
		<description><![CDATA[Fix for  &#8221;My Explain plan and Execution plan are different&#8221; You might think , that i got possessed with baselines and profiles but I like exploring them. The deeper I explore, the more fun it is. In the last post, I had covered how to convert profiles baselines into profiles. Taking a step further this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=511&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2><span style="color:#0000ff;">Fix for  &#8221;My Explain plan and Execution plan are different&#8221;</span></h2>
<p><span style="color:#000080;">You might think , that i got possessed with baselines and profiles but I like exploring them.</span></p>
<p><span style="color:#000080;"> The deeper I explore, the more fun it is.</span></p>
<p><span style="color:#003366;"><a title="SPM and Profile-Part 2" href="http://fordba.wordpress.com/2011/11/21/spm-and-profiles-part2/" target="_blank">In the last post</a>, I had covered how to convert profiles baselines into profiles.</span></p>
<p><span style="color:#000080;">Taking a step further this time, I tried to sync my explain plan with execution plan.</span></p>
<p><span style="color:#000080;">A bit of history:-</span></p>
<p><span style="color:#000080;">Some days back, I ran into issue where explain plan was looking very much optimal but when I executed the query, it was picking different plan.</span></p>
<p><span style="color:#000080;">So, i thought why not get a way to force the plan of explain plan during execution.</span></p>
<p><span style="color:#000080;">In other words, why not sync my explain plan and execution plan.</span></p>
<p><span style="color:#000080;">So, i started exploring plan_table and voila&#8230;.there it was. My favorite column other_xml.</span></p>
<p><span style="color:#000080;">By now, you must have realized, that oracle stores all the hints and some other stuff like (plan_hash2-&gt;This i will explain in some other post) in this column. When you use dbms_xplan, oracle parses this column and print in readable format.</span></p>
<p><span style="color:#000080;">I too extracted the info in my desired format from this column and create a script(xplanprofile.sql) to generate profile.</span></p>
<p><span style="color:#008080;"><strong><a title="Creating profile using explain plan" href="http://fordba.wordpress.com/2011/04/01/xplanprofile-sql/" target="_blank">xplanprofile.sql</a></strong></span></p>
<p><pre class="brush: sql;">
Session1&gt; explain plan for select * from master_log where task_id=:b1;
Session1&gt;@xplanprofile
enter original sql_id:- 9ghy678ujy345
enter bad plan hash value to be tuned :- 3709384
'===================OUTPUT========================='

declare
ar_profile_hints sys.sqlprof_attr;
begin
 ar_profile_hints := sys.sqlprof_attr(
 'BEGIN_OUTLINE_DATA',
 'INDEX_RS_ASC(@&quot;SEL$1&quot; &quot;MASTER_LOG&quot;@&quot;SEL$1&quot; (&quot;MASTER_LOG&quot;.&quot;TASK_ID&quot;))',
 'OUTLINE_LEAF(@&quot;SEL$1&quot;)',
 'OPT_PARAM(''optimizer_index_caching'' 80)',
 'OPT_PARAM(''optimizer_index_cost_adj'' 1)',
 'OPT_PARAM(''_optimizer_connect_by_cost_based'' ''false'')',
 'OPT_PARAM(''_optim_peek_user_binds'' ''false'')',
 'OPT_PARAM(''_b_tree_bitmap_plans'' ''false'')',
 'DB_VERSION(''11.2.0.2'')',
 'OPTIMIZER_FEATURES_ENABLE(''11.1.0.7'')',
 'IGNORE_OPTIM_EMBEDDED_HINTS',
 'END_OUTLINE_DATA'
);
for sql_rec in (
 select t.sql_id, t.sql_text
 from dba_hist_sqltext t, dba_hist_sql_plan p
 where t.sql_id = p.sql_id and p.sql_id = 'sehy678ujy345' and p.plan_hash_value = 3709384 and p.parent_id is null
 ) loop
 DBMS_SQLTUNE.IMPORT_SQL_PROFILE(
 sql_text =&gt; sql_rec.sql_text,profile =&gt; ar_profile_hints,name =&gt; 'PROFILE_'||sql_rec.sql_id
 );
 end loop;
end;
/

</pre></p>
<br />Filed under: <a href='http://fordba.wordpress.com/category/baselines/'>Baselines</a>, <a href='http://fordba.wordpress.com/category/uncategorized/'>Uncategorized</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fordba.wordpress.com/511/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fordba.wordpress.com/511/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fordba.wordpress.com/511/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fordba.wordpress.com/511/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fordba.wordpress.com/511/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fordba.wordpress.com/511/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fordba.wordpress.com/511/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fordba.wordpress.com/511/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fordba.wordpress.com/511/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fordba.wordpress.com/511/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fordba.wordpress.com/511/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fordba.wordpress.com/511/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fordba.wordpress.com/511/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fordba.wordpress.com/511/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=511&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fordba.wordpress.com/2012/01/23/spm-and-profiles-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0b8748224dcc3259b8c20081f7a988ac?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sbhatia83</media:title>
		</media:content>
	</item>
		<item>
		<title>SPM and Profiles -Part2</title>
		<link>http://fordba.wordpress.com/2011/11/21/spm-and-profiles-part2/</link>
		<comments>http://fordba.wordpress.com/2011/11/21/spm-and-profiles-part2/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 19:27:58 +0000</pubDate>
		<dc:creator>Sumit</dc:creator>
				<category><![CDATA[Baselines]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[active data guard]]></category>
		<category><![CDATA[ADG]]></category>
		<category><![CDATA[baseline not used in standby]]></category>
		<category><![CDATA[baselines not getting used]]></category>
		<category><![CDATA[baselines not getting used in ADG]]></category>
		<category><![CDATA[controlling execution plan]]></category>
		<category><![CDATA[converting baseline into profiles]]></category>
		<category><![CDATA[converting profiles into baselines]]></category>
		<category><![CDATA[difference baselines and profiles]]></category>
		<category><![CDATA[difference profiles and baselines]]></category>
		<category><![CDATA[hints oracle]]></category>
		<category><![CDATA[oldprofile.sql]]></category>
		<category><![CDATA[oracle execution plan]]></category>
		<category><![CDATA[oracle execution plans]]></category>
		<category><![CDATA[performance tuning]]></category>
		<category><![CDATA[planprofile.sql]]></category>
		<category><![CDATA[profile 10g]]></category>
		<category><![CDATA[profile not used in standby]]></category>
		<category><![CDATA[similarity baselines and profile]]></category>
		<category><![CDATA[similarity profiles and baselines]]></category>
		<category><![CDATA[SPM 11g]]></category>
		<category><![CDATA[spm bugs]]></category>
		<category><![CDATA[sql profile]]></category>

		<guid isPermaLink="false">http://fordba.wordpress.com/?p=471</guid>
		<description><![CDATA[Converting baselines into profiles In my last post, we have discussed various workarounds to fix the execution plan of the query if its not picking baseline. Of the given 3 methods, I was interested in the 3rd one. What got me interested is the idea if we can create profiles from  baselines.  The next obvious [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=471&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2><span style="color:#3366ff;">Converting baselines into profiles</span></h2>
<p><span style="color:#000080;"><a title="Baselines and Profiles 1" href="http://fordba.wordpress.com/2011/10/23/spm-profiles-part-1/" target="_blank">In my last post</a>, we have discussed various workarounds to fix the execution plan of the query if its not picking baseline.</span></p>
<p><span style="color:#000080;">Of the given 3 methods, I was interested in the 3rd one. What got me interested is the idea if we can create profiles from  baselines. </span></p>
<p><span style="color:#000080;">The next obvious question is &#8220;why you need to do so&#8221;.</span></p>
<p><span style="color:#000080;">The 2 reasons are</span></p>
<p><span style="color:#000080;">1. Baselines not getting used. In this case you can create a profile out of baseline and then impose oracle to use this profile.</span></p>
<p><span style="color:#000080;">2. In 11g, we have ADG (active standby database). Guess what!!! Baselines doesn&#8217;t work in ADG. So if you fix query on primary, it won&#8217;t pick the plan in standby. So you better create a profile.  Also you may need to bounce your standby in order for profile to get used (because of another bug).</span></p>
<p><span style="color:#000080;">Before I talk about script to convert baselines into profiles, lets step back and think whats is that thing which is common in baselines and profiles(if at all there is) and what is that thing which makes them different.</span></p>
<p><span style="color:#000080;">Both baselines and profiles store data in form of hints. </span></p>
<p><span style="color:#000080;">Only difference is in case of baselines oracle tries to regenerate the same plan using hints and if it can&#8217;t then it will not use the baseline.</span></p>
<p><span style="color:#000080;">However, in case of profile, oracle will use the hints to generate the execution plan which it will use. Therefore, there is no guarantee that oracle will land on same plan again and again and hence plan flip can occur.</span></p>
<p><span style="color:#000080;">I will soon write about hints and how oracle stores them for a given plan.</span></p>
<p><span style="color:#000080;">Anyway, coming back to our point, oracle stores the execution plan in form of hints. Therefore, for each plan it captures or generates, it must store them somewhere. The idea is to get those hints and create the profile.</span></p>
<h3><span style="color:#0000ff;"><a title="convert baseline into profile" href="http://fordba.wordpress.com/2011/04/01/planprofile-sql/" target="_blank">planprofile.sql:-</a></span></h3>
<p><pre class="brush: sql;">
Session1&gt;select plan_name from dba_sql_plan_baselines where rownum &lt; 2;

PLAN_NAME
------------------------------
SYS_SQL_PLAN_086da2eaeec7bdef

1 row selected.

Session1&gt;@planprofile
enter sql_id to be fixed:- dgh672sad89j4
baseline plan name:- SYS_SQL_PLAN_086da2eaeec7bdef
enter bad plan hash value to be tuned :- 12345678
'===================OUTPUT========================='

declare
ar_profile_hints sys.sqlprof_attr;
begin
 ar_profile_hints := sys.sqlprof_attr(
 'BEGIN_OUTLINE_DATA',
 'FULL(@&quot;SEL$4&quot; &quot;MRH&quot;@&quot;SEL$4&quot;)',
 'NO_ACCESS(@&quot;SEL$3&quot; &quot;from$_subquery$_007&quot;@&quot;SEL$3&quot;)',
 'FULL(@&quot;SEL$6&quot; &quot;MRH&quot;@&quot;SEL$6&quot;)',
 'NO_ACCESS(@&quot;SEL$5&quot; &quot;from$_subquery$_004&quot;@&quot;SEL$5&quot;)',
 'PQ_DISTRIBUTE(@&quot;SEL$F5BB74E1&quot; &quot;RMS&quot;@&quot;SEL$2&quot; NONE BROADCAST)',
 'USE_NL(@&quot;SEL$F5BB74E1&quot; &quot;RMS&quot;@&quot;SEL$2&quot;)',
 'LEADING(@&quot;SEL$F5BB74E1&quot; &quot;H&quot;@&quot;SEL$1&quot; &quot;RMS&quot;@&quot;SEL$2&quot;)',
 'INDEX_RS_ASC(@&quot;SEL$F5BB74E1&quot; &quot;RMS&quot;@&quot;SEL$2&quot; (&quot;METRICS_SUMMARY95&quot;.&quot;MVIEW_NAME&quot; &quot;METRICS_SUMMARY95&quot;.&quot;OWNER&quot;))',
 'NO_ACCESS(@&quot;SEL$F5BB74E1&quot; &quot;H&quot;@&quot;SEL$1&quot;)',
 'PQ_DISTRIBUTE(@&quot;MRG$1&quot; &quot;H&quot;@&quot;MRG$1&quot; BROADCAST NONE)',
 'PQ_DISTRIBUTE(@&quot;MRG$1&quot; &quot;RMS&quot;@&quot;MRG$1&quot; NONE BROADCAST)',
 'USE_MERGE_CARTESIAN(@&quot;MRG$1&quot; &quot;H&quot;@&quot;MRG$1&quot;)',
 'USE_MERGE_CARTESIAN(@&quot;MRG$1&quot; &quot;RMS&quot;@&quot;MRG$1&quot;)',
 'LEADING(@&quot;MRG$1&quot; &quot;from$_subquery$_010&quot;@&quot;MRG$1&quot; &quot;RMS&quot;@&quot;MRG$1&quot; &quot;H&quot;@&quot;MRG$1&quot;)',
 'NO_ACCESS(@&quot;MRG$1&quot; &quot;H&quot;@&quot;MRG$1&quot;)',
 'FULL(@&quot;MRG$1&quot; &quot;RMS&quot;@&quot;MRG$1&quot;)',
 'NO_ACCESS(@&quot;MRG$1&quot; &quot;from$_subquery$_010&quot;@&quot;MRG$1&quot;)',
 'OUTLINE(@&quot;SEL$2&quot;)',
 'OUTLINE(@&quot;SEL$1&quot;)',
 'OUTLINE_LEAF(@&quot;MRG$1&quot;)',
 'OUTLINE_LEAF(@&quot;SEL$5&quot;)',
 'OUTLINE_LEAF(@&quot;SEL$6&quot;)',
 'MERGE(@&quot;SEL$2&quot;)',
 'OUTLINE_LEAF(@&quot;SEL$F5BB74E1&quot;)',
 'OUTLINE_LEAF(@&quot;SEL$3&quot;)',
 'OUTLINE_LEAF(@&quot;SEL$4&quot;)',
 'OPT_PARAM(''optimizer_index_caching'' 80)',
 'OPT_PARAM(''optimizer_index_cost_adj'' 3)',
 'OPT_PARAM(''_optimizer_connect_by_cost_based'' ''false'')',
 'OPT_PARAM(''_optim_peek_user_binds'' ''false'')',
 'OPT_PARAM(''_b_tree_bitmap_plans'' ''false'')',
 'DB_VERSION(''11.1.0.7'')',
 'OPTIMIZER_FEATURES_ENABLE(''11.1.0.7'')',
 'IGNORE_OPTIM_EMBEDDED_HINTS',
 'END_OUTLINE_DATA'
);
for sql_rec in (
 select t.sql_id, t.sql_text
 from dba_hist_sqltext t, dba_hist_sql_plan p
 where t.sql_id = p.sql_id and p.sql_id = 'dgh672sad89j4' and p.plan_hash_value = 12345678 and p.parent_id is null
 ) loop
 DBMS_SQLTUNE.IMPORT_SQL_PROFILE(
 sql_text =&gt; sql_rec.sql_text,profile =&gt; ar_profile_hints,name =&gt; 'PROFILE_'||sql_rec.sql_id
 );
 end loop;
end;
/

</pre></p>
<p><span style="color:#000080;">That was simple. Isn&#8217;t it?? </span></p>
<p><span style="color:#000080;">But i was not satisfied. I wanted to take this a step further. Now i want oracle to use whatever plan I want. </span></p>
<p><span style="color:#000080;">In case oracle had changed plan , I want oracle to use previous plan. </span></p>
<p><span style="color:#000080;">In one of my database, planflip caused cpu spikes. Buffer_gets/exec increased from thousands to millions. The idea was to force old to use previous plan .</span></p>
<h3><span style="color:#0000ff;"><a title="Controlling execution plan" href="http://fordba.wordpress.com/2011/04/01/oldprofile-sql/" target="_blank">oldprofile.sql</a></span></h3>
<p><pre class="brush: sql;">&lt;/pre&gt;
Sesion1&gt;@oldprofile
enter sql_id:- 9ddv4vbt2zrxy
enter old plan hash value:- 1236769290
enter bad plan hash value to be tuned :- 3891475932
'===================OUTPUT========================='

declare
ar_profile_hints sys.sqlprof_attr;
begin
 ar_profile_hints := sys.sqlprof_attr(
 'BEGIN_OUTLINE_DATA',
 'IGNORE_OPTIM_EMBEDDED_HINTS',
 'OPTIMIZER_FEATURES_ENABLE(''11.1.0.7'')',
 'DB_VERSION(''11.1.0.7'')',
 'OPT_PARAM(''_b_tree_bitmap_plans'' ''false'')',
 'OPT_PARAM(''_optim_peek_user_binds'' ''false'')',
 'OPT_PARAM(''_optimizer_connect_by_cost_based'' ''false'')',
 'OPT_PARAM(''optimizer_index_cost_adj'' 3)',
 'OPT_PARAM(''optimizer_index_caching'' 80)',
 'OUTLINE_LEAF(@&quot;SEL$1&quot;)',
 'INDEX(@&quot;SEL$1&quot; &quot;CCS&quot;@&quot;SEL$1&quot; (&quot;COMPLETED_CUSTOMER_SHIPMENTS&quot;.&quot;CONDITION&quot; &quot;COMPLETED_CUSTOMER_SHIPMENTS&quot;.&quot;LAST_UPDATED&quot;))',
 'END_OUTLINE_DATA'
);
for sql_rec in (
 select t.sql_id, t.sql_text
 from dba_hist_sqltext t, dba_hist_sql_plan p
 where t.sql_id = p.sql_id and p.sql_id = '9ddv4vbt2zrxy' and p.plan_hash_value = 3891475932 and p.parent_id is null
 ) loop
 DBMS_SQLTUNE.IMPORT_SQL_PROFILE(
 sql_text =&gt; sql_rec.sql_text,profile =&gt; ar_profile_hints,name =&gt; 'PROFILE_'||sql_rec.sql_id
 );
 end loop;
end;
/

</pre></p>
<br />Filed under: <a href='http://fordba.wordpress.com/category/baselines/'>Baselines</a>, <a href='http://fordba.wordpress.com/category/scripts/'>Scripts</a>, <a href='http://fordba.wordpress.com/category/index/scripts-index/'>Scripts</a>, <a href='http://fordba.wordpress.com/category/uncategorized/'>Uncategorized</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fordba.wordpress.com/471/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fordba.wordpress.com/471/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fordba.wordpress.com/471/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fordba.wordpress.com/471/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fordba.wordpress.com/471/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fordba.wordpress.com/471/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fordba.wordpress.com/471/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fordba.wordpress.com/471/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fordba.wordpress.com/471/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fordba.wordpress.com/471/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fordba.wordpress.com/471/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fordba.wordpress.com/471/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fordba.wordpress.com/471/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fordba.wordpress.com/471/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=471&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fordba.wordpress.com/2011/11/21/spm-and-profiles-part2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0b8748224dcc3259b8c20081f7a988ac?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sbhatia83</media:title>
		</media:content>
	</item>
		<item>
		<title>SPM &amp; Profiles-Part 1</title>
		<link>http://fordba.wordpress.com/2011/10/23/spm-profiles-part-1/</link>
		<comments>http://fordba.wordpress.com/2011/10/23/spm-profiles-part-1/#comments</comments>
		<pubDate>Sun, 23 Oct 2011 06:58:59 +0000</pubDate>
		<dc:creator>Sumit</dc:creator>
				<category><![CDATA[Baselines]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[baselines not getting used]]></category>
		<category><![CDATA[capture baseline]]></category>
		<category><![CDATA[create baseline]]></category>
		<category><![CDATA[create profile]]></category>
		<category><![CDATA[how to create sql profile]]></category>
		<category><![CDATA[how to make oracle pick baseline]]></category>
		<category><![CDATA[link baseline]]></category>
		<category><![CDATA[oracle not picking baseline]]></category>
		<category><![CDATA[oracle not picking my baseline]]></category>
		<category><![CDATA[oracle sql baseline]]></category>
		<category><![CDATA[profiles]]></category>
		<category><![CDATA[SPM]]></category>
		<category><![CDATA[sql baseline]]></category>
		<category><![CDATA[sql plan management]]></category>
		<category><![CDATA[sql tuning]]></category>

		<guid isPermaLink="false">http://fordba.wordpress.com/?p=434</guid>
		<description><![CDATA[SPM And Profiles-Part 1 Ever encountered issue when your query does not pick baseline. In some cases, even after setting fixed=Yes, it does not pick baseline. This may happen when you try fixing the query using hints and try to link the plan of hinted query with original query. This post is intended to provide [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=434&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2><span style="color:#0000ff;">SPM And Profiles-Part 1</span></h2>
<p><span style="color:#000080;">Ever encountered issue when your query does not pick baseline. In some cases, even after setting fixed=Yes, it does not pick baseline.</span></p>
<p><span style="color:#000080;">This may happen when you try fixing the query using hints and try to link the plan of hinted query with original query.</span></p>
<p><span style="color:#000080;">This post is intended to provide you the solutions for some of those issues. (And like every post a script for the dba&#8217;s.)</span></p>
<p><span style="color:#000080;">And most important, do we need profiles now.</span></p>
<h3><span class="Apple-style-span" style="color:#0000ff;">Why oracle is not picking my baseline</span></h3>
<p><span style="color:#000080;">There are several reasons(and bugs) why oracle  does not pick baselines.</span></p>
<p><span style="color:#000080;">In my case, I tried to manually tune the query using hints and linked the plan with the original query. However, oracle refused to pick the baseline. </span></p>
<p><span style="color:#000080;">In many cases reason could be</span></p>
<ol>
<li><span style="color:#000080;">Bind Variables used in the query</span></li>
<li><span style="color:#000080;">Aliases used  for the table</span></li>
</ol>
<p><span class="Apple-style-span" style="font-size:15px;font-weight:bold;color:#339966;">Solution 1:-</span></p>
<p><span style="color:#000080;">Using bind variables prevents oracle from generating multiple versions of the same query and helps in reducing hard parsing. But what if the same bind variables creates trouble for you.</span></p>
<p><span style="color:#000080;">If  your application is using bind variable or cursor_sharing is set to &#8220;similar&#8221;or &#8220;force&#8221;, then your query should look like this.</span></p>
<p><span style="color:#000080;">For the test case, I will use <a title="mytab table" href="http://fordba.wordpress.com/2011/06/10/mytab-table/" target="_blank">mytab table</a></span></p>
<p><pre class="brush: sql;">
Session1&gt; select  * from mytab a where a.generated=:b1;

no rows selected
</pre></p>
<p><span style="color:#000080;">You can always check the values of bind variables using following query.</span></p>
<p><pre class="brush: sql;">

Session2&gt;select name,value_string from v$sql_bind_capture where sql_id='&amp;sql_id' and child_number='&amp;child';

Enter value for sql_id: 3uj38fuby1shm
Enter value for child: 0
NAME                 VALUE_STRING
-------------------- ------------------------------
:B1                  FOR
1 row selected.
</pre></p>
<p><span style="color:#000080;">In cases, where query is using bind variables like the one given above, use following approach to tune the query and the link the baseline</span></p>
<p><pre class="brush: sql;">
var b1 varchar2(20);
exec :b1:='FOR';
Session1 &gt;select /*+ index(a MYTAB_IDX2) */ * from mytab a where a.generated=:b1;
no rows selected

</pre></p>
<p><span style="color:#000080;">Now, we can link the plan of the tuned sql with the original sql as described in <a title="Implementing Hints through Baseline" href="http://fordba.wordpress.com/2011/06/11/implementing-hints-through-baseline/" target="_blank"><span style="color:#000080;">earlier post</span></a>.</span></p>
<h3><span style="color:#008080;">Solution 2:-</span></h3>
<p><span style="color:#000080;">You may need to tune the sql&#8217;s running inside plsql packages and procedures. In those cases, bind variables name could be like &#8220;:1&#8243; which is hard to tune using traditional approach of baselines.</span></p>
<p><span style="color:#800080;">e.g. select * from mytab a where a.generated=:1;</span></p>
<p><span style="color:#000080;">To tune those sql&#8217;s you need to create a anonymous block and create a cursor like one given below.</span></p>
<p><pre class="brush: sql;">
declare
sql_stmt varchar2(4000);
id varchar2(20);
TYPE CurTyp  IS REF CURSOR;
tmpcursor    CurTyp;
begin
   id:='&amp;id_val';
  sql_stmt:='select /*+ index(a MYTAB_IDX2) */ * from mytab where generated=:1';
  open tmpcursor for sql_stmt using id;
end;
/
Enter value for id_val: FOR

PL/SQL procedure successfully completed.
</pre></p>
<p><span style="color:#000080;">Now, you can find the sql_id of the query and link the baseline with original sql.</span></p>
<p><pre class="brush: sql;">
Session1&gt;select sql_id,module,sql_text from v$sql where upper(sql_text) like upper('%&amp;text%') and ( sql_text not like lower('%v$sql%') and sql_text not like '%explain plan%') group by sql_id,module,sql_text;
Enter value for text: select /*+ index(a MYTAB_IDX2) */ * from mytab where generated=:1

SQL_ID        MODULE                    SQL_TEXT
------------- ------------------------- ------------------------------------------------------------------------------------------
5vkq50nxn4gsj SQL*Plus                  declare sql_stmt varchar2(4000); id varchar2(20); TYPE CurTyp  IS REF CURSOR; tmpcursor
                                         CurTyp; begin    id:='FOR';   sql_stmt:='select /*+ index(a MYTAB_IDX2) */ * from mytab w
                                        here generated=:1';   open tmpcursor for sql_stmt using id; end;

9z3dv649q3gvy SQL*Plus                  select /*+ index(a MYTAB_IDX2) */ * from mytab where generated=:1

2 rows selected.
</pre></p>
<p><span style="color:#000080;">You can link the plan of <strong><span style="color:#993300;">9z3dv649q3gvy</span></strong> with original query to tune it.</span></p>
<h3><span style="color:#008000;">Solution 3:-</span></h3>
<p><span style="color:#000080;">The second solution of using cursor may work well if query is small or using limited number of bind variables. But for page long queries, its cumbersome to concatenate multiple bind variables.</span></p>
<p><span style="color:#000080;">We can use profiles to bypass second approach. (<a title="profile.sql" href="http://fordba.wordpress.com/2011/04/01/profile-sql/" target="_blank">profile.sql</a>)</span></p>
<p><span style="color:#000080;"><a title="profile.sql" href="http://fordba.wordpress.com/2011/04/01/profile-sql/" target="_blank">Profile.sql</a> will ask for sql_id and child number of hinted sql and the sql_id and plan hash value of the bad sql_id. You can paste the output directly to create a profile.</span></p>
<p><pre class="brush: sql;">
Session1&gt;@profile
enter hinted sql_id:- 9z3dv649q3gvy
enter child number:- 0
enter original sql_id:- 9jutgyhjutefd
enter bad plan hash value to be tuned :- 663241269
'===================OUTPUT========================='

declare
ar_profile_hints sys.sqlprof_attr;
begin
        ar_profile_hints := sys.sqlprof_attr(
                'BEGIN_OUTLINE_DATA',
                'IGNORE_OPTIM_EMBEDDED_HINTS',
                'OPTIMIZER_FEATURES_ENABLE(''11.1.0.7'')',
                'DB_VERSION(''11.1.0.7'')',
                'OPT_PARAM(''_b_tree_bitmap_plans'' ''false'')',
                'OPT_PARAM(''_optim_peek_user_binds'' ''false'')',
                'OPT_PARAM(''_optimizer_connect_by_cost_based'' ''false'')',
                'OPT_PARAM(''optimizer_index_cost_adj'' 1)',
                'OPT_PARAM(''optimizer_index_caching'' 80)',
                'OUTLINE_LEAF(@&quot;SEL$1&quot;)',
                'INDEX_RS_ASC(@&quot;SEL$1&quot; &quot;MYTAB&quot;@&quot;SEL$1&quot; (&quot;MYTAB&quot;.&quot;GENERATED&quot;))',
                'END_OUTLINE_DATA'
);
for sql_rec in (
        select t.sql_id, t.sql_text
         from dba_hist_sqltext t, dba_hist_sql_plan p
        where t.sql_id = p.sql_id and p.sql_id = '9jutgyhjutefd' and p.plan_hash_value = 663241269 and p.parent_id is null
                ) loop
              DBMS_SQLTUNE.IMPORT_SQL_PROFILE(
                sql_text    =&gt; sql_rec.sql_text,profile     =&gt; ar_profile_hints,name =&gt; 'PROFILE_'||sql_rec.sql_id
                                        );
        end loop;
end;
/
</pre></p>
<p><span style="color:#000080;">You can paste the output directly to fix the sql.</span></p>
<p><span style="color:#000080;"><br />
</span></p>
<br />Filed under: <a href='http://fordba.wordpress.com/category/baselines/'>Baselines</a>, <a href='http://fordba.wordpress.com/category/uncategorized/'>Uncategorized</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fordba.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fordba.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fordba.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fordba.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fordba.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fordba.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fordba.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fordba.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fordba.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fordba.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fordba.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fordba.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fordba.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fordba.wordpress.com/434/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=434&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fordba.wordpress.com/2011/10/23/spm-profiles-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0b8748224dcc3259b8c20081f7a988ac?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sbhatia83</media:title>
		</media:content>
	</item>
		<item>
		<title>Baselines&#8211;Part II</title>
		<link>http://fordba.wordpress.com/2011/08/28/baselines-part-ii/</link>
		<comments>http://fordba.wordpress.com/2011/08/28/baselines-part-ii/#comments</comments>
		<pubDate>Sun, 28 Aug 2011 12:37:08 +0000</pubDate>
		<dc:creator>Sumit</dc:creator>
				<category><![CDATA[Baselines]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[accepted]]></category>
		<category><![CDATA[accepted baseline]]></category>
		<category><![CDATA[advance SPM]]></category>
		<category><![CDATA[capture baseline]]></category>
		<category><![CDATA[DBMS_SPM.ALTER_SQL_PLAN_BASELINE]]></category>
		<category><![CDATA[DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE]]></category>
		<category><![CDATA[enabled]]></category>
		<category><![CDATA[enabled baseline]]></category>
		<category><![CDATA[evolve baseline]]></category>
		<category><![CDATA[EVOLVE_SQL_PLAN_BASELINE]]></category>
		<category><![CDATA[exact_matching_signature]]></category>
		<category><![CDATA[fixed]]></category>
		<category><![CDATA[fixed baseline]]></category>
		<category><![CDATA[force_matching_signature]]></category>
		<category><![CDATA[Optimizer_capture_sql_plan_baselines]]></category>
		<category><![CDATA[Optimizer_use_sql_plan_baseline]]></category>
		<category><![CDATA[oracle sql baseline]]></category>
		<category><![CDATA[SPM]]></category>
		<category><![CDATA[sql baseline]]></category>
		<category><![CDATA[sql handle]]></category>
		<category><![CDATA[sql signature]]></category>

		<guid isPermaLink="false">http://fordba.wordpress.com/?p=335</guid>
		<description><![CDATA[Baselines Part-II In my previous post,  I had described how to implement hints through baselines without changing code. Also, I touched upon two parameters namely 1. Optimizer_capture_sql_plan_baselines              2. Optimizer_use_sql_plan_baseline  As I had written &#8220;optimizer_capture_sql_plan_baseline if set to true, let oracle automatically capture sql plan baselines.&#8221; Does it mean it will not capture any plan for any [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=335&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2><span style="color:#000080;">Baselines Part-II<br />
</span></h2>
<p><span style="color:#0000ff;">In my <a title="Implementing Hints through Baseline" href="http://fordba.wordpress.com/2011/06/11/implementing-hints-through-baseline/" target="_blank"><span style="color:#0000ff;">previous post</span></a>,  I had described how to implement hints through baselines without changing code. Also, I touched upon two parameters namely </span></p>
<p><strong><span style="color:#0000ff;">1. Optimizer_capture_sql_plan_baselines</span><span style="color:#0000ff;">              2. Optimizer_use_sql_plan_baseline </span></strong></p>
<p><span style="color:#0000ff;">As I had written &#8220;optimizer_capture_sql_plan_baseline if set to true, let oracle automatically capture sql plan baselines.&#8221;</span><strong></strong></p>
<p><span style="color:#800000;"><strong>Does it mean it will not capture any plan for any sql if set to false ?</strong></span></p>
<p><span style="color:#0000ff;"><strong><span style="color:#800000;">What if we want to capture baselines for only selected queries automatically.</span></strong></span></p>
<p><span style="color:#0000ff;">The whole answer lies in values of &#8220;ENABLED,ACCEPTED AND FIXED&#8221; column if dba_sql_plan_baselines. How!!!!!? Lets find out&#8230;<strong></strong></span></p>
<p><span style="color:#0000ff;">As usual, lets create a table and insert few records</span></p>
<p><pre class="brush: sql;">
Session1&gt;show parameter capture
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
optimizer_capture_sql_plan_baselines boolean     FALSE

create table test (name varchar2(10), id number(*));

begin
for i in 1..1000
loop
insert into test values ('SUMIT',i);
end loop;
commit;
end;
/
begin
for i in 1001..10000
loop
insert into test values ('BHATIA',i);
end loop;
commit;
end;
/
begin
for i in 10001..100000
loop
insert into test values ('BASELINE',i);
end loop;
commit;
end;
/
begin
for i in 100001..1000000
loop
insert into test values ('SPM',i);
end loop;
commit;
end;
/

SELECT COUNT(*),name from test group by name order by 1;

COUNT(*) NAME
---------- ----------
1000 SUMIT
9000 BHATIA
90000 BASELINE
900000 SPM

4 rows selected.
</pre></p>
<p><span style="color:#0000ff;">Time to query table and load the plan into the baseline.<br />
</span></p>
<p><pre class="brush: sql;">
--Inserting hint to easily identify the query
Select /*+ id=1000 */  * FROM TEST where id=1000
NAME               ID
---------- ----------
SUMIT            1000

select sql_id,exact_matching_signature,force_matching_signature from v$sql where sql_text like '%id=1000%';
SQL_ID                EXACT_MATCHING_SIGNATURE         FORCE_MATCHING_SIGNATURE
------------- -------------------------------- --------------------------------
duk2ypk5fz9g6              7784548270786280511              4428329137525653294

SELECT * FROM TABLE(dbms_xplan.display_cursor('duk2ypk5fz9g6'));
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------
SQL_ID  duk2ypk5fz9g6, child number 0
-------------------------------------
select /*+ id=1000 */  * FROM TEST where id=1000
Plan hash value: 1357081020
----------------------------------
| Id  | Operation         | Name |
----------------------------------
|   0 | SELECT STATEMENT  |      |
|*  1 |  TABLE ACCESS FULL| TEST |
----------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(&quot;ID&quot;=1000)
Note
-----
- rule based optimizer used (consider using cbo)

--Creating the baseline for the plan

var v_num number;
exec :v_num:=dbms_spm.load_plans_from_cursor_cache(sql_id =&gt; 'duk2ypk5fz9g6',plan_hash_value =&gt; 1357081020 );

select sql_handle, plan_name, enabled, accepted,fixed from dba_sql_plan_baselines where signature=7784548270786280511;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX
------------------------------ ------------------------------ --- --- ---
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f97bbe3d0  YES YES NO
</pre></p>
<p><span style="color:#0000ff;">As we can see, If we load the plan manually, that will plan will be enabled and accepted but not fixed.  Its time create an index and run the query again.</span></p>
<p><pre class="brush: sql;">
create index test_id on test(id);
Index created.

select /*+ id=1000 */  * FROM TEST where id=1000
NAME               ID
---------- ----------
SUMIT            1000
</pre></p>
<p><span style="color:#0000ff;">Oracle is still using SYS_SQL_PLAN_7118fc3f97bbe3d0 baseline.<br />
</span></p>
<p><span style="color:#0000ff;">However, if we query dba_sql_plan_baselines, we will see that oracle has started capturing baselines for this sql. (plan name SYS_SQL_PLAN_7118fc3f642e4a26)<br />
</span></p>
<p><pre class="brush: sql;">
PLAN_TABLE_OUTPUT
-----------------------------------------------------------
SQL_ID  duk2ypk5fz9g6, child number 1
-------------------------------------
select /*+ id=1000 */  * FROM TEST where id=1000
Plan hash value: 1357081020
--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |       |       |   554 (100)|          |
|*  1 |  TABLE ACCESS FULL| TEST |  1643 | 32860 |   554   (2)| 00:00:07 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(&quot;ID&quot;=1000)
Note
-----
- SQL plan baseline SYS_SQL_PLAN_7118fc3f97bbe3d0 used for this statement

select sql_handle, plan_name, enabled, accepted,fixed,signature from dba_sql_plan_baselines where signature=7784548270786280511;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX             SIGNATURE
------------------------------ ------------------------------ --- --- --- ---------------------
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f642e4a26  YES NO NO   7784548270786280511
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f97bbe3d0  YES YES NO   7784548270786280511
</pre></p>
<p><span style="color:#0000ff;">So even if capture baseline is set to false, oracle will still capture the new plans and baselines for that particular sql onwards. We can evolve the  new plan and can check if index is getting used or not.</span></p>
<p><pre class="brush: sql;">
/*Evolving new plan */
SET SERVEROUTPUT ON
 SET LONG 10000
 set lines 175
 DECLARE
 report clob;
 BEGIN
 report := DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE(
 sql_handle =&gt; '&amp;sql_handle', time_limit =&gt; &amp;time);
 DBMS_OUTPUT.PUT_LINE(report);
 END;
 /
 Enter value for sql_handle:SYS_SQL_6c0845687118fc3f
Enter value for time:60

-------------------------------------------------------------------------------
 Evolve SQL Plan Baseline
 Report
 -------------------------------------------------------------------------------
Inputs:
 -------
 SQL_HANDLE = SYS_SQL_6c0845687118fc3f
 PLAN_NAME  =
 TIME_LIMIT = 60
VERIFY     = YES
 COMMIT     = YES
Plan: SYS_SQL_PLAN_7118fc3f642e4a26
 -----------------------------------
 Plan was verified: Time used .05 seconds.
 Passed
 performance criterion: Compound improvement ratio &gt;= 504.88
 Plan was changed to an accepted plan.
Baseline Plan      Test Plan     Improv. Ratio
-------------      ---------     -------------
 Execution Status:        COMPLETE       COMPLETE
 Rows Processed:                 1              1
 Elapsed Time(ms):               26             0
 CPU Time(ms):                  25              0
 Buffer Gets:                 2017              4            504.25
 Disk Reads:                     0              0
 Direct Writes:                  0              0
 Fetches:                        0              0
 Executions:                     1              1
-------------------------------------------------------------------------------
 Report
 Summary
 -------------------------------------------------------------------------------
 Number of SQL plan baselines verified: 1.
 Number of SQL plan baselines evolved: 1.
</pre></p>
<p><span style="color:#0000ff;">As we can read in the report, Oracle has marked the new plan as accepted. Oracle keeps a tab if the plan was loaded manually or captured automatically. This can be verified from origin column of dba_sql_plan_baselines.</span></p>
<p><pre class="brush: sql;">
select sql_handle, plan_name, enabled, accepted,fixed,origin from dba_sql_plan_baselines where signature=7784548270786280511;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN
------------------------------ ------------------------------ --- --- --- --------------
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f642e4a26  YES YES NO AUTO-CAPTURE
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f97bbe3d0  YES YES NO MANUAL-LOAD
</pre></p>
<p><span style="color:#0000ff;">So far, the story was pretty much straight. Here&#8217;s a quick recap what we have done</span><br />
<span style="color:#000080;"> 1. Created Table and Inserted records</span><br />
<span style="color:#000080;"> 2. Query the table and baseline the query</span><br />
<span style="color:#000080;"> 3. Created Index and verified new plan is loaded but not accepted.</span><br />
<span style="color:#000080;"> 4. Evolve the new plan and accepted=yes.</span><br />
<span style="color:#000080;"> 5. New plan(Index Range Scan) started getting used.</span></p>
<p><span style="color:#0000ff;">Its time to discuss the usage of enabled,accepted and fixed parameters.</span></p>
<h3><span style="color:#0000ff;"><span style="color:#000080;">TEST1:  ENABLED=NO.</span><br />
</span></h3>
<p><span style="color:#0000ff;">For every sql_id, oracle checks if the baselines exists or not. If yes, then it will filter all the enabled plans. The plans for which enabled=NO will not be considered even if accepted and fixed are set to yes.</span></p>
<p><span style="color:#0000ff;">Other than this, if any plan is set enabled=yes for a query,oracle will start capturing new plans also.</span></p>
<p><span style="color:#0000ff;">Therefore, enabled is the first level. If enabled is set to NO,oracle will mark not to use and evolve that plan.</span></p>
<p><span style="color:#0000ff;">Lets have a test case. I will mark enabled =no for the plan that was using index and check which plan is used.</span></p>
<p><pre class="brush: sql;">
select sql_handle, plan_name, enabled, accepted,fixed,origin from dba_sql_plan_baselines where signature=7784548270786280511;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN
------------------------------ ------------------------------ --- --- --- --------------
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f642e4a26  YES YES NO AUTO-CAPTURE
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f97bbe3d0  YES YES NO MANUAL-LOAD

/* Setting Enabled=NO for SYS_SQL_PLAN_7118fc3f642e4a26 */
declare
myplan pls_integer;
begin
myplan:=DBMS_SPM.ALTER_SQL_PLAN_BASELINE (sql_handle =&gt; '&amp;sql_handle',plan_name  =&gt; '&amp;plan_name',attribute_name =&gt; 'ENABLED',   attribute_value =&gt; 'NO');
end;
/
Enter value for sql_handle: SYS_SQL_6c0845687118fc3f
Enter value for plan_name: SYS_SQL_PLAN_7118fc3f642e4a26

select sql_handle, plan_name, enabled, accepted,fixed,origin from dba_sql_plan_baselines where signature=7784548270786280511;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN
------------------------------ ------------------------------ --- --- --- --------------
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f642e4a26  NO YES  NO  AUTO-CAPTURE
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f97bbe3d0  YES YES NO  MANUAL-LOAD
2 rows selected.

</pre></p>
<p><span style="color:#0000ff;">So, plan SYS_SQL_PLAN_7118fc3f642e4a26 is accepted but not enabled. Lets execute the query again and see which plan is getting used.</span></p>
<p><pre class="brush: sql;">
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
SQL_ID  duk2ypk5fz9g6, child number 1
-------------------------------------
select /*+ id=1000 */  * FROM TEST where id=1000
Plan hash value: 1357081020
--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |       |       |   554 (100)|          |
|*  1 |  TABLE ACCESS FULL| TEST |  1643 | 32860 |   554   (2)| 00:00:07 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(&quot;ID&quot;=1000)
Note
-----
- SQL plan baseline SYS_SQL_PLAN_7118fc3f97bbe3d0 used for this statement
</pre></p>
<p><span style="color:#0000ff;">Oracle choses SYS_SQL_PLAN_7118fc3f97bbe3, since that plan is still enabled and accepted.</span><br />
<strong><span style="color:#800000;">Therefore, minimum requirement for oracle to use a plan as baseline is, it should be marked both as ENABLED and ACCEPTED.</span></strong></p>
<p><span style="color:#0000ff;">The next level is Accepted. In this level oracle will pick all the plans that are accepted to the users and discard all &#8220;ACCEPTED=NO&#8221; plans. As we had already seen,there can be more than one plan for accepted=yes. All these plans are already evolved plans and are candidate for being  the final execution plan.</span></p>
<p><span style="color:#0000ff;">If no plan is marked &#8220;FIXED=YES&#8221;, then oracle will pick any of these plans based on the costing.</span></p>
<p><span style="color:#0000ff;">All those plans which are &#8220;ENABLED=YES&#8221; and &#8220;ACCEPTED=NO&#8221;, are candidates for evolution. We can also however marked then accepted=yes manually.</span></p>
<p><span style="color:#0000ff;">Next and the last level is Fixed. If any plan is fixed oracle will use that plan only. If more than one plan is fixed, oracle will use costing as criteria to select the plan among those.</span></p>
<h4><span style="color:#000080;">TEST2:  Setting any one plan as FIXED=YES<br />
</span></h4>
<p><span style="color:#0000ff;">Lets mark index plan as accepted again and FTS plan as fixed.</span></p>
<p><pre class="brush: sql;">
select sql_handle, plan_name, enabled, accepted,fixed,origin from dba_sql_plan_baselines where signature=7784548270786280511;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN
------------------------------ ------------------------------ --- --- --- --------------
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f642e4a26  NO  YES NO  AUTO-CAPTURE
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f97bbe3d0  YES YES NO  MANUAL-LOAD

/*Resetting SYS_SQL_PLAN_7118fc3f642e4a26 to Enabled */
declare
myplan pls_integer;
begin
myplan:=DBMS_SPM.ALTER_SQL_PLAN_BASELINE (sql_handle =&gt;'&amp;sql_handle',plan_name=&gt;'&amp;plan_name',attribute_name =&gt;'ENABLED',attribute_value =&gt;'YES');
end;
/
Enter value for sql_handle: SYS_SQL_6c0845687118fc3f
Enter value for plan_name: SYS_SQL_PLAN_7118fc3f642e4a26

/*Setting SYS_SQL_PLAN_7118fc3f97bbe3d0 to FIXED */
declare
myplan pls_integer;
begin
myplan:=DBMS_SPM.ALTER_SQL_PLAN_BASELINE (sql_handle =&gt;'&amp;sql_handle',plan_name=&gt;'&amp;plan_name',attribute_name=&gt;'FIXED',attribute_value=&gt;'YES');
end;
/
Enter value for sql_handle: SYS_SQL_6c0845687118fc3f
Enter value for plan_name: SYS_SQL_PLAN_7118fc3f97bbe3d0

select sql_handle, plan_name, enabled, accepted,fixed,origin from dba_sql_plan_baselines where signature=7784548270786280511;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN
------------------------------ ------------------------------ --- --- --- --------------
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f642e4a26  YES YES NO  AUTO-CAPTURE
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f97bbe3d0  YES YES YES MANUAL-LOAD
</pre></p>
<p><span style="color:#0000ff;">Executing the query and checking the plan again</span></p>
<p><pre class="brush: sql;">
SELECT * FROM TABLE(dbms_xplan.display_cursor('duk2ypk5fz9g6'));
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------
SQL_ID  duk2ypk5fz9g6, child number 1
-------------------------------------
select /*+ id=1000 */  * FROM TEST where id=1000
Plan hash value: 1357081020
--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |       |       |   554 (100)|          |
|*  1 |  TABLE ACCESS FULL| TEST |  1643 | 32860 |   554   (2)| 00:00:07 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(&quot;ID&quot;=1000)
Note
-----
- SQL plan baseline SYS_SQL_PLAN_7118fc3f97bbe3d0 used for this statement
</pre></p>
<p><span style="color:#0000ff;">As we can confirm oracle start using FTS as that plan is marked fixed.</span></p>
<p><strong><span style="color:#000080;">TEST3: Setting FIXED=YES for more than one plan</span></strong></p>
<p><span style="color:#0000ff;">Lets mark second plan &#8220;FIXED=YES&#8221; and re-execute the query</span></p>
<p><pre class="brush: sql;">
/*Setting SYS_SQL_PLAN_7118fc3f642e4a26 to FIXED */
declare
myplan pls_integer;
begin
myplan:=DBMS_SPM.ALTER_SQL_PLAN_BASELINE (sql_handle=&gt;'&amp;sql_handle',plan_name=&gt;'&amp;plan_name',attribute_name=&gt;'FIXED',attribute_value=&gt;'YES');
end;
/
Enter value for sql_handle: SYS_SQL_6c0845687118fc3f
Enter value for plan_name: SYS_SQL_PLAN_7118fc3f642e4a26

select sql_handle, plan_name, enabled, accepted,fixed,origin from dba_sql_plan_baselines where signature=7784548270786280511;

SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN
------------------------------ ------------------------------ --- --- --- --------------
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f642e4a26  YES YES YES AUTO-CAPTURE
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f97bbe3d0  YES YES YES MANUAL-LOAD

select /*+ id=1000 */  * FROM TEST where id=1000
NAME               ID
---------- ----------
SUMIT            1000

1 row selected.

SELECT * FROM TABLE(dbms_xplan.display_cursor('duk2ypk5fz9g6'));

PLAN_TABLE_OUTPUT
---------------------------------------------------------------
SQL_ID  duk2ypk5fz9g6, child number 0
-------------------------------------
select /*+ id=1000 */  * FROM TEST where id=1000
Plan hash value: 1699862855
---------------------------------------------------------------------------------------
| Id  | Operation                   | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |         |       |       |     1 (100)|          |
|   1 |  TABLE ACCESS BY INDEX ROWID| TEST    |     1 |    20 |     1   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN          | TEST_ID |     1 |       |     1   (0)| 00:00:01 |
---------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access(&quot;ID&quot;=1000)
Note
-----
- dynamic sampling used for this statement
- SQL plan baseline SYS_SQL_PLAN_7118fc3f642e4a26 used for this statement
</pre></p>
<h3><span style="color:#0000ff;"><strong>Test 4:</strong> </span></h3>
<p><span style="color:#0000ff;">Also, if any of the plan is marked as fixed, oracle will stop capturing and evolving new plans.</span><br />
<span style="color:#0000ff;">To simulate the test, lets again mark the plan(using index) as fixed=no and accepted=no.</span></p>
<p><pre class="brush: sql;">
select sql_handle, plan_name, enabled, accepted,fixed,origin from dba_sql_plan_baselines where signature=7784548270786280511;

SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN
------------------------------ ------------------------------ --- --- --- --------------
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f642e4a26  YES YES YES AUTO-CAPTURE
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f97bbe3d0  YES YES YES MANUAL-LOAD

/* Resetting SYS_SQL_PLAN_7118fc3f642e4a26 to FIXED=NO */
declare
myplan pls_integer;
begin
myplan:=DBMS_SPM.ALTER_SQL_PLAN_BASELINE (sql_handle =&gt; '&amp;sql_handle',plan_name  =&gt; '&amp;plan_name',attribute_name =&gt; 'FIXED',   attribute_value =&gt; 'NO');
end;
/
Enter value for sql_handle: SYS_SQL_6c0845687118fc3f
Enter value for plan_name: SYS_SQL_PLAN_7118fc3f642e4a26

/* Resetting SYS_SQL_PLAN_7118fc3f642e4a26 to ACCEPTED=NO */
declare
myplan pls_integer;
begin
myplan:=DBMS_SPM.ALTER_SQL_PLAN_BASELINE (sql_handle =&gt; '&amp;sql_handle',plan_name  =&gt; '&amp;plan_name',attribute_name =&gt; 'ACCEPTED',   attribute_value =&gt; 'NO');
end;
/
Enter value for sql_handle: SYS_SQL_6c0845687118fc3f
Enter value for plan_name: SYS_SQL_PLAN_7118fc3f642e4a26

select sql_handle, plan_name, enabled, accepted,fixed,origin from dba_sql_plan_baselines where signature=7784548270786280511;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN
------------------------------ ------------------------------ --- --- --- --------------
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f642e4a26  YES NO  NO  AUTO-CAPTURE
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f97bbe3d0  YES YES YES MANUAL-LOAD

</pre></p>
<p><span style="color:#0000ff;">Lets try to evolve the index plan (SYS_SQL_PLAN_7118fc3f642e4a26) again, like we did previously. The only difference is fixed=yes this time for plan using FTS</span></p>
<p><pre class="brush: sql;">
/* TRYING TO EVOLVE SYS_SQL_PLAN_7118fc3f642e4a26 */
SET SERVEROUTPUT ON
SET LONG 10000
set lines 175
DECLARE
report clob;
BEGIN
report := DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE(
sql_handle =&gt; '&amp;sql_handle', time_limit =&gt; &amp;time);
DBMS_OUTPUT.PUT_LINE(report);
END;
/
Enter value for sql_handle: SYS_SQL_6c0845687118fc3f
Enter value for time: 60
-------------------------------------------------------------------------------
Evolve SQL Plan Baseline
Report
-------------------------------------------------------------------------------
Inputs:
-------
SQL_HANDLE = SYS_SQL_6c0845687118fc3f
PLAN_NAME  =
TIME_LIMIT = 60
VERIFY     = YES
COMMIT     = YES
-------------------------------------------------------------------------------
Report
Summary
-------------------------------------------------------------------------------
There were no SQL plan baselines that required processing.
</pre></p>
<p><span style="color:#0000ff;">As we can confirm<code></code>, plan SYS_SQL_PLAN_7118fc3f642e4a26 is not evolved since SYS_SQL_PLAN_7118fc3f97bbe3d0 was already fixed.</span></p>
<h4><span style="color:#000080;">TEST5:</span></h4>
<p><span style="color:#0000ff;">Lets go back a step further and drop the baseline as well as index. We will try to simulate a test case to check if oracle captures new plan if any plan is marked as FIXED=YES</span></p>
<p><pre class="brush: sql;">
SET SERVEROUTPUT ON
DECLARE
l_plans_dropped  PLS_INTEGER;
BEGIN
l_plans_dropped := DBMS_SPM.drop_sql_plan_baseline (
sql_handle =&gt; 'SYS_SQL_6c0845687118fc3f',
plan_name  =&gt; 'SYS_SQL_PLAN_7118fc3f642e4a26');

DBMS_OUTPUT.put_line(l_plans_dropped);
END;
/

drop index test_id;
Index dropped.

select sql_handle, plan_name, enabled, accepted,fixed,origin from dba_sql_plan_baselines where signature=7784548270786280511;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN
------------------------------ ------------------------------ --- --- --- --------------
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f97bbe3d0  YES YES YES MANUAL-LOAD
1 row selected.
</pre></p>
<p><span style="color:#0000ff;">So, we are back to square one from where we have started. Lets again create the same index and query the table to see if it still capture new plans.</span></p>
<p><pre class="brush: sql;">
create index test_id on test(id);
Index created.

select /*+ id=1000 */  * FROM TEST where id=1000;
NAME               ID
---------- ----------
SUMIT            1000
1 row selected.

select sql_handle, plan_name, enabled, accepted,fixed,origin from dba_sql_plan_baselines where signature=7784548270786280511;

SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN
------------------------------ ------------------------------ --- --- --- --------------
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f97bbe3d0  YES YES YES MANUAL-LOAD

1 row selected.
</pre></p>
<p><span style="color:#0000ff;">As we can see, oracle has stopped capturing new plans for this sql as SYS_SQL_PLAN_7118fc3f97bbe3d0 is already fixed.</span></p>
<p><span style="color:#0000ff;">Lets mark fixed=NO again and re-execute the query. Oracle should capturing the plan again for this query.</span></p>
<p><pre class="brush: sql;">

select sql_handle, plan_name, enabled, accepted,fixed,origin from dba_sql_plan_baselines where signature=7784548270786280511;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN
------------------------------ ------------------------------ --- --- --- --------------
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f97bbe3d0  YES YES YES MANUAL-LOAD
1 row selected.

declare
myplan pls_integer;
begin
myplan:=DBMS_SPM.ALTER_SQL_PLAN_BASELINE (sql_handle =&gt; '&amp;sql_handle',plan_name  =&gt; '&amp;plan_name',attribute_name =&gt; 'FIXED',   attribute_value =&gt; 'NO');
end;
/
Enter value for sql_handle: SYS_SQL_6c0845687118fc3f
Enter value for plan_name: SYS_SQL_PLAN_7118fc3f97bbe3d0

select /*+ id=1000 */  * FROM TEST where id=1000
NAME               ID
---------- ----------
SUMIT            1000
1 row selected.

select sql_handle, plan_name, enabled, accepted,fixed,origin from dba_sql_plan_baselines where signature=7784548270786280511;

SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN
------------------------------ ------------------------------ --- --- --- --------------
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f642e4a26  YES NO  NO  AUTO-CAPTURE
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f97bbe3d0  YES YES NO  MANUAL-LOAD

2 rows selected.

</pre></p>
<p><span style="color:#0000ff;">So, as we can confirm oracle again started capturing new plans we turn FIXED=NO.</span></p>
<p><strong><span style="color:#800000;">Here&#8217;s the quick summary,</span></strong></p>
<h4><span style="color:#000080;">1.  ENABLED=YES (For any of the plan) :- Oracle will start capturing new plans for those queries.</span></h4>
<h4><span style="color:#000080;">2. Enabled=NO :-  Than plan won&#8217;t we used.</span></h4>
<h4><span style="color:#000080;">3.  Accepted=Yes (Any one Plan) :- That plan will be used for execution</span></h4>
<h4><span style="color:#000080;">4.  Accepted=YES (For Multiple plans):- Any one plan can be used if fixed=no for all plans.</span></h4>
<h4><span style="color:#000080;">5. Accepted=No: Plan wont be used.</span></h4>
<h4><span style="color:#000080;">6.  FIXED=YES (for only one plan) Only that plan will be used and oracle will stop capturing/evolving new plans.</span></h4>
<h4><span style="color:#000080;">7.  FIXED=YES (for many plans) Oracle will chose execution plan only from that pool.</span></h4>
<p><span style="color:#800000;"><strong>SPECIAL CASE :-<span style="color:#0000ff;">ENABLED=YES,FIXED=YES BUT ACCEPTED=NO.</span></strong><br />
</span></p>
<p><span style="color:#0000ff;">What if in our given scenario, we mark SYS_SQL_PLAN_7118fc3f97bbe3d0 as fixed and enabled but not accepted. Will oracle capture the new plan and will it evolve it.</span></p>
<p><pre class="brush: sql;">
select sql_handle, plan_name, enabled, accepted,fixed,origin from dba_sql_plan_baselines where signature=7784548270786280511;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN
------------------------------ ------------------------------ --- --- --- --------------
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f97bbe3d0  YES NO  YES MANUAL-LOAD
1 row selected.
</pre></p>
<p><span style="color:#0000ff;">Lets discuss the above scenario and try to figure out who takes precedence under what condition</span></p>
<p><pre class="brush: sql;">
select /*+ id=1000 */  * FROM TEST where id=1000;
NAME               ID
---------- ----------
SUMIT            1000
1 row selected.
select sql_handle, plan_name, enabled, accepted,fixed,origin from dba_sql_plan_baselines where signature=7784548270786280511;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN
------------------------------ ------------------------------ --- --- --- --------------
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f642e4a26  YES NO  NO  AUTO-CAPTURE
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f97bbe3d0  YES NO  YES MANUAL-LOAD
2 rows selected.
</pre></p>
<p><span style="color:#0000ff;">Oracle has captured new plan. Lets try to evolve that one also.</span></p>
<p><pre class="brush: sql;">
SET SERVEROUTPUT ON
SET LONG 10000
set lines 175
DECLARE
report clob;
BEGIN
report := DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE(
sql_handle =&gt; '&amp;sql_handle', time_limit =&gt; &amp;time);
DBMS_OUTPUT.PUT_LINE(report);
END;
/
-------------------------------------------------------------------------------
Evolve SQL Plan Baseline
Report
-------------------------------------------------------------------------------

Inputs:
-------
SQL_HANDLE = SYS_SQL_6c0845687118fc3f
PLAN_NAME  =
TIME_LIMIT =
60
VERIFY     = YES
COMMIT     = YES

-------------------------------------------------------------------------------
Report
Summary
-------------------------------------------------------------------------------
There were no SQL plan baselines that required processing.
select sql_handle, plan_name, enabled, accepted,fixed,origin from dba_sql_plan_baselines where signature=7784548270786280511;

SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN
------------------------------ ------------------------------ --- --- --- --------------
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f642e4a26  YES NO  NO  AUTO-CAPTURE
SYS_SQL_6c0845687118fc3f       SYS_SQL_PLAN_7118fc3f97bbe3d0  YES NO  YES MANUAL-LOAD

2 rows selected.
</pre></p>
<p><span style="color:#0000ff;">ENABLED takes precedence over FIXED in case of capturing the new plan and vice versa in case of evolving.</span></p>
<p><span style="color:#0000ff;">I hope above article will help in understanding the role/usage of ENABLE/ACCEPTED/FIXED  parameters. Please do write in case you find any discrepancy or want to share some details</span></p>
<br />Filed under: <a href='http://fordba.wordpress.com/category/baselines/'>Baselines</a>, <a href='http://fordba.wordpress.com/category/uncategorized/'>Uncategorized</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fordba.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fordba.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fordba.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fordba.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fordba.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fordba.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fordba.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fordba.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fordba.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fordba.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fordba.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fordba.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fordba.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fordba.wordpress.com/335/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=335&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fordba.wordpress.com/2011/08/28/baselines-part-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0b8748224dcc3259b8c20081f7a988ac?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sbhatia83</media:title>
		</media:content>
	</item>
		<item>
		<title>Implementing Hints through Baseline</title>
		<link>http://fordba.wordpress.com/2011/06/11/implementing-hints-through-baseline/</link>
		<comments>http://fordba.wordpress.com/2011/06/11/implementing-hints-through-baseline/#comments</comments>
		<pubDate>Sat, 11 Jun 2011 10:13:36 +0000</pubDate>
		<dc:creator>Sumit</dc:creator>
				<category><![CDATA[Baselines]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[11g new features]]></category>
		<category><![CDATA[accepting baselines]]></category>
		<category><![CDATA[baseline]]></category>
		<category><![CDATA[capture baseline]]></category>
		<category><![CDATA[hint]]></category>
		<category><![CDATA[implement baseline]]></category>
		<category><![CDATA[loading baseline from cursor cache]]></category>
		<category><![CDATA[loading plans manually]]></category>
		<category><![CDATA[oracle sql baseline]]></category>
		<category><![CDATA[Plan stability]]></category>
		<category><![CDATA[query tuning]]></category>
		<category><![CDATA[SPM]]></category>
		<category><![CDATA[sql baseline]]></category>

		<guid isPermaLink="false">http://fordba.wordpress.com/?p=287</guid>
		<description><![CDATA[Baselines SQL Plan Management(SPM) provides a mechanism to prevent unwanted plan flips. Whenever a query is hard parsed, oracle produces several execution plan and compares it with the accepted plan in a baseline. If a match is found, oracle picks that plan. The behaviour of baseline is governed by 2 parameters. Optimizer_capture_sql_plan_baselines Optimizer_use_sql_plan_baseline optimizer_capture_sql_plan_baseline if [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=287&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2><span style="color:#000080;">Baselines</span></h2>
<p><span style="color:#0000ff;">SQL Plan Management(SPM) provides a mechanism to prevent unwanted plan flips.</span></p>
<p><span style="color:#0000ff;">Whenever a query is hard parsed, oracle produces several execution plan and compares it with the accepted plan in a baseline. If a match is found, oracle picks that plan.</span></p>
<p><span style="color:#0000ff;">The behaviour of baseline is governed by 2 parameters.</span></p>
<ol>
<li><span style="color:#000080;">Optimizer_capture_sql_plan_baselines</span></li>
<li><span style="color:#000080;">Optimizer_use_sql_plan_baseline</span></li>
</ol>
<p><span style="color:#0000ff;">optimizer_capture_sql_plan_baseline if set to true, let oracle automatically capture sql plan baselines. The default value is false</span></p>
<p><span style="color:#0000ff;">Optimizer_use_sql_plan_baseline, if set to true, force oracle to use the sql plan baseline (if present). The default is true.</span></p>
<h3><span style="color:#000080;">Implementing HINTS without changing code</span></h3>
<p><span style="color:#000080;"><strong>Environment Setting :-</strong></span></p>
<ul>
<li><span style="color:#0000ff;">Optimizer_capture_sql_plan_baselines (false)</span></li>
<li><span style="color:#0000ff;">Optimizer_use_sql_plan_baseline (true)</span></li>
</ul>
<div><span style="color:#0000ff;">I created mytab table CTAS dba_objects</span></div>
<div><pre class="brush: sql;">
Session1&gt;desc mytab
Name Null? Type
----------------------------------------- -------- ----------------------------
OWNER VARCHAR2(30)
OBJECT_NAME VARCHAR2(128)
SUBOBJECT_NAME VARCHAR2(30)
OBJECT_ID NUMBER
DATA_OBJECT_ID NUMBER
OBJECT_TYPE VARCHAR2(19)
CREATED DATE
LAST_DDL_TIME DATE
TIMESTAMP VARCHAR2(19)
STATUS VARCHAR2(7)
TEMPORARY VARCHAR2(1)
GENERATED VARCHAR2(1)
SECONDARY VARCHAR2(1)
NAMESPACE NUMBER
EDITION_NAME VARCHAR2(30)
</pre></p>
<p><span style="color:#003300;"><strong>Step 1&gt; Query the mytab table without index</strong>.</span></p>
<p><pre class="brush: sql;">

select /*+woindex */ * from mytab where GENERATED='FOR';

no rows selected

SELECT * FROM TABLE(dbms_xplan.display_cursor('0ytzpgnhg1g83'));
SQL_ID  0ytzpgnhg1g83, child number 0
-------------------------------------
select /*+woindex */ * from mytab where GENERATED='FOR'
Plan hash value: 96696846
---------------------------------------------------------------------------
| Id  | Operation         | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |       |       |       |   124K(100)|          |
|*  1 |  TABLE ACCESS FULL| MYTAB |  4819K|   422M|   124K  (3)| 00:24:54 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(&quot;GENERATED&quot;='FOR')

select sql_text, sql_handle, plan_name, enabled, accepted from dba_sql_plan_baselines;
no rows selected
</pre></p>
<p><strong><span style="color:#003300;">Step 2&gt; No baseline yet exists for the current query. Lets baseline the plan to make sure it does not pick index automatically so that we can simulate the test.</span></strong></p>
<p><pre class="brush: sql;">
var v_num number;
exec :v_num:=dbms_spm.load_plans_from_cursor_cache(sql_id =&gt; '0ytzpgnhg1g83',plan_hash_value =&gt; 96696846 );
PL/SQL procedure successfully completed.
select sql_text, sql_handle, plan_name, enabled, accepted from dba_sql_plan_baselines;
SQL_TEXT                                                                         SQL_HANDLE                     PLAN_NAME                      ENA ACC

-------------------------------------------------------------------------------- ------------------------------ ------------------------------ --- ---

select /*+woindex */ * from mytab where GENERATED='FOR'                          SYS_SQL_50969e88fdd635aa       SYS_SQL_PLAN_fdd635aada00620d  YES YES

1 row selected.

</pre></p>
<p><strong><span style="color:#003300;">Step 3&gt; Lets create an index</span></strong></p>
<p><pre class="brush: sql;">
create index mytab_idx2 on mytab(GENERATED) parallel 4;
Index created.

alter index mytab_idx2 noparallel;

Index altered.

</pre></p>
<p><strong><span style="color:#003300;">Step4&gt; Execute the query to confirm its not using the index since optimizer_use_sql_plan_baseline is set to true.</span></strong></p>
<p><pre class="brush: sql;">

select * FROM TABLE(dbms_xplan.display_cursor('0ytzpgnhg1g83',1));
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID  0ytzpgnhg1g83, child number 1
-------------------------------------
select /*+woindex */ * from mytab where GENERATED='FOR'
Plan hash value: 96696846
---------------------------------------------------------------------------
| Id  | Operation         | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |       |       |       |   124K(100)|          |
|*  1 |  TABLE ACCESS FULL| MYTAB |  4819K|   422M|   124K  (3)| 00:24:54 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter(&quot;GENERATED&quot;='FOR')
Note
-----
   - SQL plan baseline SYS_SQL_PLAN_fdd635aada00620d used for this statement
22 rows selected.
</pre></p>
<p><strong><span style="color:#003300;">Step5&gt;Execute the query with index hint and create the baseline.</span></strong></p>
<p><pre class="brush: sql;">
select /*+index(mytab_idx2 mytab) */ * from mytab where GENERATED='FOR';

no rows selected

Select * FROM TABLE(dbms_xplan.display_cursor('ay757nb7anm56'));
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------
SQL_ID  ay757nb7anm56, child number 0
-------------------------------------
select /*+index(mytab_idx2 mytab) */ * from mytab where GENERATED='FOR'
Plan hash value: 3007699452
------------------------------------------------------------------------------------------
| Id  | Operation                   | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |            |       |       |   995 (100)|          |
|   1 |  TABLE ACCESS BY INDEX ROWID| MYTAB      |  4819K|   422M|   995   (1)| 00:00:12 |
|*  2 |   INDEX RANGE SCAN          | MYTAB_IDX2 |  4896K|       |    90   (2)| 00:00:02 |
------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access(&quot;GENERATED&quot;='FOR')
19 rows selected.

exec :v_num:=dbms_spm.load_plans_from_cursor_cache(sql_id =&gt; 'ay757nb7anm56',plan_hash_value =&gt; '3007699452' );
select sql_text, sql_handle, plan_name, enabled, accepted from dba_sql_plan_baselines;
SQL_TEXT                                                                         SQL_HANDLE                     PLAN_NAME                      ENA ACC

-------------------------------------------------------------------------------- ------------------------------ ------------------------------ --- ---
select /*+woindex */ * from mytab where GENERATED='FOR'                          SYS_SQL_50969e88fdd635aa       SYS_SQL_PLAN_fdd635aa041dae64  YES NO

select /*+woindex */ * from mytab where GENERATED='FOR'                          SYS_SQL_50969e88fdd635aa       SYS_SQL_PLAN_fdd635aada00620d  YES YES

select /*+index(mytab_idx2 mytab) */ * from mytab where GENERATED='FOR'          SYS_SQL_5229297eca7bb2c7       SYS_SQL_PLAN_ca7bb2c7041dae64  YES YES

3 rows selected.
</pre></p>
<p><span style="color:#003300;"><strong>Step6&gt; Now here, you can see that plan<span style="color:#000080;">(SYS_SQL_PLAN_fdd635aa041dae64 )</span> being automatically linked with sql_handle <span style="color:#000080;">(SYS_SQL_50969e88fdd635aa)</span>.</strong></span><br />
<strong><span style="color:#003300;"> You can accept it.</span></strong><br />
<strong> <span style="color:#003300;"> In case, plan is not linked with sql_handle, use the below method to link plan manually.</span></strong></p>
<p><pre class="brush: sql;">
exec :v_num:=dbms_spm.load_plans_from_cursor_cache(sql_id =&gt; 'ay757nb7anm56',plan_hash_value =&gt; 3007699452 ,sql_handle =&gt; 'SYS_SQL_50969e88fdd635aa');

select sql_text, sql_handle, plan_name, enabled, accepted from dba_sql_plan_baselines;
SQL_TEXT                                                                         SQL_HANDLE                     PLAN_NAME                      ENA ACC
-------------------------------------------------------------------------------- ------------------------------ ------------------------------ --- ---
select /*+woindex */ * from mytab where GENERATED='FOR'                          SYS_SQL_50969e88fdd635aa       SYS_SQL_PLAN_fdd635aa041dae64  YES YES

select /*+woindex */ * from mytab where GENERATED='FOR'                          SYS_SQL_50969e88fdd635aa       SYS_SQL_PLAN_fdd635aada00620d  YES YES

select /*+index(mytab_idx2 mytab) */ * from mytab where GENERATED='FOR'          SYS_SQL_5229297eca7bb2c7       SYS_SQL_PLAN_ca7bb2c7041dae64  YES YES

3 rows selected.
</pre></p>
<p><span style="color:#800000;">dbms_spm.load_plans_from_cursor_cache(sql_id =&gt; &#8216;&lt;hinted_sqlid&gt;&#8217;,plan_hash_value=&gt;&lt;hinted_plan_value&gt;,sql_handle=&gt;&#8217;&lt;sql handle of original query&gt;&#8217;)</span></p>
</div>
<br />Filed under: <a href='http://fordba.wordpress.com/category/baselines/'>Baselines</a>, <a href='http://fordba.wordpress.com/category/uncategorized/'>Uncategorized</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fordba.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fordba.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fordba.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fordba.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fordba.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fordba.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fordba.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fordba.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fordba.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fordba.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fordba.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fordba.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fordba.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fordba.wordpress.com/287/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=287&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fordba.wordpress.com/2011/06/11/implementing-hints-through-baseline/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0b8748224dcc3259b8c20081f7a988ac?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sbhatia83</media:title>
		</media:content>
	</item>
		<item>
		<title>Mytab Table</title>
		<link>http://fordba.wordpress.com/2011/06/10/mytab-table/</link>
		<comments>http://fordba.wordpress.com/2011/06/10/mytab-table/#comments</comments>
		<pubDate>Fri, 10 Jun 2011 06:14:44 +0000</pubDate>
		<dc:creator>Sumit</dc:creator>
				<category><![CDATA[Testing Env.]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CTAS]]></category>
		<category><![CDATA[MYTAB]]></category>

		<guid isPermaLink="false">http://fordba.wordpress.com/?p=446</guid>
		<description><![CDATA[Mytab structure :- CTAS dba_objects Filed under: Testing Env., Uncategorized<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=446&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2><span style="color:#000080;">Mytab structure :- CTAS dba_objects</span></h2>
<p><pre class="brush: sql;">
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 OWNER                                              VARCHAR2(30)
 OBJECT_NAME                                        VARCHAR2(128)
 SUBOBJECT_NAME                                     VARCHAR2(30)
 OBJECT_ID                                          NUMBER
 DATA_OBJECT_ID                                     NUMBER
 OBJECT_TYPE                                        VARCHAR2(19)
 CREATED                                            DATE
 LAST_DDL_TIME                                      DATE
 TIMESTAMP                                          VARCHAR2(19)
 STATUS                                             VARCHAR2(7)
 TEMPORARY                                          VARCHAR2(1)
 GENERATED                                          VARCHAR2(1)
 SECONDARY                                          VARCHAR2(1)
 NAMESPACE                                          NUMBER
 EDITION_NAME                                       VARCHAR2(30)
</pre><br />
<pre class="brush: sql;">
Session1&gt;@tableinfo
enter table name :- mytab

INDEX_NAME                     COLUMN_NAME                              COLUMN_POSITION
------------------------------ ---------------------------------------- ---------------
MYTAB_IDX                      OWNER                                                  1
MYTAB_IDX                      OBJECT_NAME                                            2
MYTAB_IDX                      SUBOBJECT_NAME                                         3
MYTAB_IDX2                     GENERATED                                              1

(Size) Mb       Size(Gb)
----------     ----------
3581.5      3.49755859
</pre></p>
<br />Filed under: <a href='http://fordba.wordpress.com/category/uncategorized/testing-env/'>Testing Env.</a>, <a href='http://fordba.wordpress.com/category/uncategorized/'>Uncategorized</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fordba.wordpress.com/446/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fordba.wordpress.com/446/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fordba.wordpress.com/446/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fordba.wordpress.com/446/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fordba.wordpress.com/446/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fordba.wordpress.com/446/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fordba.wordpress.com/446/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fordba.wordpress.com/446/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fordba.wordpress.com/446/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fordba.wordpress.com/446/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fordba.wordpress.com/446/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fordba.wordpress.com/446/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fordba.wordpress.com/446/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fordba.wordpress.com/446/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=446&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fordba.wordpress.com/2011/06/10/mytab-table/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0b8748224dcc3259b8c20081f7a988ac?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sbhatia83</media:title>
		</media:content>
	</item>
		<item>
		<title>Cleaning Journal table</title>
		<link>http://fordba.wordpress.com/2011/05/02/cleaning-journal-table/</link>
		<comments>http://fordba.wordpress.com/2011/05/02/cleaning-journal-table/#comments</comments>
		<pubDate>Mon, 02 May 2011 14:54:01 +0000</pubDate>
		<dc:creator>Sumit</dc:creator>
				<category><![CDATA[Index]]></category>
		<category><![CDATA[Index rebuild]]></category>
		<category><![CDATA[Journal table]]></category>
		<category><![CDATA[clean index]]></category>
		<category><![CDATA[clean journal table]]></category>
		<category><![CDATA[clear index entry]]></category>
		<category><![CDATA[clear journal entry]]></category>
		<category><![CDATA[dbms_repair]]></category>
		<category><![CDATA[dbms_repair.online_index_clean]]></category>
		<category><![CDATA[dbms_repait]]></category>
		<category><![CDATA[error index drop]]></category>
		<category><![CDATA[error index rebuild]]></category>
		<category><![CDATA[index build]]></category>
		<category><![CDATA[index rebuild]]></category>
		<category><![CDATA[online index rebuild]]></category>
		<category><![CDATA[online_index_clean]]></category>
		<category><![CDATA[ORA-08104]]></category>
		<category><![CDATA[ORA-08104: this index object is being online built or rebuilt]]></category>
		<category><![CDATA[oradebug]]></category>
		<category><![CDATA[oradebug wakeup]]></category>
		<category><![CDATA[wakeup]]></category>

		<guid isPermaLink="false">http://fordba.wordpress.com/?p=258</guid>
		<description><![CDATA[Journal Table cleanup process As we have seen in previous posts journal table behaviour, if the rebuild gets cancelled in between and oracle does not gets a latch, it does not clear the journal table automatically. Also, oracle won&#8217;t allow dropping or rebuilding of index. Its the responsibility of the smon to clear the indexes [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=258&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2><span style="color:#0000ff;">Journal Table cleanup process</span></h2>
<p><span style="color:#000080;">As we have seen in previous posts<a title="journal table behaviour" href="http://fordba.wordpress.com/2011/04/13/journal-table-behaviour/" target="_blank"> journal table behaviour</a>, if the rebuild gets cancelled in between and oracle does not gets a latch, it does not clear the journal table automatically.</span></p>
<p><span style="color:#000080;">Also, oracle won&#8217;t allow dropping or rebuilding of index.</span></p>
<p><pre class="brush: sql;">

session1&gt;alter index mytab_idx rebuild online;
alter index mytab_idx rebuild online
*
ERROR at line 1:
ORA-08104: this index object 98701 is being online built or rebuilt

sesion1&gt;drop index mytab_idx;
drop index mytab_idx
           *
ERROR at line 1:
ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
</pre></p>
<p><span style="color:#000080;">Its the responsibility of the smon to clear the indexes stuck in journal.</span></p>
<p><span style="color:#000080;">However, in many cases dba intervention is required.</span></p>
<p><span style="color:#000080;">There are 2 ways to clear the journal table.</span></p>
<p><span style="color:#000080;">1. By waking up smon</span></p>
<p><span style="color:#000080;">2. By using oracle supplied dbms_repair.online_index_clean package</span></p>
<h3><span style="color:#000080;">waking up smon</span></h3>
<p><span style="color:#000080;">We can post smon to clear the temporary segments and journal by issuing the following command.</span></p>
<p><pre class="brush: sql;">

select pid from v$process p, v$bgprocess b where b.paddr = p.addr and name='SMON';

oradebug wakeup &lt;pid&gt;

</pre></p>
<h3><span style="color:#0000ff;">Using dbms_repair.online_index_clean package</span></h3>
<p><span style="color:#000080;">dbms_repair is a oracle supplied package which has many procedures to detect and repair block corruption or rebuild freelists etc.</span></p>
<p><span style="color:#000080;">we can use online_index_clean to clean up the journal table. </span></p>
<p><span style="color:#000080;">Be informed that this procedure also requires initial latch. I have developed a small script <a title="Index Cleanup script" href="http://fordba.wordpress.com/2011/03/30/ndx-cleanup-sql/" target="_blank">ndx-cleanup.sql</a> to clear the journal table. It takes owner and index name as input and must be executed from SYS.                                                                                                                                                                       </span></p>
<p><pre class="brush: sql;">

Session1&gt;@ndx-cleanup
Enter value for owner: subhatia_dba
Enter value for index_name: mytab_idx
OBJECT ID OF INDEX IS -----------&gt; 98701
JOURNAL TABLE IS -----------&gt; SYS_JOURNAL_98701
CURRENT INDEX STATUS -----------&gt; VALID
INDEX CLEANUP COMPLETED
JOURNAL TABLE HAS BEEN CLEANED

PL/SQL procedure successfully completed.

</pre></p>
<br />Filed under: <a href='http://fordba.wordpress.com/category/index/'>Index</a>, <a href='http://fordba.wordpress.com/category/index/index-rebuild/'>Index rebuild</a>, <a href='http://fordba.wordpress.com/category/index/journal-table/'>Journal table</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fordba.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fordba.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fordba.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fordba.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fordba.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fordba.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fordba.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fordba.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fordba.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fordba.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fordba.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fordba.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fordba.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fordba.wordpress.com/258/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=258&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fordba.wordpress.com/2011/05/02/cleaning-journal-table/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0b8748224dcc3259b8c20081f7a988ac?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sbhatia83</media:title>
		</media:content>
	</item>
		<item>
		<title>Journal table &#8212; Behaviour and Issues</title>
		<link>http://fordba.wordpress.com/2011/04/13/journal-table-behaviour/</link>
		<comments>http://fordba.wordpress.com/2011/04/13/journal-table-behaviour/#comments</comments>
		<pubDate>Wed, 13 Apr 2011 10:12:27 +0000</pubDate>
		<dc:creator>Sumit</dc:creator>
				<category><![CDATA[Index]]></category>
		<category><![CDATA[Index rebuild]]></category>
		<category><![CDATA[Journal table]]></category>
		<category><![CDATA[cancel index rebuild]]></category>
		<category><![CDATA[clear journal table]]></category>
		<category><![CDATA[clearing index rebuild]]></category>
		<category><![CDATA[index rebuild online]]></category>
		<category><![CDATA[index stuck]]></category>
		<category><![CDATA[journal table]]></category>
		<category><![CDATA[ndx-progress]]></category>
		<category><![CDATA[what are journal tabe]]></category>

		<guid isPermaLink="false">http://fordba.wordpress.com/?p=202</guid>
		<description><![CDATA[Journal Tables are like any other IOT tables. I had explained their strcture in the recent post.  This post will cover following points Behaviour of journal table. Effects of killing index in between. Please click here to understand the basic structure of journal table. Behaviour of Journal Table As discussed earlier, journal tables are created [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=202&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="color:#000080;">Journal Tables are like any other IOT tables. I had explained their strcture in the recent post.  </span><span style="color:#000080;">This post will cover following points</span></p>
<ol>
<li><span style="color:#000080;">Behaviour of journal table.</span></li>
<li><span style="color:#000080;">Effects of killing index in between.</span></li>
</ol>
<p><span style="color:#000080;"><a title="Journal Table structure" href="http://fordba.wordpress.com/2011/04/12/journal-table-what-are-those/" target="_blank">Please click here to understand the basic structure of journal table.</a></span></p>
<h3><span style="color:#0000ff;">Behaviour of Journal Table</span></h3>
<p><span style="color:#000080;">As discussed earlier, journal tables are created when we issue alter index command and gets dropped only after the job completes successfully or cleans or cancelled successfully.  </span><span style="color:#000080;">Whenever we kill our session or cancel our job, oracle tries to clean the journal table . </span><span style="color:#000080;">If you have killed your job (CTL C), oracle tries to get a latch and then merge the entries and then drop the journal table.</span></p>
<p><span style="color:#000080;"> </span><span style="color:#000080;">In case it does not, it will try fixed number of times and will then fail. This behaviour is explained in detail in later section. </span><span style="color:#000080;">However, we must verify that journal tables are no longer present.</span></p>
<h3><span style="color:#0000ff;">Test Case:-</span></h3>
<p><span style="color:#000080;">From session 1 insert a row  and issue rebuild comand from session 2 and then hit ctl c to cancel the job.</span></p>
<p><pre class="brush: sql;">

Session1&gt;insert into mytab select * from mytab where rownum&lt;2;

Session2&gt;alter index mytab_idx rebuild online;
alter index mytab_idx rebuild online
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation&lt;

/*it will error out after 2000 retries or 20000 milli seconds. Discussed later */

</pre></p>
<p><span style="color:#000080;">Lets check if the journal table exists or not.</span></p>
<p><pre class="brush: sql;">

sesion2&gt;select object_name,object_type,object_id from dba_objects where object_name='MYTAB_IDX';

OBJECT_NAME          OBJECT_TYPE           OBJECT_ID
-------------------- -------------------- ----------
MYTAB_IDX            INDEX                     98701

1 row selected.

session2&gt;select object_name,object_type from dba_objects where object_name='SYS_JOURNAL_98701';

OBJECT_NAME          OBJECT_TYPE
-------------------- --------------------
SYS_JOURNAL_98701    TABLE

1 row selected.
</pre></p>
<p><span style="color:#000080;">As suspected , oracle timesout and left the cleaning part. </span><span style="color:#000080;">All the transaction entries will now go</span><span style="color:#000080;"> into the journal table from now since the trigger has not been changed back to point to the index. Its still pointing to the journal table. </span><span style="color:#0000ff;"><span style="color:#000080;">As we can see,if the index rebuild job does not perform cleaning, the entries will stuck in journal table and we have to take manual steps to recover it.</span></span></p>
<p><pre class="brush: sql;">

session1&gt;select * from SYS_JOURNAL_98701;

session1&gt;insert into mytab(owner,object_name) values ('AFTER INDEX','CANCEL');

1 row created.
session1&gt;commit;

Commit complete.

C0                   C1         C2    OPCODE     PARTNO RID
-------------------- ---------- ----- ---------- ------ ------------------
AFTER INDEX          CANCEL           I               0 D/////AAEAAAwQHAAL

1 row selected.
</pre></p>
<h3><span style="color:#0000ff;">Effects of killing index in between</span></h3>
<p><span style="color:#000080;">As we had already discussed that even after killing index job, oracle sometimes does not able to drop the journal table. Oracle will try exactly 2000 times with avg waitng time of 10 millli second (20,000 milli seconds in all), in case all the blocking sessions are inactive,  to acquire a latch to clean the journal table.</span></p>
<h3><span style="color:#000080;"><span style="color:#0000ff;">Test Case</span></span></h3>
<p><span style="color:#000080;">Lets insert a row without commiting and start rebuilding from next session.</span></p>
<p><pre class="brush: sql;">

Session1&gt;insert into mytab select * from mytab where rownum&lt;2;

1 row created.

Session2&gt;alter index mytab_idx rebuild online; 

</pre></p>
<p><span style="color:#000080;">Lets check the status from session 3 using our ndx-progress.sql</span></p>
<p><pre class="brush: sql;">

SESSION3&gt;@ndx-progress
Enter value for sid: 2178

SID              ----&gt;2178
SERIAL           ----&gt;6537
MODULE           ----&gt;SQL*Plus
MACHINE          ----&gt;db-fc-admin-6001.iad6.amazon.com
USERNAME         ----&gt;SUBHATIA_DBA
OSUSER           ----&gt;subhatia
SQL TEXT         ----&gt;alter index mytab_idx rebuild online
SQL ID           ----&gt;7sk4sratkuvq8
JOURNAL NAME     ----&gt;SYS_JOURNAL_98701
TABLE NAME       ----&gt;MYTAB
EVENT_NAME       ----&gt;enq: TX - row lock contention
IDLE SINCE       ----&gt;223
CPU TIME         ----&gt;35995
ELAPSED TIME     ----&gt;219143299
JOURNAL COUNT    ----&gt;0
STAGE            ----&gt;Waiting for first latch.
LONGOPS          ----&gt;INDEX REBUILD NOT STARTED YET
PROGRESS         ----&gt;No Tx started after index rebuild has commited yet. There are 0 rows in journal table
------------SESSIONS BLOCKING FIRST LATCH ARE-------------
SID     SERIAL  STATUS          LAST_CALL_ET            COMMAND         SQL_ID          PREV_SQL_ID             MODULE          MACHINE
2154    9407    INACTIVE                249             0               NONE            9babjv8yq8ru3           SQL*Plus        db-fc-admin-6001.iad6.amazon.com
------------SESSIONS THAT MAY BLOCK LAST LATCH ARE-------------
SID     SERIAL  STATUS          LAST_CALL_ET            COMMAND         SQL_ID          PREV_SQL_ID             MODULE          MACHINE

NO POTENTIAL BLOCKERS FOUND FOR THE LAST LATCH

</pre></p>
<p><span style="color:#000080;">As expected, our insert has blocked the index rebuild. </span><span style="color:#000080;">Lets cancel the job(ctl c) and check whats happening now using ndx-progress.</span></p>
<p><span style="color:#000080;">Yes, ndx-progress can report that one too (amazing).</span></p>
<p><span style="color:#000080;"><a title="ndx-progress.sql" href="http://fordba.wordpress.com/2011/03/30/ndx-progress-sql/" target="_blank">click here for ndx-progress</a></span></p>
<p><pre class="brush: sql;">

SESSION3&gt;@ndx-progress
Enter value for sid: 2178
Index Rebuild has been cancelled. Cleaning going on
SID              ----&gt;2178
SERIAL           ----&gt;6537
MODULE           ----&gt;SQL*Plus
MACHINE          ----&gt;db-fc-admin-6001.iad6.amazon.com
USERNAME         ----&gt;SUBHATIA_DBA
OSUSER           ----&gt;subhatia
SQL TEXT         ----&gt;alter index mytab_idx rebuild online
SQL ID           ----&gt;7sk4sratkuvq8
JOURNAL NAME     ----&gt;SYS_JOURNAL_98701
TABLE NAME       ----&gt;MYTAB
EVENT_NAME       ----&gt;index (re)build online cleanup
IDLE SINCE       ----&gt;2116
CPU TIME         ----&gt;2164672
ELAPSED TIME     ----&gt;2113894321
JOURNAL COUNT    ----&gt;0
------------SESSIONS BLOCKING CLEANING PROCESS-------------
SID     SERIAL  STATUS          LAST_CALL_ET            COMMAND         SQL_ID          PREV_SQL_ID             MODULE          MACHINE
2154    9407    INACTIVE                2145            0               NONE            9babjv8yq8ru3           SQL*Plus        db-fc-admin-6001.iad6.amazon.com
------------CLEANUP PROCESS TIMOUT-------------
EVENT                                   TOTAL WAITS             TOTAL TIMEOUTS          TIME WAITED             AVG WAIT                MAX WAIT
index (re)build online cleanup          1967                    1967                    19799                   10.07                   10                  10

</pre></p>
<p><span style="color:#000080;">On checking the status, index job was cancelled but journal entry was still there</span></p>
<p><pre class="brush: sql;">

Session2&gt;alter index mytab_idx rebuild online;
alter index mytab_idx rebuild online
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation
SESSION3&gt;select event,total_waits,total_timeouts,time_waited,average_wait,max_wait from v$session_event where sid=2178 and event='index (re)build online cleanup';
EVENT                          TOTAL_WAITS TOTAL_TIMEOUTS TIME_WAITED AVERAGE_WAIT   MAX_WAIT
------------------------------ ----------- -------------- ----------- ------------ ----------
index (re)build online cleanup        2000           2000       20131        10.07         10
1 row selected.
</pre></p>
<p><span style="color:#000080;">As we can check, oracle tries for 2000  times but timeout each time. it kept tring for 2000*10 ms and then error out.</span></p>
<br />Filed under: <a href='http://fordba.wordpress.com/category/index/'>Index</a>, <a href='http://fordba.wordpress.com/category/index/index-rebuild/'>Index rebuild</a>, <a href='http://fordba.wordpress.com/category/index/journal-table/'>Journal table</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fordba.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fordba.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fordba.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fordba.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fordba.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fordba.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fordba.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fordba.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fordba.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fordba.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fordba.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fordba.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fordba.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fordba.wordpress.com/202/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=202&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fordba.wordpress.com/2011/04/13/journal-table-behaviour/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0b8748224dcc3259b8c20081f7a988ac?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sbhatia83</media:title>
		</media:content>
	</item>
		<item>
		<title>Journal Table &#8212; What are those</title>
		<link>http://fordba.wordpress.com/2011/04/12/journal-table-what-are-those/</link>
		<comments>http://fordba.wordpress.com/2011/04/12/journal-table-what-are-those/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 14:42:47 +0000</pubDate>
		<dc:creator>Sumit</dc:creator>
				<category><![CDATA[Index]]></category>
		<category><![CDATA[Index rebuild]]></category>
		<category><![CDATA[Journal table]]></category>
		<category><![CDATA[index rebuild]]></category>
		<category><![CDATA[index stuck]]></category>
		<category><![CDATA[journal table in oracle]]></category>
		<category><![CDATA[journal tables]]></category>
		<category><![CDATA[oracle journal table]]></category>
		<category><![CDATA[what are journal tables]]></category>

		<guid isPermaLink="false">http://fordba.wordpress.com/?p=98</guid>
		<description><![CDATA[Many DBA’s have tendency to hit CTL C or kill the session, when there session does not comes out. Ever tries doing that with index rebuild and you will find that your index is stuck in journal table. This post is intended to describe the nature of journal table and how to clear the mess. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=98&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3><span style="color:#000080;"><span style="font-family:Calibri;font-size:small;">Many DBA’s have tendency to hit CTL C or kill the session, when there session does not comes out. </span><span style="font-family:Calibri;font-size:small;">Ever tries doing that with index rebuild and you will find that your index is stuck in journal table. </span><span style="font-family:Calibri;font-size:small;">This post is intended to describe the nature of journal table and how to clear the mess.</span></span></h3>
<div><span style="color:#000080;"><span style="font-family:Calibri;font-size:small;"> </span><span style="font-family:Calibri;font-size:small;">It’s been divided into following sections</span></span></div>
<ol>
<li><span style="font-family:Calibri;color:#000080;font-size:small;">Structure and understanding of journal table</span></li>
<li><span style="font-family:Calibri;color:#000080;font-size:small;">Behaviour of journal table.</span></li>
<li><span style="font-family:Calibri;color:#000080;font-size:small;">Effect of killing the index rebuild in between.</span></li>
<li><span style="color:#000080;"><span style="font-family:Calibri;font-size:small;">Clearing the journal table.</span></span></li>
</ol>
<h2><strong><span style="color:#0000ff;">Structure of Journal Table </span></strong></h2>
<p><span style="color:#000080;"><strong> </strong><span style="font-family:Calibri;font-size:small;">Oracle creates journal table inside the owner schema as soon as we issue “alter index rebuild online”. </span><span style="font-family:Calibri;font-size:small;">It doesn’t matter if oracle has acquired the first latch or not. </span><span style="font-family:Calibri;font-size:small;">The entries of all the transactions started after we issue the command will be logged into the journal table. </span><span style="font-family:Calibri;font-size:small;">Journal table is the index organized table and their name will essentially be SYS_JOURNAL_&lt;index object_id&gt;.</span></span></p>
<p><span style="color:#000080;"><span style="font-family:Calibri;font-size:small;">To understand index rebuilding check the following link.</span></span></p>
<p><span style="color:#000080;"><span style="font-family:Calibri;font-size:small;"><a title="Index Rebuild Online" href="http://fordba.wordpress.com/2011/04/05/online-ndx-rebuild/" target="_blank">Index Rebuild Online</a></span></span></p>
<p><span style="font-family:Calibri;color:#000080;font-size:small;">The structure is as follows</span></p>
<p><span style="font-family:Calibri;font-size:small;"> </span><span style="color:#0000ff;"> <span style="color:#000080;">As you might have noticed, there is no &#8220;U&#8221; for update in opcode since update essentially is Delete+ Insert. Two entries will be recorded for each update statement in the journal table.  </span></span></p>
<p><pre class="brush: sql;">
Name                    Null?    Type
C0                      NOT NULL VARCHAR2(30) --&gt;first column of index

C1                      NOT NULL VARCHAR2(128) --&gt;second column of index(composite index)
C2                      NOT NULL VARCHAR2(30) --&gt;third column of index (composite index)
OPCODE                           CHAR(1) --&gt;I for insert, D for delete.
PARTNO                           NUMBER
RID                     NOT NULL ROWID --&gt;rowid from 7th char to end
</pre></p>
<p> <span style="color:#000080;">C0,C1,C2(columns of index) and RID will form the primary key of the journal table and will have a unique index with the name SYS_IOT_TOP_&lt;journal object id&gt;</span></p>
<p><span style="color:#000080;">The columns of journal table(c0,c1,c2) will have same data type as of base table and will always be not null irrespective of constarints on base table.</span></p>
<h4><span style="color:#0000ff;">TEST CASE</span></h4>
<p><span style="color:#000080;">I have created a table mytab (select * from dba_objects) and created a composite index mytab_idx on (owner,object_name,subobject_name).</span></p>
<p><span style="color:#000080;">As I started the rebuild, i could see following entries in my schema.</span></p>
<p><pre class="brush: sql;">

session4&gt; select object_name,object_type,object_id from dba_objects where owner='SUBHATIA_DBA';

OBJECT_NAME                                        OBJECT_TYPE          OBJECT_ID
-------------------------------------------------- ------------------- ----------
MYTAB                                              TABLE                    98699
SYS_JOURNAL_98701                                  TABLE                   101871
SYS_IOT_TOP_101871                                 INDEX                   101872
MYTAB_IDX                                          INDEX                    98701

4 rows selected.

</pre></p>
<p><span style="color:#000080;">As we can confirm the name of the journal table is SYS_JOURNAL_98701 (where 98701 is object id of index) and IOT index is SYS_IOT_TOP_101871  where 101871 is object_id of journal table.</span></p>
<h4><span style="color:#0000ff;">Usage of Journal Tables</span></h4>
<p><span style="color:#000080;">When we rebuild index online, oracle does not read from the existing index. Instead it reads the base table. So whats the use of existiing index.</span></p>
<p><span style="color:#000080;">Well, oracle put the existing index into read only mode and records all the new transaction entries into the journal table.</span></p>
<p><span style="color:#000080;">Journal table is like any other IOT table. So whenever, any select statement needs to traverse a row, it gets the rowid from the new journal table and then access the table using that rowid.</span></p>
<p>Question1) Does journal table is always there in the database</p>
<p><span style="color:#000080;">Answer) Journal tables are created as we issue the rebuild command and gets dropped as soon as the command finishes.</span></p>
<p><span style="color:#003300;">Question 2) Does journal table record entries of transactions which starts before the alter index rebuild command was issued.</span></p>
<p><span style="color:#000080;">Answer) No, it does not. It will only capture entries of those transactions that have started after we fired rebuild. Oracle doesn&#8217;t know you are going to fire rebuild command.</span></p>
<p><span style="color:#003300;">Question3) Does journal table records entries of transactions started after rebuild only after we commit.</span></p>
<p><span style="color:#000080;">Answer) Journal table is like any other table. In case you performed some DML while index rebuid is going on and does not commit, you will be able to see those entries into the journal table from same session but others won&#8217;t. Others will see only if you commit them. Oracle follows basic ACID principle for journal tables too.</span></p>
<h4><span style="color:#0000ff;">Test case</span></h4>
<p><span style="color:#000080;">Lets verify all the above points</span></p>
<p><strong><span style="color:#000080;">Are journal tables there forever??</span></strong></p>
<p><span style="color:#000080;">Currently I have only 2 objects in my schema.</span><span style="color:#000080;"> </span></p>
<p><pre class="brush: sql;">

session4&gt;select object_name,object_type,object_id from dba_objects where owner='SUBHATIA_DBA';

OBJECT_NAME                                        OBJECT_TYPE          OBJECT_ID
-------------------------------------------------- ------------------- ----------
MYTAB_IDX                                          INDEX                    98701
MYTAB                                              TABLE                    98699

2 rows selected.
</pre></p>
<p><span style="color:#000080;">Lets insert few rows from 1st session to block the rebuild and issue alter index command from 2nd session</span></p>
<p><pre class="brush: sql;">
SESSION1&gt;insert into mytab select * from mytab where rownum&lt;5;
4 rows created.
/*alter index from session 2 */
session2&gt;alter index mytab_idx rebuild online;  --&gt;will get stuck

/*lets check again from session 1 */

session1&gt;select object_name,object_type,object_id from dba_objects where owner='SUBHATIA_DBA';

OBJECT_NAME                                        OBJECT_TYPE          OBJECT_ID
-------------------------------------------------- ------------------- ----------
MYTAB                                              TABLE                    98699
SYS_JOURNAL_98701                                  TABLE                   101877
SYS_IOT_TOP_101877                                 INDEX                   101878
MYTAB_IDX                                          INDEX                    98701

4 rows selected.

</pre></p>
<p><strong><span style="color:#000080;">Does journal table record entries of transactions which starts before the alter index rebuild command was issued??</span></strong></p>
<p><span style="color:#000080;">Check the count of journal table from the session holding the lock.</span></p>
<p><pre class="brush: sql;">

SESSION1&gt;select count(*) from SYS_JOURNAL_98701;

  COUNT(*)
----------
         0

1 row selected.

</pre></p>
<p><span style="color:#000080;"><strong>Does journal table records entries of transactions started after rebuild only after we commit??</strong></span></p>
<p><span style="color:#000080;"> Lets open a new session and insert few rows without committing.</span></p>
<p><pre class="brush: sql;">

session4&gt;insert into mytab select * from mytab where rownum&lt;5;

4 rows created.

session4&gt;select count(*) from SYS_JOURNAL_98701;

  COUNT(*)
----------
         4

1 row selected.

/*lets query from some another session*/

SESSION1&gt;select count(*) from SYS_JOURNAL_98701;

  COUNT(*)
----------
         0

1 row selected.

/*Lets commit and again check count from another session */

SESSION1&gt;select count(*) from SYS_JOURNAL_98701;

  COUNT(*)
----------
         4

1 row selected.

</pre></p>
<h2><span style="color:#0000ff;"><strong>Understanding of Journal Table</strong></span></h2>
<p><span style="color:#0000ff;"><span style="color:#000080;">When we say, journal table hold entries then the next obvious question is what entries. How does it store and what does it mean.</span></span><span style="color:#0000ff;"><span style="color:#000080;">Moreover, is there any mechanism to understand those.</span></span> <span style="color:#0000ff;"><span style="color:#000080;"> </span></span></p>
<p><span style="color:#0000ff;"><span style="color:#000080;">The answer is YES, we can.</span></span></p>
<p><span style="color:#0000ff;"><span style="color:#000080;">Lets try out this test case.</span></span></p>
<p><span style="color:#0000ff;"><span style="color:#000080;">Insert a row from session1 to block the index rebuild and start rebuilding index from another session.</span></span> <span style="color:#0000ff;"> </span></p>
<p><pre class="brush: sql;">
SESSION1&gt;insert into mytab select * from mytab where rownum&lt;5;

4 rows created.
/* Start rebuild from Session 2. Your session will stuck here even if its a pretty small index*/
session2&gt;alter index mytab_idx rebuild Online;
/*Open a new session and insert a row */
session3&gt;insert into mytab(owner,object_name,subobject_name) values('SUMIT','RANDOM','RANDOM');
1 row created.
session3&gt;SELECT * FROM SYS_JOURNAL_98701;

C0                             C1                   C2                             O     PARTNO RID
------------------------------ -------------------- ------------------------------ - ---------- ------------------
SUMIT                          RANDOM               RANDOM                         I          0 D/////AAEAAAwQHAAU

 /*Let's update a row as well */
session3&gt;update mytab set owner='DBA' where owner='SUMIT' AND object_name='RANDOM';

1 row updated.

session3&gt;SELECT * FROM SYS_JOURNAL_98701;

C0         C1         C2         O     PARTNO RID
---------- ---------- ---------- - ---------- ------------------
DBA        RANDOM     RANDOM     I          0 D/////AAEAAAwQHAAU
SUMIT      RANDOM     RANDOM     D          0 D/////AAEAAAwQHAAU

2 rows selected.

</pre></p>
<p><span style="color:#000080;">Here we can see 2 entries. But there should be 3. Remember update=D+I.</span></p>
<p><span style="color:#000080;">Oracle knew we have updated the row which we just inserted and the entry was already there. So it removes the earlier entry and added 2 new entries for update only.</span></p>
<p><span style="color:#000080;">Now, the entry for Sumit is marked as &#8220;D&#8221; wich was earlier &#8220;I&#8221; and a new entry &#8220;DBA&#8221;  has been added as &#8220;I&#8221;.</span></p>
<p><span style="color:#000080;">Last question, why oracle has not stored initial 6 letters of rowid and can we trace it back.</span></p>
<p><span style="color:#000080;">Yes, we can trace it back. We can use following query (but it is a bit slower)</span></p>
<p><pre class="brush: sql;">

session3&gt;select owner,object_name,SUBOBJECT_NAME from mytab where substr(rowid,7)='AAEAAAwQHAAU';

OWNER                OBJECT_NAME                                        SUBOBJECT_NAME
-------------------- -------------------------------------------------- ------------------------------
DBA                  RANDOM                                             RANDOM

1 row selected.

</pre></p>
<p><span style="color:#000080;">Oracle is not showing inital 6 letters because those always refer to object id.</span></p>
<p><span style="color:#000080;">We can use this method which is relatively faster.</span></p>
<p><pre class="brush: sql;">

session3&gt;select substr(rowid,1,6) from  mytab  where rownum&lt;2;

SUBSTR(ROWID,1,6)
------------------
AAAYGL

1 row selected.
session3&gt;select owner,object_name,SUBOBJECT_NAME from mytab where rowid='AAAYGLAAEAAAwQHAAU';

OWNER                OBJECT_NAME                                        SUBOBJECT_NAME
-------------------- -------------------------------------------------- ------------------------------
DBA                  RANDOM                                             RANDOM

1 row selected.

</pre></p>
<br />Filed under: <a href='http://fordba.wordpress.com/category/index/'>Index</a>, <a href='http://fordba.wordpress.com/category/index/index-rebuild/'>Index rebuild</a>, <a href='http://fordba.wordpress.com/category/index/journal-table/'>Journal table</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fordba.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fordba.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fordba.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fordba.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fordba.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fordba.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fordba.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fordba.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fordba.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fordba.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fordba.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fordba.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fordba.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fordba.wordpress.com/98/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=98&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fordba.wordpress.com/2011/04/12/journal-table-what-are-those/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0b8748224dcc3259b8c20081f7a988ac?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sbhatia83</media:title>
		</media:content>
	</item>
		<item>
		<title>Online Index Rebuild oracle 11g&#8211;&gt;Behind the scene</title>
		<link>http://fordba.wordpress.com/2011/04/05/online-ndx-rebuild/</link>
		<comments>http://fordba.wordpress.com/2011/04/05/online-ndx-rebuild/#comments</comments>
		<pubDate>Tue, 05 Apr 2011 14:26:53 +0000</pubDate>
		<dc:creator>Sumit</dc:creator>
				<category><![CDATA[Index]]></category>
		<category><![CDATA[Index rebuild]]></category>
		<category><![CDATA[11g index rebuild]]></category>
		<category><![CDATA[enq TM contention]]></category>
		<category><![CDATA[index rebuild]]></category>
		<category><![CDATA[lock index rebuild]]></category>
		<category><![CDATA[online index rebuild]]></category>
		<category><![CDATA[performance index rebuild]]></category>
		<category><![CDATA[troubleshoot index rebuild]]></category>

		<guid isPermaLink="false">http://fordba.wordpress.com/?p=8</guid>
		<description><![CDATA[Index are used to speed up the select statements. But over a period of time, they may get fragmented because of constant DML&#8217;s occurring on the table. These bloated indexes may slow down the select or may cause plan flips too. One way to avoid all these is to rebuild indexes.However, many of us might [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=8&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="color:#333333;">Index are used to speed up the select statements.</span><br />
<span style="color:#333333;">But over a period of time, they may get fragmented because of constant DML&#8217;s occurring on the table. These bloated indexes may slow down the select or may cause plan flips too.</span></p>
<p><span style="color:#333333;">One way to avoid all these is to rebuild indexes.However, many of us might have faced issues while rebuilding indexes. Sometimes, it causes performance issues (due to enq TM contention) or the command won&#8217;t come out.</span></p>
<p><span style="color:#333333;">Ever wonder, why the index rebuilding is suddenly taking such a long time. Why my session is not coming out or exactly where is it stuck.</span></p>
<p><span style="color:#333333;">This post is intended to explore the internals of online index rebuild in oracle11g. I have developed a customized script which will tell exactly where the session is stuck.</span></p>
<p><a title="ndx-progress.sql" href="http://fordba.wordpress.com/2011/03/30/ndx-progress-sql/" target="_blank"><span style="color:#0000ff;">http://fordba.wordpress.com/2011/03/30/ndx-progress-sql/</span></a></p>
<blockquote><p><span style="color:#0000ff;"><strong>The script is just an anonymous plsql block and does not perform any DDL/DML.</strong></span></p>
<p><span style="color:#0000ff;"><strong>It queries various v$ views to present the current picture before you and does not cause or have any adverse impact</strong></span></p></blockquote>
<p><span style="color:#333333;">For online index rebuild oracle requires 2 latches. One at the beginning and one at the end of the operation.</span></p>
<h3><span style="color:#003366;">Online Index Rebuild Stages (No Parallel)</span></h3>
<p><span style="color:#333333;">During Online index rebuild oracle performs following in the given order :-</span></p>
<ol>
<li><span style="color:#333333;">Create the journal table (inside index owner schema) SYS_JOURNAL_&lt;objectid_index&gt;</span></li>
<li><span style="color:#333333;">Wait for the first latch (enq: TX &#8211; row lock contention)</span></li>
<li><span style="color:#333333;">As soon as it gets latch, will perform db file sequential read to merge journal entries</span></li>
<li><span style="color:#333333;">Will start scattered read of the base table</span></li>
<li><span style="color:#333333;">Will again perform the sequential read to merge the journal entries which got generated during scattered read.</span></li>
<li><span style="color:#333333;">Will perform direct path read temp.</span></li>
<li><span style="color:#333333;">wait for the end latch</span></li>
</ol>
<p><span style="color:#333333;">The good thing about index rebuild in 11g is , it does not cause locking for the DML&#8217;s (enq TM contention, which was there in 10g).</span></p>
<h4><span style="color:#000080;">Test Case</span></h4>
<p>Environment:- Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 &#8211; 64bit Production</p>
<p>1. Create a new table and insert few records.</p>
<p><pre class="brush: sql;">
SESSION1&gt;CREATE TABLE mytab as select * from dba_objects;
Table created.

SESSION1&gt;insert into mytab select * from mytab;
12459 rows created.

SESSION1&gt;/
12459 rows created.
SESSION1&gt;create index mytab_idx on myt(owner,OBJECT_NAME,SUBOBJECT_NAME);

Index created.
</pre></p>
<p>You may want to insert more rows to grow the size of index.</p>
<p>2. Insert a new records into the table.</p>
<p><pre class="brush: sql;">
SESSION1&gt;insert into mytab select * from mytab where rownum&lt;10;
9 rows created.</pre></p>
<p>3. Open a new session (note down its sid) and issue alter index command.</p>
<p><pre class="brush: sql;">
SESSION2&gt;select sid from v$mystat where rownum&lt;2;
SID
----------
2195
1 row selected.
SESSION2&gt;ALTER INDEX MYTAB_IDX REBUILD ONLINE;
</pre></p>
<p>4. Open a new session to see exactly whats happening.</p>
<pre>SESSION3&gt;@ndx-progress.sql
Enter value for sid: 2195
SQL TEXT IS      ----&gt;ALTER INDEX MYTAB_IDX REBUILD ONLINE
SQL ID IS        ----&gt;drs3mtb5w9knb
JOURNAL TABLE IS ----&gt;SYS_JOURNAL_98701
TABLE NAME IS    ----&gt;MYTAB
<span style="color:#ff0000;">EVENT_NAME IS    ----&gt;enq: TX - row lock contention</span>
JOURNAL COUNT    ----&gt;0
<span style="color:#ff0000;">STAGE            ----&gt;Waiting for first latch.</span>
PROGRESS         ----&gt;No Tx started after index rebuild has commited yet. There are 0 rows in journal table
------------SESSIONS BLOCKING FIRST LATCH ARE-------------
SID     SERIAL  STATUS          LAST_CALL_ET            COMMAND         SQL_ID          PREV_SQL_ID             MODULE          MACHINE
2161    19807   INACTIVE                425             0               NONE            9babjv8yq8ru3           SQL*Plus        db-fc-admin-6001.iad6.amazon.com
------------SESSIONS THAT MAY BLOCK LAST LATCH ARE-------------
SID     SERIAL  STATUS          LAST_CALL_ET            COMMAND         SQL_ID          PREV_SQL_ID             MODULE          MACHINE
NO POTENTIAL BLOCKERS FOUND FOR THE LAST LATCH</pre>
<p>5. In the above output, you can see the session is waiting on enq: TX &#8211; row lock contention and has not acquired the first latch.</p>
<p>It will keep on waiting for all the transactions which have started before issueing index rebuild.</p>
<p>For any transactions started after index rebuild comand issued, they will cause locking at the last stage when end latch is required.</p>
<p>In case they commit, there entries will go into the journal table.</p>
<p>Lets open another session and insert few rows and wait for 30 seconds(This is the limit i set in my script to find potential blockers)</p>
<p><pre class="brush: sql;">
SESSION4&gt;insert into mytab select * from mytab where rownum&lt;101;
100 rows created.

</pre></p>
<p>6. Lets check whats happening again. The journal count is still 0, since session 4 has not commited yet and the session is appearing on potential blockers list</p>
<pre>SESSION3&gt;/
Enter value for sid: 2195
SQL TEXT IS      ----&gt;ALTER INDEX MYTAB_IDX REBUILD ONLINE
SQL ID IS        ----&gt;drs3mtb5w9knb
JOURNAL TABLE IS ----&gt;SYS_JOURNAL_98701
TABLE NAME IS    ----&gt;MYTAB
EVENT_NAME IS    ----&gt;enq: TX - row lock contention
<span style="color:#ff0000;">JOURNAL COUNT    ----&gt;0</span>
STAGE            ----&gt;Waiting for first latch.
<span style="color:#ff0000;">PROGRESS         ----&gt;No Tx started after index rebuild has commited yet. There are 0 rows in journal table</span>
------------SESSIONS BLOCKING FIRST LATCH ARE-------------
SID     SERIAL  STATUS          LAST_CALL_ET            COMMAND         SQL_ID          PREV_SQL_ID             MODULE          MACHINE
2161    19807   INACTIVE                1015            0               NONE            9babjv8yq8ru3           SQL*Plus        db-fc-admin-6001.iad6.amazon.com
------------SESSIONS THAT MAY BLOCK LAST LATCH ARE-------------
SID     SERIAL  STATUS          LAST_CALL_ET            COMMAND         SQL_ID          PREV_SQL_ID             MODULE          MACHINE
<span style="color:#ff0000;">2164    36539   INACTIVE                130             0               NONE            9babjv8yq8ru3           SQL*Plus        db-fc-admin-6001.iad6.amazon.com</span></pre>
<p>7. Lets commit from session 4 and see the difference in count of journal table. It will disappear from potential blockers list as it has committed and there will be entries into the journal table</p>
<pre>SESSION3&gt;/
Enter value for sid: 2195
SQL TEXT IS      ----&gt;ALTER INDEX MYTAB_IDX REBUILD ONLINE
SQL ID IS        ----&gt;drs3mtb5w9knb
JOURNAL TABLE IS ----&gt;SYS_JOURNAL_98701
TABLE NAME IS    ----&gt;MYTAB
EVENT_NAME IS    ----&gt;enq: TX - row lock contention
<span style="color:#ff0000;">JOURNAL COUNT    ----&gt;100</span>
STAGE            ----&gt;Waiting for first latch.
<span style="color:#ff0000;">PROGRESS         ----&gt;Few Tx started after index rebuild command have been commited and there is/are 100 rows into journal table</span>
------------SESSIONS BLOCKING FIRST LATCH ARE-------------
SID     SERIAL  STATUS          LAST_CALL_ET            COMMAND         SQL_ID          PREV_SQL_ID             MODULE          MACHINE
2161    19807   INACTIVE                1134            0               NONE            9babjv8yq8ru3           SQL*Plus        db-fc-admin-6001.iad6.amazon.com

------------SESSIONS THAT MAY BLOCK LAST LATCH ARE-------------
SID     SERIAL  STATUS          LAST_CALL_ET            COMMAND         SQL_ID          PREV_SQL_ID             MODULE          MACHINE
<span style="color:#ff0000;">NO POTENTIAL BLOCKERS FOUND FOR THE LAST LATCH
</span></pre>
<p>8. So far we have observed that index is stuck. Lets insert few more rows (100k approx) so that we could observe step3 else we wont able to catch the initial db file sequential read merging and check the status.</p>
<p><pre class="brush: sql;">
SESSION4&gt;insert into mytab select * from mytab where rownum&lt;100001;
100000 rows created.
SESSION4&gt;commit;
Commit complete.
</pre></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-check from session 3&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<pre>SESSION3&gt;/
Enter value for sid: 2195
SQL TEXT IS      ----&gt;ALTER INDEX MYTAB_IDX REBUILD ONLINE
SQL ID IS        ----&gt;drs3mtb5w9knb
JOURNAL TABLE IS ----&gt;SYS_JOURNAL_98701
TABLE NAME IS    ----&gt;MYTAB
EVENT_NAME IS    ----&gt;enq: TX - row lock contention
<span style="color:#ff0000;">JOURNAL COUNT    ----&gt;100100</span>
STAGE            ----&gt;Waiting for first latch.
PROGRESS         ----&gt;Few Tx started after index rebuild command have been commited and there is/are 100100 rows into journal table
------------SESSIONS BLOCKING FIRST LATCH ARE-------------
SID     SERIAL  STATUS          LAST_CALL_ET            COMMAND         SQL_ID          PREV_SQL_ID             MODULE          MACHINE
2161    19807   INACTIVE                1717            0               NONE            9babjv8yq8ru3           SQL*Plus        db-fc-admin-6001.iad6.amazon.com
------------SESSIONS THAT MAY BLOCK LAST LATCH ARE-------------
SID     SERIAL  STATUS          LAST_CALL_ET            COMMAND         SQL_ID          PREV_SQL_ID             MODULE          MACHINE
NO POTENTIAL BLOCKERS FOUND FOR THE LAST LATCH</pre>
<p>9. Insert few more rows again from session 4, to ensure we block the last latch too.</p>
<p><pre class="brush: sql;">
SESSION4&gt;insert into mytab select * from mytab where rownum&lt;100;
99 rows created.

</pre></p>
<p>10. Lets commit from session 1 to release initial lock and check status from session 3.</p>
<pre>SESSION3&gt;/
Enter value for sid: 2195
SQL TEXT IS      ----&gt;ALTER INDEX MYTAB_IDX REBUILD ONLINE
SQL ID IS        ----&gt;drs3mtb5w9knb
JOURNAL TABLE IS ----&gt;SYS_JOURNAL_98701
TABLE NAME IS    ----&gt;MYTAB
EVENT_NAME IS    ----&gt;db file sequential read
<span style="color:#ff0000;">JOURNAL COUNT    ----&gt;0</span>
<span style="color:#ff0000;">STAGE            ----&gt;First latch acquired.db file sequential read going on. Direct path read pending after this step.</span>
<span style="color:#ff0000;">PROGRESS         ----&gt;All Tx started before index rebuild have been commited (first latch acquired and cleared) and no entries into journal table now.</span></pre>
<p>As we can see, oracle always merge the journal table entries before performing scatterd read(FTS on base table).</p>
<p>Once that gets completed, oracle will start scattered read. Scattered read does not need any lock, so at this time our session 4 wont lock the index rebuild. it will lock during last phase.</p>
<pre>SESSION3&gt;/
Enter value for sid: 2195
SQL TEXT IS      ----&gt;ALTER INDEX MYTAB_IDX REBUILD ONLINE
SQL ID IS        ----&gt;drs3mtb5w9knb
JOURNAL TABLE IS ----&gt;SYS_JOURNAL_98701
TABLE NAME IS    ----&gt;MYTAB
<span style="color:#ff0000;">EVENT_NAME IS    ----&gt;db file scattered read</span>
JOURNAL COUNT    ----&gt;0
<span style="color:#ff0000;">STAGE            ----&gt;First latch acquired. FTS going on</span>
<span style="color:#ff0000;">PROGRESS         ----&gt;All Tx started before index rebuild have been commited (first latch acquired and cleared) and no entries into journal table now.</span></pre>
<p><span style="color:#333333;">Once that is done,oracle will perform sequential read and direct path read temp to merge entries generated during scattered read and then will wait for end latch.</span></p>
<pre>Enter value for sid: 2195
SQL TEXT IS      ----&gt;ALTER INDEX MYTAB_IDX REBUILD ONLINE
SQL ID IS        ----&gt;drs3mtb5w9knb
JOURNAL TABLE IS ----&gt;SYS_JOURNAL_98701
TABLE NAME IS    ----&gt;MYTAB
EVENT_NAME IS    ----&gt;enq: TX - row lock contention
JOURNAL COUNT    ----&gt;0
<span style="color:#ff0000;">STAGE            ----&gt;Operation completed.Waiting for ending latch</span>
PROGRESS         ----&gt;All Tx started before index rebuild have been commited (first latch acquired and cleared) and no entries into journal table now.

------------SESSIONS BLOCKING LAST LATCH ARE-------------
SID     SERIAL  STATUS          LAST_CALL_ET            COMMAND         SQL_ID          PREV_SQL_ID             MODULE          MACHINE
<span style="color:#ff0000;">2164    36539   INACTIVE                367             0               NONE            9babjv8yq8ru3           SQL*Plus        db-fc-admin-6001.iad6.amazon.com</span></pre>
<p><span style="color:#333333;">Once commit, index rebuild fiishes</span></p>
<h3><span style="color:#333399;">Online Index Rebuild Stages (Parallel Clause)</span></h3>
<p>Oracle performs following sequence of events with parallel clause</p>
<ol>
<li>Create the journal table (inside index owner schema) SYS_JOURNAL_&lt;objectid_index&gt;</li>
<li>Wait for the &#8220;first latch&#8221; (enq: TX &#8211; row lock contention)</li>
<li>As soon as it gets latch, will perform , it will spawn its slave process</li>
<li>Slave process will perform db file sequential read to merge the journal table entries</li>
<li>Each slave process will perform scattered read for its bunch of blocks.</li>
<li>Slave process will again perform the sequential read to merge the journal entries which got generated during scattered read.</li>
<li>slave process job will end here here.</li>
<li>Master process will wait for the &#8220;end latch&#8221;.</li>
</ol>
<h4><span style="color:#333399;">Test Case</span></h4>
<p><span style="color:#333333;">Insert few records from the first session to block index rebuild.</span></p>
<p><pre class="brush: sql;">
SESSION1&gt;insert into mytab select * from mytab where rownum&lt;101;
100 rows created.
</pre></p>
<p>Open another session and rebuild index with parallel clause</p>
<p><pre class="brush: sql;">
SESSION2&gt;ALTER INDEX MYTAB_IDX REBUILD ONLINE parallel 4;
</pre></p>
<p>Checking the status</p>
<pre>SESSION3&gt;/
Enter value for sid: 2195
SQL TEXT IS      ----&gt;ALTER INDEX MYTAB_IDX REBUILD ONLINE parallel 4
SQL ID IS        ----&gt;7qr6scnthqh0f
JOURNAL TABLE IS ----&gt;SYS_JOURNAL_98701
TABLE NAME IS    ----&gt;MYTAB
EVENT_NAME IS    ----&gt;enq: TX - row lock contention
JOURNAL COUNT    ----&gt;0
<span style="color:#ff0000;">STAGE            ----&gt;Waiting for first latch.</span>
PROGRESS         ----&gt;No transaction started after rebuiding has committed.
------------SESSIONS BLOCKING FIRST LATCH ARE-------------
SID     SERIAL  STATUS          LAST_CALL_ET            COMMAND         SQL_ID          PREV_SQL_ID             MODULE          MACHINE
2161    19807   INACTIVE                152             0               NONE            9babjv8yq8ru3           SQL*Plus        db-fc-admin-6001.iad6.amazon.com
------------SESSIONS THAT MAY BLOCK LAST LATCH ARE-------------
SID     SERIAL  STATUS          LAST_CALL_ET            COMMAND         SQL_ID          PREV_SQL_ID             MODULE          MACHINE
NO POTENTIAL BLOCKERS FOUND FOR THE LAST LATCH</pre>
<p>As we commit the first session, parallel process will start the processing.</p>
<pre>SESSION3&gt;/
Enter value for sid: 2195
SQL TEXT IS      ----&gt;ALTER INDEX MYTAB_IDX REBUILD ONLINE parallel 4
SQL ID IS        ----&gt;7qr6scnthqh0f
JOURNAL TABLE IS ----&gt;SYS_JOURNAL_98701
TABLE NAME IS    ----&gt;MYTAB
<span style="color:#ff0000;">EVENT_NAME IS    ----&gt;PX Deq: Execute Reply</span>
JOURNAL COUNT    ----&gt;0
<span style="color:#ff0000;">STAGE            ----&gt;First latch acquired. Parallel processing going on</span>
------------TOTAL SLAVES ARE-------------
SID     SERIAL  DEGREE          REQ_DEGREE              EVENT
2149    46710   4               4               direct path read temp
2154    22192   4               4               PX Deq: Execution Msg
2156    23451   4               4               PX Deq: Execution Msg
2157    2939    4               4               PX Deq: Execution Msg
2159    55050   4               4               direct path read temp
2168    5080    4               4               direct path read temp
2184    46569   4               4               direct path read temp
2193    3495    4               4               PX Deq: Execution Msg
------------LONGOPS SLAVES ARE-------------
SID     SERIAL  TOTALWORK               SOFAR           TIME REMAINING                  ELAPSED SECONDS         OPNAME                  EVENT
2168    5080    40531                   16913           20                              14                      Sort Output             direct path read temp
2149    46710   37403                   16918           17                              14                      Sort Output             direct path read temp
2159    55050   32739                   16872           14                              15                      Sort Output             direct path read temp
2184    46569   30720                   17012           11                              14                      Sort Output             direct path read temp</pre>
<br />Filed under: <a href='http://fordba.wordpress.com/category/index/'>Index</a>, <a href='http://fordba.wordpress.com/category/index/index-rebuild/'>Index rebuild</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fordba.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fordba.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fordba.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fordba.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fordba.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fordba.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fordba.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fordba.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fordba.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fordba.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fordba.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fordba.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fordba.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fordba.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&amp;blog=21441750&amp;post=8&amp;subd=fordba&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fordba.wordpress.com/2011/04/05/online-ndx-rebuild/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0b8748224dcc3259b8c20081f7a988ac?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sbhatia83</media:title>
		</media:content>
	</item>
	</channel>
</rss>
