<?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/"
		>
<channel>
	<title>Comments on: There Is No Time Like &#039;%NOW%&#039; To Use Dynamic Sampling</title>
	<atom:link href="http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/feed/" rel="self" type="application/rss+xml" />
	<link>http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/</link>
	<description>Oracle Database Performance And Scalability Blog</description>
	<lastBuildDate>Mon, 01 Mar 2010 22:11:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Rainer Stenzel</title>
		<link>http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/comment-page-1/#comment-178</link>
		<dc:creator>Rainer Stenzel</dc:creator>
		<pubDate>Fri, 13 Jun 2008 13:55:51 +0000</pubDate>
		<guid isPermaLink="false">http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/#comment-178</guid>
		<description>Hello Greg,
unfortunately I did not see your hint to 11.1.0.6 first time and can not test on 11g  by myself currently.I did some tests on 10g again and found:
1) if using literals (or bind peeking ?) the optimizer
1.1) is applying s(column NOT LIKE pattern)=1-s(column LIKE pattern) as expected and
1.2) is using different fixed selectivities for wildcard prefixed patterns and not wildcard prefixed patterns.
1.3) is using different fixed selectivities for non wildcard prefixed patterns with varying length.
2) is using the same selectivity (5%) for LIKE :v as for NOT LIKE :v when using bind variables and (however) not using bind peeking.
May be things changed again with using 11g and adaptive cursor sharing,
==&gt; but at least on 10g I would expect a better cardinality estimation by the optimizer than presented from your example.
Have a look at the different cardinality assumptions at the example below:
&lt;pre&gt;
select * from T where UID not like &#039;LMN%&#039;
union all
select * from T where UID like &#039;LMN%&#039;
union all
select * from T where UID not like &#039;%LMN%&#039;
union all
select * from T where UID like &#039;%LMN%&#039;
union all
select * from T;

Ausführungsplan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=FIRST_ROWS (Cost=14476 Card=6013368 Bytes=234521352)
   1    0   UNION-ALL
   2    1     TABLE ACCESS (FULL) OF &#039;T&#039; (TABLE) (Cost=3624 Card=2004453 Bytes=78173667)
   3    1     TABLE ACCESS (BY INDEX ROWID) OF &#039;T&#039; (TABLE) (Cost=1 Card=3 Bytes=117)
   4    3       INDEX (RANGE SCAN) OF &#039;PIT&#039; (INDEX (UNIQUE)) (Cost=1 Card=3)
   5    1     TABLE ACCESS (FULL) OF &#039;T&#039; (TABLE) (Cost=3624 Card=1904233 Bytes=74265087)
   6    1     TABLE ACCESS (FULL) OF &#039;T&#039; (TABLE) (Cost=3618 Card=100223 Bytes=3908697)
   7    1     TABLE ACCESS (FULL) OF &#039;T&#039; (TABLE) (Cost=3609 Card=2004456 Bytes=78173784)

variable b1 varchar2(20);

select * from T where UID not like :b1
union all
select * from T where UID like :b1
union all
select * from T;

Ausführungsplan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=FIRST_ROWS (Cost=7929 Card=2204902 Bytes=85991178)
   1    0   UNION-ALL
   2    1     TABLE ACCESS (FULL) OF &#039;T&#039; (TABLE) (Cost=3618 Card=100223 Bytes=3908697)
   3    1     TABLE ACCESS (BY INDEX ROWID) OF &#039;T&#039; (TABLE) (Cost=702 Card=100223 Bytes=3908697)
   4    3       INDEX (RANGE SCAN) OF &#039;PIT&#039; (INDEX (UNIQUE)) (Cost=10 Card=18040)
   5    1     TABLE ACCESS (FULL) OF &#039;T&#039; (TABLE) (Cost=3609 Card=2004456 Bytes=78173784)
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Hello Greg,<br />
unfortunately I did not see your hint to 11.1.0.6 first time and can not test on 11g  by myself currently.I did some tests on 10g again and found:<br />
1) if using literals (or bind peeking ?) the optimizer<br />
1.1) is applying s(column NOT LIKE pattern)=1-s(column LIKE pattern) as expected and<br />
1.2) is using different fixed selectivities for wildcard prefixed patterns and not wildcard prefixed patterns.<br />
1.3) is using different fixed selectivities for non wildcard prefixed patterns with varying length.<br />
2) is using the same selectivity (5%) for LIKE :v as for NOT LIKE :v when using bind variables and (however) not using bind peeking.<br />
May be things changed again with using 11g and adaptive cursor sharing,<br />
==&gt; but at least on 10g I would expect a better cardinality estimation by the optimizer than presented from your example.<br />
Have a look at the different cardinality assumptions at the example below:</p>
<pre>
select * from T where UID not like 'LMN%'
union all
select * from T where UID like 'LMN%'
union all
select * from T where UID not like '%LMN%'
union all
select * from T where UID like '%LMN%'
union all
select * from T;

