<?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>Timur Akhmadeev&#039;s blog</title>
	<atom:link href="http://timurakhmadeev.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://timurakhmadeev.wordpress.com</link>
	<description></description>
	<lastBuildDate>Mon, 06 May 2013 16:00:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='timurakhmadeev.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Timur Akhmadeev&#039;s blog</title>
		<link>http://timurakhmadeev.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://timurakhmadeev.wordpress.com/osd.xml" title="Timur Akhmadeev&#039;s blog" />
	<atom:link rel='hub' href='http://timurakhmadeev.wordpress.com/?pushpress=hub'/>
		<item>
		<title>System statistics poll</title>
		<link>http://timurakhmadeev.wordpress.com/2013/04/12/system-statistics-poll/</link>
		<comments>http://timurakhmadeev.wordpress.com/2013/04/12/system-statistics-poll/#comments</comments>
		<pubDate>Fri, 12 Apr 2013 08:10:34 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[CBO]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[poll]]></category>
		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=899</guid>
		<description><![CDATA[Recent thread in the OakTable mailing list prompted me to create a poll and ask about the ways DBAs use system statistics in real systems. If you struggle to understand what system statistics is and what are the available options, here is the suggested reading: Documentation &#8211; System Statistics Best Practices for Gathering Optimizer Statistics, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=899&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Recent thread in the OakTable mailing list prompted me to create a poll and ask about the ways DBAs use system statistics in real systems. If you struggle to understand what system statistics is and what are the available options, here is the suggested reading:<br />
<a href="http://docs.oracle.com/cd/E11882_01/server.112/e16638/stats.htm#PFGRF94743" target="_blank">Documentation &#8211; System Statistics</a><br />
<a href="http://www.oracle.com/technetwork/database/focus-areas/bi-datawarehousing/twp-bp-optimizer-stats-04042012-1577139.pdf" target="_blank">Best Practices for Gathering Optimizer Statistics</a>, Oracle whitepaper<br />
<a href="http://books.google.ru/books?id=b3DIkYO2gBQC&amp;lpg=PA117&amp;ots=yUVuHG7duH&amp;pg=PA111#v=onepage&amp;q&amp;f=false" target="_blank">System Statistics</a> &#8211; Troubleshooting Oracle Performance<br />
<a href="http://oracle-randolf.blogspot.ru/2009/04/understanding-different-modes-of-system.html" target="_blank">Understanding the different modes of System Statistics</a>, blog series<br />
<a name="pd_a_7032173"></a>
<div class="PDS_Poll" id="PDI_container7032173" data-settings="{&quot;url&quot;:&quot;http:\/\/static.polldaddy.com\/p\/7032173.js&quot;}" style="display:inline-block;"></div>
<div id="PD_superContainer"></div>
<noscript><a href="http://polldaddy.com/poll/7032173">Take Our Poll</a></noscript></p>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/oracle/cbo/'>CBO</a>, <a href='http://timurakhmadeev.wordpress.com/category/oracle/'>Oracle</a> Tagged: <a href='http://timurakhmadeev.wordpress.com/tag/poll/'>poll</a>, <a href='http://timurakhmadeev.wordpress.com/tag/statistics/'>statistics</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/899/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/899/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=899&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2013/04/12/system-statistics-poll/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>
	</item>
		<item>
		<title>Ignoring hints</title>
		<link>http://timurakhmadeev.wordpress.com/2013/04/02/ignoring-hints/</link>
		<comments>http://timurakhmadeev.wordpress.com/2013/04/02/ignoring-hints/#comments</comments>
		<pubDate>Tue, 02 Apr 2013 17:59:11 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[CBO]]></category>
		<category><![CDATA[Hints]]></category>
		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=888</guid>
		<description><![CDATA[A hint is an instruction to the optimizer This is what&#8217;s written in Oracle documentation. Instruction is defined as a code that tells a computer to perform a particular operation Which means Oracle CBO must obey the hints and must perform particular operation. The latter is hard to define correctly and explain precisely because it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=888&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<blockquote><p><em>A <strong>hint</strong> is an instruction to the optimizer</em></p></blockquote>
<p>This is what&#8217;s written in <a href="http://docs.oracle.com/cd/E11882_01/server.112/e16638/hintsref.htm#i17496" target="_blank">Oracle documentation</a>. <em>Instruction</em> is <a href="http://www.merriam-webster.com/dictionary/instruction" target="_blank">defined</a> as</p>
<blockquote><p><em>a code that tells a computer to perform a particular operation</em></p></blockquote>
<p>Which means Oracle CBO must obey the hints and must perform <i>particular operation</i>. The latter is hard to define correctly and explain precisely because it involves the logic of the block-box (what Cost Based Optimizer is). Some of the operations are mentioned in the standard Oracle documentation, some of them scattered across different places, and there are exceptions as usual. I think I&#8217;ll list here these cases which could lead to &#8220;ignoring hints&#8221; with the links to documentation/blogs.</p>
<p><span id="more-888"></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="805" height="20"><strong>Description</strong></td>
<td width="144"><strong>Hints affected</strong></td>
<td width="565"><strong>Reference</strong></td>
</tr>
<tr>
<td width="805" height="20">The hint has a syntax error, or doesn&#8217;t follow DELETE/INSERT/SELECT/MERGE/UPDATE keyword, or conflicts with other hints</td>
<td>All</td>
<td><a href="http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements006.htm#sthref482" rel="nofollow">http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements006.htm#sthref482</a></td>
</tr>
<tr>
<td width="805" height="21">The optimizer ignores FIRST_ROWS in DELETE and UPDATE statement blocks and in SELECT statement blocks that include any blocking operations, such as sorts or groupings</td>
<td>FIRST_ROWS</td>
<td><a href="http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements006.htm#sthref524" rel="nofollow">http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements006.htm#sthref524</a></td>
</tr>
<tr>
<td width="805" height="60">The LEADING hint is ignored if the tables specified cannot be joined first in the order specified because of dependencies in the join graph. If you specify two or more conflicting LEADING hints, then all of them are ignored. If you specify the ORDERED hint, it overrides all LEADING hints.</td>
<td>LEADING, ORDERED</td>
<td><a href="http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements006.htm#sthref564" rel="nofollow">http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements006.htm#sthref564</a></td>
</tr>
<tr>
<td width="805" height="63">If a NO_INDEX hint and an index hint (INDEX, INDEX_ASC,INDEX_DESC, INDEX_COMBINE, or INDEX_FFS) both specify the same indexes, then the database ignores both the NO_INDEX hint and the index hint for the specified indexes and considers those indexes for use during execution of the statement.</td>
<td>INDEX*</td>
<td><a href="http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements006.htm#sthref589" rel="nofollow">http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements006.htm#sthref589</a></td>
</tr>
<tr>
<td width="805" height="40">If two or more query blocks have the same name, or if the same query block is hinted twice with different names, then the optimizer ignores all the names and the hints referencing that query block.</td>
<td>QB_NAME</td>
<td><a href="http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements006.htm#sthref692" rel="nofollow">http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements006.htm#sthref692</a></td>
</tr>
<tr>
<td width="805" height="20">If a hint specifies an unavailable access path, the optimizer ignores it</td>
<td>Access path</td>
<td><a href="http://docs.oracle.com/cd/E11882_01/server.112/e16638/hintsref.htm#PFGRF94938" rel="nofollow">http://docs.oracle.com/cd/E11882_01/server.112/e16638/hintsref.htm#PFGRF94938</a></td>
</tr>
<tr>
<td width="805" height="20">If the statement uses an alias for the table, then use the alias rather than the table name in the hint</td>
<td>Access path</td>
<td><a href="http://docs.oracle.com/cd/E11882_01/server.112/e16638/hintsref.htm#PFGRF94938" rel="nofollow">http://docs.oracle.com/cd/E11882_01/server.112/e16638/hintsref.htm#PFGRF94938</a></td>
</tr>
<tr>
<td width="805" height="20">The table name within the hint should not include the schema name if the schema name is present in the statement</td>
<td>Access path</td>
<td><a href="http://docs.oracle.com/cd/E11882_01/server.112/e16638/hintsref.htm#PFGRF94938" rel="nofollow">http://docs.oracle.com/cd/E11882_01/server.112/e16638/hintsref.htm#PFGRF94938</a></td>
</tr>
<tr>
<td width="805" height="20">For access path hints, Oracle Database ignores the hint if you specify the SAMPLE option in the FROM clause of a SELECT statement</td>
<td>Access path</td>
<td><a href="http://docs.oracle.com/cd/E11882_01/server.112/e16638/hintsref.htm#PFGRF94938" rel="nofollow">http://docs.oracle.com/cd/E11882_01/server.112/e16638/hintsref.htm#PFGRF94938</a></td>
</tr>
<tr>
<td width="805" height="20">The hints USE_NL &amp; USE_MERGE are ignored if the referenced table is the outer table in the join</td>
<td>Join operations</td>
<td><a href="http://docs.oracle.com/cd/E11882_01/server.112/e16638/hintsref.htm#autoId7" rel="nofollow">http://docs.oracle.com/cd/E11882_01/server.112/e16638/hintsref.htm#autoId7</a></td>
</tr>
<tr>
<td width="805" height="20">Oracle Database ignores global hints that refer to multiple query blocks</td>
<td>?</td>
<td><a href="http://docs.oracle.com/cd/E11882_01/server.112/e16638/hintsref.htm#i21188" rel="nofollow">http://docs.oracle.com/cd/E11882_01/server.112/e16638/hintsref.htm#i21188</a></td>
</tr>
<tr>
<td width="805" height="41">Access path and join hints on referenced views are ignored unless the view contains a single table or references an Additional Hints view with a single table.</td>
<td>?</td>
<td><a href="http://docs.oracle.com/cd/E11882_01/server.112/e16638/hintsref.htm#autoId21" rel="nofollow">http://docs.oracle.com/cd/E11882_01/server.112/e16638/hintsref.htm#autoId21</a></td>
</tr>
<tr>
<td width="805" height="46">With nonmergeable views, optimization approach and goal hints inside the view are ignored. Access path hints on the view in the top-level query are ignored.</td>
<td>?</td>
<td><a href="http://docs.oracle.com/cd/E11882_01/server.112/e16638/hintsref.htm#autoId23" rel="nofollow">http://docs.oracle.com/cd/E11882_01/server.112/e16638/hintsref.htm#autoId23</a></td>
</tr>
<tr>
<td width="805" height="20">If an invalid hint is a valid SQL keyword, it causes other hints to be ignored</td>
<td>All</td>
<td><a href="https://support.oracle.com/epmos/faces/DocumentDisplay?id=826893.1" rel="nofollow">https://support.oracle.com/epmos/faces/DocumentDisplay?id=826893.1</a></td>
</tr>
<tr>
<td width="805" height="20">When parallel_instance_group points to a non-existent service name, PARALLEL hint will be ignored</td>
<td>PARALLEL</td>
<td><a href="https://support.oracle.com/epmos/faces/DocumentDisplay?id=1467447.1" rel="nofollow">https://support.oracle.com/epmos/faces/DocumentDisplay?id=1467447.1</a></td>
</tr>
<tr>
<td width="805" height="20">INDEX hint may be &#8220;ignored&#8221; if materialized query rewrite produces plan with lower cost</td>
<td>?</td>
<td><a href="http://jonathanlewis.wordpress.com/2007/02/21/ignoring-hints/" rel="nofollow">http://jonathanlewis.wordpress.com/2007/02/21/ignoring-hints/</a></td>
</tr>
<tr>
<td width="805" height="20">Transitive closure and join elimination may produce a plan which ignores USE_HASH hint</td>
<td>Join operations</td>
<td><a href="http://jonathanlewis.wordpress.com/2010/02/11/ignoring-hints-2/" rel="nofollow">http://jonathanlewis.wordpress.com/2010/02/11/ignoring-hints-2/</a></td>
</tr>
<tr>
<td width="805" height="20">Hints in ANSI joins could be ignored due to query transformation and introduction of new query blocks</td>
<td>?</td>
<td><a href="http://jonathanlewis.wordpress.com/2010/12/03/ansi-argh/" rel="nofollow">http://jonathanlewis.wordpress.com/2010/12/03/ansi-argh/</a></td>
</tr>
<tr>
<td width="805" height="20">Undocumented limit of 20 chars for query block name causes QB_NAME to be ignored</td>
<td>QB_NAME</td>
<td><a href="http://oracle-randolf.blogspot.com/2013/02/qbname-hint-query-block-name-length.html" rel="nofollow">http://oracle-randolf.blogspot.com/2013/02/qbname-hint-query-block-name-length.html</a></td>
</tr>
</tbody>
</table>
<p>Unsurprisingly, most of the cases are covered by the documentation. Good to know.<br />
PS. Apart from documentation, an excellent source of information about hinting is <a href="http://jonathanlewis.files.wordpress.com/2009/05/hints_on_hints.pdf">presentation</a> and paper <a href="http://jonathanlewis.files.wordpress.com/2009/05/hints_on_hints.doc" target="_blank">Hint on Hints</a> by Jonathan Lewis.</p>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/oracle/cbo/'>CBO</a>, <a href='http://timurakhmadeev.wordpress.com/category/oracle/hints-oracle/'>Hints</a>, <a href='http://timurakhmadeev.wordpress.com/category/oracle/'>Oracle</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/888/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/888/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=888&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2013/04/02/ignoring-hints/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>
	</item>
		<item>
		<title>OIC(A) again</title>
		<link>http://timurakhmadeev.wordpress.com/2013/03/21/oica-again/</link>
		<comments>http://timurakhmadeev.wordpress.com/2013/03/21/oica-again/#comments</comments>
		<pubDate>Thu, 21 Mar 2013 19:00:08 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[CBO]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[10.2.0.3]]></category>
		<category><![CDATA[indexes]]></category>
		<category><![CDATA[IOT]]></category>
		<category><![CDATA[OIC]]></category>
		<category><![CDATA[OICA]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=873</guid>
		<description><![CDATA[Issues with OICA/OIC (OPTIMIZER_INDEX_COST_ADJ/OPTIMIZER_INDEX_CACHING) parameters have already been mentioned many times. Recently I&#8217;ve noticed one more and I think I didn&#8217;t see this case somewhere else on the Internet so I&#8217;ll share it. Here&#8217;s a simple table T1 holding 1M rows with the indexed column X having 10 distinct values: I run multiple EXPLAIN PLANs [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=873&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Issues with OICA/OIC (<a href="http://docs.oracle.com/cd/E11882_01/server.112/e25513/initparams168.htm#REFRN10143" target="_blank">OPTIMIZER_INDEX_COST_ADJ</a>/<a href="http://docs.oracle.com/cd/E11882_01/server.112/e25513/initparams167.htm#REFRN10142" target="_blank">OPTIMIZER_INDEX_CACHING</a>) parameters have already been mentioned many times. Recently I&#8217;ve noticed one more and I think I didn&#8217;t see this case somewhere else on the Internet so I&#8217;ll share it.</p>
<p><span id="more-873"></span><br />
Here&#8217;s a simple table T1 holding 1M rows with the indexed column X having 10 distinct values:</p>
<pre class="brush: sql; title: ; notranslate">
drop table t1 cascade constraints purge;
create table t1 (id, x, pad, constraint t1_pk primary key(id))
as
select rownum
     , mod(rownum, 10)
     , lpad('x', 200, 'x')
  from all_source s1, all_source s2
 where rownum &lt;= 1e6;
 
create index t1_indx on t1(x);
exec dbms_stats.gather_table_stats(user, 't1', method_opt=&gt;'for all columns size 1', cascade=&gt;true, no_invalidate=&gt;false)
</pre>
<p>I run multiple EXPLAIN PLANs for a query accessing T1 by a single X value using T1_INDX range scan. I know it&#8217;s a very inefficient way to access the data in this case, but it fits perfectly well for my purposes. I&#8217;m using different OICA/OIC settings with the help of OPT_PARAM hint and print the resulting IO cost for the query based on the PLAN_TABLE data:</p>
<pre class="brush: sql; title: ; notranslate">
delete plan_table;
commit;

set serveroutput on
declare
  l_query varchar2(4000);
begin
  for oica in 0..10 loop
    for oic in 0..10 loop
      l_query := 'explain plan set statement_id = ''' || oica*10 || ',' || oic*10 || ''' for ' ||
                  'select /*+ index_rs(t1 t1_indx) ' || 
                            ' opt_param(''optimizer_index_cost_adj'' ' || oica*10 || ') ' ||
                            ' opt_param(''optimizer_index_caching'' ' || oic*10 || ') */ * ' ||
                  '  from t1 ' ||
                  ' where x = :1';
--      dbms_output.put_line(l_query);
      execute immediate l_query;
    end loop;
  end loop;
end;
/

set numwidth 7

select *
  from (select to_number(substr(statement_id, 1, instr(statement_id, ',') - 1)) oica
              ,to_number(substr(statement_id, instr(statement_id, ',') + 1)) oic
              ,io_cost
          from plan_table
         where id = 0) 
  pivot(max(io_cost) for oic in (0  as oic_0
                                ,10 as oic_10
                                ,20 as oic_20
                                ,30 as oic_30
                                ,40 as oic_40
                                ,50 as oic_50
                                ,60 as oic_60
                                ,70 as oic_70
                                ,80 as oic_80
                                ,90 as oic_90
                                ,100 as oic_100))
 order by oica desc;
</pre>
<p>The results are expected:</p>
<pre class="brush: plain; title: ; notranslate">
   OICA   OIC_0  OIC_10  OIC_20  OIC_30  OIC_40  OIC_50  OIC_60  OIC_70  OIC_80  OIC_90 OIC_100
------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- -------
    100   30499   30499   30499   30499   30499   30499   30499   30499   30499   30499   30499
     90   27449   27449   27449   27449   27449   27449   27449   27449   27449   27449   27449
     80   24399   24399   24399   24399   24399   24399   24399   24399   24399   24399   24399
     70   21349   21349   21349   21349   21349   21349   21349   21349   21349   21349   21349
     60   18299   18299   18299   18299   18299   18299   18299   18299   18299   18299   18299
     50   15250   15250   15250   15250   15250   15250   15250   15250   15250   15250   15250
     40   12200   12200   12200   12200   12200   12200   12200   12200   12200   12200   12200
     30    9150    9150    9150    9150    9150    9150    9150    9150    9150    9150    9150
     20    6100    6100    6100    6100    6100    6100    6100    6100    6100    6100    6100
     10    3050    3050    3050    3050    3050    3050    3050    3050    3050    3050    3050
      0       1       1       1       1       1       1       1       1       1       1       1
</pre>
<p>Since the table is around 30K blocks and the data associated with any given value X is spread across all of the table blocks and the data is poorly clustered, I&#8217;m expecting the query cost to be around the number of table blocks, with table access being the major contributor, and it&#8217;s true by default:</p>
<pre class="brush: sql; title: ; notranslate">
---------------------------------------------------------------------------------------
| Id  | Operation                   | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |         |   100K|    19M| 30511   (1)| 00:06:07 |
|   1 |  TABLE ACCESS BY INDEX ROWID| T1      |   100K|    19M| 30511   (1)| 00:06:07 |
|*  2 |   INDEX RANGE SCAN          | T1_INDX |   100K|       |   197   (1)| 00:00:03 |
---------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access(&quot;X&quot;=TO_NUMBER(:1))
</pre>
<p>With the changes of OICA, the query cost changes almost linearly, except for some rounding error. Changes to the OIC do not impact query cost, as the documentation suggests:</p>
<blockquote><p><em>OPTIMIZER_INDEX_CACHING lets you adjust the behavior of cost-based optimization to favor nested loops joins and IN-list iterators.</em></p></blockquote>
<p>And I have nor NLJ, nor IN-list iterator here.</p>
<p>Now let&#8217;s change the table layout: make it index-organized and run the same PL/SQL test &amp; query for the PLAN_TABLE results</p>
<pre class="brush: sql; highlight: [3]; title: ; notranslate">
drop table t1 cascade constraints purge;
create table t1 (id, x, pad, constraint t1_pk primary key(id))
organization index
as
select rownum
     , mod(rownum, 10)
     , lpad('x', 200, 'x')
  from all_source s1, all_source s2
 where rownum &lt;= 1e6;
 
create index t1_indx on t1(x);
exec dbms_stats.gather_table_stats(user, 't1', method_opt=&gt;'for all columns size 1', cascade=&gt;true, no_invalidate=&gt;false)
</pre>
<pre class="brush: plain; title: ; notranslate">
   OICA   OIC_0  OIC_10  OIC_20  OIC_30  OIC_40  OIC_50  OIC_60  OIC_70  OIC_80  OIC_90 OIC_100
------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- -------
    100   30582     255     226     198     170     142     113      85      57      29   30304
     90   27524     230     203     178     153     128     102      77      51      26   27274
     80   24466     204     181     158     136     114      90      68      46      23   24243
     70   21407     179     158     139     119      99      79      60      40      20   21213
     60   18349     153     136     119     102      85      68      51      34      17   18182
     50   15291     128     113      99      85      71      57      43      29      15   15152
     40   12233     102      90      79      68      57      45      34      23      12   12122
     30    9175      77      68      59      51      43      34      26      17       9    9091
     20    6116      51      45      40      34      28      23      17      11       6    6061
     10    3058      26      23      20      17      14      11       9       6       3    3030
      0       1       1       1       1       1       1       1       1       1       1       1
</pre>
<p>This time the results are amusing. As long as the OIC doesn&#8217;t change, everything goes pretty much similar to the heap-organized table, with the query cost being a little bit higher &#8211; that&#8217;s OK as secondary indexes, based on logical rowids, may be slightly <a href="http://docs.oracle.com/cd/E11882_01/server.112/e25789/indexiot.htm#autoId25" target="_blank">less efficient</a> than indexes on heap tables.<br />
When the OIC changes, everything gets too crazy. By modifying the CBO index caching assumption to a mere 10%, the query cost drops by <em><strong>two orders of magnitude</strong></em>! This is tremendous shift in the costing which poses terrific consequences for <em><a href="https://twitter.com/fritshoogland/status/299074137048104960" target="_blank">legacy</a></em> applications trying to utilize IOTs advantages.<br />
It looks like the issue was introduced by the bug fix <a href="https://support.oracle.com/epmos/faces/DocumentDisplay?id=5236908.8" target="_blank">5236908</a>, which is described in the V$SESSION_FIX_CONTROL as &#8220;Allow _optimizer_index_caching to affect IOT primary keys&#8221; and was introduced in the 10.2.0.4. Probably they did it wrong: they&#8217;ve discounted UQ scan completely, thus dropping major part of the cost in some cases:</p>
<pre class="brush: sql; title: ; notranslate">
SQL&gt; explain plan for select /*+ index(t1 t1_indx) opt_param('optimizer_index_caching' 10) */ * from t1 where x = :1;

Explained.

SQL&gt; @xp

PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------------------
Plan hash value: 728231638

-----------------------------------------------------------------------------
| Id  | Operation         | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |         |   100K|    19M|   257   (1)| 00:00:04 |
|*  1 |  INDEX UNIQUE SCAN| T1_PK   |   100K|    19M|   257   (1)| 00:00:04 |
|*  2 |   INDEX RANGE SCAN| T1_INDX |   100K|       |   256   (1)| 00:00:04 |
-----------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - access(&quot;X&quot;=TO_NUMBER(:1))
   2 - access(&quot;X&quot;=TO_NUMBER(:1))

SQL&gt; explain plan for select /*+ index(t1 t1_indx) opt_param('optimizer_index_caching' 10) */ * from t1 where id in (:1);

Explained.

SQL&gt; @xp

PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------------------------------------------------
Plan hash value: 426392120

---------------------------------------------------------------------------
| Id  | Operation         | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |       |     1 |   209 |     0   (0)| 00:00:01 |
|*  1 |  INDEX UNIQUE SCAN| T1_PK |     1 |   209 |     0   (0)| 00:00:01 |
---------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - access(&quot;ID&quot;=TO_NUMBER(:1))

SQL&gt; explain plan for select /*+ index(t1 t1_indx) opt_param('optimizer_index_caching' 10) */ * from t1 where id in (:1, :2);

Explained.

SQL&gt; @xp

PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1529266855

----------------------------------------------------------------------------
| Id  | Operation          | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |       |     2 |   418 |     2   (0)| 00:00:01 |
|   1 |  INLIST ITERATOR   |       |       |       |            |          |
|*  2 |   INDEX UNIQUE SCAN| T1_PK |     2 |   418 |     2   (0)| 00:00:01 |
----------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access(&quot;ID&quot;=TO_NUMBER(:1) OR &quot;ID&quot;=TO_NUMBER(:2))
</pre>
<p>The bug fix can&#8217;t be turned off with _fix_control for some reason and I don&#8217;t have an old Oracle database to run the test so I can&#8217;t confirm if the bug-fix is the culprit or not. Anyway it looks stupid. I&#8217;ll try to submit bug report for this issue.</p>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/oracle/cbo/'>CBO</a>, <a href='http://timurakhmadeev.wordpress.com/category/oracle/'>Oracle</a> Tagged: <a href='http://timurakhmadeev.wordpress.com/tag/10-2-0-3/'>10.2.0.3</a>, <a href='http://timurakhmadeev.wordpress.com/tag/indexes/'>indexes</a>, <a href='http://timurakhmadeev.wordpress.com/tag/iot/'>IOT</a>, <a href='http://timurakhmadeev.wordpress.com/tag/oic/'>OIC</a>, <a href='http://timurakhmadeev.wordpress.com/tag/oica/'>OICA</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/873/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/873/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=873&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2013/03/21/oica-again/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>
	</item>
		<item>
		<title>Fixed stats</title>
		<link>http://timurakhmadeev.wordpress.com/2013/02/25/fixed-stats/</link>
		<comments>http://timurakhmadeev.wordpress.com/2013/02/25/fixed-stats/#comments</comments>
		<pubDate>Mon, 25 Feb 2013 19:42:47 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=882</guid>
		<description><![CDATA[Some time ago I had two questions about fixed objects statistics for which I couldn&#8217;t quickly find the answers. Questions are: how to gather fixed object stats for a given X$ should I gather fixed objects stats on both RAC nodes why I can&#8217;t gather stats on some X$-tables At the time of asking these [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=882&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Some time ago I had two questions about fixed objects statistics for which I couldn&#8217;t quickly find the answers. Questions are:</p>
<ul>
<li><a href="https://twitter.com/tmmdv/status/243981449810821120">how to gather</a> fixed object stats for a given X$</li>
<li>should I gather fixed objects stats <a href="https://twitter.com/tmmdv/status/245891276942221312">on both RAC nodes</a></li>
<li>why I can&#8217;t gather stats on some X$-tables</li>
</ul>
<p>At the time of asking these question I&#8217;ve read CBO development team <a href="https://blogs.oracle.com/optimizer/entry/fixed_objects_statistics_and_why">blog post</a> on the topic, but still I was unable to answer them distinctly. Well, it appears the questions are simple and could probably be deduced after careful reading (first two questions for sure). The core phrase is:</p>
<blockquote><p>The DBMS_STATS.GATHER_FIXED_OBJECTS_STATS procedure gathers the same statistics as DBMS_STATS.GATHER_TABLE_STATS except for the number of blocks</p></blockquote>
<p>That&#8217;s the key, the statistics are the same, except for the number of blocks. Which effectively means, you can gather the statistics on the specific X$-table in the same way as you do with a normal table, by using DBMS_STATS.GATHER_TABLE_STATS procedure. The only difference would be you will not populate the number of blocks (but you can do this manually). Now, since these statistics are essentially the same as statistics for normal tables, it makes no sense to run the GATHER_FIXED_OBJECTS_STATS procedure on all RAC nodes. After all, the database is still the same and it doesn&#8217;t care about the table statistics in relation to RAC node (at least for now in 11g).</p>
<p>I wish I was that smart back then <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I&#8217;ve found the answers recently via MOS notes updates:<br />
<a href="https://t.co/KUyxBvfYfZ">In RAC, Should We Execute GATHER_FIXED_OBJECTS_STATS And Gather_dictionary_stats In Both Nodes? [ID 1479804.1]</a> which gives the definitive answer &#8220;No&#8221; and<br />
<a href="https://support.oracle.com/epmos/faces/DocumentDisplay?id=1355608.1">Why do some Fixed Tables not have Optimizer Statistics [ID 1355608.1]</a> which explains that some fixed tables cannot have optimizer statistics by design decisions made by Oracle.<br />
What I don&#8217;t understand after getting better idea of fixed stats is why Oracle made the choice to introduce a specific new procedure, without any parameters/configuration options if they could have better done it inside the standard procedure for statistics gathering? To me it looks very strange and I would prefer not to introduce one more complication to the already over-complicated statistics package.</p>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/oracle/'>Oracle</a> Tagged: <a href='http://timurakhmadeev.wordpress.com/tag/statistics/'>statistics</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/882/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/882/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=882&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2013/02/25/fixed-stats/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>
	</item>
		<item>
		<title>Tom Kyte in Moscow &#8211; 2</title>
		<link>http://timurakhmadeev.wordpress.com/2012/12/12/tom-kyte-in-moscow-2/</link>
		<comments>http://timurakhmadeev.wordpress.com/2012/12/12/tom-kyte-in-moscow-2/#comments</comments>
		<pubDate>Wed, 12 Dec 2012 19:33:24 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[12c]]></category>
		<category><![CDATA[presentations]]></category>
		<category><![CDATA[Tom Kyte]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=877</guid>
		<description><![CDATA[On December 11th Tom Kyte performed &#8220;AskTom in Moscow&#8221; for the second time (first time was almost three years ago in February 2010). I was there and enjoyed presentations, tweeted a lot about the content and in the end I&#8217;ve won a signed copy of the Expert Oracle Database Architecture (2nd edition, in Russian)! The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=877&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>On December 11th Tom Kyte performed &#8220;AskTom in Moscow&#8221; for the second time (first time was almost <a href="http://timurakhmadeev.wordpress.com/2010/02/28/tom-kyte-in-moscow/" />three years ago</a> in February 2010). I was there and enjoyed presentations, tweeted a lot about the content and in the end I&#8217;ve won a signed copy of the Expert Oracle Database Architecture (2nd edition, in Russian)!</p>
<p><span id="more-877"></span></p>
<p>The start<br />
<img src="https://pbs.twimg.com/media/A9z9adlCcAAS_d6.jpg:large" /></p>
<p>A glass for questions. It was full in the end of the day<br />
<img src="https://pbs.twimg.com/media/A90MQy8CMAA4sTv.jpg:large" /></p>
<p>Tom started with a bit of history of how Oracle developed its database. Old stuff, C compilers, 37kg disk drives <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  followed by the modern, upcoming features in 12c. Pluggable Databases mostly &#8211; the biggest change in the Oracle architecture since version 6, he asserted.<br />
<img src="https://pbs.twimg.com/media/A90OEvyCMAAYNDm.jpg:large" /><br />
Also mentioned: automatic data tiering, aka &#8220;data heat maps&#8221;, data redaction, adaptive query optimization (scary 12c feature of), parallel execution and partitioning improvements.<br />
One thing about adaptive query optimization that is not mentioned is you can&#8217;t change any given execution in run time. I think it&#8217;s only possible if the client (or some buffered row source before giving data back to the client) didn&#8217;t fetch any row. Otherwise I believe it&#8217;s not possible to guarantee the same row order output.</p>
<p>Next in agenda was Security. Key points: everybody afraid to delete data (not only for historic reason, inserting data could be much faster &#8211; see Tim Gorman&#8217;s article in the <a href="http://www.nocoug.org/Journal/NoCOUG_Journal_201211.pdf">latest NoCOUG journal</a>), it&#8217;s hard to detect data theft, SQL Injection is dangerous; Database Firewall could help in protecting the database (for example, no DDL in production). Audit trails in the 12c will be someway different, &#8220;unified&#8221;. Advanced Security will be free in the next release. Different ways to encrypt: tablespace, column, backup&#8230; Interesting way of getting a part (like 10%) of the database masked and copied to QA/dev environment. New feature to detect which privileges are actually needed to application, to be able to easily turn off unnecessary grants. More separation of duties: new SYSBACKUP, SYSDG, SYSKM roles.</p>
<p>New features in the development was after a coffee break. A lot of new features expected in 12c: transaction guard, application continuity (very interesting client-side analog of TAF). With SQL Translator Oracle will be able to run code created for different databases (but will it be correct?).<br />
APEX can do a lot of work even on a low-end machine. With 12c there&#8217;s option to install it either on CDB or PDB level.<br />
IDENTITY columns &#8211; finally!<br />
SQL Developer is evolving towards developer <em>and</em> DBA toolkit. I need to start using it.<br />
The number of new features in 12c is astonishing. A lot of new stuff I don&#8217;t remember already! Good thing I was able to record the whole event, so I can hear Tom again when I would like to.<br />
You can do this too, <strong><a href="http://db.tt/Y0eSPoES">here are</a> 99MB (5h30min) of Tom Kyte speaking</strong>. Enjoy!</p>
<p>What I do remember clearly: Tom answered my questions and gave me a signed copy of his book. I made sure that he will get the questions: I first asked Tom <a href="https://twitter.com/search?q=%23AskTomMSK&amp;src=typd">in twitter</a> and then repeated questions on paper:<br />
<img src="https://pbs.twimg.com/media/A90gb7ZCcAAwbUP.jpg:large" alt="Questions to Tom" /><br />
As for the first question, the lack of statistical data in V$SQL for redo/undo, Tom said he understands why somebody would want this information be available; to actually get this feature in Oracle means the need to open an enhancement request. I&#8217;ll see if I&#8217;m allowed to submit ER and if I&#8217;m allowed I&#8217;ll definitely submit it.<br />
The second question, about <a href="http://timurakhmadeev.wordpress.com/2012/06/06/flashback-cursors/">flashback cursors</a>, had a mistake. Tom has built a test case to show that flashback query builds new child cursor on every <em>parse</em> call, not <em>execution</em> as I thought it was. Still Tom thinks that this behavior looks like a bug and he promised to file a bug on this matter. Great! My questions deserved a book <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  which I&#8217;ll try to read next year.<br />
<img src="https://pbs.twimg.com/media/A91Ym2LCEAAVH1l.jpg:large" alt="Expert Oracle Database Architecture" /></p>
<p>It was again a very well-organized, day of Oracle presentations of excellent quality by one of the best presenters in the world. Big thanks to Oracle CIS and Tom for the event!</p>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/oracle/'>Oracle</a> Tagged: <a href='http://timurakhmadeev.wordpress.com/tag/12c/'>12c</a>, <a href='http://timurakhmadeev.wordpress.com/tag/presentations/'>presentations</a>, <a href='http://timurakhmadeev.wordpress.com/tag/tom-kyte/'>Tom Kyte</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/877/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/877/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=877&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2012/12/12/tom-kyte-in-moscow-2/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>

		<media:content url="https://pbs.twimg.com/media/A9z9adlCcAAS_d6.jpg:large" medium="image" />

		<media:content url="https://pbs.twimg.com/media/A90MQy8CMAA4sTv.jpg:large" medium="image" />

		<media:content url="https://pbs.twimg.com/media/A90OEvyCMAAYNDm.jpg:large" medium="image" />

		<media:content url="https://pbs.twimg.com/media/A90gb7ZCcAAwbUP.jpg:large" medium="image">
			<media:title type="html">Questions to Tom</media:title>
		</media:content>

		<media:content url="https://pbs.twimg.com/media/A91Ym2LCEAAVH1l.jpg:large" medium="image">
			<media:title type="html">Expert Oracle Database Architecture</media:title>
		</media:content>
	</item>
		<item>
		<title>Adaptive STAT lines in SQL trace</title>
		<link>http://timurakhmadeev.wordpress.com/2012/07/31/adaptive-stat-lines-in-sql-trace/</link>
		<comments>http://timurakhmadeev.wordpress.com/2012/07/31/adaptive-stat-lines-in-sql-trace/#comments</comments>
		<pubDate>Tue, 31 Jul 2012 17:22:45 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[11.2.0.2]]></category>
		<category><![CDATA[sql_trace]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=868</guid>
		<description><![CDATA[Lately I&#8217;ve been using SQL runtime execution statistics combined with SQL monitor for performance diagnostics and, honestly, almost forgot about SQL trace. So this note is not very useful to me but it might be to someone: along with ALL_EXECUTIONS option appeared in (I believe) 11gR2, there&#8217;s a new option starting with 11.2.0.2 which can [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=868&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Lately I&#8217;ve been using SQL runtime execution statistics combined with SQL monitor for performance diagnostics and, honestly, almost forgot about SQL trace. So this note is not very useful to me but it might be to someone: along with <a href="http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/d_sessio.htm#ARPLS68058">ALL_EXECUTIONS</a> option appeared in (I believe) 11gR2, there&#8217;s a new option starting with 11.2.0.2 which can significantly decrease amount of data in the trace files for STAT lines compared to ALL_EXECUTIONS, still providing some of them from time to time.</p>
<p><span id="more-868"></span></p>
<p>Here is a case to demonstrate:</p>
<pre class="brush: sql; title: ; notranslate">
declare
    n number := 0;
begin
    dbms_session.session_trace_enable(true, true, 'all_executions');
   
    for x in 1..10 loop
        for y in (select * from all_source) loop
            n := n + length(y.text);
        end loop;
    end loop;

    dbms_session.session_trace_disable;
end;
/
</pre>
<p>And if I search through the resulting trace file, I&#8217;ll find 10 occurrences of the STAT lines for runtime execution statistics of the SQL, as desired:</p>
<pre class="brush: plain; title: ; notranslate">
C:\Users\Tim&gt;grep &quot;VIEW  ALL_SOURCE&quot; d:\oracle\diag\rdbms\test\test\trace/test_ora_1660.trc
STAT #191268904 id=1 cnt=633054 pid=0 pos=1 obj=4813 op='VIEW  ALL_SOURCE (cr=39988 pr=0 pw=0 time=2369570 us cost=1039 size=569297377 card=276761)'
STAT #191268904 id=1 cnt=633054 pid=0 pos=1 obj=4813 op='VIEW  ALL_SOURCE (cr=39988 pr=0 pw=0 time=2329706 us cost=1039 size=569297377 card=276761)'
STAT #191268904 id=1 cnt=633054 pid=0 pos=1 obj=4813 op='VIEW  ALL_SOURCE (cr=39988 pr=0 pw=0 time=2351289 us cost=1039 size=569297377 card=276761)'
STAT #191268904 id=1 cnt=633054 pid=0 pos=1 obj=4813 op='VIEW  ALL_SOURCE (cr=39988 pr=0 pw=0 time=2334011 us cost=1039 size=569297377 card=276761)'
STAT #191268904 id=1 cnt=633054 pid=0 pos=1 obj=4813 op='VIEW  ALL_SOURCE (cr=39988 pr=0 pw=0 time=2350335 us cost=1039 size=569297377 card=276761)'
STAT #191268904 id=1 cnt=633054 pid=0 pos=1 obj=4813 op='VIEW  ALL_SOURCE (cr=39988 pr=0 pw=0 time=2337449 us cost=1039 size=569297377 card=276761)'
STAT #191268904 id=1 cnt=633054 pid=0 pos=1 obj=4813 op='VIEW  ALL_SOURCE (cr=39988 pr=0 pw=0 time=2340285 us cost=1039 size=569297377 card=276761)'
STAT #191268904 id=1 cnt=633054 pid=0 pos=1 obj=4813 op='VIEW  ALL_SOURCE (cr=39988 pr=0 pw=0 time=2329053 us cost=1039 size=569297377 card=276761)'
STAT #191268904 id=1 cnt=633054 pid=0 pos=1 obj=4813 op='VIEW  ALL_SOURCE (cr=39988 pr=0 pw=0 time=2362534 us cost=1039 size=569297377 card=276761)'
STAT #191268904 id=1 cnt=633054 pid=0 pos=1 obj=4813 op='VIEW  ALL_SOURCE (cr=39988 pr=0 pw=0 time=2326067 us cost=1039 size=569297377 card=276761)'
</pre>
<p>Now I&#8217;ll change the way I&#8217;m enabling trace and repeat the case in another session with 30 iterations:</p>
<pre class="brush: sql; title: ; notranslate">
alter session set events 'sql_trace wait=true, bind=true, plan_stat=adaptive';

declare
    n number := 0;
begin
    for x in 1..30 loop
        for y in (select * from all_source) loop
            n := n + length(y.text);
        end loop;
    end loop;
end;
/

alter session set events 'sql_trace off';
</pre>
<p>Using new 11g syntax for the EVENTS I&#8217;ve set PLAN_STAT option to ADAPTIVE and the plan appears two times in the trace:</p>
<pre class="brush: plain; title: ; notranslate">
C:\Users\Tim&gt;grep &quot;VIEW  ALL_SOURCE&quot; d:\oracle\diag\rdbms\test\test\trace/test_ora_1788.trc
STAT #191264936 id=1 cnt=633054 pid=0 pos=1 obj=4813 op='VIEW  ALL_SOURCE (cr=39988 pr=0 pw=0 time=2337943 us cost=1039 size=569297377 card=276761)'
STAT #191264936 id=1 cnt=633054 pid=0 pos=1 obj=4813 op='VIEW  ALL_SOURCE (cr=39988 pr=0 pw=0 time=2352998 us cost=1039 size=569297377 card=276761)'
</pre>
<p>One for the first execution and the second after 18th execution of the cursor. Why 18th? It&#8217;s because per 1 execution the DB spends 2.3 seconds of time on average and after 10 + 18 executions for this child cursor the time spent by the DB has gone beyond 60 seconds and this triggered dumping execution statistics again. It should probably happened after 27th execution one might think. Most likely it relates to the time when the statistics in the V$ view is refreshed and the check is performed.<br />
Anyway this is nice improvement to the SQL trace. Here is the bug for this improvement: <a href="https://support.oracle.com/epmos/faces/ui/km/DocumentDisplay.jspx?id=8328200.8">Bug 8328200 &#8211; Misleading or excessive STAT# lines for SQL_TRACE / 10046</a>. One minor issue is the new option is not available with DBMS_SESSION/DBMS_MONITOR packages and works only with EVENTS syntax &#8211; I hope it will be fixed some day, as well as documentation.</p>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/oracle/'>Oracle</a>, <a href='http://timurakhmadeev.wordpress.com/category/performance/'>Performance</a> Tagged: <a href='http://timurakhmadeev.wordpress.com/tag/11-2-0-2/'>11.2.0.2</a>, <a href='http://timurakhmadeev.wordpress.com/tag/sql_trace/'>sql_trace</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/868/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/868/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=868&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2012/07/31/adaptive-stat-lines-in-sql-trace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>
	</item>
		<item>
		<title>Consultancy</title>
		<link>http://timurakhmadeev.wordpress.com/2012/06/13/consultancy/</link>
		<comments>http://timurakhmadeev.wordpress.com/2012/06/13/consultancy/#comments</comments>
		<pubDate>Wed, 13 Jun 2012 18:50:08 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[CBO]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JDBC]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=839</guid>
		<description><![CDATA[I have a permanent job at the NetCracker&#8216;s System Performance group. Recently I was offered to do one day job outside, on-site in another company, which coincidentally has an office close to NetCracker&#8217;s Moscow office. It was an opportunity to apply my skills in a completely different situation which I couldn&#8217;t miss; plus I&#8217;ve never [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=839&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I have a permanent job at the <a href="http://www.netcracker.com/en/">NetCracker</a>&#8216;s System Performance group. Recently I was offered to do one day job outside, on-site in another company, which coincidentally has an office close to NetCracker&#8217;s Moscow office. It was an opportunity to apply my skills in a completely different situation which I couldn&#8217;t miss; plus I&#8217;ve never done public presentations before and this was a good occasion to practice that. Here I&#8217;d like to write down some notes how the event went.</p>
<p><span id="more-839"></span></p>
<p>2 or 3 weeks before the event I&#8217;ve got the list of topics to work on. It included several Java and Oracle subjects. I&#8217;ve offered couple of topics myself too. The preparation went well although it took a lot of time to make some slides (which I don&#8217;t really like doing hence as a result slides look clumsy. Just as my blog <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ) and to put together meaningful examples. In fact I didn&#8217;t prepare everything in the volume I thought about initially because of the time &#8211; and as it turned out it was right decision. I didn&#8217;t practice presentations even though I tried. Each time I&#8217;ve tried I took different ways to describe same things so I&#8217;ve decided to go unprepared and see how it will go. Since I have clear understanding of what I&#8217;m talking about and had a plan in slides it wasn&#8217;t so hard. What was a bit of a problem I didn&#8217;t know what to expect from the audience and how to keep the balance between interesting and boring slides. Both problems didn&#8217;t materialize and were somehow avoided <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Must be because of simplicity I think. I tried hard to make it simple and keep what&#8217;s important in my opinion.</p>
<p>So I took a day off and went to present. It started badly. My notebook is a tiny Aspire S3 with only HDMI output available. When I tried to connect it to the projector, it just didn&#8217;t work. I spent half an hour trying different things until when I did something wrong and the screen went black with nothing on the projector screen. After a reboot laptop didn&#8217;t boot up properly, and I had no other choice than to use safe mode and apply System Restore which added another 10 minutes. Luckily restore finished well. It must have been Friday 13th impact <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  but no. Turned out the plug I tried was not for the projector, but for the speakers!! The right plug was hided behind the screen wall. Fortunately there was another laptop available with DVI port, which I used to show slides. Mine notebook was behind the wall connected via HDMI, so each time I needed to show a demo I had to go up, switch the projector&#8217;s input and hide myself from the audience (the only thing visible was my back) appearing from time to time. It was funny.</p>
<p>First part was about JVM performance. I talked about general HotSpot JVM features such as <a href="http://www.oracle.com/technetwork/java/hotspotfaq-138619.html#compiler_types">just in time compiler</a> and <a href="http://www.oracle.com/technetwork/java/javase/tech/index-jsp-136373.html">garbage collection</a>. The latter was the main topic of this part. I covered JVM memory layout, GC types, their high-level algorithms and options to tune them based on my experience. In the end of the section there was a demo for out-of-the-box <a href="http://docs.oracle.com/javase/6/docs/technotes/tools/#monitor">monitoring/debugging/analyzing</a> and third-party tools such as <a href="http://www.eclipse.org/mat/">Memory Analyzer</a>. With only 16 slides it took almost 2 hours to talk and answer questions. I didn&#8217;t anticipate it that long, and expected to fit into an hour or so. Apparently I can talk for a long time <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Next topic was Oracle JDBC. I&#8217;ve started with an overview of what is end-to-end workflow of an Oracle client, i.e. basic Oracle instance architecture, connection methods and cursors life cycle. Then I showed demos of several important JDBC features: <a href="http://docs.oracle.com/cd/E11882_01/java.112/e16548/resltset.htm#i1023619">fetch size</a>; <a href="http://docs.oracle.com/cd/E11882_01/java.112/e16548/oraperf.htm#i1056232">update batching</a>; working with <a href="http://docs.oracle.com/cd/E11882_01/java.112/e16548/oraarr.htm#g1072333">Oracle collections</a>; client- and server-side cursors cache. Examples were focused on the performance of the work with database and its consequences for the client. I&#8217;ve finished this section with an explanation how important it is to <a href="http://docs.oracle.com/cd/B19306_01/java.102/b14355/endtoend.htm#BEICGHJH">instrument</a> applications (which is a must for all Oracle-based apps) and a short list of common JDBC driver exceptions. Most of the things I&#8217;ve explained are pretty well described in the <a href="http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html">FAQ</a>, <a href="http://docs.oracle.com/cd/E11882_01/java.112/e16548/toc.htm">documentation</a> and <a href="http://www.oracle.com/technetwork/database/enterprise-edition/memory.pdf">white papers</a>.</p>
<p>Then I went to database topics, beginning with a general topic of &#8220;Performance&#8221;. Although I&#8217;ve been working in this area for about five years, it was hard to find the right words to begin. And I have to admit it sucked a little bit. Two opening slides &amp; explanation were not the same quality as the rest. I know that, because I didn&#8217;t sound convincing to myself. Good thing it was only introduction and it didn&#8217;t take too much time to go through. After introduction I&#8217;ve reviewed most common Oracle tools for performance diagnostics: out-of-the-box, such as SQL Trace and SQL Monitor, and also some third-party tools, such as <a href="http://www.oracle-developer.net/content/utilities/moats.zip">MOATS</a> and <a href="http://tech.e2sn.com/oracle-scripts-and-tools/session-snapper">Snapper</a>. I also showed what scripts and queries I use most of the time in my work. They are very simple BTW; I plan to write about them some day in the blog.<br />
As part of this section I thought I should talk about reading execution plans. But after some thinking I&#8217;ve decided to skip this very important and necessary topic and just point to the excellent  <a href="http://antognini.ch/papers/InterpretingExecutionPlans_20091017.pdf">Christian Antognini&#8217;s paper</a>. Instead I showed how to get run-time execution statistics for a plan with an example and where to look at to understand why the query runs slow. Initially I thought I&#8217;ll create just one complex example based on a query I&#8217;ve seen recently, and then use it throughout the event to also demonstrate several CBO issues such as blind guesses, arithmetic bugs, transformations and something &#8220;unknown&#8221; which I&#8217;ve never seen before. Unfortunately I wasn&#8217;t able to build a test case as I wanted, and it served only as an example of a bad performing query.<br />
Then I moved to interpreting Statspack reports. I had sample reports from their production system which experienced some issues. Based on these reports I&#8217;ve shown how to approach analysis of the information, what (not) to expect from reports, and where (not) to look for and how to make balanced conclusions about the amount of work done by the database. Also I&#8217;ve explained some questionable configuration parameters; where to look next for more data and tried to explain what a potential reason of the problem could be. It is in fact the impossible reason (which I&#8217;ve picked up in the OakTable mailing list), but fits perfectly well and explains all issues at once. It is unfortunate system&#8217;s DBA missed the event so I couldn&#8217;t talk about all of the &#8220;why&#8221;s. Maybe next time <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I also thought about showing some more reports but once again it took me almost an hour to overview just a single report even without looking at the SQL execution statistics sections. I think I did this part very well and it was enough of analyzing reports for one day.</p>
<p>And the final topic of the day was statistics. This part was a basic explanation of how Oracle deals with execution plans, what kind of features influences its decisions, how they impact building an execution plan and fundamental understanding of what is statistics and what are the things to consider when it should (not) be gathered. I didn&#8217;t try to explain the term &#8220;cost&#8221; in this section and I only talked about cardinality estimates instead. It is enough for beginning, I think. For demos I&#8217;ve shown two very common examples when CBO estimates may go off: linear decay for out of range values (which can be &#8220;fixed&#8221; by manual adjustment to low/high column values) and correlation between columns (which is nicely covered by 11g&#8217;s extended statistics).<br />
I&#8217;ve also shown in action my <a href="https://sites.google.com/site/timurakhmadeev/scripts/stat.sql">script stat.sql</a> which I use all the time to get the basic understanding of table and index statistics.<br />
I have to admit that in this section I only touched this complicated topic. It&#8217;s relatively easy to talk about it for the whole day with tons of examples and gotchas. Nevertheless I&#8217;m sure that I&#8217;ve covered the basics.<br />
And the last part was supposed to be Q&amp;A session (with questions given to me before the event), but I didn&#8217;t have time to try and write some code so it went without examples.</p>
<p>All in all it went smoothly; not everything went very well, but some parts were pretty darn good and some were normal. It sucked little bit for 10 minutes or so, which is acceptable. Presentations looked not too sexy &#8211; plain text with minimal drawings. Well, it wasn&#8217;t about presentations after all. I know there&#8217;s plenty of room for improvement in this area. The feedback from the audience was quite positive which is excellent. To me it was a very good experience and I&#8217;m happy I did it.</p>
<p>Lessons learned:</p>
<ul>
<li>HDMI may be a problem</li>
<li>Don&#8217;t try to cover too much the same day</li>
<li>Preparation takes longer than expected due to various reasons</li>
<li>Preparation brings something new</li>
<li>It&#8217;s better to know who will attend</li>
<li>It would be better not only talk, but also &#8220;do something&#8221; useful with a real system</li>
<li>VM is better choice for demos</li>
<li>Google Docs and Dropbox offer very good services</li>
</ul>
<p>PS. If you think you may need something similar in (preferably) Moscow region, drop me an <a href="mailto:timur.akhmadeev@gmail.com">e-mail</a>. It&#8217;s doable.</p>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/oracle/cbo/'>CBO</a>, <a href='http://timurakhmadeev.wordpress.com/category/java/'>Java</a>, <a href='http://timurakhmadeev.wordpress.com/category/java/jdbc/'>JDBC</a>, <a href='http://timurakhmadeev.wordpress.com/category/oracle/'>Oracle</a>, <a href='http://timurakhmadeev.wordpress.com/category/performance/'>Performance</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/839/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/839/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=839&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2012/06/13/consultancy/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>
	</item>
		<item>
		<title>Unnesting disjunctive subqueries (with OR predicate)</title>
		<link>http://timurakhmadeev.wordpress.com/2012/06/07/unnesting-disjunctive-subqueries-with-or-predicate/</link>
		<comments>http://timurakhmadeev.wordpress.com/2012/06/07/unnesting-disjunctive-subqueries-with-or-predicate/#comments</comments>
		<pubDate>Thu, 07 Jun 2012 09:40:01 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[CBO]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[CBQT]]></category>
		<category><![CDATA[subquery unnesting]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=863</guid>
		<description><![CDATA[Jonathan Lewis has recently posted a good example of CBO not good enough in transforming specific query types. A recent thread on the SQL.ru Oracle forum reminded me of this issue. Basically OP has a query with disjuncted (OR-ed) predicate which started to fail after 11.2.0.3 upgrade with ORA-01790: expression must have same datatype as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=863&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Jonathan Lewis has recently <a href="http://jonathanlewis.wordpress.com/2012/05/23/logical-tuning">posted</a> a good example of CBO not good enough in transforming specific query types. A recent <a href="http://www.sql.ru/forum/actualthread.aspx?tid=946574">thread</a> on the SQL.ru Oracle forum reminded me of this issue.</p>
<p><span id="more-863"></span></p>
<p>Basically OP has a query with disjuncted (OR-ed) predicate which started to fail after 11.2.0.3 upgrade with ORA-01790: expression must have same datatype as corresponding expression. Here is a test case (I&#8217;ve renamed column and table names cause I&#8217;ve used to such naming):</p>
<pre class="brush: sql; title: ; notranslate">
drop table t1 cascade constraints purge;
drop table t2 cascade constraints purge;

create table t1 (
  x int not null,
  y varchar2(13)
);
                 
insert into t1 values(0,100);
insert into t1 values(0,100);
insert into t1 values(0,100);
                 
create table t2 (
 x number,
 y number(15)
);

insert into t2 values(1,100);
insert into t2 values(2,100);
insert into t2 values(1,100);
insert into t2 values(1,100);

commit;

exec dbms_stats.gather_table_stats(user, 't1', no_invalidate=&gt;false)
exec dbms_stats.gather_table_stats(user, 't2', no_invalidate=&gt;false)
</pre>
<p>Now let&#8217;s try to run following query:</p>
<pre class="brush: sql; title: ; notranslate">
SQL&gt; select *
  2    from t2
  3   where not exists
  4          (select 1
  5            from t1
  6           where (t1.y = t2.y)
  7              or (t1.x = t2.y));
            or (t1.x = t2.y))
                *
ERROR at line 7:
ORA-01790: expression must have same datatype as corresponding expression
</pre>
<p>Oops. But if you change second condition with swapping left and right parts it is executed OK:</p>
<pre class="brush: sql; title: ; notranslate">
SQL&gt; ed
Wrote file afiedt.buf

  1  select *
  2    from t2
  3   where not exists
  4          (select 1
  5            from t1
  6           where (t1.y = t2.y)
  7*             or (t2.y = t1.x))
SQL&gt; /

no rows selected
</pre>
<p>And the plan is FILTER-based</p>
<pre class="brush: sql; title: ; notranslate">
---------------------------------------------------------------------------
| Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |      |     1 |     6 |     7   (0)| 00:00:01 |
|*  1 |  FILTER            |      |       |       |            |          |
|   2 |   TABLE ACCESS FULL| T2   |     4 |    24 |     3   (0)| 00:00:01 |
|*  3 |   TABLE ACCESS FULL| T1   |     1 |     6 |     2   (0)| 00:00:01 |
---------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter( NOT EXISTS (SELECT 0 FROM &quot;T1&quot; &quot;T1&quot; WHERE &quot;T1&quot;.&quot;X&quot;=:B1
              OR TO_NUMBER(&quot;T1&quot;.&quot;Y&quot;)=:B2))
   3 - filter(&quot;T1&quot;.&quot;X&quot;=:B1 OR TO_NUMBER(&quot;T1&quot;.&quot;Y&quot;)=:B2)
</pre>
<p>So why first query error-ed? Let&#8217;s look at the critical lines of 10053 trace file (which is incomplete due to error):</p>
<pre class="brush: plain; highlight: [19]; title: ; notranslate">
SU: Unnesting query blocks in query block SEL$1 (#1) that are valid to unnest.
Subquery Unnesting on query block SEL$1 (#1)SU: Performing unnesting that does not require costing.
SU: Considering subquery unnest on query block SEL$1 (#1).
SU:   Checking validity of unnesting subquery SEL$2 (#2)
SU:   Passed validity checks.
Branch query block:******* UNPARSED QUERY IS *******
SELECT 1 &quot;1&quot; FROM &quot;TIM&quot;.&quot;T1&quot; &quot;T1&quot; WHERE &quot;T1&quot;.&quot;Y&quot;=&quot;T2&quot;.&quot;Y&quot; OR &quot;T1&quot;.&quot;X&quot;=&quot;T2&quot;.&quot;Y&quot;
Branch query block:******* UNPARSED QUERY IS *******
SELECT 1 &quot;1&quot; FROM &quot;TIM&quot;.&quot;T1&quot; &quot;T1&quot; WHERE &quot;T1&quot;.&quot;Y&quot;=&quot;T2&quot;.&quot;Y&quot; OR &quot;T1&quot;.&quot;X&quot;=&quot;T2&quot;.&quot;Y&quot;
Set query block:******* UNPARSED QUERY IS *******
 (SELECT 1 &quot;1&quot; FROM &quot;TIM&quot;.&quot;T1&quot; &quot;T1&quot; WHERE &quot;T1&quot;.&quot;Y&quot;=&quot;T2&quot;.&quot;Y&quot;) UNION ALL  (SELECT 1 &quot;1&quot; FROM &quot;TIM&quot;.&quot;T1&quot; &quot;T1&quot; WHERE &quot;T1&quot;.&quot;X&quot;=&quot;T2&quot;.&quot;Y&quot;)
Registered qb: SET$E74BECDC 0xd0e9a0c8 (COMPLEX SUBQUERY UNNEST SEL$2)
---------------------
QUERY BLOCK SIGNATURE
---------------------
  signature (): qb_name=SET$E74BECDC nbfros=1 flg=0
    fro(0): flg=0 objn=0 hint_alias=&quot;NULL_HALIAS&quot;@&quot;SET$E74BECDC&quot;

Query block after disjuncts converted to set:******* UNPARSED QUERY IS *******
SELECT &quot;T2&quot;.&quot;X&quot; &quot;X&quot;,&quot;T2&quot;.&quot;Y&quot; &quot;Y&quot; FROM &quot;TIM&quot;.&quot;T2&quot; &quot;T2&quot; WHERE  NOT EXISTS ( (SELECT 1 &quot;1&quot; FROM &quot;TIM&quot;.&quot;T1&quot; &quot;T1&quot; WHERE &quot;T1&quot;.&quot;Y&quot;=&quot;T2&quot;.&quot;Y&quot;) UNION ALL  (SELECT 1 &quot;1&quot; FROM &quot;TIM&quot;.&quot;T1&quot; &quot;T1&quot; WHERE &quot;T1&quot;.&quot;X&quot;=&quot;T2&quot;.&quot;Y&quot;))
SU:   Unnesting subquery query block SET$E74BECDC (#0)Registered qb: SET$7FD77EFD 0xd0e9a0c8 (SUBQ INTO VIEW FOR COMPLEX UNNEST SET$E74BECDC)
...
SELECT &quot;T2&quot;.&quot;X&quot; &quot;X&quot;,&quot;T2&quot;.&quot;Y&quot; &quot;Y&quot; FROM  ( (SELECT &quot;T1&quot;.&quot;Y&quot; &quot;ITEM_1&quot; FROM &quot;TIM&quot;.&quot;T1&quot; &quot;T1&quot;) UNION ALL  (SELECT &quot;T1&quot;.&quot;X&quot; &quot;ITEM_2&quot; FROM &quot;TIM&quot;.&quot;T1&quot; &quot;T1&quot;)) &quot;VW_SQ_1&quot;,&quot;TIM&quot;.&quot;T2&quot; &quot;T2&quot; WHERE &quot;VW_SQ_1&quot;.&quot;VW_COL_1&quot;=&quot;T2&quot;.&quot;Y&quot;
</pre>
<p>Basically Oracle tries to transform the query to replace disjunct predicate with a set (UNION ALL) of two subqueries, which allows it to unnest the resulting subquery and then join it. It&#8217;s not merged though due to UNION ALL presence.<br />
And since for reasons unknown to me Oracle throws an exception for a query block:</p>
<pre class="brush: sql; title: ; notranslate">
select 'x' from dual
union all
select 2 from dual
</pre>
<p>original query fails. It can be avoided with an explicit type conversion which will still allow unnesting to happen:</p>
<pre class="brush: sql; title: ; notranslate">
SQL&gt; explain plan for
  2  select *
  3    from t2
  4   where not exists
  5          (select 1
  6            from t1
  7           where (to_number(t1.y) = t2.y)
  8              or (t1.x = t2.y));

Explained.

SQL&gt; @xp

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 1288684780

--------------------------------------------------------------------------------
| Id  | Operation            | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |         |     1 |    19 |    10  (10)| 00:00:01 |
|*  1 |  HASH JOIN ANTI      |         |     1 |    19 |    10  (10)| 00:00:01 |
|   2 |   TABLE ACCESS FULL  | T2      |     4 |    24 |     3   (0)| 00:00:01 |
|   3 |   VIEW               | VW_SQ_1 |     6 |    78 |     6   (0)| 00:00:01 |
|   4 |    UNION-ALL         |         |       |       |            |          |
|   5 |     TABLE ACCESS FULL| T1      |     3 |    12 |     3   (0)| 00:00:01 |
|   6 |     TABLE ACCESS FULL| T1      |     3 |     6 |     3   (0)| 00:00:01 |
--------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - access(&quot;VW_COL_1&quot;=&quot;T2&quot;.&quot;Y&quot;)
</pre>
<p>But if you don&#8217;t need unnesting, then by using hidden _optimizer_unnest_disjunctive_subq parameter you can turn off the transformation (for me it does so, but be careful with the hidden stuff):</p>
<pre class="brush: sql; title: ; notranslate">
explain plan for
select /*+ opt_param('_optimizer_unnest_disjunctive_subq', 'false') */ *
  from t2
 where not exists 
        (select 1
          from t1
         where (t1.y = t2.y)
            or (t1.x = t2.y));
@xp

---------------------------------------------------------------------------
| Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |      |     1 |     6 |     7   (0)| 00:00:01 |
|*  1 |  FILTER            |      |       |       |            |          |
|   2 |   TABLE ACCESS FULL| T2   |     4 |    24 |     3   (0)| 00:00:01 |
|*  3 |   TABLE ACCESS FULL| T1   |     1 |     6 |     2   (0)| 00:00:01 |
---------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter( NOT EXISTS (SELECT 0 FROM &quot;T1&quot; &quot;T1&quot; WHERE &quot;T1&quot;.&quot;X&quot;=:B1
              OR TO_NUMBER(&quot;T1&quot;.&quot;Y&quot;)=:B2))
   3 - filter(&quot;T1&quot;.&quot;X&quot;=:B1 OR TO_NUMBER(&quot;T1&quot;.&quot;Y&quot;)=:B2)
</pre>
<p>And in Jonathan&#8217;s case it&#8217;s also possible to invoke such optimization. All that is needed is a simple modification of a predicate to move 1000 to the left, which will allow Oracle to hash join the resulting view without a problem:</p>
<pre class="brush: sql; highlight: [13]; title: ; notranslate">
SQL&gt; explain plan for
  2  select
  3      *
  4  from
  5      t2
  6  where
  7      not exists (
  8          select  /*+ unnest */
  9              null
 10          from    t3
 11          where   n3a = n2a
 12          and n3b = n2b
 13          and (id3 = id2 or id3 - 1000 = id2)
 14      )
 15  ;

Explained.

SQL&gt; @xp

PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------
Plan hash value: 3482347739

-----------------------------------------------------------------------------------
| Id  | Operation               | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------
|   0 | SELECT STATEMENT        |         |  5000 |   776K|    33   (4)| 00:00:01 |
|*  1 |  HASH JOIN RIGHT ANTI   |         |  5000 |   776K|    33   (4)| 00:00:01 |
|   2 |   VIEW                  | VW_SQ_1 | 10000 |   380K|    10   (0)| 00:00:01 |
|   3 |    UNION-ALL            |         |       |       |            |          |
|   4 |     INDEX FAST FULL SCAN| T3_PK   |  5000 | 60000 |     5   (0)| 00:00:01 |
|   5 |     INDEX FAST FULL SCAN| T3_PK   |  5000 | 60000 |     5   (0)| 00:00:01 |
|   6 |   TABLE ACCESS FULL     | T2      |  5000 |   585K|    22   (0)| 00:00:01 |
-----------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - access(&quot;VW_COL_1&quot;=&quot;ID2&quot; AND &quot;VW_COL_2&quot;=&quot;N2A&quot; AND &quot;VW_COL_3&quot;=&quot;N2B&quot;)
</pre>
<p>What&#8217;s in total:</p>
<ol>
<li>Predicates order matters sometimes</li>
<li>The way a predicate is written matters sometimes</li>
</ol>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/oracle/cbo/'>CBO</a>, <a href='http://timurakhmadeev.wordpress.com/category/oracle/'>Oracle</a> Tagged: <a href='http://timurakhmadeev.wordpress.com/tag/cbqt/'>CBQT</a>, <a href='http://timurakhmadeev.wordpress.com/tag/subquery-unnesting/'>subquery unnesting</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/863/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/863/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=863&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2012/06/07/unnesting-disjunctive-subqueries-with-or-predicate/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>
	</item>
		<item>
		<title>Flashback cursors</title>
		<link>http://timurakhmadeev.wordpress.com/2012/06/06/flashback-cursors/</link>
		<comments>http://timurakhmadeev.wordpress.com/2012/06/06/flashback-cursors/#comments</comments>
		<pubDate>Wed, 06 Jun 2012 08:59:52 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[flashback query]]></category>
		<category><![CDATA[shared cursors]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=858</guid>
		<description><![CDATA[Flashback query allows to get data as of required point in time. It&#8217;s a nice feature. It&#8217;s strange in the implementation though. If you try to use AS OF SCN query with bind variables, it won&#8217;t help you to keep number of child cursors low: each execution (independently of the incoming SCN value) will cause [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=858&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://docs.oracle.com/cd/E11882_01/appdev.112/e25518/adfns_flashback.htm#ADFNS01003">Flashback query</a> allows to get data as of required point in time. It&#8217;s a nice feature. It&#8217;s strange in the implementation though. If you try to use AS OF SCN query with bind variables, it won&#8217;t help you to keep number of child cursors low: each execution (independently of the incoming SCN value) will cause a new child cursor to appear with <a href="http://docs.oracle.com/cd/E11882_01/server.112/e25513/dynviews_3059.htm#r36c1-t68">FLASHBACK_CURSOR</a> as the cause. I don&#8217;t understand why Oracle is doing it this way.</p>
<p><span id="more-858"></span></p>
<p>In the OakTable mailing list there was an idea that it could be due to some additional data stored alongside with the child cursor which may be used by the query, such as index validness or object statistics as of different time. This is just an idea, which doesn&#8217;t seem correct to me since with normal queries it&#8217;s very easy to get a re-parse on execute if something changes between the parse and execute calls. Like this:</p>
<pre class="brush: sql; title: ; notranslate">
drop table t cascade constraints purge;
create table t as select * from all_objects;
create index t_indx on t(object_id);
exec dbms_stats.gather_table_stats(user, 't', cascade=&gt;true, no_invalidate=&gt;false)

exec dbms_session.session_trace_enable

var x number
var n varchar2(100)
begin
    <img src='http://s2.wp.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' />  := dbms_sql.open_cursor;
    dbms_sql.parse(:x, 'select object_name from t where object_id = 42', dbms_sql.native);
    dbms_sql.define_column(:x, 1, :n, 100);
end;
/

drop index t_indx;

declare
    l_tmp number := dbms_sql.execute(:x);
begin
    if dbms_sql.fetch_rows(:x) &gt; 0 then
        dbms_sql.column_value(:x, 1, :n);
    end if;
    dbms_sql.close_cursor(:x);
end;
/

exec dbms_session.session_trace_disable
</pre>
<p>I parse a cursor at one point in time, then drop an index on the accessed table and execute the query. And necessary part the trace file is:</p>
<pre class="brush: plain; highlight: [13,18]; title: ; notranslate">
PARSING IN CURSOR #47420142723192 len=177 dep=0 uid=62 oct=47 lid=62 tim=1338964506334918 hv=1969760827 ad='70b47a5d8' sqlid='3mmfzntuqhajv'
begin
    <img src='http://s2.wp.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' />  := dbms_sql.open_cursor;
    dbms_sql.parse(:x, 'select object_name from t where object_id = 42', dbms_sql.native);
    dbms_sql.define_column(:x, 1, :n, 100);
end;
END OF STMT
PARSE #47420142723192:c=0,e=27,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=0,tim=1338964506334917
=====================
PARSING IN CURSOR #47420144475512 len=46 dep=1 uid=62 oct=3 lid=62 tim=1338964506335822 hv=3206175636 ad='6a7f9ef50' sqlid='a75z50azjnqwn'
select object_name from t where object_id = 42
END OF STMT
PARSE #47420144475512:c=1000,e=709,p=0,cr=0,cu=0,mis=1,r=0,dep=1,og=1,plh=4155885868,tim=1338964506335821
WAIT #47420142723192: nam='SQL*Net message to client' ela= 1 driver id=1413697536 #bytes=1 p3=0 obj#=7035526 tim=1338964506335882
EXEC #47420142723192:c=1000,e=922,p=0,cr=0,cu=0,mis=0,r=1,dep=0,og=1,plh=0,tim=1338964506335899
WAIT #47420142723192: nam='SQL*Net message from client' ela= 8405 driver id=1413697536 #bytes=1 p3=0 obj#=7035526 tim=1338964506344329
...
EXEC #47420144475512:c=13998,e=13591,p=0,cr=79,cu=0,mis=1,r=0,dep=1,og=1,plh=1601196873,tim=1338964506406680
FETCH #47420144475512:c=4999,e=4864,p=0,cr=1042,cu=0,mis=0,r=0,dep=1,og=1,plh=1601196873,tim=1338964506411587
STAT #47420144475512 id=1 cnt=0 pid=0 pos=1 obj=7035525 op='TABLE ACCESS FULL T (cr=1042 pr=0 pw=0 time=4864 us cost=235 size=32 card=1)'
CLOSE #47420144475512:c=0,e=4,dep=1,type=0,tim=1338964506411685
</pre>
<p>Notice that the cursor was parsed twice &#8211; first on the PARSE and then on the EXEC call. And the plan at those two calls are different: they have different PLAN_HASH_VALUE (plh).<br />
So this doesn&#8217;t look like a the cause to me. Oracle can do all the associated work on the execute if it needs to.<br />
What else could it be? I&#8217;ve checked how normal and flashback cursors are different in the shared memory chunks using a simple case:</p>
<pre class="brush: sql; title: ; notranslate">
col curr_date new_value curr_date
select to_char(sysdate, 'HH24MISS') curr_date from dual;
set define on serveroutput off

var x number
exec <img src='http://s2.wp.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' />  := dbms_flashback.get_system_change_number
select /* &amp;curr_date */ * from t as of scn <img src='http://s2.wp.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' />  where object_id = 42;

col prev_sql_id new_value sql_id_1
select prev_sql_id from v$session where sid = userenv('sid');

exec <img src='http://s2.wp.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' />  := 42
select /* &amp;curr_date */ * from t where object_id = <img src='http://s2.wp.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' /> ;

col prev_sql_id  new_value sql_id_2
select prev_sql_id from v$session where sid = userenv('sid');

select function, chunk_com from v$sql_shared_memory where sql_id = '&amp;sql_id_1'
minus
select function, chunk_com from v$sql_shared_memory where sql_id = '&amp;sql_id_2';
</pre>
<p>With the help of <a href="http://docs.oracle.com/cd/E11882_01/server.112/e25513/dynviews_3060.htm#REFRN30255">V$SQL_SHARED_MEMORY</a>  it&#8217;s easy to check what&#8217;s inside shared cursors. And it looks like a simple flashback cursor has only 3 more chunks allocated:</p>
<pre class="brush: plain; title: ; notranslate">
FUNCTION                                                         CHUNK_COM
---------------------------------------------------------------- ----------------
kkfdParal                                                        pqctx:kkfdParal
ktfxfsnp                                                         qeSnp: ktfxfsnp
qkexrXfo                                                         ub1[]: qkexrXfo
</pre>
<p>On a 10.2.0.4 the final query produced no output at all, which makes me think that there&#8217;s nothing significant inside a flashback cursor. So why it works this way? I guess it&#8217;s to make things easier in implementation. With a new child for each flashback query execution there&#8217;s no need to check that executions plan is valid. With a DDL (drop index in my example) it&#8217;s a different story &#8211; it invalidates dependent cursors and on the execution attempt Oracle knows that the plan is no longer valid. Kind of hard making the same for flashback query. How to implement objects dependency for any given point in time? The simplest approach in my opinion is &#8220;just don&#8217;t&#8221; and try using an existent flashback child cursor and in case of an error &#8211; like missing index at this point in time &#8211; build a new cursor. I have no idea if it&#8217;s doable or not, but I&#8217;d like to see it implemented. We use flashback query; it causes hundreds of child cursors to appear in Oracle versions before 11.2.0.3 (this version <a href="http://timurakhmadeev.wordpress.com/2012/03/19/obsolete-cursors/">limits</a> number of child cursors to 100 by default). Of course they should be purged from shared pool relatively quickly, but still this could be done better.</p>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/oracle/'>Oracle</a> Tagged: <a href='http://timurakhmadeev.wordpress.com/tag/flashback-query/'>flashback query</a>, <a href='http://timurakhmadeev.wordpress.com/tag/shared-cursors/'>shared cursors</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/858/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/858/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=858&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2012/06/06/flashback-cursors/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>
	</item>
		<item>
		<title>ORA-600 Troubleshooting Tool</title>
		<link>http://timurakhmadeev.wordpress.com/2012/05/14/ora-600-troubleshooting-tool/</link>
		<comments>http://timurakhmadeev.wordpress.com/2012/05/14/ora-600-troubleshooting-tool/#comments</comments>
		<pubDate>Mon, 14 May 2012 14:27:52 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[ORA-00600]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=847</guid>
		<description><![CDATA[I&#8217;ve just noticed that the new HTML MOS introduced a nice addition to the old ORA-600/ORA-7445 Error Look-up Tool: now there is a new ORA-600 Troubleshooting Tool (if the link is not opened automatically for you try refreshing the page with F5 &#8211; works for me in Chrome). Within a few minutes it allows you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=847&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve just noticed that the new HTML MOS introduced a nice addition to the old <a href="https://support.oracle.com/CSP/main/article?cmd=show&amp;type=NOT&amp;doctype=TROUBLESHOOTING&amp;id=153788.1">ORA-600/ORA-7445 Error Look-up Tool</a>: now there is a new <a href="https://supporthtml.oracle.com/epmos/faces/ui/gr/GrHome.jspx?domainId=ORA600">ORA-600 Troubleshooting Tool</a> (if the link is not opened automatically for you try refreshing the page with F5 &#8211; works for me in Chrome).<br />
Within a few minutes it allows you to upload a generated trace file and then automatically redirects you to the search results based on the error reported in the trace. The tool should be useful to those who don&#8217;t know what to do with the trace. It also allows you to save the results in a &#8220;report&#8221;. It&#8217;s definitely a very nice addition to the MOS functionality.</p>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/oracle/'>Oracle</a> Tagged: <a href='http://timurakhmadeev.wordpress.com/tag/ora-00600/'>ORA-00600</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/847/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/847/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=847&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2012/05/14/ora-600-troubleshooting-tool/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>
	</item>
		<item>
		<title>Statistics poll</title>
		<link>http://timurakhmadeev.wordpress.com/2012/04/16/statistics-poll/</link>
		<comments>http://timurakhmadeev.wordpress.com/2012/04/16/statistics-poll/#comments</comments>
		<pubDate>Mon, 16 Apr 2012 19:55:22 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=833</guid>
		<description><![CDATA[Thanks to everyone for spreading the link and participating in the poll on statistics. As it was pointed out in the comments, the poll isn&#8217;t very specific, I know. My point was to get an idea how many people use the defaults (I considered Oracle version 11g) for stats collection, how many do a very [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=833&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Thanks to everyone for spreading the link and participating <a href="http://timurakhmadeev.wordpress.com/2012/04/09/method_opt/">in the poll</a> on statistics. As it was pointed out in the comments, the poll isn&#8217;t very specific, I know. My point was to get an idea how many people use the defaults (I considered Oracle version 11g) for stats collection, how many do a very simple and reasonable <a href="http://www.pythian.com/news/867/stabilize-oracle-10gs-bind-peeking-behaviour-by-cutting-histograms/">tweak to get more stable execution plans</a>, and how many people prefer custom statistics management. Well, I think the results will not change much and here are as following (326 votes at the time of writing):</p>
<ul>
<li><strong>42%</strong> use the defaults (if you <em>truncate</em> the value. I can&#8217;t put something other than 42 here, sorry guys <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> )</li>
<li><strong>16%</strong> don&#8217;t like <a href="http://www.youtube.com/watch?v=USHHQRodF88">unexpected histograms</a> <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' />  and prefer to take situation under control</li>
<li>OMG another <strong>42%</strong> (since it&#8217;s not <a href="http://gawker.com/5864945/putin-clings-to-victory-as-russias-voter-turnout-exceeds-146">Russian elections</a> it has to be 100% in total, you know) use custom statistics management</li>
</ul>
<p>Nice! Now we know that the defaults are suited to less than a half of Oracle installations. And my opinion is there would be more than a half using the defaults, should Oracle decided to switch the default METHOD_OPT value to &#8216;FOR ALL COLUMNS SIZE REPEAT&#8217;. Consider Tim Hall&#8217;s reply &#8220;On low priority systems the defaults are fine in many cases&#8221;, and think about why defaults are fine for such systems? My humble opinion is: nobody cares about low priority systems. So it doesn&#8217;t really matter if it&#8217;s reliable or not, whether there are histograms present or not, whether a system is stable or not &#8211; it&#8217;s low priority anyway. It will survive <em>somehow</em>. For me it means it&#8217;s not too much of a problem to go back <del>to the future</del> and modify default METHOD_OPT so that no histograms are gathered initially by default &#8211; as all should do manually now /me thinks.<br />
PS. I wouldn&#8217;t mind switching GATHER_TEMP back to the FALSE and returning it to the documentation too, as <a href="http://docs.oracle.com/cd/B10501_01/appdev.920/a96612/d_stats2.htm#1003995">it was in 9i</a>.</p>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/oracle/'>Oracle</a> Tagged: <a href='http://timurakhmadeev.wordpress.com/tag/statistics/'>statistics</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/833/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/833/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=833&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2012/04/16/statistics-poll/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>
	</item>
		<item>
		<title>Information exchange</title>
		<link>http://timurakhmadeev.wordpress.com/2012/04/16/information-exchange/</link>
		<comments>http://timurakhmadeev.wordpress.com/2012/04/16/information-exchange/#comments</comments>
		<pubDate>Mon, 16 Apr 2012 18:51:59 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[blogs]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=830</guid>
		<description><![CDATA[This is a short note on the topic of information exchange. I use OraNA.info to get up-to-date technology news. This is a blog aggregator I&#8217;ve tried first and have been using it since then, which is 3-4 years I guess. It&#8217;s great and I&#8217;d like to use this opportunity to say Thank You to Eddie [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=830&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This is a short note on the topic of information exchange. I use <a href="http://orana.info/">OraNA.info</a> to get up-to-date technology news. This is a blog aggregator I&#8217;ve tried first and have been using it since then, which is 3-4 years I guess. It&#8217;s great <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  and I&#8217;d like to use this opportunity to say Thank You to Eddie Awad for a great blogs collection!<br />
If you still don&#8217;t use blog aggregators and rely on your own blog collection in Google Reader or something else, then consider using one entry point instead of multiple, it&#8217;s much easier. Also I&#8217;d like to suggest using <a href="http://awads.net/wp/contact/">contact form</a> on the OraNA to suggest new blogs if you know some which are not <a href="http://orana.info/aggregated-blogs/">aggregated</a>. I use it regularly when I find something interesting; I have contributed about a dozen of new blogs to OraNA so far. You can [should] do the same.</p>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/other/'>Other</a> Tagged: <a href='http://timurakhmadeev.wordpress.com/tag/blogs/'>blogs</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/830/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/830/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=830&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2012/04/16/information-exchange/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>
	</item>
		<item>
		<title>METHOD_OPT</title>
		<link>http://timurakhmadeev.wordpress.com/2012/04/09/method_opt/</link>
		<comments>http://timurakhmadeev.wordpress.com/2012/04/09/method_opt/#comments</comments>
		<pubDate>Mon, 09 Apr 2012 18:58:05 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[defaults]]></category>
		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=825</guid>
		<description><![CDATA[Here is a poll prompted by today twitter talks on the default METHOD_OPT value (which is &#8216;for all columns size auto&#8217; since 10g) and automatic statistics gathering job (auto-task since 11g). CBO development team suggests to use the default job to gather statistics with default options. Do you use the job exactly this way with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=825&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Here is a poll prompted by today twitter talks on the default METHOD_OPT value (which is &#8216;for all columns size auto&#8217; since 10g) and automatic statistics gathering job (auto-task since 11g). CBO development team <a href="https://blogs.oracle.com/optimizer/entry/lies_damned_lies_and_statistics1">suggests</a> to use the default job to gather statistics with default options. Do you use the job exactly this way with real production databases? I&#8217;m very interested to see some numbers. Please share the poll link <a href="http://poll.fm/3n7pn">http://poll.fm/3n7pn</a> so that more people vote. Thanks.<br />
<a name="pd_a_6121931"></a>
<div class="PDS_Poll" id="PDI_container6121931" data-settings="{&quot;url&quot;:&quot;http:\/\/static.polldaddy.com\/p\/6121931.js&quot;}" style="display:inline-block;"></div>
<div id="PD_superContainer"></div>
<noscript><a href="http://polldaddy.com/poll/6121931">Take Our Poll</a></noscript></p>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/oracle/'>Oracle</a> Tagged: <a href='http://timurakhmadeev.wordpress.com/tag/defaults/'>defaults</a>, <a href='http://timurakhmadeev.wordpress.com/tag/statistics/'>statistics</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/825/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/825/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=825&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2012/04/09/method_opt/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>
	</item>
		<item>
		<title>Fail</title>
		<link>http://timurakhmadeev.wordpress.com/2012/04/05/fail/</link>
		<comments>http://timurakhmadeev.wordpress.com/2012/04/05/fail/#comments</comments>
		<pubDate>Thu, 05 Apr 2012 19:18:38 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[flashback database]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=821</guid>
		<description><![CDATA[The post reminded me of my own fail happened several months ago. I was in a performance testing project on a customer&#8217;s environment. It was RAC and included two DBs plus two standbys. In the process of testing it was necessary to rollback changes made to the databases during one test run. Flashback database was [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=821&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>The <a href="http://www.thatjeffsmith.com/archive/2012/04/that-time-i-accidentally-deleted-all-the-oracle-databases/">post</a> reminded me of my own fail happened several months ago.</p>
<p><span id="more-821"></span></p>
<p>I was in a performance testing project on a customer&#8217;s environment. It was RAC and included two DBs plus two standbys. In the process of testing it was necessary to rollback changes made to the databases during one test run. Flashback database was chosen as a way to do that. The approach was tested by DBAs and we&#8217;ve started working according to our plan. Unfortunately Flashback didn&#8217;t work out very well. Minor issues with available space in fast recovery area were solved, but more importantly the procedure took valuable DBA&#8217;s time and made our project highly contended on shared resource <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  That was very bad because we were out of the plan by a week (or two) already. So after pushing hard we were given direct access to the databases to not disturb DBAs and to do everything we need by ourselves. That &#8220;we&#8221; was me of course.<br />
Now little background how do I feel about mine DBA skills. Obviously I can do everything <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  in some time &#8211; and depending on the topic the time it will take me to do something will vary from seconds to days or maybe weeks. With the backup and recovery I was at the level of absolute zero: I&#8217;ve never done PITR; I&#8217;ve never done flashback DB; I&#8217;ve never used RMAN. So you can imagine that for me doing all that wasn&#8217;t easy and it wasn&#8217;t fun either due to time pressure.<br />
Anyway after I&#8217;ve tried it and it worked pretty easy I&#8217;ve decided that doing it manually is so boring and time consuming that I need a script. Especially since I knew I will need to repeat the same operation several dozen times in the next weeks.<br />
Now little background how do I feel about my scripting abilities. Obviously I can do everything <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' />  but my scripting skill is on a level similar to DBA. So I spent several hours to come up with something that will do the right thing in reasonable time. It was actually several scripts with one main entry point that called other scripts concurrently. The problem was: nor did I have time to test, nor did I have a test environment. So I was very nervous when I launched it like this: </p>
<pre class="brush: plain; title: ; notranslate">./flashback.sh &quot;20120405 18:00&quot;</pre>
<p>And I was so happy it finished without any error! It actually flashed back all 4 databases. The only problem was, as it turned out, the date was not correct. The time portion was ignored. I didn&#8217;t forget to include double apostrophes on the command line, but I forgot to add them inside the main script, which passed the parameter to the next scripts. And then, in turn, the date became two parameters instead of one. So when actually flashback database to timestamp command was issued the date was without time!! OMFG that was 1 day of work lost&#8230;<br />
Now I know that it was too stupid to try it this way. Anyway after fixing the error the script was successfully used many times and usually worked about 20 minutes &#8211; that was good. Well, sometimes it didn&#8217;t work due to ORA-600, but that&#8217;s a different story.</p>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/oracle/'>Oracle</a> Tagged: <a href='http://timurakhmadeev.wordpress.com/tag/flashback-database/'>flashback database</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/821/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/821/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=821&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2012/04/05/fail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>
	</item>
		<item>
		<title>Statspack quiz</title>
		<link>http://timurakhmadeev.wordpress.com/2012/04/03/statspack-quiz/</link>
		<comments>http://timurakhmadeev.wordpress.com/2012/04/03/statspack-quiz/#comments</comments>
		<pubDate>Tue, 03 Apr 2012 13:25:47 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[quiz]]></category>
		<category><![CDATA[Statspack]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=815</guid>
		<description><![CDATA[I&#8217;ve a level 5 Statspack report from a real production 11.2.0.2 database with the following Top 5 Timed events section: The complete report (without SQL and several other sections) is here. Can you explain what &#38; why is wrong in this Top? I must admit I don&#8217;t have the definitive answer (probably yet), but I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=815&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve a level 5 Statspack report from a real production 11.2.0.2 database with the following Top 5 Timed events section:</p>
<pre class="brush: sql; title: ; notranslate">
Top 5 Timed Events                                                    Avg %Total
~~~~~~~~~~~~~~~~~~                                                   wait   Call
Event                                            Waits    Time (s)   (ms)   Time
----------------------------------------- ------------ ----------- ------ ------
log buffer space                                    28       1,396  49870   41.0
buffer busy waits                                   51       1,049  20567   30.8
CPU time                                                       320           9.4
log file parallel write                          4,011         159     40    4.7
log file sync                                    3,275         153     47    4.5
</pre>
<p>The complete report (without SQL and several other sections) is <a href="http://dl.dropbox.com/u/60615479/sp_13316_13324.lst">here</a>. Can you explain what &amp; why is wrong in this Top?<br />
I must admit I don&#8217;t have the definitive answer (probably yet), but I have partial explanation of the issue as well as several ideas.</p>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/oracle/'>Oracle</a>, <a href='http://timurakhmadeev.wordpress.com/category/performance/'>Performance</a> Tagged: <a href='http://timurakhmadeev.wordpress.com/tag/quiz/'>quiz</a>, <a href='http://timurakhmadeev.wordpress.com/tag/statspack/'>Statspack</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/815/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/815/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=815&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2012/04/03/statspack-quiz/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>
	</item>
		<item>
		<title>Patents</title>
		<link>http://timurakhmadeev.wordpress.com/2012/03/22/patents/</link>
		<comments>http://timurakhmadeev.wordpress.com/2012/03/22/patents/#comments</comments>
		<pubDate>Thu, 22 Mar 2012 18:21:20 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=809</guid>
		<description><![CDATA[If you you want to get an idea how some feature may be implemented by Oracle, then you ought to have a look for patents. Here are several examples I find quite interesting and containing valuable information: Method and apparatus for reapplying changes to a database &#8211; gives you an algorithm how Oracle optimizes recovery [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=809&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>If you you want to get an idea how some feature may be implemented by Oracle, then you ought to have a look for <a href="https://www.google.com/search?q=assignee%3Aoracle&amp;btnG=Search+Patents&amp;tbm=pts&amp;tbo=1&amp;hl=en">patents</a>. Here are several examples I find quite interesting and containing valuable information:</p>
<ul>
<li><a href="http://www.google.com/patents/US5974425">Method and apparatus for reapplying changes to a database</a> &#8211; gives you an algorithm how Oracle optimizes recovery process</li>
<li><a href="http://www.google.com/patents/US7039773">Method and mechanism for efficient implementation of ordered records</a> &#8211; another redo-related patent with the title hiding concept of multiple redo log buffers</li>
<li><a href="http://www.google.com/patents/US6618822">Method and mechanism for relational access of recovery logs in a database system</a> &#8211; basically it&#8217;s describing LogMiner</li>
<li><a href="http://www.google.com/patents/US20110208757">METHOD AND SYSTEM FOR IMPLEMENTING EFFICIENT CURSOR PRUNING</a> &#8211; a very good-looking patent that describes how Oracle handles sharing of the child cursors nicely. Actually after reading this I realized that V$SQL_SHARED_CURSOR isn&#8217;t just an informational data supplied for diagnostic purpose, but rather it&#8217;s used and supported by Oracle to minimize number of comparisons while searching for a child with the required properties.</li>
<li><a href="http://www.google.com/patents/US20090037404">EXTENDED CURSOR SHARING</a> &#8211; this one is also on the topic of cursor sharing features related to adaptive optimization in run-time</li>
<li><a href="http://www.google.com/patents/US20050132383">Compilation and processing a parallel single cursor model</a> &#8211; describes the way in which a database can build and use parallel cursor without additional slave SQL. This is what Oracle does since 10g.</li>
</ul>
<p>The list can go on. Just use &#8220;assignee:oracle&#8221; in the search box if you want to see Oracle&#8217;s patents only. What I like the most in these documents is they are unique. You will rarely find such a precisely described algorithms with block diagrams describing inner workings of a potential database system. Of course the information in patents is not the exact features description, nevertheless I find it quite useful. </p>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/oracle/'>Oracle</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/809/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/809/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=809&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2012/03/22/patents/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>
	</item>
		<item>
		<title>Obsolete cursors</title>
		<link>http://timurakhmadeev.wordpress.com/2012/03/19/obsolete-cursors/</link>
		<comments>http://timurakhmadeev.wordpress.com/2012/03/19/obsolete-cursors/#comments</comments>
		<pubDate>Mon, 19 Mar 2012 11:35:18 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[11.2.0.3]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[dynamic views]]></category>
		<category><![CDATA[shared cursors]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=801</guid>
		<description><![CDATA[In the previous post I wrote about strangely behaving V$SQL. For some reason there were duplicate rows leading to wrong results issue when running DBMS_XPLAN.DISPLAY_CURSOR for a particular child cursor. I tried to reproduce the issue using simple test case &#8211; and it was reproduced. Here it is. I&#8217;m starting to execute a simple query [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=801&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In the <a href="http://timurakhmadeev.wordpress.com/2012/03/15/vsql-is_obsolete/">previous post</a> I wrote about strangely behaving V$SQL. For some reason there were duplicate rows leading to wrong results issue when running DBMS_XPLAN.DISPLAY_CURSOR for a particular child cursor. I tried to reproduce the issue using simple test case &#8211; and it was reproduced.</p>
<p><span id="more-801"></span></p>
<p>Here it is. I&#8217;m starting to execute a simple query against DUAL while constantly changing optimizer environment, forcing Oracle to build a new child cursor for each execution:</p>
<pre class="brush: sql; title: ; notranslate">
alter session set workarea_size_policy=manual;
col curr_date new_value curr_date
select to_char(sysdate, 'HH24MISS') curr_date from dual;
set define on verify off

begin
    for i in 1..100 loop
        execute immediate 'alter session set sort_area_size=' || to_char(100000 + i*1024);
        execute immediate 'select /* &amp;&amp;curr_date */ count(*) from dual';
    end loop;
end;
/

col sql_id new_value sql_id
select sql_id, address from v$sqlarea where sql_text = 'select /* &amp;&amp;curr_date */ count(*) from dual';
clear columns
select count(*) from v$sql_shared_cursor where sql_id = '&amp;&amp;sql_id';
@unshared &amp;&amp;sql_id
</pre>
<p>As expected, I&#8217;ve got 100 child cursors and 99 of them were created due to OPTIMIZER_MISMATCH:</p>
<pre class="brush: sql; title: ; notranslate">
SQL&gt; select sql_id, address from v$sqlarea where sql_text = 'select /* &amp;&amp;curr_date */ count(*) from dual';

SQL_ID        ADDRESS
------------- ----------------
8ugq0vhq0z7pb 000007FF5D45C0B0

SQL&gt; clear columns
columns cleared
SQL&gt; select count(*) from v$sql_shared_cursor where sql_id = '&amp;&amp;sql_id';

            COUNT(*)
--------------------
                 100

SQL&gt; @unshared &amp;&amp;sql_id

SQL_ID        NONSHARED_REASON                          COUNT(*)
------------- ----------------------------- --------------------
8ugq0vhq0z7pb OPTIMIZER_MISMATCH                              99
</pre>
<p>Now let&#8217;s continue and see what will happen:</p>
<pre class="brush: sql; title: ; notranslate">
begin
    for i in 101..250 loop
        execute immediate 'alter session set sort_area_size=' || to_char(100000 + i*1024);
        execute immediate 'select /* &amp;&amp;curr_date */ count(*) from dual';
    end loop;
end;
/

select count(*) from v$sql_shared_cursor where sql_id = '&amp;&amp;sql_id';

select sum(cnt), avg(cnt), min(child_number), max(child_number)
  from (select child_number, count(*) cnt
          from v$sql
         where sql_id = '&amp;&amp;sql_id'
         group by child_number);

select address, count(*) from v$sql where sql_id='&amp;&amp;sql_id' group by address;
select sql_id, address from v$sqlarea where sql_text = 'select /* &amp;&amp;curr_date */ count(*) from dual';
@unshared &amp;&amp;sql_id
select * from table(dbms_xplan.display_cursor('&amp;&amp;sql_id', 1));
</pre>
<pre class="brush: sql; title: ; notranslate">
SQL&gt; select count(*) from v$sql_shared_cursor where sql_id = '&amp;&amp;sql_id';

            COUNT(*)
--------------------
                 250

SQL&gt;
SQL&gt; select sum(cnt), avg(cnt), min(child_number), max(child_number)
  2    from (select child_number, count(*) cnt
  3            from v$sql
  4           where sql_id = '&amp;&amp;sql_id'
  5           group by child_number);

            SUM(CNT)             AVG(CNT)    MIN(CHILD_NUMBER)    MAX(CHILD_NUMBER)
-------------------- -------------------- -------------------- --------------------
                 250                  2.5                    0                   99

SQL&gt;
SQL&gt; select address, count(*) from v$sql where sql_id='&amp;&amp;sql_id' group by address;

ADDRESS                      COUNT(*)
---------------- --------------------
000007FF5D1E18A8                   50
000007FF5D45C0B0                  100
000007FF5D5BA268                  100

SQL&gt; select sql_id, address from v$sqlarea where sql_text = 'select /* &amp;&amp;curr_date */ count(*) from dual';

SQL_ID        ADDRESS
------------- ----------------
8ugq0vhq0z7pb 000007FF5D1E18A8

SQL&gt; @unshared &amp;&amp;sql_id

SQL_ID        NONSHARED_REASON                          COUNT(*)
------------- ----------------------------- --------------------
8ugq0vhq0z7pb OPTIMIZER_MISMATCH                             249

SQL&gt; select * from table(dbms_xplan.display_cursor('&amp;&amp;sql_id', 1));

PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------------------------------
SQL_ID  8ugq0vhq0z7pb, child number 1
-------------------------------------
An uncaught error happened in prepare_sql_statement : ORA-01422: exact fetch returns more than requested number of rows

Plan hash value: 3910148636

-----------------------------------------------------------------
| Id  | Operation        | Name | Rows  | Cost (%CPU)| Time     |
-----------------------------------------------------------------
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
-----------------------------------------------------------------

SQL_ID  8ugq0vhq0z7pb, child number 1
-------------------------------------
An uncaught error happened in prepare_sql_statement : ORA-01422: exact fetch returns more than requested number of rows

Plan hash value: 3910148636

-----------------------------------------------------------------
| Id  | Operation        | Name | Rows  | Cost (%CPU)| Time     |
-----------------------------------------------------------------
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
-----------------------------------------------------------------

SQL_ID  8ugq0vhq0z7pb, child number 1
-------------------------------------
An uncaught error happened in prepare_sql_statement : ORA-01422: exact fetch returns more than requested number of rows

Plan hash value: 3910148636

-----------------------------------------------------------------
| Id  | Operation        | Name | Rows  | Cost (%CPU)| Time     |
-----------------------------------------------------------------
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   0 | SELECT STATEMENT |      |       |     2 (100)|          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   1 |  SORT AGGREGATE  |      |     1 |            |          |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
|   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
-----------------------------------------------------------------


114 rows selected.
</pre>
<p>Bingo. After the point of 100 child cursors per parent, Oracle builds a new parent (V$SQL.ADDRESS holds its address) cursor, marking old parent and child cursors as obsolete. V$SQLAREA handles the situation well, but V$SQL doesn&#8217;t and that&#8217;s clearly a bug. The threshold point of when to build a new parent cursor is 100 by default and is controlled with a new hidden parameter <b>_cursor_obsolete_threshold</b>. I&#8217;ve tested setting this parameter to 150 and it worked as expected. Note that this bug-fix-improvement-again-bugs <a href="https://support.oracle.com/CSP/main/article?cmd=show&amp;type=NOT&amp;doctype=PATCH&amp;id=10187168.8">10187168</a> claimed to be included into Patch Set Update 11.2.0.2.2 (and higher). I&#8217;ve tested 11.2.0.2.3 &amp; 11.2.0.2.5 and it seems the improvement is not enabled by default and they act the old, pre-11.2.0.3 way; most likely the bug-fix have to be enabled explicitly with event 106001 in the 11.2.0.2 PSUs. I haven&#8217;t tested it though.<br />
PS. If you have time and desire, please file a bug to Oracle.</p>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/oracle/'>Oracle</a> Tagged: <a href='http://timurakhmadeev.wordpress.com/tag/11-2-0-3/'>11.2.0.3</a>, <a href='http://timurakhmadeev.wordpress.com/tag/bug/'>bug</a>, <a href='http://timurakhmadeev.wordpress.com/tag/dynamic-views/'>dynamic views</a>, <a href='http://timurakhmadeev.wordpress.com/tag/shared-cursors/'>shared cursors</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/801/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/801/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=801&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2012/03/19/obsolete-cursors/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>
	</item>
		<item>
		<title>V$SQL.IS_OBSOLETE</title>
		<link>http://timurakhmadeev.wordpress.com/2012/03/15/vsql-is_obsolete/</link>
		<comments>http://timurakhmadeev.wordpress.com/2012/03/15/vsql-is_obsolete/#comments</comments>
		<pubDate>Thu, 15 Mar 2012 18:11:14 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[11.2.0.3]]></category>
		<category><![CDATA[bug-or-feature]]></category>
		<category><![CDATA[dynamic views]]></category>
		<category><![CDATA[shared cursors]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=794</guid>
		<description><![CDATA[The column is there for a long time &#8211; even 9i documentation have it. I&#8217;ve never thought about it until today when I caought something extraordinary on 11.2.0.3 instance. Starting with 10g oracle introduced SQL_ID for simplicity; it is used in combination with CHILD_NUMBER to locate a particular row in the V$SQL. The documentation is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=794&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>The column is there for a long time &#8211; even <a href="http://docs.oracle.com/cd/B10501_01/server.920/a96536/ch3191.htm#1124440">9i documentation</a> have it. I&#8217;ve never thought about it until today when I caought something extraordinary on 11.2.0.3 instance.</p>
<p><span id="more-794"></span></p>
<p>Starting with 10g oracle introduced <a href="http://blog.tanelpoder.com/2009/02/22/sql_id-is-just-a-fancy-representation-of-hash-value/">SQL_ID</a> for simplicity; it is used in combination with CHILD_NUMBER to locate a particular row in the V$SQL. The documentation is clear (bold is mine):</p>
<blockquote><p>V$SQL lists statistics on shared SQL areas without the GROUP BY clause and contains <strong>one row for each child</strong> of the original SQL text entered</p></blockquote>
<p>Today I&#8217;ve seen a query that was running too long on a 11.2.0.3 instance. I&#8217;ve tried to get its runtime execution plan with DBMS_XPLA.DISPLAY_CURSOR, as I usually do, and it took literally a minute to get it although I&#8217;ve supplied CHILD_NUMBER and there was no much load on the DB. It was strange. When I got the result I was astonished. DISPLAY_CURSOR selected more than 80K rows and the plan was a total mess composed of numerous identical plans merged together. WTF?! I&#8217;ve started looking around and noticed that parent cursor has 1800+ child cursors &#8211; absolutely no good situation. Since there&#8217;s no <a href="http://timurakhmadeev.wordpress.com/2012/02/21/oracle-database-features-wish-list-2-vsql_unshared_cursor/">v$sql_unshared_cursor</a> (yet <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ) to show why there are so many child cursors in easy way, I wrote a query to return something like this with what I have right now &#8211; V$SQL_SHARED_CURSOR + DBA_TAB_COLS:</p>
<pre class="brush: sql; title: ; notranslate">
select * from
(select sql_id, nonshared_reason, count(*) from v$sql_shared_cursor
unpivot
(nonshared_value for nonshared_reason in (
UNBOUND_CURSOR as 'UNBOUND_CURSOR',
SQL_TYPE_MISMATCH as 'SQL_TYPE_MISMATCH',
OPTIMIZER_MISMATCH as 'OPTIMIZER_MISMATCH',
OUTLINE_MISMATCH as 'OUTLINE_MISMATCH',
STATS_ROW_MISMATCH as 'STATS_ROW_MISMATCH',
LITERAL_MISMATCH as 'LITERAL_MISMATCH',
FORCE_HARD_PARSE as 'FORCE_HARD_PARSE',
EXPLAIN_PLAN_CURSOR as 'EXPLAIN_PLAN_CURSOR',
BUFFERED_DML_MISMATCH as 'BUFFERED_DML_MISMATCH',
PDML_ENV_MISMATCH as 'PDML_ENV_MISMATCH',
INST_DRTLD_MISMATCH as 'INST_DRTLD_MISMATCH',
SLAVE_QC_MISMATCH as 'SLAVE_QC_MISMATCH',
TYPECHECK_MISMATCH as 'TYPECHECK_MISMATCH',
AUTH_CHECK_MISMATCH as 'AUTH_CHECK_MISMATCH',
BIND_MISMATCH as 'BIND_MISMATCH',
DESCRIBE_MISMATCH as 'DESCRIBE_MISMATCH',
LANGUAGE_MISMATCH as 'LANGUAGE_MISMATCH',
TRANSLATION_MISMATCH as 'TRANSLATION_MISMATCH',
BIND_EQUIV_FAILURE as 'BIND_EQUIV_FAILURE',
INSUFF_PRIVS as 'INSUFF_PRIVS',
INSUFF_PRIVS_REM as 'INSUFF_PRIVS_REM',
REMOTE_TRANS_MISMATCH as 'REMOTE_TRANS_MISMATCH',
LOGMINER_SESSION_MISMATCH as 'LOGMINER_SESSION_MISMATCH',
INCOMP_LTRL_MISMATCH as 'INCOMP_LTRL_MISMATCH',
OVERLAP_TIME_MISMATCH as 'OVERLAP_TIME_MISMATCH',
EDITION_MISMATCH as 'EDITION_MISMATCH',
MV_QUERY_GEN_MISMATCH as 'MV_QUERY_GEN_MISMATCH',
USER_BIND_PEEK_MISMATCH as 'USER_BIND_PEEK_MISMATCH',
TYPCHK_DEP_MISMATCH as 'TYPCHK_DEP_MISMATCH',
NO_TRIGGER_MISMATCH as 'NO_TRIGGER_MISMATCH',
FLASHBACK_CURSOR as 'FLASHBACK_CURSOR',
ANYDATA_TRANSFORMATION as 'ANYDATA_TRANSFORMATION',
PDDL_ENV_MISMATCH as 'PDDL_ENV_MISMATCH',
TOP_LEVEL_RPI_CURSOR as 'TOP_LEVEL_RPI_CURSOR',
DIFFERENT_LONG_LENGTH as 'DIFFERENT_LONG_LENGTH',
LOGICAL_STANDBY_APPLY as 'LOGICAL_STANDBY_APPLY',
DIFF_CALL_DURN as 'DIFF_CALL_DURN',
BIND_UACS_DIFF as 'BIND_UACS_DIFF',
PLSQL_CMP_SWITCHS_DIFF as 'PLSQL_CMP_SWITCHS_DIFF',
CURSOR_PARTS_MISMATCH as 'CURSOR_PARTS_MISMATCH',
STB_OBJECT_MISMATCH as 'STB_OBJECT_MISMATCH',
CROSSEDITION_TRIGGER_MISMATCH as 'CROSSEDITION_TRIGGER_MISMATCH',
PQ_SLAVE_MISMATCH as 'PQ_SLAVE_MISMATCH',
TOP_LEVEL_DDL_MISMATCH as 'TOP_LEVEL_DDL_MISMATCH',
MULTI_PX_MISMATCH as 'MULTI_PX_MISMATCH',
BIND_PEEKED_PQ_MISMATCH as 'BIND_PEEKED_PQ_MISMATCH',
MV_REWRITE_MISMATCH as 'MV_REWRITE_MISMATCH',
ROLL_INVALID_MISMATCH as 'ROLL_INVALID_MISMATCH',
OPTIMIZER_MODE_MISMATCH as 'OPTIMIZER_MODE_MISMATCH',
PX_MISMATCH as 'PX_MISMATCH',
MV_STALEOBJ_MISMATCH as 'MV_STALEOBJ_MISMATCH',
FLASHBACK_TABLE_MISMATCH as 'FLASHBACK_TABLE_MISMATCH',
LITREP_COMP_MISMATCH as 'LITREP_COMP_MISMATCH',
PLSQL_DEBUG as 'PLSQL_DEBUG',
LOAD_OPTIMIZER_STATS as 'LOAD_OPTIMIZER_STATS',
ACL_MISMATCH as 'ACL_MISMATCH',
FLASHBACK_ARCHIVE_MISMATCH as 'FLASHBACK_ARCHIVE_MISMATCH',
LOCK_USER_SCHEMA_FAILED as 'LOCK_USER_SCHEMA_FAILED',
REMOTE_MAPPING_MISMATCH as 'REMOTE_MAPPING_MISMATCH',
LOAD_RUNTIME_HEAP_FAILED as 'LOAD_RUNTIME_HEAP_FAILED',
HASH_MATCH_FAILED as 'HASH_MATCH_FAILED',
PURGED_CURSOR as 'PURGED_CURSOR',
BIND_LENGTH_UPGRADEABLE as 'BIND_LENGTH_UPGRADEABLE',
USE_FEEDBACK_STATS as 'USE_FEEDBACK_STATS'
))
where nonshared_value = 'Y'
group by sql_id, nonshared_reason
)
where sql_id = :sql_id
</pre>
<p>And the result was</p>
<pre class="brush: plain; title: ; notranslate">
NONSHARED_REASON                          COUNT(*)
----------------------------- --------------------
INSUFF_PRIVS_REM                              1815
AUTH_CHECK_MISMATCH                           1815
</pre>
<p>The query uses DB links, so I was not surprised to see the reason of non-shared cursors as &#8220;Insufficient privileges on remote objects referenced by the existing child cursor&#8221;. But why so many of them? I don&#8217;t know. Maybe it is supposed to work this way &#8211; if an error is caused by insufficient privileges on a remote system, Oracle marks child as &#8220;wrong&#8221; and tries again next time with a new child. It sounds like an easy implementation option but looks very clumsy.<br />
I looked at a particular child cursor and&#8230;</p>
<pre class="brush: sql; title: ; notranslate">SQL&gt; select sql_id, child_address from v$sql where sql_id = '22d06uj1ut8d4' and child_number = 63;

SQL_ID        CHILD_ADDRESS
------------- ----------------
22d06uj1ut8d4 00000002C76328D0
22d06uj1ut8d4 00000002CF528C90
22d06uj1ut8d4 00000002D45C6E58
22d06uj1ut8d4 00000002AF4C1470
22d06uj1ut8d4 00000002AF3D8C10
22d06uj1ut8d4 00000002C78AD830
22d06uj1ut8d4 00000002971BF538
22d06uj1ut8d4 00000002864ABFF0
22d06uj1ut8d4 00000002B7FAC550
22d06uj1ut8d4 00000002BFC95E50
22d06uj1ut8d4 00000002A7AB1B98
22d06uj1ut8d4 000000029E76EAA8
22d06uj1ut8d4 00000002B67A7C38
22d06uj1ut8d4 000000027F23AFF8
22d06uj1ut8d4 0000000276EF9040
22d06uj1ut8d4 00000002969C4A68
22d06uj1ut8d4 00000002BEC691C8
22d06uj1ut8d4 00000002869F2AF0

18 rows selected.</pre>
<p>Wow. This just can&#8217;t be right. Next I run a query to see if this behavior is system-wide or cursor-specific and it turned out it&#8217;s cursor-specific. No other cursors have more than 1 row with the same SQL_ID and CHILD_NUMBER in V$SQL. After some more experiments it turned out that the statement from documentation for this particular cursor is incorrect; and a correct version would have been written as</p>
<blockquote><p>V$SQL lists statistics on shared SQL areas without the GROUP BY clause and contains one row for each <strong>not obsolete</strong> child of the original SQL text entered</p></blockquote>
<p>See:</p>
<pre class="brush: sql; title: ; notranslate">
SQL&gt; select sql_id, child_number, is_obsolete, max(cnt)
  2    from (select sql_id
  3                ,child_number
  4                ,is_obsolete
  5                ,count(*) over(partition by sql_id, child_number, is_obsolete) cnt
  6                ,count(*) over(partition by sql_id, child_number) total_cnt
  7            from v$sql)
  8   where total_cnt &gt; 1
  9   group by sql_id, child_number, is_obsolete
 10   order by sql_id, child_number;


               Child
SQL_ID        number I             MAX(CNT)
------------- ------ - --------------------
22d06uj1ut8d4      0 N                    1
22d06uj1ut8d4      0 Y                   14
22d06uj1ut8d4      1 N                    1
22d06uj1ut8d4      1 Y                   14
22d06uj1ut8d4      2 N                    1
...
22d06uj1ut8d4     95 Y                   15
22d06uj1ut8d4     96 Y                   15
22d06uj1ut8d4     97 Y                   15
22d06uj1ut8d4     98 Y                   15
22d06uj1ut8d4     99 Y                   15
</pre>
<p>So the pattern is: either there is just 1 non obsolete child cursor for a given child number and some obsolete children or there&#8217;re obsolete children only. I don&#8217;t have an explanation of what is going on, but clearly, it looks like a bug. Even Oracle&#8217;s code to show an execution plan can&#8217;t handle this situation right. I also think it may have something to do with bug <a href="https://support.oracle.com/CSP/main/article?cmd=show&amp;type=NOT&amp;doctype=PATCH&amp;id=10187168.8">10187168.8</a>.<br />
Please leave a comment here if you see something similar in your 11.2.0.3 environment. You can use a query to find such evil cursors with a query (but please be careful &#8211; it&#8217;s not safe to run it on a production system)</p>
<pre class="brush: sql; title: ; notranslate">
select sql_id, avg(cnt), sum(cnt), count(*)
  from (select sql_id, child_number, count(*) cnt from v$sql 
         group by sql_id, child_number having count(*) &gt; 1)
 group by sql_id
</pre>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/oracle/'>Oracle</a>, <a href='http://timurakhmadeev.wordpress.com/category/oracle/sql/'>SQL</a> Tagged: <a href='http://timurakhmadeev.wordpress.com/tag/11-2-0-3/'>11.2.0.3</a>, <a href='http://timurakhmadeev.wordpress.com/tag/bug-or-feature/'>bug-or-feature</a>, <a href='http://timurakhmadeev.wordpress.com/tag/dynamic-views/'>dynamic views</a>, <a href='http://timurakhmadeev.wordpress.com/tag/shared-cursors/'>shared cursors</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/794/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/794/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=794&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2012/03/15/vsql-is_obsolete/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>
	</item>
		<item>
		<title>DST in Russia</title>
		<link>http://timurakhmadeev.wordpress.com/2012/02/24/dst-in-russia/</link>
		<comments>http://timurakhmadeev.wordpress.com/2012/02/24/dst-in-russia/#comments</comments>
		<pubDate>Fri, 24 Feb 2012 14:29:55 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[WLS]]></category>
		<category><![CDATA[ASH]]></category>
		<category><![CDATA[DST]]></category>
		<category><![CDATA[timestamp]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=785</guid>
		<description><![CDATA[Daylight Saving Time in Russia has been changed last year. Oracle published a FAQ on the support site about this: Russia abandons DST in 2011 &#8211; Impact on Oracle RDBMS [ID 1335999.1]. In short if you are using DATEs and TIMESTAMPs without time zone in your application, you are almost &#8220;safe&#8221; and there&#8217;s most likely [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=785&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Daylight Saving Time in Russia has been <a href="http://www.timeanddate.com/news/time/russia-dst-law.html">changed last year</a>. Oracle published a FAQ on the support site about this: <a href="https://support.oracle.com/CSP/main/article?cmd=show&amp;type=NOT&amp;doctype=BULLETIN&amp;id=1335999.1">Russia abandons DST in 2011 &#8211; Impact on Oracle RDBMS [ID 1335999.1]</a>. </p>
<p><span id="more-785"></span></p>
<p>In short if you are using DATEs and TIMESTAMPs without time zone in your application, you are almost &#8220;safe&#8221; and there&#8217;s most likely no need to do anything in particular on the database software level. In our application we use DATE and TIMESTAMP without time zone, so I thought it all should be fine. Not until today when I found out that I&#8217;ve a difference of 1 hour between stored TIMESTAMP and current date. Turns out it&#8217;s <i>client&#8217;s</i> issue (not a rare situation). The client is a WebLogic running Oracle JDK version 6u26 (1.6.0_26). And, unlike Oracle RDBMS, Oracle JRE is not consistent with OS time, so when you create a new <a href="http://docs.oracle.com/javase/1.5.0/docs/api/java/sql/Timestamp.html">java.sql.Timestamp</a> from a current time, it will take DST into account and will return value correspondingly &#8211; this was news to me. In my case without time zone patch it means 1 hour behind actual time. The time zone data is fixed in the JDK update 31 (release date 14 Feb 2012); it also can be patched easily with the help of <a href="http://www.oracle.com/technetwork/java/javase/tzupdater-readme-136440.html">Timezone Updater Tool</a>:</p>
<pre class="brush: plain; title: ; notranslate">
$ ./bin/java -jar tzupdater.jar -V
tzupdater version 1.3.45-b01
JRE time zone data version: tzdata2011g
Embedded time zone data version: tzdata2011n
$ ./bin/java -jar tzupdater.jar -u
$ ./bin/java -jar tzupdater.jar -V
tzupdater version 1.3.45-b01
JRE time zone data version: tzdata2011n
Embedded time zone data version: tzdata2011n
</pre>
<p>Oracle&#8217;s internal JVM (aka Aurora) in Oracle 11.2.0.3 looks to be unaffected and works correctly. It reports itself as version 1.5.0_10:</p>
<pre class="brush: sql; title: ; notranslate">
SQL&gt; create or replace and compile java source named &quot;test&quot; as
  2  import java.util.Date;
  3  public class test {
  4      public static String getCurrentDate() {
  5          return &quot;&quot; + new Date();
  6      }
  7  };
  8  /

Java created.

SQL&gt; sho err
No errors.
SQL&gt;
SQL&gt; create or replace function fnc_get_date return varchar2 as
  2  language java name 'test.getCurrentDate() return java.lang.String';
  3  /

Function created.

SQL&gt; sho err
No errors.

SQL&gt; select fnc_get_date, sysdate from dual;

FNC_GET_DATE                             SYSDATE
---------------------------------------- -----------------
Fri Feb 24 17:59:25 GMT+04:00 2012       20120224 17:59:25
</pre>
<p>And one more thing on the subject. I&#8217;d be happy if somebody would explain an anomaly with V$ACTIVE_SESSION_HISTORY.SAMPLE_TIME:</p>
<pre class="brush: sql; title: ; notranslate">
SQL&gt; select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE    11.2.0.2.0      Production
TNS for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production

SQL&gt; select startup_time from v$instance;

STARTUP_TIME
-----------------
20111020 16:38:21

SQL&gt; sho parameter nls

NAME_COL_PLUS_SHOW_PARAM                 TYPE        VALUE
---------------------------------------- ----------- ----------------------------
nls_calendar                             string      GREGORIAN
nls_comp                                 string      BINARY
nls_currency                             string      $
nls_date_format                          string      YYYYMMDD HH24:MI:SS
nls_date_language                        string      AMERICAN
nls_dual_currency                        string      $
nls_iso_currency                         string      AMERICA
nls_language                             string      AMERICAN
nls_length_semantics                     string      BYTE
nls_nchar_conv_excp                      string      FALSE
nls_numeric_characters                   string      .,
nls_sort                                 string      BINARY
nls_territory                            string      AMERICA
nls_time_format                          string      HH.MI.SSXFF AM
nls_time_tz_format                       string      HH.MI.SSXFF AM TZR
nls_timestamp_format                     string      DD-MON-RR HH.MI.SSXFF AM
nls_timestamp_tz_format                  string      DD-MON-RR HH.MI.SSXFF AM TZR

-- this is the question: v$active_session_history.sample_time lags 1 hour behind
SQL&gt; select systimestamp, sysdate, max(sample_time) from v$active_session_history;

SYSTIMESTAMP                                                                SYSDATE           MAX(SAMPLE_TIME)
--------------------------------------------------------------------------- ----------------- -------------------------
24-FEB-12 06.27.25.685962 PM +04:00                                         20120224 18:27:25 24-FEB-12 05.27.22.510 PM
</pre>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/java/'>Java</a>, <a href='http://timurakhmadeev.wordpress.com/category/oracle/'>Oracle</a>, <a href='http://timurakhmadeev.wordpress.com/category/java/wls/'>WLS</a> Tagged: <a href='http://timurakhmadeev.wordpress.com/tag/ash/'>ASH</a>, <a href='http://timurakhmadeev.wordpress.com/tag/dst/'>DST</a>, <a href='http://timurakhmadeev.wordpress.com/tag/timestamp/'>timestamp</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/785/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/785/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=785&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2012/02/24/dst-in-russia/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>
	</item>
		<item>
		<title>Load profile</title>
		<link>http://timurakhmadeev.wordpress.com/2012/02/21/load-profile/</link>
		<comments>http://timurakhmadeev.wordpress.com/2012/02/21/load-profile/#comments</comments>
		<pubDate>Tue, 21 Feb 2012 19:15:18 +0000</pubDate>
		<dc:creator>Timur Akhmadeev</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[AWR]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[Statspack]]></category>

		<guid isPermaLink="false">http://timurakhmadeev.wordpress.com/?p=780</guid>
		<description><![CDATA[I like Load profile section of Statspack or AWR reports (who doesn&#8217;t). It&#8217;s short and gives a brief understanding of what kind of work a database does. But what if you don&#8217;t have an access to Statspack or AWR but still want to see something similar? It&#8217;s possible to use V$SYSMETRIC to get this numbers [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=780&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I like Load profile section of Statspack or AWR reports (who doesn&#8217;t). It&#8217;s short and gives a brief understanding of what kind of work a database does. But what if you don&#8217;t have an access to Statspack or AWR but still want to see something similar? It&#8217;s possible to use <a href="http://docs.oracle.com/cd/E11882_01/server.112/e25513/dynviews_3090.htm#REFRN30343">V$SYSMETRIC</a> to get this numbers for last 60 or 15 seconds. I wanted to write a script to do this for a long time. Here it is.</p>
<p><span id="more-780"></span></p>
<pre class="brush: sql; title: ; notranslate">
col short_name  format a20              heading 'Load Profile'
col per_sec     format 999,999,999.9    heading 'Per Second'
col per_tx      format 999,999,999.9    heading 'Per Transaction'
set colsep '   '

select lpad(short_name, 20, ' ') short_name
     , per_sec
     , per_tx from
    (select short_name
          , max(decode(typ, 1, value)) per_sec
          , max(decode(typ, 2, value)) per_tx
          , max(m_rank) m_rank 
       from
        (select /*+ use_hash(s) */ 
                m.short_name
              , s.value * coeff value
              , typ
              , m_rank
           from v$sysmetric s,
               (select 'Database Time Per Sec'                      metric_name, 'DB Time' short_name, .01 coeff, 1 typ, 1 m_rank from dual union all
                select 'CPU Usage Per Sec'                          metric_name, 'DB CPU' short_name, .01 coeff, 1 typ, 2 m_rank from dual union all
                select 'Redo Generated Per Sec'                     metric_name, 'Redo size' short_name, 1 coeff, 1 typ, 3 m_rank from dual union all
                select 'Logical Reads Per Sec'                      metric_name, 'Logical reads' short_name, 1 coeff, 1 typ, 4 m_rank from dual union all
                select 'DB Block Changes Per Sec'                   metric_name, 'Block changes' short_name, 1 coeff, 1 typ, 5 m_rank from dual union all
                select 'Physical Reads Per Sec'                     metric_name, 'Physical reads' short_name, 1 coeff, 1 typ, 6 m_rank from dual union all
                select 'Physical Writes Per Sec'                    metric_name, 'Physical writes' short_name, 1 coeff, 1 typ, 7 m_rank from dual union all
                select 'User Calls Per Sec'                         metric_name, 'User calls' short_name, 1 coeff, 1 typ, 8 m_rank from dual union all
                select 'Total Parse Count Per Sec'                  metric_name, 'Parses' short_name, 1 coeff, 1 typ, 9 m_rank from dual union all
                select 'Hard Parse Count Per Sec'                   metric_name, 'Hard Parses' short_name, 1 coeff, 1 typ, 10 m_rank from dual union all
                select 'Logons Per Sec'                             metric_name, 'Logons' short_name, 1 coeff, 1 typ, 11 m_rank from dual union all
                select 'Executions Per Sec'                         metric_name, 'Executes' short_name, 1 coeff, 1 typ, 12 m_rank from dual union all
                select 'User Rollbacks Per Sec'                     metric_name, 'Rollbacks' short_name, 1 coeff, 1 typ, 13 m_rank from dual union all
                select 'User Transaction Per Sec'                   metric_name, 'Transactions' short_name, 1 coeff, 1 typ, 14 m_rank from dual union all
                select 'User Rollback UndoRec Applied Per Sec'      metric_name, 'Applied urec' short_name, 1 coeff, 1 typ, 15 m_rank from dual union all
                select 'Redo Generated Per Txn'                     metric_name, 'Redo size' short_name, 1 coeff, 2 typ, 3 m_rank from dual union all
                select 'Logical Reads Per Txn'                      metric_name, 'Logical reads' short_name, 1 coeff, 2 typ, 4 m_rank from dual union all
                select 'DB Block Changes Per Txn'                   metric_name, 'Block changes' short_name, 1 coeff, 2 typ, 5 m_rank from dual union all
                select 'Physical Reads Per Txn'                     metric_name, 'Physical reads' short_name, 1 coeff, 2 typ, 6 m_rank from dual union all
                select 'Physical Writes Per Txn'                    metric_name, 'Physical writes' short_name, 1 coeff, 2 typ, 7 m_rank from dual union all
                select 'User Calls Per Txn'                         metric_name, 'User calls' short_name, 1 coeff, 2 typ, 8 m_rank from dual union all
                select 'Total Parse Count Per Txn'                  metric_name, 'Parses' short_name, 1 coeff, 2 typ, 9 m_rank from dual union all
                select 'Hard Parse Count Per Txn'                   metric_name, 'Hard Parses' short_name, 1 coeff, 2 typ, 10 m_rank from dual union all
                select 'Logons Per Txn'                             metric_name, 'Logons' short_name, 1 coeff, 2 typ, 11 m_rank from dual union all
                select 'Executions Per Txn'                         metric_name, 'Executes' short_name, 1 coeff, 2 typ, 12 m_rank from dual union all
                select 'User Rollbacks Per Txn'                     metric_name, 'Rollbacks' short_name, 1 coeff, 2 typ, 13 m_rank from dual union all
                select 'User Transaction Per Txn'                   metric_name, 'Transactions' short_name, 1 coeff, 2 typ, 14 m_rank from dual union all
                select 'User Rollback Undo Records Applied Per Txn' metric_name, 'Applied urec' short_name, 1 coeff, 2 typ, 15 m_rank from dual) m
          where m.metric_name = s.metric_name
            and s.intsize_csec &gt; 5000
            and s.intsize_csec &lt; 7000)
      group by short_name)
 order by m_rank;
</pre>
<p>Couple of notes:</p>
<ul>
<li>It&#8217;s a simple piece of code with most of it being copy-paste to select data that is only required and to sort it the same way as AWR does</li>
<li>I&#8217;ve deliberately supplied a USE_HASH hint to the query because on one DB without a fixed objects statistics (or wrong &#8211; not sure) Oracle decided to do a NESTED LOOP with a FULL SCAN of a huge in-memory structure so the query took around a second to execute. Don&#8217;t wanna that happen</li>
<li>It&#8217;s possible to utilize PIVOT in the query, but it&#8217;ll limit applicability to 11g only &#8211; and I want this SQL to be able to run on 10g too</li>
</ul>
<p>And here is a sample output. Looks familiar <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<pre class="brush: sql; title: ; notranslate">
Load Profile               Per Second   Per Transaction
--------------------   --------------   ---------------
             DB Time               .7
              DB CPU               .7
           Redo size        217,570.3       4,283,958.7
       Logical reads          4,177.1          82,248.0
       Block changes          1,475.5          29,053.0
      Physical reads               .1               2.0
     Physical writes               .4               8.3
          User calls               .3               6.0
              Parses              8.2             161.3
         Hard Parses              7.3             144.0
              Logons               .1               1.3
            Executes            722.3          14,222.3
           Rollbacks               .0
        Transactions               .1
        Applied urec               .1               1.0
</pre>
<br />Filed under: <a href='http://timurakhmadeev.wordpress.com/category/oracle/'>Oracle</a>, <a href='http://timurakhmadeev.wordpress.com/category/performance/'>Performance</a> Tagged: <a href='http://timurakhmadeev.wordpress.com/tag/awr/'>AWR</a>, <a href='http://timurakhmadeev.wordpress.com/tag/scripts/'>scripts</a>, <a href='http://timurakhmadeev.wordpress.com/tag/statspack/'>Statspack</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/timurakhmadeev.wordpress.com/780/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/timurakhmadeev.wordpress.com/780/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=timurakhmadeev.wordpress.com&#038;blog=8326986&#038;post=780&#038;subd=timurakhmadeev&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://timurakhmadeev.wordpress.com/2012/02/21/load-profile/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/8da4a7facd3f297e8ce07c67ba766951?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Timur Akhmadeev</media:title>
		</media:content>
	</item>
	</channel>
</rss>
