<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	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>Comments on: Bind Peeking</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Wed, 22 May 2013 12:40:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Bind Peeking, Ad Hoc Queries, Stable Performance. On 10G you can only pick any two.</title>
		<link>http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-30450</link>
		<dc:creator><![CDATA[Bind Peeking, Ad Hoc Queries, Stable Performance. On 10G you can only pick any two.]]></dc:creator>
		<pubDate>Wed, 12 Mar 2008 13:04:36 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-30450</guid>
		<description><![CDATA[[...] have been plenty of posts about bind peeking. Alex Gorbachev wrote about it last year, and so did Jonathan Lewis. It&#8217;s a well known issue. However what hasn&#8217;t been written about is when it is expected [...]]]></description>
		<content:encoded><![CDATA[<p>[...] have been plenty of posts about bind peeking. Alex Gorbachev wrote about it last year, and so did Jonathan Lewis. It&#8217;s a well known issue. However what hasn&#8217;t been written about is when it is expected [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vivek Sharma</title>
		<link>http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-14157</link>
		<dc:creator><![CDATA[Vivek Sharma]]></dc:creator>
		<pubDate>Tue, 03 Jul 2007 09:56:44 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-14157</guid>
		<description><![CDATA[oops....I knew this but while testing it slipped my mind.

Explain Plan and AUTOTRACE reports wrong cardinality whereas, v$sql_plan shows correct figure and also that it peeks the bind variable.

Regards
Vivek]]></description>
		<content:encoded><![CDATA[<p>oops&#8230;.I knew this but while testing it slipped my mind.</p>
<p>Explain Plan and AUTOTRACE reports wrong cardinality whereas, v$sql_plan shows correct figure and also that it peeks the bind variable.</p>
<p>Regards<br />
Vivek</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vivek Sharma</title>
		<link>http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-14156</link>
		<dc:creator><![CDATA[Vivek Sharma]]></dc:creator>
		<pubDate>Tue, 03 Jul 2007 08:37:13 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-14156</guid>
		<description><![CDATA[Hi Jonathan,

Optimizer used density to calculate the selectivity of the form column_name = constant or column_name = bind_variable. So, with histogram in place, the selecivity of a simple equality predicate can change even for queries involving bind variables.

I have tested this with Oracle 8i / 9i and 10g release 2, but have not found this. For a equality predicate with constant and histogram in place, optimizer is able get a correct cardinality but with bind variables in place, the cardinality comes out as 1/num_distinct * num_rows.

Where am I going wrong ?

Vivek]]></description>
		<content:encoded><![CDATA[<p>Hi Jonathan,</p>
<p>Optimizer used density to calculate the selectivity of the form column_name = constant or column_name = bind_variable. So, with histogram in place, the selecivity of a simple equality predicate can change even for queries involving bind variables.</p>
<p>I have tested this with Oracle 8i / 9i and 10g release 2, but have not found this. For a equality predicate with constant and histogram in place, optimizer is able get a correct cardinality but with bind variables in place, the cardinality comes out as 1/num_distinct * num_rows.</p>
<p>Where am I going wrong ?</p>
<p>Vivek</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex Gorbachev</title>
		<link>http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-12486</link>
		<dc:creator><![CDATA[Alex Gorbachev]]></dc:creator>
		<pubDate>Thu, 14 Jun 2007 03:50:39 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-12486</guid>
		<description><![CDATA[&lt;i&gt;Alex, your example uses partitions, does this only happens with partitioned tables?&lt;/i&gt;
A bit late but still I should mention that the answer is no as far as I could see. Bind variable peeking happens all the time and presence of histograms is the most common for varying execution plans. Partition is another one. Ranges might be the third one and probably there are other cases as well.]]></description>
		<content:encoded><![CDATA[<p><i>Alex, your example uses partitions, does this only happens with partitioned tables?</i><br />
A bit late but still I should mention that the answer is no as far as I could see. Bind variable peeking happens all the time and presence of histograms is the most common for varying execution plans. Partition is another one. Ranges might be the third one and probably there are other cases as well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alberto Dell'Era</title>
		<link>http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-8488</link>
		<dc:creator><![CDATA[Alberto Dell'Era]]></dc:creator>
		<pubDate>Tue, 15 May 2007 20:57:38 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-8488</guid>
		<description><![CDATA[Yuriy - 10g and dbms_stats with estimate_percent = AUTO or much less than 100% ?
I remember a test case - column GENDER, 1 &#039;M&#039;, 999,000 &#039;F&#039;. dbms_stats missed the only M, so it was outside the min/max range, so (check Jonathan&#039;s &quot;Cost Based Oracle&quot;, page 49) it estimated a cardinality of 1 for &quot;where gender = :b&quot; when :b = &#039;M&#039;, and a cardinality close to 1 million when :b = &#039;F&#039;. Index scan for the former, full table scan for the last; it is the same plan you would get with an histogram.]]></description>
		<content:encoded><![CDATA[<p>Yuriy &#8211; 10g and dbms_stats with estimate_percent = AUTO or much less than 100% ?<br />
I remember a test case &#8211; column GENDER, 1 &#8216;M&#8217;, 999,000 &#8216;F&#8217;. dbms_stats missed the only M, so it was outside the min/max range, so (check Jonathan&#8217;s &#8220;Cost Based Oracle&#8221;, page 49) it estimated a cardinality of 1 for &#8220;where gender = :b&#8221; when :b = &#8216;M&#8217;, and a cardinality close to 1 million when :b = &#8216;F&#8217;. Index scan for the former, full table scan for the last; it is the same plan you would get with an histogram.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yuriy</title>
		<link>http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-8464</link>
		<dc:creator><![CDATA[Yuriy]]></dc:creator>
		<pubDate>Tue, 15 May 2007 15:27:37 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-8464</guid>
		<description><![CDATA[Jonathan,

I believe David wanted to ask not &quot;why&quot; Oracle is creating two different plans, but &quot;how&quot; does he do it? 

Say, table t1 has no histograms collected and hence no knowledge of data distribution. And yet for &quot;select * from t1 where c1=:a1&quot; the optimizer comes up with two different plans, say index access for :a1=5 and fts for :a1=15, and rightly so as we have only 1% of data in t1 table where c1=5 and 99% of data where c1=15

Yet the question remains: How does Oracle know it? Again, there are no histograms collected, but bind variable peeking comes into play and somehow manages to realize that we have unevenly distributed data and produce different plans for different values of bind variables. 

How?]]></description>
		<content:encoded><![CDATA[<p>Jonathan,</p>
<p>I believe David wanted to ask not &#8220;why&#8221; Oracle is creating two different plans, but &#8220;how&#8221; does he do it? </p>
<p>Say, table t1 has no histograms collected and hence no knowledge of data distribution. And yet for &#8220;select * from t1 where c1=:a1&#8243; the optimizer comes up with two different plans, say index access for :a1=5 and fts for :a1=15, and rightly so as we have only 1% of data in t1 table where c1=5 and 99% of data where c1=15</p>
<p>Yet the question remains: How does Oracle know it? Again, there are no histograms collected, but bind variable peeking comes into play and somehow manages to realize that we have unevenly distributed data and produce different plans for different values of bind variables. </p>
<p>How?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-5123</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Sun, 08 Apr 2007 15:52:18 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-5123</guid>
		<description><![CDATA[David,  
Oracle always peeks at binds when it optimizes a statement. (Bugs and hidden parameters excepted).

The obvious examples of getting multiple plans for the same text come from range-based predicates:
&lt;code&gt;
select from orders_table where order_date &gt; :b1;
&lt;/code&gt;

If your call to this query uses yesterday&#039;s data and my call uses a date from 3 months ago,  we probably ought to get different plans. In most cases, though, the first one to execute sets the plan for everyone else. There are cases though - different optimizer environments, for example - where different sessions force extra child cursors (i.e. separate optimizations) to appear.]]></description>
		<content:encoded><![CDATA[<p>David,<br />
Oracle always peeks at binds when it optimizes a statement. (Bugs and hidden parameters excepted).</p>
<p>The obvious examples of getting multiple plans for the same text come from range-based predicates:<br />
<code><br />
select from orders_table where order_date &gt; :b1;<br />
</code></p>
<p>If your call to this query uses yesterday&#8217;s data and my call uses a date from 3 months ago,  we probably ought to get different plans. In most cases, though, the first one to execute sets the plan for everyone else. There are cases though &#8211; different optimizer environments, for example &#8211; where different sessions force extra child cursors (i.e. separate optimizations) to appear.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Perez</title>
		<link>http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-4552</link>
		<dc:creator><![CDATA[David Perez]]></dc:creator>
		<pubDate>Sun, 01 Apr 2007 09:32:18 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-4552</guid>
		<description><![CDATA[Hi Alex and Jonathan

I was wondering how CBO can choose different plans when there no histograms (assumming statistics is unchanged)? How can he know the data distribution and choose full or index scan?

Alex, your example uses partitions, does this only happens with partitioned tables?

I have seen bind peeking happens with no histograms but I cannot find a explanation (9.2.0.7). The queries which I have seen this happen are usually not a plain query involving tables, they always involves JOIN.

Cheers

David]]></description>
		<content:encoded><![CDATA[<p>Hi Alex and Jonathan</p>
<p>I was wondering how CBO can choose different plans when there no histograms (assumming statistics is unchanged)? How can he know the data distribution and choose full or index scan?</p>
<p>Alex, your example uses partitions, does this only happens with partitioned tables?</p>
<p>I have seen bind peeking happens with no histograms but I cannot find a explanation (9.2.0.7). The queries which I have seen this happen are usually not a plain query involving tables, they always involves JOIN.</p>
<p>Cheers</p>
<p>David</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-3243</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Fri, 09 Feb 2007 16:14:45 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-3243</guid>
		<description><![CDATA[Marc, I&#039;m always a little dubious about setting up a system to automate things like this. Many systems are likely to have a few thousand SQL statements with SQL plans that need to be trapped. Writing code that gets &lt;i&gt;&quot;before&quot;&lt;/i&gt; and &lt;i&gt;&quot;after&quot;&lt;/i&gt; plans into a structured form that allows them to be cross-checked seems looks like a task that could take a lot of effort and still not work.
I have to say that my strategy would be to capture the &lt;i&gt;&quot;before&quot;&lt;/i&gt; plans (possibly as simple flat text using &lt;a href=&quot;http://jonathanlewis.wordpress.com/2006/11/27/event-10132/&quot; rel=&quot;nofollow&quot;&gt;the 10132 event&lt;/a&gt; I have mentioned previously) and then simply wait for the (few ?)problem statements to appear after the upgrade and check them back manually.]]></description>
		<content:encoded><![CDATA[<p>Marc, I&#8217;m always a little dubious about setting up a system to automate things like this. Many systems are likely to have a few thousand SQL statements with SQL plans that need to be trapped. Writing code that gets <i>&#8220;before&#8221;</i> and <i>&#8220;after&#8221;</i> plans into a structured form that allows them to be cross-checked seems looks like a task that could take a lot of effort and still not work.<br />
I have to say that my strategy would be to capture the <i>&#8220;before&#8221;</i> plans (possibly as simple flat text using <a href="http://jonathanlewis.wordpress.com/2006/11/27/event-10132/" rel="nofollow">the 10132 event</a> I have mentioned previously) and then simply wait for the (few ?)problem statements to appear after the upgrade and check them back manually.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marc</title>
		<link>http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-3234</link>
		<dc:creator><![CDATA[Marc]]></dc:creator>
		<pubDate>Fri, 09 Feb 2007 11:27:00 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/2006/12/11/bind-peeking/#comment-3234</guid>
		<description><![CDATA[Jonathan,
I came to the same idea of examining plan - diff&#039;s ( from that oracle white paper you are here refering to ) 
But it seems they have never used their approach on a real system ( e.g. migration 9i-10g ). Oracle 10g has changed the PLAN notation of operations for PQ ... e.g. PX SEND / RECEIVE which in 9i could be represented as PARTITION HASH/RANGE etc.
Anyway I still like the approach and like to know if you think that it would produce reasonable good results by filtering out all the PQ-nodes of the plan and only focussing on (operation,options,object_name) in the diff ?
Kind regards
Marc.]]></description>
		<content:encoded><![CDATA[<p>Jonathan,<br />
I came to the same idea of examining plan &#8211; diff&#8217;s ( from that oracle white paper you are here refering to )<br />
But it seems they have never used their approach on a real system ( e.g. migration 9i-10g ). Oracle 10g has changed the PLAN notation of operations for PQ &#8230; e.g. PX SEND / RECEIVE which in 9i could be represented as PARTITION HASH/RANGE etc.<br />
Anyway I still like the approach and like to know if you think that it would produce reasonable good results by filtering out all the PQ-nodes of the plan and only focussing on (operation,options,object_name) in the diff ?<br />
Kind regards<br />
Marc.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
