<?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: CBO: NewDensity for Frequency Histograms,11g-10.2.0.4 (densities part IV)</title>
	<atom:link href="http://www.adellera.it/blog/2009/10/23/cbo-newdensity-for-frequency-histograms11g-10204-densities-part-iv/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.adellera.it/blog/2009/10/23/cbo-newdensity-for-frequency-histograms11g-10204-densities-part-iv/</link>
	<description>A blog about Oracle - Un blog riguardo Oracle</description>
	<lastBuildDate>Wed, 11 Aug 2010 14:30:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Alberto Dell'Era</title>
		<link>http://www.adellera.it/blog/2009/10/23/cbo-newdensity-for-frequency-histograms11g-10204-densities-part-iv/comment-page-1/#comment-276</link>
		<dc:creator>Alberto Dell'Era</dc:creator>
		<pubDate>Thu, 03 Dec 2009 18:18:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.adellera.it/blog/?p=352#comment-276</guid>
		<description>Randolf,

&gt;So you mean to say: Using your SP you&#039;ve manually modified the density 
&gt;while preserving the histogram - and the CBO uses then the manually 
&gt;modified density from the dictionary for calculation but not the NewDensity any longer?

Yes if you use the default and only supported value (null) for the &quot;flags&quot; parameter of dbms_stats.set_column_stats - as far as I understand, in this case the statistics get labeled as &quot;user generated stats&quot; (dba_tab_cols.user_stats = &#039;YES&#039;). If you set &quot;flags&quot; to 2, you are pretending to be dbms_stats or a system routine (dba_tab_cols.user_stats = &#039;NO&#039;) and hence NewDensity gets used.

It makes sense - if the user has provided her own value for &quot;density&quot;, use it instead of NewDensity. 

NB: I have exchanged in the past many, many emails with Wolfgang and I&#039;ve noticed that He commonly uses flags=2 in his scripts ... that should explain everything nicely :)</description>
		<content:encoded><![CDATA[<p>Randolf,</p>
<p>&gt;So you mean to say: Using your SP you&#8217;ve manually modified the density<br />
&gt;while preserving the histogram &#8211; and the CBO uses then the manually<br />
&gt;modified density from the dictionary for calculation but not the NewDensity any longer?</p>
<p>Yes if you use the default and only supported value (null) for the &#8220;flags&#8221; parameter of dbms_stats.set_column_stats &#8211; as far as I understand, in this case the statistics get labeled as &#8220;user generated stats&#8221; (dba_tab_cols.user_stats = &#8216;YES&#8217;). If you set &#8220;flags&#8221; to 2, you are pretending to be dbms_stats or a system routine (dba_tab_cols.user_stats = &#8216;NO&#8217;) and hence NewDensity gets used.</p>
<p>It makes sense &#8211; if the user has provided her own value for &#8220;density&#8221;, use it instead of NewDensity. </p>
<p>NB: I have exchanged in the past many, many emails with Wolfgang and I&#8217;ve noticed that He commonly uses flags=2 in his scripts &#8230; that should explain everything nicely :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Randolf Geist</title>
		<link>http://www.adellera.it/blog/2009/10/23/cbo-newdensity-for-frequency-histograms11g-10204-densities-part-iv/comment-page-1/#comment-275</link>
		<dc:creator>Randolf Geist</dc:creator>
		<pubDate>Thu, 03 Dec 2009 16:44:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.adellera.it/blog/?p=352#comment-275</guid>
		<description>Alberto,

thanks for the clarification.

So you mean to say: Using your SP you&#039;ve manually modified the density while preserving the histogram - and the CBO uses then the manually modified density from the dictionary for calculation but not the NewDensity any longer?

I thought that Wolfgang meant to say that he has generated a histogram manually along with a density, but the CBO sill applied the NewDensity algorithm to his made-up histogram.

At least two things come into my mind that might matter:
- I don&#039;t know the version he has used to test
- He seems to have setup a made-up histogram rather than preserving an existing one, however I don&#039;t see where this exactly should make any difference

Anyway, thanks for the feedback. If I find some time I&#039;ll test it myself resp. ask Wolfgang for clarification what he did and what version he used to test.

Randolf</description>
		<content:encoded><![CDATA[<p>Alberto,</p>
<p>thanks for the clarification.</p>
<p>So you mean to say: Using your SP you&#8217;ve manually modified the density while preserving the histogram &#8211; and the CBO uses then the manually modified density from the dictionary for calculation but not the NewDensity any longer?</p>
<p>I thought that Wolfgang meant to say that he has generated a histogram manually along with a density, but the CBO sill applied the NewDensity algorithm to his made-up histogram.</p>
<p>At least two things come into my mind that might matter:<br />
- I don&#8217;t know the version he has used to test<br />
- He seems to have setup a made-up histogram rather than preserving an existing one, however I don&#8217;t see where this exactly should make any difference</p>
<p>Anyway, thanks for the feedback. If I find some time I&#8217;ll test it myself resp. ask Wolfgang for clarification what he did and what version he used to test.</p>
<p>Randolf</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alberto Dell'Era</title>
		<link>http://www.adellera.it/blog/2009/10/23/cbo-newdensity-for-frequency-histograms11g-10204-densities-part-iv/comment-page-1/#comment-274</link>
		<dc:creator>Alberto Dell'Era</dc:creator>
		<pubDate>Thu, 03 Dec 2009 15:59:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.adellera.it/blog/?p=352#comment-274</guid>
		<description>Hi Randolf,

thank you very much for your positive feedback, I really appreciate it - as you &quot;may&quot; know, it takes a lot of time to write about this kind of things trying to be clear and exhaustive ...

I use the following tiny SP to set the density while preserving the histogram:
[sql]
-- a utility procedure to change density, preserving the histogram
create or replace procedure set_density (
  p_table_name  varchar2,
  p_column_name varchar2,
  p_new_density number,
  p_flags       number default null
)
is
  l_distcnt     number;
  l_old_density number;
  l_nullcnt     number;
  l_srec        dbms_stats.statrec;
  l_avgclen     number;
  l_new_density number;
begin
  -- get the current column statistics
  dbms_stats.get_column_stats (
    ownname =&gt; user,
    tabname =&gt; p_table_name,
    colname =&gt; p_column_name,
    distcnt =&gt; l_distcnt,
    density =&gt; l_old_density,
    nullcnt =&gt; l_nullcnt,
    srec    =&gt; l_srec,
    avgclen =&gt; l_avgclen
  );

  -- reset them, overwriting &quot;density&quot;
  if p_new_density is not null then
    l_new_density := p_new_density;
  else
    l_new_density := l_old_density;
  end if;
  
  dbms_stats.set_column_stats (
    ownname =&gt; user,
    tabname =&gt; p_table_name,
    colname =&gt; p_column_name,
    distcnt =&gt; l_distcnt,
    density =&gt; l_new_density,
    nullcnt =&gt; l_nullcnt,
    srec    =&gt; l_srec,
    avgclen =&gt; l_avgclen,
    no_invalidate =&gt; false,
    flags         =&gt; p_flags
  );
  
  dbms_output.put_line (&#039;density of &#039;&#124;&#124;p_table_name&#124;&#124;&#039;.&#039;&#124;&#124;p_column_name&#124;&#124;&#039; changed from &#039;&#124;&#124;l_old_density&#124;&#124;&#039; to &#039;&#124;&#124; l_new_density);

end set_density;
/
show errors;
[/sql]
I&#039;ve tested it right now again, albeit on 11.1.0.7 only, and it actually preserves the histogram. It is a script I&#039;ve used for some years now.

Notice how it works : it fetches the histogram from the data dictionary, and rewrites it back verbatim with a new density, possibly changing the &quot;flags&quot; as well ...</description>
		<content:encoded><![CDATA[<p>Hi Randolf,</p>
<p>thank you very much for your positive feedback, I really appreciate it &#8211; as you &#8220;may&#8221; know, it takes a lot of time to write about this kind of things trying to be clear and exhaustive &#8230;</p>
<p>I use the following tiny SP to set the density while preserving the histogram:</p>
<pre class="brush: sql;">
-- a utility procedure to change density, preserving the histogram
create or replace procedure set_density (
  p_table_name  varchar2,
  p_column_name varchar2,
  p_new_density number,
  p_flags       number default null
)
is
  l_distcnt     number;
  l_old_density number;
  l_nullcnt     number;
  l_srec        dbms_stats.statrec;
  l_avgclen     number;
  l_new_density number;
begin
  -- get the current column statistics
  dbms_stats.get_column_stats (
    ownname =&gt; user,
    tabname =&gt; p_table_name,
    colname =&gt; p_column_name,
    distcnt =&gt; l_distcnt,
    density =&gt; l_old_density,
    nullcnt =&gt; l_nullcnt,
    srec    =&gt; l_srec,
    avgclen =&gt; l_avgclen
  );

  -- reset them, overwriting &quot;density&quot;
  if p_new_density is not null then
    l_new_density := p_new_density;
  else
    l_new_density := l_old_density;
  end if;

  dbms_stats.set_column_stats (
    ownname =&gt; user,
    tabname =&gt; p_table_name,
    colname =&gt; p_column_name,
    distcnt =&gt; l_distcnt,
    density =&gt; l_new_density,
    nullcnt =&gt; l_nullcnt,
    srec    =&gt; l_srec,
    avgclen =&gt; l_avgclen,
    no_invalidate =&gt; false,
    flags         =&gt; p_flags
  );

  dbms_output.put_line ('density of '||p_table_name||'.'||p_column_name||' changed from '||l_old_density||' to '|| l_new_density);

end set_density;
/
show errors;
</pre>
<p>I&#8217;ve tested it right now again, albeit on 11.1.0.7 only, and it actually preserves the histogram. It is a script I&#8217;ve used for some years now.</p>
<p>Notice how it works : it fetches the histogram from the data dictionary, and rewrites it back verbatim with a new density, possibly changing the &#8220;flags&#8221; as well &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Randolf Geist</title>
		<link>http://www.adellera.it/blog/2009/10/23/cbo-newdensity-for-frequency-histograms11g-10204-densities-part-iv/comment-page-1/#comment-273</link>
		<dc:creator>Randolf Geist</dc:creator>
		<pubDate>Thu, 03 Dec 2009 14:38:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.adellera.it/blog/?p=352#comment-273</guid>
		<description>Alberto,

regarding your comment &quot;Playing with density&quot;: I&#039;ve suggested in a recent discussion to refer to your excellent blog series on Oracle-l (and try to set the density manually to get the &quot;old&quot; density behaviour back) - yesterday Wolfgang Breitling mentioned when we met at the UKOUG that manually setting the density actually removes the histogram, and generating a histogram manually will still use the NewDensity but not the density provided as part of the user-generated statistics.

I haven&#039;t had time yet to test this personally, but now that Wolfgang has mentioned it I&#039;m quite sure I remember that he&#039;s right regarding setting the density manually - it removes the complete histogram immediately.

Can you comment on what you meant by above: &quot;If you set your own column stats using dbms_stats.set_column_stats...&quot;?

Have you tried to modify the density only or generating your own histogram?

Randolf</description>
		<content:encoded><![CDATA[<p>Alberto,</p>
<p>regarding your comment &#8220;Playing with density&#8221;: I&#8217;ve suggested in a recent discussion to refer to your excellent blog series on Oracle-l (and try to set the density manually to get the &#8220;old&#8221; density behaviour back) &#8211; yesterday Wolfgang Breitling mentioned when we met at the UKOUG that manually setting the density actually removes the histogram, and generating a histogram manually will still use the NewDensity but not the density provided as part of the user-generated statistics.</p>
<p>I haven&#8217;t had time yet to test this personally, but now that Wolfgang has mentioned it I&#8217;m quite sure I remember that he&#8217;s right regarding setting the density manually &#8211; it removes the complete histogram immediately.</p>
<p>Can you comment on what you meant by above: &#8220;If you set your own column stats using dbms_stats.set_column_stats&#8230;&#8221;?</p>
<p>Have you tried to modify the density only or generating your own histogram?</p>
<p>Randolf</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Blogroll Report 16/10/2009-23/10/2009 &#171; Coskan&#8217;s Approach to Oracle</title>
		<link>http://www.adellera.it/blog/2009/10/23/cbo-newdensity-for-frequency-histograms11g-10204-densities-part-iv/comment-page-1/#comment-227</link>
		<dc:creator>Blogroll Report 16/10/2009-23/10/2009 &#171; Coskan&#8217;s Approach to Oracle</dc:creator>
		<pubDate>Tue, 03 Nov 2009 12:48:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.adellera.it/blog/?p=352#comment-227</guid>
		<description>[...] Alberto Dell&#8217;Era-CBO: NewDensity for Frequency Histograms,11g-10.2.0.4 (densities part IV) [...]</description>
		<content:encoded><![CDATA[<p>[...] Alberto Dell&#8217;Era-CBO: NewDensity for Frequency Histograms,11g-10.2.0.4 (densities part IV) [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