Ausführungsplan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=FIRST_ROWS (Cost=14476 Card=6013368 Bytes=234521352)
   1    0   UNION-ALL
   2    1     TABLE ACCESS (FULL) OF 'T' (TABLE) (Cost=3624 Card=2004453 Bytes=78173667)
   3    1     TABLE ACCESS (BY INDEX ROWID) OF 'T' (TABLE) (Cost=1 Card=3 Bytes=117)
   4    3       INDEX (RANGE SCAN) OF 'PIT' (INDEX (UNIQUE)) (Cost=1 Card=3)
   5    1     TABLE ACCESS (FULL) OF 'T' (TABLE) (Cost=3624 Card=1904233 Bytes=74265087)
   6    1     TABLE ACCESS (FULL) OF 'T' (TABLE) (Cost=3618 Card=100223 Bytes=3908697)
   7    1     TABLE ACCESS (FULL) OF 'T' (TABLE) (Cost=3609 Card=2004456 Bytes=78173784)

variable b1 varchar2(20);

select * from T where UID not like :b1
union all
select * from T where UID like :b1
union all
select * from T;

Ausführungsplan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=FIRST_ROWS (Cost=7929 Card=2204902 Bytes=85991178)
   1    0   UNION-ALL
   2    1     TABLE ACCESS (FULL) OF 'T' (TABLE) (Cost=3618 Card=100223 Bytes=3908697)
   3    1     TABLE ACCESS (BY INDEX ROWID) OF 'T' (TABLE) (Cost=702 Card=100223 Bytes=3908697)
   4    3       INDEX (RANGE SCAN) OF 'PIT' (INDEX (UNIQUE)) (Cost=10 Card=18040)
   5    1     TABLE ACCESS (FULL) OF 'T' (TABLE) (Cost=3609 Card=2004456 Bytes=78173784)
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg Rahn</title>
		<link>http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/comment-page-1/#comment-180</link>
		<dc:creator>Greg Rahn</dc:creator>
		<pubDate>Thu, 12 Jun 2008 18:20:19 +0000</pubDate>
		<guid isPermaLink="false">http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/#comment-180</guid>
		<description>@Rainer

Q: Why the optimizer is not regarding the NOT operator ?
In my opinion the estimated selectivity for the negated LIKE predicate should be:
s(NOT LIKE)=1-s(LIKE)

A: Because that is not currently the logic in the code.  They are not equivalent today.

I only performed my tests on 11.1.0.6.

