<?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>Mon, 20 May 2013 06:26:58 +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>Profile Baselines Patches</title>
		<link>http://fordba.wordpress.com/2013/03/02/profile-baselines-patches/</link>
		<comments>http://fordba.wordpress.com/2013/03/02/profile-baselines-patches/#comments</comments>
		<pubDate>Fri, 01 Mar 2013 20:55:22 +0000</pubDate>
		<dc:creator>Sumit</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[baseline]]></category>
		<category><![CDATA[baseline not picking]]></category>
		<category><![CDATA[baseline not working]]></category>
		<category><![CDATA[comp_data]]></category>
		<category><![CDATA[difference between profile and baseline]]></category>
		<category><![CDATA[flags]]></category>
		<category><![CDATA[handle]]></category>
		<category><![CDATA[hints]]></category>
		<category><![CDATA[hints oracle]]></category>
		<category><![CDATA[obj_type]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[other_xml]]></category>
		<category><![CDATA[patch]]></category>
		<category><![CDATA[plan]]></category>
		<category><![CDATA[plan_hash_2]]></category>
		<category><![CDATA[plan_hash_2 in oracle]]></category>
		<category><![CDATA[plan_id]]></category>
		<category><![CDATA[Profile]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql patch]]></category>
		<category><![CDATA[sql profiles]]></category>
		<category><![CDATA[SQLOBJ$]]></category>
		<category><![CDATA[SQLOBJ$AUXDATA]]></category>
		<category><![CDATA[SQLOBJ$DATA]]></category>
		<category><![CDATA[sql_patch]]></category>
		<category><![CDATA[sql_profiles]]></category>

		<guid isPermaLink="false">http://fordba.wordpress.com/?p=551</guid>
		<description><![CDATA[Whats the difference &#8230; I should have written this one earlier but better late than never. So, lots of DBA&#8217;s might me thinking, why oracle has 3 ways to accomplish same task (plan stability). This post is intended to reflect the way profiles/patches and baselines work and also the same old question &#8220;why oracle is [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&#038;blog=21441750&#038;post=551&#038;subd=fordba&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<h2><span style="color:#3366ff;">Whats the difference &#8230;</span></h2>
<p><span style="color:#000080;">I should have written this one earlier but better late than never.</span></p>
<p><span style="color:#000080;">So, lots of DBA&#8217;s might me thinking, why oracle has 3 ways to accomplish same task (plan stability).</span></p>
<p><span style="color:#000080;">This post is intended to reflect the way profiles/patches and baselines work and also the same old question &#8220;why oracle is not picking my baseline&#8221;. (of-course there could be bug but not in every case).</span></p>
<p><span style="color:#000080;">To start with, all of them uses the same common table (sqlobj$ and sqlobj$auxdata) in their view definition. (sql$text and sql$ are used just for matching the signature of the query).</span></p>
<p><span style="color:#000080;">Lets target these table one by one  to understand what they store and how oracle uses this information.</span></p>
<h4><strong><span style="color:#3366ff;">1. SQLOBJ$</span></strong></h4>
<p><span style="color:#000080;">Other than the signature and type (profile/baseline/profile), this table necessarily stores the state of the underlying object using the column flags.</span></p>
<p><span style="color:#000080;">Oracle matches the signature on this table with exact_matching (or force_matching of v$sql depending on case ) with signature of this column to extract the eligible candidates (profiles/baselines/patches).</span></p>
<p><span style="color:#000080;">Object_type  1 corresponds to profiles, type 2 to baselines and type 3 to patches. Then oracle checks the flags value to filter out them.</span></p>
<ol>
<li><span style="color:#000080;">flag 0,1  corresponds to state (enabled/disabled) in case of profiles/patches.</span></li>
<li><span style="color:#000080;">flag value in case of  baselines corresponds to enabled,accepted,fixed,reproduced, auto purged.</span></li>
</ol>
<p><span style="color:#000080;">The name column corresponds to the name of the profile/baseline/patch.</span></p>
<p><span style="color:#000080;">Plan_id is always 0 in case of profile/patches and corresponds to plan_hash_2(other_xml of v$sql) in case of baselines.</span></p>
<p><span style="color:#000080;">This brings us back to our original question: why baselines are not getting used and whats the difference between plan_hash and plan_hash_2.</span></p>
<p><span style="color:#000080;">In general, we can refer any execution plan with plan_hash, however in many cases oracle generates different plan_hash if its using temp tables (whose name can differ).</span></p>
<p><span style="color:#000080;">so oracle is using plan_hash_2 which is independent of the intermediate objects name conventions which oracle creates for himself for executing a query.</span></p>
<p><span style="color:#000080;">In case of baseline, oracle matches plan_hash_2 with plan_id and if they differ, oracle refuses to use them.</span></p>
<p><span style="color:#000080;">As mentioned earlier, in case of profiles and patches, plan_id is always 0 which means oracle does not match the plan_hash_2.</span></p>
<p><span style="color:#3366ff;">How does it affects the working of profiles/patches and baselines:-</span></p>
<p><span style="color:#000080;">In case of profiles/patches, since oracle never compares the plan_hash_2, it uses the hints (which are stored in sqlobj$data table), to come up with an execution plan.</span></p>
<p><span style="color:#000080;">In case of baselines, oracle uses the hints to come up with the execution plan and compares the plan_hash_2 of that plan with already stored plan_id. If it matches, oracle uses the plan else it simply ignores it.</span></p>
<p><span style="color:#000080;">The important point here to be noted is oracle uses same sqlobj$data table to store the hints for all the 3 approaches. It just that how oracle interpret these ones, change the behavior.</span></p>
<p><span style="color:#000000;">That raises another very interesting question. If oracle himself is capturing the hints for baselines, then why plan_id and plan_hash_2 differs.</span></p>
<p><span style="color:#000080;">Lets say, you want to scan a particular table using parallel clause and then you can to use this baseline to link to the query not using parallel hint.</span></p>
<p><span style="color:#000080;">select /*+ full(a) parallel (a 4) */ * from emp  &#8211;&gt; select * from emp</span></p>
<p><span style="color:#000080;">Well you can do so by using linkbaseline.sql . </span></p>
<p><span style="color:#000080;">Oracle will link the plan with the handle but will not use it in case you try to run the latter.</span></p>
<p><strong>Reason:- Oracle never captures parallel hint. (<em> I will demonstrate how to overcome this using patch in my next post)</em></strong></p>
<p><span style="color:#000080;">So there you are. While generating the plan, oracle stored the plan_id but when oracle tried to reproduce the same using the hints, it can&#8217;t.</span></p>
<p><span style="color:#000080;">And that&#8217;s why your baseline won&#8217;t get used.</span></p>
<h4></h4>
<h4><strong><span style="color:#0000ff;">2. SQLOBJ$AUXDATA</span></strong></h4>
<p><span style="color:#000080;">As name suggests this table captures auxiliary information like created by, created date, last modified date etc.</span></p>
<p><span style="color:#000080;">In case of baselines, it also stores buffer_gets/disk_reads etc, since you need this info to evolve or accept a better plan.</span></p>
<p><span style="color:#000080;">In case of profile/patches, these fields are marked as null.</span></p>
<p><span style="color:#000080;">It also captures, the task_id etc if case you are not loading plans manually.</span></p>
<h4></h4>
<h4><strong><span style="color:#0000ff;">3.  SQLOBJ$DATA</span></strong></h4>
<p><span style="color:#000080;">This is the table where oracle stores the hint (comp_data) for the profiles/baselines and patches.</span></p>
<p><span style="color:#000080;">This point is worth noting that oracle captures different set of hints for profile/baselines/patches.</span></p>
<p><span style="color:#000080;">For e.g. if you have an existing profile(or patch) in your database, and capture is set to true, oracle will create a baseline on top of it.</span></p>
<p><span style="color:#000080;">And you may have notice, that execution plan reports both profile and baseline getting used.</span></p>
<p><span style="color:#000080;">How oracle is working ? Is it picking profile or baseline?</span></p>
<p><span style="color:#000080;">oracle is basically using the profile in this case. Once oracle uses the hints stored in profile and come up with execution plan, it compares the plan_hash_2 with plan-id for the baseline.</span></p>
<p><span style="color:#000080;">Since baseline is sitting on top of profile, it will match and oracle will report both profile and baselines are getting used.</span></p>
<p><span style="color:#000080;">Basically in this case, baseline hints will be subset of profile hints.</span></p>
<p><span style="color:#000080;">What will happen if you drop profile? Oracle may stop using baseline. As I have mentioned earlier, oracle captures different set of hints for profiles and baselines.</span></p>
<p><span style="color:#000080;">If you drop a profile, chances are oracle may not able to regenerate the plan using the hints stored for baseline as it was just a subset.</span></p>
<br />Filed under: <a href='http://fordba.wordpress.com/category/uncategorized/'>Uncategorized</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fordba.wordpress.com/551/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fordba.wordpress.com/551/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&#038;blog=21441750&#038;post=551&#038;subd=fordba&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fordba.wordpress.com/2013/03/02/profile-baselines-patches/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>DBA_SNAPSHOTS Vs. DBA_MVIEWS</title>
		<link>http://fordba.wordpress.com/2012/04/14/dba_snapshots-vs-dba_mviews/</link>
		<comments>http://fordba.wordpress.com/2012/04/14/dba_snapshots-vs-dba_mviews/#comments</comments>
		<pubDate>Sat, 14 Apr 2012 05:22:56 +0000</pubDate>
		<dc:creator>Sumit</dc:creator>
				<category><![CDATA[Mview]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[advance mviews]]></category>
		<category><![CDATA[basic of mviews]]></category>
		<category><![CDATA[complete refresh]]></category>
		<category><![CDATA[current_snapshot ahead of sysdate]]></category>
		<category><![CDATA[current_snapshot in future]]></category>
		<category><![CDATA[current_snapshot wrong]]></category>
		<category><![CDATA[dba_mviews]]></category>
		<category><![CDATA[dba_registered_snapshots]]></category>
		<category><![CDATA[dba_snapshots]]></category>
		<category><![CDATA[dba_snapshot_logs]]></category>
		<category><![CDATA[fast refresh]]></category>
		<category><![CDATA[how fast refresh works]]></category>
		<category><![CDATA[last_refresh ahead of sysdate]]></category>
		<category><![CDATA[last_refresh in future]]></category>
		<category><![CDATA[last_refresh worng]]></category>
		<category><![CDATA[mlog not purging]]></category>
		<category><![CDATA[mlog purge]]></category>
		<category><![CDATA[mlog$]]></category>
		<category><![CDATA[snaptime]]></category>
		<category><![CDATA[sys.slog$]]></category>
		<category><![CDATA[sys.snap_reftime$]]></category>
		<category><![CDATA[sys.sum$]]></category>

		<guid isPermaLink="false">http://fordba.wordpress.com/?p=535</guid>
		<description><![CDATA[Couple of my last posts were solely based on oracle profiles and baselines. This time, I thought of putting some stuff related to Mviews. There are various blogs which explains the working on Mviews refresh and usage of SYS.SNAP$ and SYS.MLOG$. Before proceeding further, I would like to echo, that you should have basic understanding on [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&#038;blog=21441750&#038;post=535&#038;subd=fordba&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><span style="color:#000080;">Couple of my last posts were solely based on oracle profiles and baselines. </span></p>
<p><span style="color:#000080;">This time, I thought of putting some stuff related to Mviews. </span></p>
<p><span style="color:#000080;">There are various blogs which explains the working on Mviews refresh and usage of SYS.SNAP$ and SYS.MLOG$.</span></p>
<p><span style="color:#000080;">Before proceeding further, I would like to echo, that you should have basic understanding on mviews and fast refreshes.</span></p>
<p><span style="color:#000080;">Coming back to the main topic, </span></p>
<p><span style="color:#0000ff;">1. what is the difference between a snapshot and a mview.</span></p>
<p><span style="color:#0000ff;">2. Are these same, and If yes, why they coexisted.</span></p>
<p><span style="color:#0000ff;">3. If not, then what is the difference.</span></p>
<h2><span style="color:#000080;">Snapshot &amp; Mviews</span></h2>
<p><span style="color:#000080;">The term snapshots and mviews are used interchangeably. Various blogs will report that these are the same things with no difference.</span></p>
<p><span style="color:#000080;">If there is no difference, then why do we have dba_snapshots and dba_mviews in the database.</span></p>
<p><span style="color:#000080;">And if both these mviews co-exists , just for &#8220;backward compatibility&#8221;, then why their definitions are different. Why not just a synonym.</span></p>
<p><span style="color:#000080;">I stumble on these questions during one of my production issue. </span></p>
<p><span style="color:#000080;">As I dig further,I found that there is a difference, which in Newton&#8217;s language should be called as &#8220;Frame of Reference&#8221;.</span></p>
<h3><span style="color:#000080;">SNAPSHOTS</span></h3>
<p><span style="color:#000080;">Consider a situation, where multiple snapshot sites are pulling data from one master site.</span></p>
<p><span style="color:#000080;">Think if you are sitting right at top of the box and can see the data flowing downstream to the snapshot sites.</span></p>
<p><span style="color:#000080;">So, the master site is your frame of reference and you use the term snapshot.</span></p>
<h3><span style="color:#000080;">MVIEWS</span></h3>
<p><span style="color:#000080;">Imagine you are sitting at the snapshot site and you can see the data flowing into the site from master sites.</span></p>
<p><span style="color:#000080;">Your frame of refernce is snapshot site and you use the term mview.</span></p>
<h3><span style="color:#000080;">What does it means to oracle</span></h3>
<p><span style="color:#000080;">Lets consider a real time example.</span></p>
<p><span style="color:#000080;">Imagine if two different snapshot sites are performing fast refresh from a master site.</span></p>
<p><span style="color:#000080;">The Mlog at the master site can not purge the data, unless all the snapshot sites have refreshed.</span></p>
<p><span style="color:#000080;">It reads OLDEST_PK and YOUNGEST from sys.mlog$ to decide which data it can purge.</span></p>
<pre class="brush: sql; title: ; notranslate">

select OLDEST_PK,SYSDATE,YOUNGEST from sys.mlog$ where master='TEST';

OLDEST_PK                 SYSDATE             YOUNGEST
-------------------- -------------------- --------------------
14-apr-2012 11:55:01 14-apr-2012 12:00:50 14-apr-2012 12:00:42

</pre>
<p><span style="color:#000080;">As we can see, it can safely purge data before 14-apr-2012 11:55:01.</span></p>
<p><span style="color:#000080;">Lets make the situation complex.</span></p>
<p><span style="color:#000080;">What if these two databases are running on ten different countries in ten different timezones.</span></p>
<p><span style="color:#000080;">What will happen if Master site happens to be in US (UTC timezone) and one client site in China(CST-8) and other in US(PST8PDT).</span></p>
<p><span style="color:#000080;">As we know, China&#8217;s time is ahead of US.</span></p>
<p><span style="color:#000080;">For E.g</span></p>
<p><span style="color:#000080;">Lets say, currently at 4pm china time (1am US time), CHINA1 gets refreshed from master site.</span></p>
<p><span style="color:#000080;">After that, another snapshot site US2 gets refreshed.</span></p>
<p><span style="color:#000080;">In case Master site uses Snapshot Sites local sysdate to record when they got last refresh, then CHINA2 will report 4PM which is ahead of sysdate of master site.</span></p>
<p><span style="color:#000080;">Clearly, this can&#8217;t be the case. SYSDATE has to be ahead of LAST_REFRESH.</span></p>
<p><span style="color:#000080;">Therefore, whenever a site gets refreshed, master updates oldest_pk and youngest with local sysdate(timezone).</span></p>
<p><span style="color:#000080;">O</span><span style="color:#0000ff;">r in short, SYS.mlog$ will report time from master site timezone.</span></p>
<p><span style="color:#000080;">Now, lets say, you logged into China database.</span></p>
<p><span style="color:#000080;">You wanted to check last_refresh date of the mview.</span></p>
<p><span style="color:#000080;">Now, in this case if oracle uses Master Site date, then it will show you that mview got refreshed 13hours before. This is not correct.</span></p>
<p><span style="color:#0000ff;">Therefore Oracle created 2 Views</span></p>
<p><span style="color:#0000ff;">1. DBA_SNAPSHOTS which gets last_refresh from sys.snap_reftime$ which reports date of master site.</span></p>
<p><span style="color:#0000ff;">2. DBA_MVIEWS which gets current_snapshot from sys.sum$ which reports sysdate from local database.</span></p>
<p><span style="color:#000080;">Therefore, if you are at master site and you wanted to check which mview got refreshed at what time, you should use dba_snapshpot_logs (sys.slog$) which shows last_refresh with respect to master site.</span></p>
<p><span style="color:#000080;">In case, you are at snapshot site, you should use dba_mviews , which will show you last_refresh with respect to local sysdate.</span></p>
<p><span style="color:#0000ff;">TestCase</span></p>
<p><span style="color:#000080;">Master site timezone (UTC)</span></p>
<p><span style="color:#000080;">Snapshot Site (CST-8)</span></p>
<pre class="brush: sql; title: ; notranslate">

MASTER&gt;&gt;select sysdate from dual;
SYSDATE
--------------------
14-apr-2012 04:36:01

CLIENT&gt;&gt;select sysdate from dual;
SYSDATE
--------------------
14-apr-2012 12:36:20

MASTER&gt;&gt;select site.SNAPSHOT_SITE,logs.CURRENT_SNAPSHOTS,sysdate from dba_registered_snapshots site,dba_snapshot_logs logs where site.snapshot_id=logs.snapshot_id and MASTER='TEST' ORDER BY 3 DESC;
SNAPSHOT_SITE         CURRENT_SNAPSHOTS                SYSDATE
-------------------- -------------------         --------------------
CHINA1                14-apr-2012 04:36:01         14-apr-2012 04:41:33
US1                   14-apr-2012 04:36:21         14-apr-2012 04:41:33
</pre>
<p><span style="color:#000080;">Lets check the behavior on snapshot site, first using dba_snapshot view which should report last_refresh wrt master_site</span></p>
<pre class="brush: sql; title: ; notranslate">
CHINA1&gt;&gt;select name,sysdate,last_refresh from dba_snapshots where name='TEST';
     NAME                       SYSDATE             LAST_REFRESH
 -------------------    --------------------     --------------------
   TEST                    14-apr-2012 12:38:34  14-apr-2012 04:36:01
</pre>
<p><span style="color:#000080;">Now, if we query the same thing from dba_mviews this should report wrt local timezone.</span></p>
<pre class="brush: sql; title: ; notranslate">
CHINA1&gt;&gt;select last_refresh_date,sysdate from dba_mviews where mview_name='TEST';

LAST_REFRESH_DATE           SYSDATE
 --------------------     --------------------
 14-apr-2012 12:36:02     14-apr-2012 12:39:59
</pre>
<h3><span style="color:#000080;">In the nutshell</span></h3>
<p><span style="color:#0000ff;">sys.slog$ and sys.snap_reftime$ shows last_refreshed_date as per master_site timezone and therefore dba_snapshots and dba_snapshot_logs reports time as per master_site sysdate.</span></p>
<p><span style="color:#0000ff;">sys.sum$ updates current_snapshot as per snapshot site time and therefore dba_mviews reports last_refresh_date as of snapshot site time.</span></p>
<br />Filed under: <a href='http://fordba.wordpress.com/category/mview/'>Mview</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/535/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fordba.wordpress.com/535/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&#038;blog=21441750&#038;post=535&#038;subd=fordba&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fordba.wordpress.com/2012/04/14/dba_snapshots-vs-dba_mviews/feed/</wfw:commentRss>
		<slash:comments>4</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 &#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 [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&#038;blog=21441750&#038;post=511&#038;subd=fordba&#038;ref=&#038;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>
<pre class="brush: sql; title: ; notranslate">
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>
<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> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&#038;blog=21441750&#038;post=511&#038;subd=fordba&#038;ref=&#038;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 [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&#038;blog=21441750&#038;post=471&#038;subd=fordba&#038;ref=&#038;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>
<pre class="brush: sql; title: ; notranslate">
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><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>
<pre class="brush: sql; title: ; notranslate">&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>
<br />Filed under: <a href='http://fordba.wordpress.com/category/baselines/'>Baselines</a>, <a href='http://fordba.wordpress.com/category/index/scripts-index/'>Scripts</a>, <a href='http://fordba.wordpress.com/category/scripts/'>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> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&#038;blog=21441750&#038;post=471&#038;subd=fordba&#038;ref=&#038;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 [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&#038;blog=21441750&#038;post=434&#038;subd=fordba&#038;ref=&#038;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>
<pre class="brush: sql; title: ; notranslate">
Session1&gt; select  * from mytab a where a.generated=:b1;

no rows selected
</pre>
<p><span style="color:#000080;">You can always check the values of bind variables using following query.</span></p>
<pre class="brush: sql; title: ; notranslate">

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><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>
<pre class="brush: sql; title: ; notranslate">
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><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>
<pre class="brush: sql; title: ; notranslate">
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><span style="color:#000080;">Now, you can find the sql_id of the query and link the baseline with original sql.</span></p>
<pre class="brush: sql; title: ; notranslate">
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><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>
<pre class="brush: sql; title: ; notranslate">
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><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> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&#038;blog=21441750&#038;post=434&#038;subd=fordba&#038;ref=&#038;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 [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&#038;blog=21441750&#038;post=335&#038;subd=fordba&#038;ref=&#038;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>
<pre class="brush: sql; title: ; notranslate">
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><span style="color:#0000ff;">Time to query table and load the plan into the baseline.<br />
</span></p>
<pre class="brush: sql; title: ; notranslate">
--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><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>
<pre class="brush: sql; title: ; notranslate">
create index test_id on test(id);
Index created.

select /*+ id=1000 */  * FROM TEST where id=1000
NAME               ID
---------- ----------
SUMIT            1000
</pre>
<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>
<pre class="brush: sql; title: ; notranslate">
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><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>
<pre class="brush: sql; title: ; notranslate">
/*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><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>
<pre class="brush: sql; title: ; notranslate">
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><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>
<pre class="brush: sql; title: ; notranslate">
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><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>
<pre class="brush: sql; title: ; notranslate">
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><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>
<pre class="brush: sql; title: ; notranslate">
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><span style="color:#0000ff;">Executing the query and checking the plan again</span></p>
<pre class="brush: sql; title: ; notranslate">
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><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>
<pre class="brush: sql; title: ; notranslate">
/*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>
<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>
<pre class="brush: sql; title: ; notranslate">
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><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>
<pre class="brush: sql; title: ; notranslate">
/* 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><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>
<pre class="brush: sql; title: ; notranslate">
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><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>
<pre class="brush: sql; title: ; notranslate">
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><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>
<pre class="brush: sql; title: ; notranslate">

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><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>
<pre class="brush: sql; title: ; notranslate">
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><span style="color:#0000ff;">Lets discuss the above scenario and try to figure out who takes precedence under what condition</span></p>
<pre class="brush: sql; title: ; notranslate">
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><span style="color:#0000ff;">Oracle has captured new plan. Lets try to evolve that one also.</span></p>
<pre class="brush: sql; title: ; notranslate">
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><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> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&#038;blog=21441750&#038;post=335&#038;subd=fordba&#038;ref=&#038;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>4</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 [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&#038;blog=21441750&#038;post=287&#038;subd=fordba&#038;ref=&#038;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; title: ; notranslate">
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><span style="color:#003300;"><strong>Step 1&gt; Query the mytab table without index</strong>.</span></p>
<pre class="brush: sql; title: ; notranslate">

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><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>
<pre class="brush: sql; title: ; notranslate">
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><strong><span style="color:#003300;">Step 3&gt; Lets create an index</span></strong></p>
<pre class="brush: sql; title: ; notranslate">
create index mytab_idx2 on mytab(GENERATED) parallel 4;
Index created.

alter index mytab_idx2 noparallel;

Index altered.

</pre>
<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>
<pre class="brush: sql; title: ; notranslate">

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><strong><span style="color:#003300;">Step5&gt;Execute the query with index hint and create the baseline.</span></strong></p>
<pre class="brush: sql; title: ; notranslate">
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><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>
<pre class="brush: sql; title: ; notranslate">
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><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> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&#038;blog=21441750&#038;post=287&#038;subd=fordba&#038;ref=&#038;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&#038;blog=21441750&#038;post=446&#038;subd=fordba&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<h2><span style="color:#000080;">Mytab structure :- CTAS dba_objects</span></h2>
<pre class="brush: sql; title: ; notranslate">
 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>
<pre class="brush: sql; title: ; notranslate">
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>
<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> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&#038;blog=21441750&#038;post=446&#038;subd=fordba&#038;ref=&#038;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 [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&#038;blog=21441750&#038;post=258&#038;subd=fordba&#038;ref=&#038;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>
<pre class="brush: sql; title: ; notranslate">

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><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>
<pre class="brush: sql; title: ; notranslate">

select pid from v$process p, v$bgprocess b where b.paddr = p.addr and name='SMON';

oradebug wakeup &lt;pid&gt;

</pre>
<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>
<pre class="brush: sql; title: ; notranslate">

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>
<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> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&#038;blog=21441750&#038;post=258&#038;subd=fordba&#038;ref=&#038;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 [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&#038;blog=21441750&#038;post=202&#038;subd=fordba&#038;ref=&#038;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>
<pre class="brush: sql; title: ; notranslate">

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><span style="color:#000080;">Lets check if the journal table exists or not.</span></p>
<pre class="brush: sql; title: ; notranslate">

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><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>
<pre class="brush: sql; title: ; notranslate">

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>
<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>
<pre class="brush: sql; title: ; notranslate">

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><span style="color:#000080;">Lets check the status from session 3 using our ndx-progress.sql</span></p>
<pre class="brush: sql; title: ; notranslate">

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><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>
<pre class="brush: sql; title: ; notranslate">

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><span style="color:#000080;">On checking the status, index job was cancelled but journal entry was still there</span></p>
<pre class="brush: sql; title: ; notranslate">

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><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> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fordba.wordpress.com&#038;blog=21441750&#038;post=202&#038;subd=fordba&#038;ref=&#038;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>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>
	</channel>
</rss>
