<?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: CBO Surprise</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2010/02/22/cbo-surprise/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2010/02/22/cbo-surprise/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Mon, 20 May 2013 01:44:54 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: CBO Surprise 2 &#171; Oracle Scratchpad</title>
		<link>http://jonathanlewis.wordpress.com/2010/02/22/cbo-surprise/#comment-36607</link>
		<dc:creator><![CDATA[CBO Surprise 2 &#171; Oracle Scratchpad]]></dc:creator>
		<pubDate>Tue, 29 Jun 2010 09:35:29 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3170#comment-36607</guid>
		<description><![CDATA[[...] Filed under: CBO,Execution plans,Partitioning &#8212; Jonathan Lewis @ 7:45 pm UTC Feb 24,2010   In an earlier article I gave a description of how splitting a single date ranges into a pair of date ranges with an OR [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Filed under: CBO,Execution plans,Partitioning &#8212; Jonathan Lewis @ 7:45 pm UTC Feb 24,2010   In an earlier article I gave a description of how splitting a single date ranges into a pair of date ranges with an OR [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2010/02/22/cbo-surprise/#comment-35833</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Sat, 20 Mar 2010 20:14:23 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3170#comment-35833</guid>
		<description><![CDATA[Stefan,

Because date columns can include time components, one of the versions loses the data that starts after (day only) 12th Feb and ends before (day only) 13th Feb - i.e. everything from &quot;12-Feb-2010 00:00:01&quot; to  &quot;12-Feb-2010 23:59:59&quot;.

Physically there may be no such data (because of the application code, perhaps), but logically the database has no information that tells it that such rows cannot exist.]]></description>
		<content:encoded><![CDATA[<p>Stefan,</p>
<p>Because date columns can include time components, one of the versions loses the data that starts after (day only) 12th Feb and ends before (day only) 13th Feb &#8211; i.e. everything from &#8220;12-Feb-2010 00:00:01&#8243; to  &#8220;12-Feb-2010 23:59:59&#8243;.</p>
<p>Physically there may be no such data (because of the application code, perhaps), but logically the database has no information that tells it that such rows cannot exist.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stefan</title>
		<link>http://jonathanlewis.wordpress.com/2010/02/22/cbo-surprise/#comment-35828</link>
		<dc:creator><![CDATA[Stefan]]></dc:creator>
		<pubDate>Sat, 20 Mar 2010 16:05:04 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3170#comment-35828</guid>
		<description><![CDATA[Hello Jonathan,
thanks for your response.

Maybe i am overlooking something very common or my first post was not clear enough.

You said:
&gt; The first thing to note about these queries is that they are not logically equivalent even 
though they may have produced the same result

If i check the access predicates between the following code:
-------------------8&lt;--------------------
(  
t1.date_col 
between to_date(&#039;01-feb-2010&#039;,&#039;dd-mon-yyyy&#039;)  and     to_date(&#039;12-feb-2010&#039;,&#039;dd-mon-yyyy&#039;)  
or  
t1.date_col 
between to_date(&#039;13-feb-2010&#039;,&#039;dd-mon-yyyy&#039;)  
and     to_date(&#039;25-feb-2010&#039;,&#039;dd-mon-yyyy&#039;)  
)  
-------------------8&lt;--------------------

and the original predicates
-------------------8&lt;--------------------
t1.date_col 
between to_date(&#039;01-feb-2010&#039;,&#039;dd-mon-yyyy&#039;)  
and     to_date(&#039;25-feb-2010&#039;,&#039;dd-mon-yyyy&#039;)  
-------------------8&lt;--------------------

Why are they logical different?

If i check the acess predicates between the original statement and the OR concetanation, the access predicates on DATE_COL are the logical the same, or?

Thanks and Regards
Stefan]]></description>
		<content:encoded><![CDATA[<p>Hello Jonathan,<br />
thanks for your response.</p>
<p>Maybe i am overlooking something very common or my first post was not clear enough.</p>
<p>You said:<br />
&gt; The first thing to note about these queries is that they are not logically equivalent even<br />
though they may have produced the same result</p>
<p>If i check the access predicates between the following code:<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-8&lt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
(<br />
t1.date_col<br />
between to_date(&#039;01-feb-2010&#039;,&#039;dd-mon-yyyy&#039;)  and     to_date(&#039;12-feb-2010&#039;,&#039;dd-mon-yyyy&#039;)<br />
or<br />
t1.date_col<br />
between to_date(&#039;13-feb-2010&#039;,&#039;dd-mon-yyyy&#039;)<br />
and     to_date(&#039;25-feb-2010&#039;,&#039;dd-mon-yyyy&#039;)<br />
)<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-8&lt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>and the original predicates<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-8&lt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
t1.date_col<br />
between to_date(&#039;01-feb-2010&#039;,&#039;dd-mon-yyyy&#039;)<br />
and     to_date(&#039;25-feb-2010&#039;,&#039;dd-mon-yyyy&#039;)<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-8&lt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Why are they logical different?</p>
<p>If i check the acess predicates between the original statement and the OR concetanation, the access predicates on DATE_COL are the logical the same, or?</p>
<p>Thanks and Regards<br />
Stefan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2010/02/22/cbo-surprise/#comment-35825</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Sat, 20 Mar 2010 13:45:36 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3170#comment-35825</guid>
		<description><![CDATA[Stefan,

The column is of type DATE, but you&#039;re overlooking the fact that a DATE column in Oracle is implicitly date-and-time with a granularity of one second.]]></description>
		<content:encoded><![CDATA[<p>Stefan,</p>
<p>The column is of type DATE, but you&#8217;re overlooking the fact that a DATE column in Oracle is implicitly date-and-time with a granularity of one second.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stefan</title>
		<link>http://jonathanlewis.wordpress.com/2010/02/22/cbo-surprise/#comment-35801</link>
		<dc:creator><![CDATA[Stefan]]></dc:creator>
		<pubDate>Fri, 19 Mar 2010 09:33:53 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3170#comment-35801</guid>
		<description><![CDATA[Hi  Jonathan,
nice blog post.

Just one short question to the following &quot;assumption&quot;:
&gt; It’s possible that the end user knows that the data in column date_col is always date-only (which is the constraint which would ensure the two queries return identical results) but the database (hence the optimizer) doesn’t know this

I guess, that the column date_col is of colum n type DATE. 
So why shouldn&#039;t the optimizer know that the result of the &quot;OR results&quot; always will be date? You only can store &quot;date&quot;-data in this column, or?

Thanks and Regards
Stefan]]></description>
		<content:encoded><![CDATA[<p>Hi  Jonathan,<br />
nice blog post.</p>
<p>Just one short question to the following &#8220;assumption&#8221;:<br />
&gt; It’s possible that the end user knows that the data in column date_col is always date-only (which is the constraint which would ensure the two queries return identical results) but the database (hence the optimizer) doesn’t know this</p>
<p>I guess, that the column date_col is of colum n type DATE.<br />
So why shouldn&#8217;t the optimizer know that the result of the &#8220;OR results&#8221; always will be date? You only can store &#8220;date&#8221;-data in this column, or?</p>
<p>Thanks and Regards<br />
Stefan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2010/02/22/cbo-surprise/#comment-35584</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Tue, 23 Feb 2010 10:36:43 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3170#comment-35584</guid>
		<description><![CDATA[David,

I remember the entertaining time you had with using the &lt;a href=&quot;http://oraclesponge.wordpress.com/2006/12/18/more-on-partition-key-statistics-and-an-oddly-harmful-constraint/&quot; rel=&quot;nofollow&quot;&gt;&lt;em&gt;&lt;strong&gt;&quot;obviously sensible&quot; check constraints&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt;. And &lt;a href=&quot;http://oraclesponge.wordpress.com/2008/05/21/a-fix-for-check-constraints-that-harm-cardinalities/&quot; rel=&quot;nofollow&quot;&gt;&lt;em&gt;&lt;strong&gt;your reference to the bugfix&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt; posted by Oracle.

I&#039;ll have to run my tests on 10.2.0.4 and 11.1 upwards - but the effect on this 10.2.0.3 test case is even more &quot;amusing&quot; than you might at first guess.]]></description>
		<content:encoded><![CDATA[<p>David,</p>
<p>I remember the entertaining time you had with using the <a href="http://oraclesponge.wordpress.com/2006/12/18/more-on-partition-key-statistics-and-an-oddly-harmful-constraint/" rel="nofollow"><em><strong>&#8220;obviously sensible&#8221; check constraints</strong></em></a>. And <a href="http://oraclesponge.wordpress.com/2008/05/21/a-fix-for-check-constraints-that-harm-cardinalities/" rel="nofollow"><em><strong>your reference to the bugfix</strong></em></a> posted by Oracle.</p>
<p>I&#8217;ll have to run my tests on 10.2.0.4 and 11.1 upwards &#8211; but the effect on this 10.2.0.3 test case is even more &#8220;amusing&#8221; than you might at first guess.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Aldridge</title>
		<link>http://jonathanlewis.wordpress.com/2010/02/22/cbo-surprise/#comment-35583</link>
		<dc:creator><![CDATA[David Aldridge]]></dc:creator>
		<pubDate>Tue, 23 Feb 2010 10:17:11 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3170#comment-35583</guid>
		<description><![CDATA[&gt;&gt; If you want to make these two queries equivalent you’ll have to add the check constraint check (date_col = trunc(date_col). (We’ll do that later, and see what happens).

I think that the problem of check constraints causing incorrect estimated cardinalities wasn&#039;t fixed until 10.2.0.4, as I recall. Another CBO surprise!]]></description>
		<content:encoded><![CDATA[<p>&gt;&gt; If you want to make these two queries equivalent you’ll have to add the check constraint check (date_col = trunc(date_col). (We’ll do that later, and see what happens).</p>
<p>I think that the problem of check constraints causing incorrect estimated cardinalities wasn&#8217;t fixed until 10.2.0.4, as I recall. Another CBO surprise!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2010/02/22/cbo-surprise/#comment-35582</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Tue, 23 Feb 2010 10:11:12 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3170#comment-35582</guid>
		<description><![CDATA[Martin,

I just did a quick re-run with &lt;em&gt;&lt;strong&gt;optimizer_dynamic_sampling&lt;/strong&gt;&lt;/em&gt; set to 4, and it didn&#039;t change the plans. (sampling took place in both cases, and - with the 10g &lt;em&gt;&lt;strong&gt;seed()&lt;/strong&gt;&lt;/em&gt; call in the sample size - the estimated cardinality was the same for both plans at 1,238 rows. That&#039;s not surprising given the actual data - it favours Oracle getting a reasonable estimate using its standard arithmetic.

I was just a little surprised that this drop didn&#039;t make the full tablescan plan change to a bitmap conversion, but I still don&#039;t have a complete picture of the optimizer&#039;s costing of bitmaps and bitmap conversions.

&lt;em&gt;Update: I&#039;ve just realised that another effect on costing is that the nature of the predicate forces Oracle to consider taking two bites (not bytes) at the index, so we&#039;re also seeing an anomaly similar to the &quot;OR&quot; adjustment where the cost of scanning two adjacent sections of an index is not the same as the cost of scanning the entire range in one bite.&lt;/em&gt;



News for today - I&#039;ve decided to switch on the &quot;Nero&quot; ratings on the blog to see if this tells me anything about how useful my notes are. I may switch them off if they seem to be slowing down the speed that pages load.
]]></description>
		<content:encoded><![CDATA[<p>Martin,</p>
<p>I just did a quick re-run with <em><strong>optimizer_dynamic_sampling</strong></em> set to 4, and it didn&#8217;t change the plans. (sampling took place in both cases, and &#8211; with the 10g <em><strong>seed()</strong></em> call in the sample size &#8211; the estimated cardinality was the same for both plans at 1,238 rows. That&#8217;s not surprising given the actual data &#8211; it favours Oracle getting a reasonable estimate using its standard arithmetic.</p>
<p>I was just a little surprised that this drop didn&#8217;t make the full tablescan plan change to a bitmap conversion, but I still don&#8217;t have a complete picture of the optimizer&#8217;s costing of bitmaps and bitmap conversions.</p>
<p><em>Update: I&#8217;ve just realised that another effect on costing is that the nature of the predicate forces Oracle to consider taking two bites (not bytes) at the index, so we&#8217;re also seeing an anomaly similar to the &#8220;OR&#8221; adjustment where the cost of scanning two adjacent sections of an index is not the same as the cost of scanning the entire range in one bite.</em></p>
<p>News for today &#8211; I&#8217;ve decided to switch on the &#8220;Nero&#8221; ratings on the blog to see if this tells me anything about how useful my notes are. I may switch them off if they seem to be slowing down the speed that pages load.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ung Kok Aik</title>
		<link>http://jonathanlewis.wordpress.com/2010/02/22/cbo-surprise/#comment-35581</link>
		<dc:creator><![CDATA[Ung Kok Aik]]></dc:creator>
		<pubDate>Tue, 23 Feb 2010 09:31:27 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3170#comment-35581</guid>
		<description><![CDATA[Insightful.]]></description>
		<content:encoded><![CDATA[<p>Insightful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mwidlake</title>
		<link>http://jonathanlewis.wordpress.com/2010/02/22/cbo-surprise/#comment-35577</link>
		<dc:creator><![CDATA[mwidlake]]></dc:creator>
		<pubDate>Mon, 22 Feb 2010 20:01:53 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3170#comment-35577</guid>
		<description><![CDATA[Nice.

I wonder what happens if you set DYNAMIC_SAMPLING to above the default value of 2 for V10.2? I&#039;d predict the CBO would check the guesses about correlation it made and revert back to the full tabe scan...
If I get chance, I&#039;ll try to replicate your test.]]></description>
		<content:encoded><![CDATA[<p>Nice.</p>
<p>I wonder what happens if you set DYNAMIC_SAMPLING to above the default value of 2 for V10.2? I&#8217;d predict the CBO would check the guesses about correlation it made and revert back to the full tabe scan&#8230;<br />
If I get chance, I&#8217;ll try to replicate your test.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