If you check out Cost-Based Oracle Fundamentals by Jonathan Lewis, page 133, table 6-6 &quot;Fixed Percentages Used for Selectivity on Character Expressions&quot;, you can see his observations.</description>
		<content:encoded><![CDATA[<p>@Rainer</p>
<p>Q: Why the optimizer is not regarding the NOT operator ?<br />
In my opinion the estimated selectivity for the negated LIKE predicate should be:<br />
s(NOT LIKE)=1-s(LIKE)</p>
<p>A: Because that is not currently the logic in the code.  They are not equivalent today.</p>
<p>I only performed my tests on 11.1.0.6.</p>
<p>If you check out Cost-Based Oracle Fundamentals by Jonathan Lewis, page 133, table 6-6 &#8220;Fixed Percentages Used for Selectivity on Character Expressions&#8221;, you can see his observations.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rainer Stenzel</title>
		<link>http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/comment-page-1/#comment-174</link>
		<dc:creator>Rainer Stenzel</dc:creator>
		<pubDate>Thu, 12 Jun 2008 13:05:17 +0000</pubDate>
		<guid isPermaLink="false">http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/#comment-174</guid>
		<description>additional question and remark after some tests:
Was the presented scenario investigated with Oracle 9i ?
With Oracle 10g I found modified selectivities
with literals:
5%  for column LIKE wild_card_prefixed_pattern
50% for column NOT LIKE wild_card_prefixed_pattern
respective with bind variables:
1% for column LIKE pattern_bind_variable
5% for column NOT LIKE pattern_bind_variable
undocumented and consequently quite wired.
Regards,
Rainer Stenzel</description>
		<content:encoded><![CDATA[<p>additional question and remark after some tests:<br />
Was the presented scenario investigated with Oracle 9i ?<br />
With Oracle 10g I found modified selectivities<br />
with literals:<br />
5%  for column LIKE wild_card_prefixed_pattern<br />
50% for column NOT LIKE wild_card_prefixed_pattern<br />
respective with bind variables:<br />
1% for column LIKE pattern_bind_variable<br />
5% for column NOT LIKE pattern_bind_variable<br />
undocumented and consequently quite wired.<br />
Regards,<br />
Rainer Stenzel</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rainer Stenzel</title>
		<link>http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/comment-page-1/#comment-175</link>
		<dc:creator>Rainer Stenzel</dc:creator>
		<pubDate>Thu, 12 Jun 2008 11:02:49 +0000</pubDate>
		<guid isPermaLink="false">http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/#comment-175</guid>
		<description>my first question was (and still is), why the optimizer is not regarding the NOT operator ?
In my opinion the estimated selectivity for the negated LIKE predicate shoud be:
s(NOT  LIKE =1-s( LIKE )
but instead it seems to be equal.
Applying this to the presented query the total reduction for those four predicates should only be 95%^4 (about 0.8) instead of 5%^4 resulting into an about 100.000 times greater cardinality estimation.
Regards,
Rainer Stenzel</description>
		<content:encoded><![CDATA[<p>my first question was (and still is), why the optimizer is not regarding the NOT operator ?<br />
In my opinion the estimated selectivity for the negated LIKE predicate shoud be:<br />
s(NOT  LIKE =1-s( LIKE )<br />
but instead it seems to be equal.<br />
Applying this to the presented query the total reduction for those four predicates should only be 95%^4 (about 0.8) instead of 5%^4 resulting into an about 100.000 times greater cardinality estimation.<br />
Regards,<br />
Rainer Stenzel</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Todor Botev</title>
		<link>http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/comment-page-1/#comment-172</link>
		<dc:creator>Todor Botev</dc:creator>
		<pubDate>Wed, 23 Apr 2008 12:25:19 +0000</pubDate>
		<guid isPermaLink="false">http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/#comment-172</guid>
		<description>OK, so playing out with the level seems to be worth the effort.

As for level 1 - could it be that level 1 (OPTIMIZIER HINT) is only for the unanalyzed tables and it is missing in the docs?</description>
		<content:encoded><![CDATA[<p>OK, so playing out with the level seems to be worth the effort.</p>
<p>As for level 1 &#8211; could it be that level 1 (OPTIMIZIER HINT) is only for the unanalyzed tables and it is missing in the docs?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg Rahn</title>
		<link>http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/comment-page-1/#comment-171</link>
		<dc:creator>Greg Rahn</dc:creator>
		<pubDate>Wed, 23 Apr 2008 12:02:43 +0000</pubDate>
		<guid isPermaLink="false">http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/#comment-171</guid>
		<description>Todor-

I had chosen 4 because I had initially used &lt;code&gt;optimizer_dynamic_sampling = 4&lt;/code&gt;.  I do recognize that they are not equals.  I did just run a quick test and ran through all 10 levels of the hint.  Here are  the results:

&lt;pre&gt;
DS Level  Rows
-------- -----
1            9
2         355K
3        1874K
4        1606K
5        1249K
6         654K
7        1419K
8         953K
9        1232K
10       1324K
&lt;/pre&gt;

Interesting enough, a larger sample does not always mean a more accurate estimate.  This is probably data dependent.  For some reason, level 1 did not produce a note in the explain plan that dynamic sampling was used, and thus the low estimate of 9.  I&#039;ll investigate this.</description>
		<content:encoded><![CDATA[<p>Todor-</p>
<p>I had chosen 4 because I had initially used <code>optimizer_dynamic_sampling = 4</code>.  I do recognize that they are not equals.  I did just run a quick test and ran through all 10 levels of the hint.  Here are  the results:</p>
<pre>
DS Level  Rows
-------- -----
1            9
2         355K
3        1874K
4        1606K
5        1249K
6         654K
7        1419K
8         953K
9        1232K
10       1324K
</pre>
<p>Interesting enough, a larger sample does not always mean a more accurate estimate.  This is probably data dependent.  For some reason, level 1 did not produce a note in the explain plan that dynamic sampling was used, and thus the low estimate of 9.  I&#8217;ll investigate this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Todor Botev</title>
		<link>http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/comment-page-1/#comment-170</link>
		<dc:creator>Todor Botev</dc:creator>
		<pubDate>Wed, 23 Apr 2008 09:58:10 +0000</pubDate>
		<guid isPermaLink="false">http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/#comment-170</guid>
		<description>Great post! I liked the &quot;methodology&quot; of adding the predicates one at a time.

Why did you choose level 4 for dynamic sampling? According to the docs (11g), when you use a hint like in your case, level 1 could be enough.</description>
		<content:encoded><![CDATA[<p>Great post! I liked the &#8220;methodology&#8221; of adding the predicates one at a time.</p>
<p>Why did you choose level 4 for dynamic sampling? According to the docs (11g), when you use a hint like in your case, level 1 could be enough.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Choosing An Optimal Stats Gathering Strategy &#124; Structured Data</title>
		<link>http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/comment-page-1/#comment-173</link>
		<dc:creator>Choosing An Optimal Stats Gathering Strategy &#124; Structured Data</dc:creator>
		<pubDate>Wed, 26 Mar 2008 08:05:04 +0000</pubDate>
		<guid isPermaLink="false">http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/#comment-173</guid>
		<description>[...] for DSS and data warehouse databases, where queries run for minutes, not seconds. See my post There Is No Time Like ‘%NOW%’ To Use Dynamic Sampling for a real-world [...]</description>
		<content:encoded><![CDATA[<p>[...] for DSS and data warehouse databases, where queries run for minutes, not seconds. See my post There Is No Time Like ‘%NOW%’ To Use Dynamic Sampling for a real-world [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Aldridge</title>
		<link>http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/comment-page-1/#comment-179</link>
		<dc:creator>David Aldridge</dc:creator>
		<pubDate>Tue, 18 Mar 2008 20:54:35 +0000</pubDate>
		<guid isPermaLink="false">http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/#comment-179</guid>
		<description>I find that dynamic sampling to be very seductive. For quite a while I&#039;ve been telling report developers who have problems with execution plans to turn up the dynamic sampling setting through a hint to see if the plan improves -- sometime the default sampling rate is not high enough, and frankly it&#039;s often an easy win.

If they&#039;d just learn to apply dynamic sampling by default then I&#039;d be practically out of a job.</description>
		<content:encoded><![CDATA[<p>I find that dynamic sampling to be very seductive. For quite a while I&#8217;ve been telling report developers who have problems with execution plans to turn up the dynamic sampling setting through a hint to see if the plan improves &#8212; sometime the default sampling rate is not high enough, and frankly it&#8217;s often an easy win.</p>
<p>If they&#8217;d just learn to apply dynamic sampling by default then I&#8217;d be practically out of a job.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg Rahn</title>
		<link>http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/comment-page-1/#comment-177</link>
		<dc:creator>Greg Rahn</dc:creator>
		<pubDate>Fri, 07 Mar 2008 03:43:45 +0000</pubDate>
		<guid isPermaLink="false">http://structureddata.org/2008/03/05/there-is-no-time-like-now-to-use-dynamic-sampling/#comment-177</guid>
		<description>You are completely spot on Steve.  Sometimes sampling data is the only way to get the true relationship between the columns.

Currently multi-column/extended statistics only work for single equality predicates so dynamic sampling may be one of the only ways to get the cardinality estimate close.</description>
		<content:encoded><![CDATA[<p>You are completely spot on Steve.  Sometimes sampling data is the only way to get the true relationship between the columns.</p>
<p>Currently multi-column/extended statistics only work for single equality predicates so dynamic sampling may be one of the only ways to get the cardinality estimate close.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
