<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2257062243512934022</id><updated>2011-12-26T12:11:08.904+05:30</updated><category term='Tuning'/><category term='Execution Plan'/><category term='materialized view'/><category term='OLAP'/><category term='General'/><category term='Nested table'/><category term='CBO'/><category term='Oracle Arch'/><category term='Tips'/><category term='Space management'/><category term='Index Rebuild'/><category term='Export/Import'/><category term='Oracle 11g new features'/><title type='text'>Sachin Arora's Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>43</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-7174821376812979390</id><published>2009-02-09T12:01:00.005+05:30</published><updated>2009-02-09T12:06:52.860+05:30</updated><title type='text'>Index range Scan Vs Nested loop in IN-LIST ?</title><content type='html'>&lt;div&gt;Which one is better over the above? This question has been the one of the latest topic in our performance team when using a viable solution for varying In-List management.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;Background:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We all know Oracle's shared pool is sensitive to the way sql is written - whitespace, uppercase/lowercase difference, number of bind variables in IN-Clause.&lt;/div&gt;&lt;div&gt;To avoid shared pool being bombarded with thousands of sqls of same type, we currently are using buckets for IN-clause.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;Ex:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;select * from emp where empno in (:B1,:B2,:B3,......,:B16) -- this is bucket size 16.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So, if user passes only one bind value, the rest of bind values will go as null. &lt;/div&gt;&lt;div&gt;And if user passes two bind values, the rest of bind values will go as null. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This way we control, the number of sqls which needs to be maintained in shared pool.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We implement different size of buckets: 16, 32, 64, 128, 256, 512, 768, 1000&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Upon searching i came across Tomy kyte's solution mentioned here (http://tkyte.blogspot.com/2006/06/varying-in-lists.html).&lt;/div&gt;&lt;div&gt;Initially i used his 8i solution and results were somehow unexpected:&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;blockquote&gt;&lt;/blockquote&gt;Here is the testcase:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;SQL&gt; create or replace type stringTableType as table of varchar2(4000);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;  2  /&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;Type created.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;SQL&gt; SQL&gt;   2    3    4&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;  5      v_str   long default p_str || ',';&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;  6&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;  7      v_n        number;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;  8&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;  9      v_data    stringTableType := stringTableType();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 10&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 11  begin&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 12&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 13      loop&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 14&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 15          v_n := instr( v_str, ',' );&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 16&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 17          exit when (nvl(v_n,0) = 0);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 18&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 19          v_data.extend;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 20&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 21          v_data( v_data.count ) := ltrim(rtrim(substr(v_str,1,v_n-1)));&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 22&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 23          v_str := substr( v_str, v_n+1 );&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 24&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 25      end loop;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 26&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 27      return v_data;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 28&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 29  end;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 30&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; 31  /&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;Function created.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;SQL&gt; create table test as select rownum r from dual connect by level&lt;=100000;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;Table created.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;SQL&gt; create index test_ux on test(r);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;Index created.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;SQL&gt; exec dbms_stats.gather_table_stats(user,'TEST',cascade=&gt;true)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;PL/SQL procedure successfully completed.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;Now running a NORMAL in-list with 10 inlist values:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;SQL&gt; declare&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;a number;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;begin&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;for i in 1..10000 loop&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;select count(*) into a from test where r in (1,2,3,4,5,6,7,8,9,10);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;end loop;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;end;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;/&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;PL/SQL procedure successfully completed.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;Elapsed: 00:00:01.23&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;Note the "Elapsed" time. It is 1.5 secs.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;Now using the Collection method:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;SQL&gt; SQL&gt; declare&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;a number;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;begin&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;for i in 1..10000 loop&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;select count(*) into a from test&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;where r in ( select /*+ cardinality(10) */ * from THE ( select cast( convert2Table( '1,2,3,4,5,6,7,8,9,10' ) as stringTableType ) from dual ) );&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;end loop;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;end;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;/&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;PL/SQL procedure successfully completed.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;Elapsed: 00:00:22.41&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:medium;"&gt;Note the "Elapsed" time is almost 15x more than normal inlist.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:medium;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:medium;"&gt;This was a bit surprising.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:medium;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:medium;"&gt;I did the same test under 10046 + tkprof eyes.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;SELECT COUNT(*)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;FROM&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt; TEST WHERE R IN (1,2,3,4,5,6,7,8,9,10)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;call     count       cpu    elapsed       disk      query    current        rows&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;------- ------  -------- ---------- ---------- ---------- ----------  ----------&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;Parse        1      0.00       0.00          0          0          0           0&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;Execute  10000      0.46       0.42          0          0          0           0&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;Fetch    10000      1.99       2.00          0     200000          0       10000&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;------- ------  -------- ---------- ---------- ---------- ----------  ----------&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;total    20001      2.46       2.43          0     200000          0       10000&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;Rows     Row Source Operation&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;-------  ---------------------------------------------------&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;  10000  SORT AGGREGATE (cr=200000 pr=0 pw=0 time=2117708 us)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt; 100000   INLIST ITERATOR  (cr=200000 pr=0 pw=0 time=2271474 us)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt; 100000    INDEX RANGE SCAN TEST_UX (cr=200000 pr=0 pw=0 time=1354629 us)(object id 60859168)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;SELECT COUNT(*)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;FROM&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt; TEST WHERE R IN ( SELECT /*+ cardinality(10) */ * FROM THE ( SELECT CAST(&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;  CONVERT2TABLE( '1,2,3,4,5,6,7,8,9,10' ) AS STRINGTABLETYPE ) FROM DUAL ) )&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;call     count       cpu    elapsed       disk      query    current        rows&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;------- ------  -------- ---------- ---------- ---------- ----------  ----------&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;Parse        1      0.01       0.01          0         48          0           0&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;Execute  10000      5.40       5.42          0          0          0           0&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;Fetch    10000      9.57       9.65          0     120000          0       10000&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;------- ------  -------- ---------- ---------- ---------- ----------  ----------&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;total    20001     14.99      15.09          0     120048          0       10000&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;Rows     Row Source Operation&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;-------  ---------------------------------------------------&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;  10000  SORT AGGREGATE (cr=120000 pr=0 pw=0 time=13856299 us)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt; 100000   NESTED LOOPS  (cr=120000 pr=0 pw=0 time=16447839 us)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt; 100000    VIEW  VW_NSO_1 (cr=0 pr=0 pw=0 time=11596021 us)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt; 100000     HASH UNIQUE (cr=0 pr=0 pw=0 time=11085381 us)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt; 100000      COLLECTION ITERATOR PICKLER FETCH CONVERT2TABLE (cr=0 pr=0 pw=0 time=3527457 us)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;  20000       FAST DUAL  (cr=0 pr=0 pw=0 time=151992 us)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt; 100000    INDEX RANGE SCAN TEST_UX (cr=120000 pr=0 pw=0 time=2182846 us)(object id 60859168)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The difference between 2 is sea. Although the later did almost 1/2 LIO yet the total time spent on CPU was huge.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It seems to me that NL over INLIST ITERATOR is not a good choice ATLEAST for 10 values.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now, I tried with 1000 values -- i didnt capture the screen shots. But here is what i saw.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;-  for loop that runs 1000 times -- the "R in (1,2,3...1000)" took 54 secs. And using the Tom Kyte's suggested methood - it took 16 minutes.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Am i missing something?&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-7174821376812979390?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/7174821376812979390/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=7174821376812979390' title='21 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/7174821376812979390'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/7174821376812979390'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2009/02/index-range-scan-vs-nested-loop-in-in.html' title='Index range Scan Vs Nested loop in IN-LIST ?'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>21</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-1020827695551865892</id><published>2008-12-19T15:42:00.000+05:30</published><updated>2008-12-27T12:58:37.943+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='CBO'/><category scheme='http://www.blogger.com/atom/ns#' term='Tuning'/><title type='text'>Partition stats usage with Bind peeking disabled</title><content type='html'>&lt;div&gt;Last week, I was working on a package, which is used to collect stats.&lt;/div&gt;&lt;div&gt;I realized we collect stats of all partioned tables,indexes at both partition and global level.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;While working on that package, i was pondering when will we actually use partition/local level stats (over global stats) in real-world scenario as most of our "where" clause &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;values are passed using bind variables. How will optimizer will come to know which partition (stats) to use because value passed will checked run time except in the case when it &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;is run for the first time and Bind peek happens.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;A bit confused with this I performed a test, where my test case was inspired by &lt;a href="http://oraclesponge.wordpress.com/2006/10/28/partition-pruning-and-bind-variables/"&gt;David Aldridge's blog post &lt;/a&gt;(however i conducted a different set of tests).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I first checked the difference in 10053 trace in sqls where we pass literals Vs bind variables - when bind peek is enabled (default - enabled, but not in our case).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;Test case:&lt;/div&gt;&lt;div&gt;============&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;drop table test_par&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;/&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;create table test_par&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;   (&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;   col1 number not null,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;   col2 number not null&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;   )&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;nologging compress pctfree 0&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;partition by range (col1)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;(partition p1_to_4 values less than (5),&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;partition p5 values less than (6)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;/&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;insert /*+ append */ into test_par&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;select mod(rownum,4)+1,rownum&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;from dual&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;connect by level &lt;= 100000&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;/&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;insert into test_par values(5,10);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;commit;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;create index idx02_test_par&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;on test_par (col2)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;local nologging&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;/&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;DBMS_STATS.GATHER_TABLE_STATS (&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;   ownname          =&gt; user,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;   tabname          =&gt; 'test_par',&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;   partname         =&gt; null,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;   estimate_percent =&gt; 100,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;   block_sample     =&gt; false,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;   method_opt       =&gt; 'for all columns size 1',&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;   degree           =&gt; null,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;   granularity      =&gt; 'ALL',&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;   cascade          =&gt; true,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;   stattab          =&gt; NULL, &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;   statid           =&gt; NULL,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;   statown          =&gt; NULL,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;   no_invalidate    =&gt; FALSE);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;end;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;/&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So - i have 75000 rows in partition p1_to_4 and 1 row in p5 &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; select count(*),col1 from test_par partition(p1_to_4) group by col1;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  COUNT(*)       COL1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;---------- ----------&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;     25000          1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;     25000          2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;     25000          4&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;     25000          3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt;  select count(*),col1 from test_par partition(p5) group by col1;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  COUNT(*)       COL1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;---------- ----------&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;         1          5&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now we have the set up ready, we have to enable the trace and check which stats are used when.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="text-decoration: underline;"&gt;Case 1: - Bind peek enable. I use literal value to query table and see which stats are used.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; alter session set "_optim_peek_user_binds"=true;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; alter session set events '10053 trace name context forever, level 2';&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; select * from test_par where col1=2 and col2=5;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now checking the trace file, we see:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;BASE STATISTICAL INFORMATION&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;***********************&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;Table Stats::&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  Table: TEST_PAR  Alias: TEST_PAR  Partition [0]  --&lt;span class="Apple-style-span" style="font-weight: bold;"&gt; &lt;span class="Apple-style-span" style="font-style: italic;"&gt;Do you see Partition stats getting used?&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-style: italic; font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;    #Rows: 100000  #Blks:  149  AvgRowLen:  7.00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;    #Rows: 100000  #Blks:  149  AvgRowLen:  7.00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;Index Stats::&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  Index: IDX02_TEST_PAR  Col#: 2  PARTITION [0]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;    LVLS: 1  #LB: 222  #DK: 100000  LB/K: 1.00  DB/K: 1.00  CLUF: 149.00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;    LVLS: 1  #LB: 222  #DK: 100000  LB/K: 1.00  DB/K: 1.00  CLUF: 149.00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;***************************************&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;So, with Bind peek enabled - we use partition stat (when we should) when literals are used&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="text-decoration: underline;"&gt;Case 2: Bind peek enable. I use Bind value to query table and see which stats are used.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; alter session set "_optim_peek_user_binds"=true;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; alter session set events '10053 trace name context forever, level 2';&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; variable lcol1 number;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; variable lcol2 number;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; execute :lcol1:=2;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; execute :lcol2:=5;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; select * from test_par where col1=:lcol1 and col2=:lcol2;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Trace file:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;***************************************&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;BASE STATISTICAL INFORMATION&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;***********************&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;Table Stats::&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  Table: TEST_PAR  Alias: TEST_PAR  Partition [0]  &lt;span class="Apple-style-span" style="font-style: italic; font-weight: bold;"&gt;-- Here again, partition stats getting used&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;    #Rows: 100000  #Blks:  149  AvgRowLen:  7.00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;    #Rows: 100000  #Blks:  149  AvgRowLen:  7.00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;Index Stats::&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  Index: IDX02_TEST_PAR  Col#: 2  PARTITION [0]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;    LVLS: 1  #LB: 222  #DK: 100000  LB/K: 1.00  DB/K: 1.00  CLUF: 149.00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;    LVLS: 1  #LB: 222  #DK: 100000  LB/K: 1.00  DB/K: 1.00  CLUF: 149.00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;***************************************&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Since this was the first time, we used this sql, Bind peek had to happen.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This is confirmed by following section of trace file:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;*******************************************&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;Peeked values of the binds in SQL statement&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;*******************************************&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;kkscoacd&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt; Bind#0&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  oacdty=02 mxl=22(22) mxlc=00 mal=00 scl=00 pre=00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  oacflg=03 fl2=1000000 frm=00 csi=00 siz=48 off=0&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  kxsbbbfp=2a973589d8  bln=22  avl=02  flg=05&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  value=2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt; Bind#1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  oacdty=02 mxl=22(22) mxlc=00 mal=00 scl=00 pre=00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  oacflg=03 fl2=1000000 frm=00 csi=00 siz=0 off=24&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  kxsbbbfp=2a973589f0  bln=22  avl=02  flg=01&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  value=5&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="text-decoration: underline;"&gt;CASE 3: Bind peek enabled - I use Bind value to query table and see which stats are used. &lt;/span&gt;&lt;/span&gt;-- This will be 2nd time - so this time i dont expect peeking to happen.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; alter session set "_optim_peek_user_binds"=true;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; alter session set events '10053 trace name context forever, level 2';&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; variable lcol1 number;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; variable lcol2 number;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; execute :lcol1:=5;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; execute :lcol2:=10;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; select * from test_par where col1=:lcol1 and col2=:lcol2;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Trace file:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;***************************************&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;BASE STATISTICAL INFORMATION&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;***********************&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;Table Stats::&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  Table: TEST_PAR  Alias: TEST_PAR  Partition [0] &lt;span class="Apple-style-span" style="font-style: italic; font-weight: bold;"&gt;-- Part Stats .. again&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;    #Rows: 100000  #Blks:  149  AvgRowLen:  7.00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;    #Rows: 100000  #Blks:  149  AvgRowLen:  7.00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;Index Stats::&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  Index: IDX02_TEST_PAR  Col#: 2  PARTITION [0]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;    LVLS: 1  #LB: 222  #DK: 100000  LB/K: 1.00  DB/K: 1.00  CLUF: 149.00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;    LVLS: 1  #LB: 222  #DK: 100000  LB/K: 1.00  DB/K: 1.00  CLUF: 149.00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;***************************************&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In this case - we still use old execution path and old stats - which is agony of 10g. &lt;/div&gt;&lt;div&gt;We had only one row for this partition and we ended up using INDEX access when direct access would be really fast.&lt;/div&gt;&lt;div&gt;I heard about Adaptive cursor sharing in 11g will avoid this, but still to run tests on it.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now we will run the same tests by keeping the bind peeking disabled (as in my environment)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="text-decoration: underline;"&gt;CASE 4: Bind peek disabled - we use literals&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; alter system flush shared_pool;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; alter session set "_optim_peek_user_binds"=false;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; alter session set events '10053 trace name context forever, level 2';&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; select * from test_par where col1=5 and col2=10;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;***************************************&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;BASE STATISTICAL INFORMATION&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;***********************&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;Table Stats::&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  Table: TEST_PAR  Alias: TEST_PAR  Partition [1] &lt;span class="Apple-style-span" style="font-style: italic; font-weight: bold;"&gt;-- Picked the right stats of right partition&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;    #Rows: 1  #Blks:  1  AvgRowLen:  6.00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;    #Rows: 1  #Blks:  1  AvgRowLen:  6.00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;Index Stats::&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  Index: IDX02_TEST_PAR  Col#: 2  PARTITION [1]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;    LVLS: 0  #LB: 1  #DK: 1  LB/K: 1.00  DB/K: 1.00  CLUF: 1.00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;    LVLS: 0  #LB: 1  #DK: 1  LB/K: 1.00  DB/K: 1.00  CLUF: 1.00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;***************************************&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Literals - as seen knows where to go.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="text-decoration: underline;"&gt;CASE 5: Bind peek disabled - we use binds&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; variable lcol1 number;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; variable lcol2 number;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; execute :lcol1:=5;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; execute :lcol2:=10;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; alter session set "_optim_peek_user_binds"=false;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; alter session set events '10053 trace name context forever, level 2';&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;SQL&gt; select * from test_par where col1=:lcol1 and col2=:lcol2;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Trace file:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;***************************************&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;BASE STATISTICAL INFORMATION&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;***********************&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;Table Stats::&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  Table: TEST_PAR  Alias: TEST_PAR  (Using composite stats) &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt; -- These are global stats &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;    #Rows: 100001  #Blks:  75  AvgRowLen:  7.00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;Index Stats::&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;  Index: IDX02_TEST_PAR  Col#: 2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;    USING COMPOSITE STATS&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;    LVLS: 1  #LB: 223  #DK: 100000  LB/K: 1.00  DB/K: 1.00  CLUF: 150.00&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-size:x-small;"&gt;***************************************&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So - the conclusion is :&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;When we have BIND peeeking disabled, and with usage of bind values - we are most likely (any one of you could come up where above doesnt hold good) NOT using partiton stats.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-1020827695551865892?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/1020827695551865892/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=1020827695551865892' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/1020827695551865892'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/1020827695551865892'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2008/12/partition-stats-usage-with-bind-peeking.html' title='Partition stats usage with Bind peeking disabled'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-8546201704358762128</id><published>2008-11-13T14:36:00.000+05:30</published><updated>2008-11-13T14:42:13.236+05:30</updated><title type='text'>Oracle Bitmap indexes - implementation</title><content type='html'>&lt;p class="MsoNormal"&gt;Oracle uses BBC (Byte aligned Bitmap Code) 1-sided algorithm to store Bitmap indexes.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;What is BBC?&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Thinking of Bitmap indexes, most of us recall a simple Bitmap Index such as the one mention below:&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;/p&gt;&lt;table class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0" style="border-collapse:collapse;border:none;mso-border-alt:solid windowtext .5pt;  mso-yfti-tbllook:480;mso-padding-alt:0in 5.4pt 0in 5.4pt;mso-border-insideh:  .5pt solid windowtext;mso-border-insidev:.5pt solid windowtext"&gt;  &lt;tbody&gt;&lt;tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes"&gt;   &lt;td width="59" valign="top" style="width:44.25pt;border:solid windowtext 1.0pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;Columns&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.25pt;border:solid windowtext 1.0pt;   border-left:none;mso-border-left-alt:solid windowtext .5pt;mso-border-alt:   solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;Row 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.25pt;border:solid windowtext 1.0pt;   border-left:none;mso-border-left-alt:solid windowtext .5pt;mso-border-alt:   solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;Row 2&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.25pt;border:solid windowtext 1.0pt;   border-left:none;mso-border-left-alt:solid windowtext .5pt;mso-border-alt:   solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;Row 3&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border:solid windowtext 1.0pt;   border-left:none;mso-border-left-alt:solid windowtext .5pt;mso-border-alt:   solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;Row 4&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border:solid windowtext 1.0pt;   border-left:none;mso-border-left-alt:solid windowtext .5pt;mso-border-alt:   solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;Row 5&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border:solid windowtext 1.0pt;   border-left:none;mso-border-left-alt:solid windowtext .5pt;mso-border-alt:   solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;Row 6&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border:solid windowtext 1.0pt;   border-left:none;mso-border-left-alt:solid windowtext .5pt;mso-border-alt:   solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;Row 7&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border:solid windowtext 1.0pt;   border-left:none;mso-border-left-alt:solid windowtext .5pt;mso-border-alt:   solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;Row 8&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border:solid windowtext 1.0pt;   border-left:none;mso-border-left-alt:solid windowtext .5pt;mso-border-alt:   solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;Row 9&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="mso-yfti-irow:1"&gt;   &lt;td width="59" valign="top" style="width:44.25pt;border:solid windowtext 1.0pt;   border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;   padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;Red&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="mso-yfti-irow:2"&gt;   &lt;td width="59" valign="top" style="width:44.25pt;border:solid windowtext 1.0pt;   border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;   padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;Green &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="mso-yfti-irow:3;mso-yfti-lastrow:yes"&gt;   &lt;td width="59" valign="top" style="width:44.25pt;border:solid windowtext 1.0pt;   border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;   padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;Blue&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td width="59" valign="top" style="width:44.3pt;border-top:none;border-left:none;   border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier;font-size:10.0pt;"&gt;0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;Fig: 1 - Table having 9 rows with data distribution shown as 0 and 1.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;In the above style of storing bits is uncompressed i.e. all 0s and 1s are stored as it is. So, while doing any bitwise operation (and/or/xor), we use the uncompressed version of bitmaps. &lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="text-decoration: underline;"&gt;Potential drawbacks of using this technique:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ol style="margin-top:0in" start="1" type="1"&gt;  &lt;li class="MsoNormal" style="mso-list:l0 level1 lfo1;tab-stops:list .5in"&gt;high      storage cost&lt;/li&gt;  &lt;li class="MsoNormal" style="mso-list:l0 level1 lfo1;tab-stops:list .5in"&gt;high      query cost&lt;/li&gt; &lt;/ol&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;i style="mso-bidi-font-style:normal"&gt;&lt;span class="Apple-style-span" style="text-decoration: underline;"&gt;Can compression be achieved?&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Yes, we can compress 0s and 1s which are consecutive. Think of compressing seven 0s as one with a special header saying that this 0 is equivalent to seven 0s.&lt;span style="mso-spacerun:yes"&gt;  &lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;But this has its own disadvantage. For any bit-wise operation, I have to &lt;i style="mso-bidi-font-style:normal"&gt;first decompress&lt;/i&gt; bitmap indexes in question and do the “and”/”or” operation, which &lt;i style="mso-bidi-font-style:normal"&gt;outweighs any savings in storage costs.&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;So, the need was for a compress bitmap technique using which bit-wise operations could be done on the compressed state.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;One such example of such techniques is BBC (used by Oracle) – called Byte aligned bitmap code.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;This technique of bitmap compression is based on run-length encoding. Using this encoding BITMAPs are aligned along the BYTE boundaries. Each aligned BYTE is called a gap-byte (GBYTE) if all the bits of that BYTE store the same logical value (0 or 1). If it’s a mix of bits having different logical values, its called a non-gap-byte or map-byte (MBYTE). Adjacent bytes of the same class are grouped and controlled by a control byte (CBYTE), which keeps the information whether the bytes following it are MBYTE or GBYTE and if its GBYTE what is the length of bytes? And if it’s a MBYTE, which type of MBYTE (is it an offset or not? – offset is a MBYTE having only single bit different from other bits in that byte)&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;In the above explanation, a gap-byte could be for 0 or for 1. so, it is called &lt;span class="Apple-style-span" style="font-style: italic;"&gt;2-sided BBC.&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;Oracle uses 1-sided BBC&lt;/span&gt;, in which only 0s are candidate for GBYTE not 1s. All 1s will still make an MBYTE in Oracle. I’m not sure why Oracle uses 1-sided BBC technique. It could be due to integration complexities with other part of RDBMS-engine. &lt;/p&gt;  &lt;p class="MsoNormal"&gt;But going back on the question, why do we need Byte alignment when I can compress without it?&lt;/p&gt;  &lt;ol style="margin-top:0in" start="1" type="1"&gt;  &lt;li class="MsoNormal" style="mso-list:l1 level1 lfo2;tab-stops:list .5in"&gt;Computers      are happy dealing with BYTEs than BITS. &lt;/li&gt;  &lt;li class="MsoNormal" style="mso-list:l1 level1 lfo2;tab-stops:list .5in"&gt;I can      do BIT-WISE operations as efficiently (in fact better) as I can do in decompress      form.&lt;/li&gt;  &lt;li class="MsoNormal" style="mso-list:l1 level1 lfo2;tab-stops:list .5in"&gt;Control      Bytes (CBYTES) are very handy in decoding the compress BITMAP.&lt;/li&gt; &lt;/ol&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Can this BITMAP compression and query response get better?&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;From what I see after doing research on net, the answer is &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Yes.&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;b style="mso-bidi-font-weight:normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;The technique of handling the bits BYTEs way has gotten better by handling the WORD way.&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;The concepts are similar to the ones followed in BBC, the major difference is aligning the bits using “word” rather than “byte”.&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt; Computers today are more friendly dealing in words (multiple bytes) than on byte.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;I will write more on word aligned hybrid compression technique in perspective of oracle in coming days.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Thanks for reading!&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;Inputs: &lt;/p&gt;  &lt;p class="MsoNormal"&gt;Patent# 5363098 – by &lt;span class="apple-style-span"&gt;&lt;span style="font-family:Arial;font-size:9.0pt;color:#333333;"&gt;Antoshenkov, Gennady&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style=" ;font-family:Arial;font-size:9.0pt;color:#333333;"&gt; &lt;/span&gt; (Oracle corp).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-8546201704358762128?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/8546201704358762128/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=8546201704358762128' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/8546201704358762128'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/8546201704358762128'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2008/11/oracle-bitmap-indexes-implementation.html' title='Oracle Bitmap indexes - implementation'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-4094263439848846412</id><published>2008-05-09T14:29:00.000+05:30</published><updated>2008-05-09T14:52:15.787+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips'/><category scheme='http://www.blogger.com/atom/ns#' term='materialized view'/><category scheme='http://www.blogger.com/atom/ns#' term='OLAP'/><title type='text'>ORA-14097 - when using materialized view and partition table</title><content type='html'>This one was an interesting issue which came up few days back. I spent quite sometime before I solved it.&lt;br /&gt;&lt;br /&gt;Issue was - A developer came upto me and told that he is getting "ORA-14097 - : column type or size mismatch in ALTER TABLE EXCHANGE PARTITION" while exchanging partitions.&lt;br /&gt;&lt;br /&gt;This guy is working on a warehouse design in which huge data loads will happen on base tables through out the day and there are mviews based on which it mines  and these mviews' data should be moved fact tables at midnight 12.&lt;br /&gt;&lt;br /&gt;Now we strategize in a way that at midnight when base tables will be truncated for fresh load of next day, we exchange the partitions of these mviews with temporary partitioned tables and use "Insert /*+ append */" to move it to final fact tables. We could not have directly exchanged partitions of fact table as they might not be partitioned by day.&lt;br /&gt;&lt;br /&gt;Now the above is all background. While investigating the issue, I was perplexed for some time when he showed me the issue. He created a temporary partitioned table using "create table as select .. the mview where 1=2" and while doing exchange partition he was getting ORA-14097.&lt;br /&gt;&lt;br /&gt;Let me give you a simple test case:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;SQL&gt;  create table test(a number);&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;SQL&gt;  create materialized view log on test with rowid including new values;&lt;br /&gt;&lt;br /&gt;Materialized view log created.&lt;br /&gt;&lt;br /&gt;SQL&gt;   create materialized view test_mv refresh fast on demand with rowid as select * from test;&lt;br /&gt;&lt;br /&gt;Materialized view created.&lt;br /&gt;&lt;br /&gt;SQL&gt;  insert into test values(1);&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;SQL&gt;   commit;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;SQL&gt;  exec dbms_mview.refresh('test_mv','F')&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now both table and mview have on erow each.&lt;br /&gt;&lt;br /&gt;Let's try and exchange partition of this mview with another table.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;SQL&gt;  select partition_name from user_tab_partitions where table_name='TEST_PART';&lt;br /&gt;&lt;br /&gt;PARTITION_NAME&lt;br /&gt;------------------------------&lt;br /&gt;SYS_P3446&lt;br /&gt;&lt;br /&gt;SQL&gt;  alter table test_part  exchange partition SYS_P3446 with table test_mv;&lt;br /&gt;alter table test_part  exchange partition SYS_P3446 with table test_mv&lt;br /&gt;                                                              *&lt;br /&gt;ERROR at line 1:&lt;br /&gt;ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;I used CTAS, there is no question abt data type and column order.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;SQL&gt; desc test_part&lt;br /&gt;Name                                      Null?    Type&lt;br /&gt;----------------------------------------- -------- ----------------------------&lt;br /&gt;A                                                  NUMBER&lt;br /&gt;&lt;br /&gt;SQL&gt; desc test_mv&lt;br /&gt;Name                                      Null?    Type&lt;br /&gt;----------------------------------------- -------- ----------------------------&lt;br /&gt;A                                                  NUMBER&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;After doing some research, i got through this metalink article: &lt;a href="https://metalink.oracle.com/metalink/plsql/f?p=130:14:1483823492787880407::::p14_database_id,p14_docid,p14_show_header,p14_show_help,p14_black_frame,p14_font:NOT,72332.1,1,1,1,helvetica"&gt;&lt;span style="font-family:helvetica;"&gt;&lt;strong&gt;72332.1&lt;/strong&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;According to that : "If a table has a FUNCTIONAL index on it there is an extra hidden column in COL$ which will cause an EXCHANGE to fail. Comparing USER_TAB_COLUMNS will not show this, nor will USER_UNUSED_COL_TABS but COL$ will show the difference."&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;SQL&gt;  select col#, name&lt;br /&gt;2  from sys.col$&lt;br /&gt;3   where obj# in&lt;br /&gt;4  (select object_id from user_objects where object_name = 'TEST_MV');&lt;br /&gt;&lt;br /&gt;    COL# NAME&lt;br /&gt;---------- ------------------------------&lt;br /&gt;       0 M_ROW$$&lt;br /&gt;       1 A&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now there you go - this M_ROW$$ was creating the problem for me.&lt;br /&gt;&lt;br /&gt;Old saying - identifying is problem is 80% of tak that entails solving it.&lt;br /&gt;&lt;br /&gt;Now - i created test_mv using primary key (not using rowid) and the whole exchange process worked fine!&lt;br /&gt;&lt;br /&gt;For those who donot have PK in their tables can consider having a separate column which can be seeded using a sequence and treat that as PK to combat this issue.&lt;br /&gt;&lt;br /&gt;Though it was trivial issue and solution. it kept me thinking for some time!&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;pre style="font-family: arial;"&gt;&lt;span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-4094263439848846412?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/4094263439848846412/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=4094263439848846412' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/4094263439848846412'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/4094263439848846412'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2008/05/ora-14097-when-using-materialized-view.html' title='ORA-14097 - when using materialized view and partition table'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-4261172792361477723</id><published>2008-05-08T23:14:00.000+05:30</published><updated>2008-05-09T00:53:26.825+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Oracle 11g new features'/><title type='text'>Query result cache in 11g</title><content type='html'>&lt;span style="font-family:arial;"&gt;In 11g its possible to store the result of the SQL in a special section of shared pool called RESULT CACHE.&lt;br /&gt;&lt;br /&gt;As the name suggests, this cache stores results. This makes subsequent SQLs run damn fast resulting in better performance.&lt;br /&gt;&lt;br /&gt;To me, this features sounds like Materialized view - because those also when introduced boosted the performance of queries which used to take a lot of time while computing the result. The resultant data of mview was stored in table (i.e. segment/disk). And this case the resultant data is stored in memory. Though memory not being persistent, this feature still helps in subsequent runs of the same query.&lt;br /&gt;&lt;br /&gt;The feature is broadly governed by init.ora parameter  - RESULT_CACHE_MODE - which can be changed using "alter system" or "alter session". The default value of this parameter is MANUAL. You can switch it to FORCE (not recommended).&lt;br /&gt;&lt;br /&gt;Now after this parameter has taken effect, you can modify your SQL to see its affect.&lt;br /&gt;&lt;br /&gt;SQL&gt; select /*+ result_cache */ deptno,sum(sal) from emp group by deptno;&lt;br /&gt;&lt;br /&gt;  DEPTNO   SUM(SAL)&lt;br /&gt;---------- ----------&lt;br /&gt;      30       9400&lt;br /&gt;      20      10875&lt;br /&gt;      10       8750&lt;br /&gt;&lt;br /&gt;NOw run this query again - with hint&lt;br /&gt;and this time with autotrace traconly explain option:&lt;br /&gt;&lt;br /&gt;SQL&gt; set autotrace traceonly exp&lt;br /&gt;SQL&gt; /&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 4067220884&lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation           | Name                       | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;--------------------------------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT    |                            |     3 |    21 |     4  (25)| 00:00:01 |&lt;br /&gt;|   1 |  RESULT CACHE       | bw8bd7rpb6h0sg1rcrwyx3rz0x |       |       |            |          |&lt;br /&gt;|   2 |   HASH GROUP BY     |                            |     3 |    21 |     4  (25)| 00:00:01 |&lt;br /&gt;|   3 |    TABLE ACCESS FULL| EMP                        |    14 |    98 |     3   (0)| 00:00:01 |&lt;br /&gt;--------------------------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;Here you see data being fetched from result cache.&lt;br /&gt;&lt;br /&gt;There are some dynamic views which can give more insight.&lt;br /&gt;&lt;br /&gt;SQL&gt; select table_name from dict where lower(table_name) like '%result%';&lt;br /&gt;&lt;br /&gt;TABLE_NAME&lt;br /&gt;------------------------------&lt;br /&gt;DBA_METHOD_RESULTS&lt;br /&gt;USER_METHOD_RESULTS&lt;br /&gt;ALL_METHOD_RESULTS&lt;br /&gt;V$CLIENT_RESULT_CACHE_STATS&lt;br /&gt;GV$RESULT_CACHE_DEPENDENCY&lt;br /&gt;GV$RESULT_CACHE_MEMORY&lt;br /&gt;GV$RESULT_CACHE_OBJECTS&lt;br /&gt;GV$RESULT_CACHE_STATISTICS&lt;br /&gt;V$RESULT_CACHE_DEPENDENCY&lt;br /&gt;V$RESULT_CACHE_MEMORY&lt;br /&gt;V$RESULT_CACHE_OBJECTS&lt;br /&gt;&lt;br /&gt;TABLE_NAME&lt;br /&gt;------------------------------&lt;br /&gt;V$RESULT_CACHE_STATISTICS&lt;br /&gt;GV$CLIENT_RESULT_CACHE_STATS&lt;br /&gt;CLIENT_RESULT_CACHE_STATS$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I used V$RESULT_CACHE_OBJECTS:&lt;br /&gt;&lt;br /&gt;1* select id,status,block_count,name from V$RESULT_CACHE_OBJECTS&lt;br /&gt;SQL&gt; /&lt;br /&gt;&lt;br /&gt;      ID STATUS    BLOCK_COUNT&lt;br /&gt;---------- --------- -----------&lt;br /&gt;NAME&lt;br /&gt;----------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;       0 Published           1&lt;br /&gt;SCOTT.EMP&lt;br /&gt;&lt;br /&gt;       1 Published           1&lt;br /&gt;select /*+ result_cache */ deptno,sum(sal) from emp group by deptno&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Similar to the hint "result_cache" - there is another hint - "no_result_cache"&lt;br /&gt;&lt;br /&gt;&gt;&gt; no_result_cache is to be used when you have set database parameter: RESULT_CACHE_MODE to FORCE - which means oracle will try to cache the result of all queries.&lt;br /&gt;&lt;br /&gt;Ex: select /*+ no_result_cache */ deptno,sum(sal) from emp group by deptno&lt;br /&gt;&lt;br /&gt;To see the memory utlization - there are few dynamic views, database functions available.&lt;br /&gt;&lt;br /&gt;SQL&gt; set serverout on&lt;br /&gt;SQL&gt; exec dbms_result_cache.memory_report&lt;br /&gt;R e s u l t   C a c h e   M e m o r y   R e p o r t&lt;br /&gt;[Parameters]&lt;br /&gt;Block Size          = 1K bytes&lt;br /&gt;Maximum Cache Size  = 3488K bytes (3488 blocks)&lt;br /&gt;Maximum Result Size = 174K bytes (174 blocks)&lt;br /&gt;[Memory]&lt;br /&gt;Total Memory = 136340 bytes [0.064% of the Shared Pool]&lt;br /&gt;... Fixed Memory = 5140 bytes [0.002% of the Shared Pool]&lt;br /&gt;... Dynamic Memory = 131200 bytes [0.061% of the Shared Pool]&lt;br /&gt;....... Overhead = 65664 bytes&lt;br /&gt;....... Cache Memory = 64K bytes (64 blocks)&lt;br /&gt;........... Unused Memory = 29 blocks&lt;br /&gt;........... Used Memory = 35 blocks&lt;br /&gt;............... Dependencies = 1 blocks (1 count)&lt;br /&gt;............... Results = 34 blocks&lt;br /&gt;................... SQL     = 34 blocks (34 count)&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;There is again an init.ora parameter governing the size of max result cache size i.e result_cache_max_size&lt;br /&gt;&lt;br /&gt;This value is also seen in dbms_result_cache.memory_report output in "Maximum Cache Size " header.&lt;br /&gt;&lt;br /&gt;Conclusion: SQL Result cache seems to be a great feature which can immensly improve the sql performance of many applications SQLs. I wish there are no major bugs in this :)&lt;br /&gt;&lt;br /&gt;Note: Its just the begining that I have started looking into these features. If you happen to research something which I may have missed, please add to the note.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-4261172792361477723?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/4261172792361477723/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=4261172792361477723' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/4261172792361477723'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/4261172792361477723'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2008/05/query-result-cache-in-11g.html' title='Query result cache in 11g'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-301722345358527181</id><published>2008-03-28T15:02:00.000+05:30</published><updated>2008-03-28T16:12:58.501+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Oracle 11g new features'/><title type='text'>Password is case sensitive now - Oracle 11g</title><content type='html'>Good news for people who always wanted oracle schema passwords to be case sensitive.&lt;br /&gt;Oracle has done this in 11g.&lt;br /&gt;&lt;br /&gt;Just to show an example:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;C:\Documents and Settings\sachin.arora&gt;sqlplus "/ as sysdba"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;SQL*Plus: Release 11.1.0.6.0 - Production on Fri Mar 28 15:02:56 2008&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Copyright (c) 1982, 2007, Oracle.  All rights reserved.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Connected to:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;With the Partitioning, OLAP, Data Mining and Real Application Testing options&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;SQL&gt; create user test identified by AroRa default tablespace users;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;User created.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;SQL&gt; grant create session to test;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Grant succeeded.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; connect test/arora&lt;br /&gt;ERROR:&lt;br /&gt;ORA-01017: invalid username/password; logon denied&lt;br /&gt;&lt;br /&gt;SQL&gt; connect test/AroRa&lt;br /&gt;Connected.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;With 11g, Oracle has made significant changes in password maintenence algorithm.&lt;br /&gt;The password verifier is based on 160 bit SHA-1 hashing algorithm. This empowers Oracle to not only allow case sensitive passwords, but also enable the users to keep a strong password that can include special characters.&lt;br /&gt;&lt;br /&gt;For pre-11g users, when they migrate to 11g, their password still behave password insensitive. However, i feel its good to take the advantage of this useful feature and change the password.&lt;br /&gt;&lt;br /&gt;For applications which cant afford to change their passwords for xyzee purpose, Oracle has supplied an init.ora i.e. SEC_CASE_SENSITIVE_LOGON that can be set to true/false.&lt;br /&gt;Default value of this parameter is true which means passwords should be case sensitive.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-301722345358527181?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/301722345358527181/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=301722345358527181' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/301722345358527181'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/301722345358527181'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2008/03/password-is-case-sensitive-now-oracle.html' title='Password is case sensitive now - Oracle 11g'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-1573886790438924363</id><published>2008-03-27T16:36:00.000+05:30</published><updated>2008-03-28T16:12:58.501+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Oracle 11g new features'/><title type='text'>Memory parameters in 11g -  MEMORY_TARGET and MEMORY_MAX_TARGET</title><content type='html'>Few days back, I was checking metalink and came across few good notes on 11g memory management.&lt;br /&gt;Though we are not using 11g in our development environment, i have downloaded a copy of 11g rel1 on my windows machine.&lt;br /&gt;&lt;br /&gt;Testing out these new paarmeters gave me an insight on how Oracle has improvised its memory management.&lt;br /&gt;&lt;br /&gt;Oracle has introduced 2 new parameters (along with many others!) - MEMORY_TARGET and MEMORY_MAX_TARGET&lt;br /&gt;&lt;br /&gt;Using these parameters, you can manage SGA and PGA together rather than managing them separately (using SGA_TARGET, SGA_MAX_SIZE , PGA_AGGREGATE_TARGET and WORKAREA_SIZE_POLICY in 10g)&lt;br /&gt;&lt;br /&gt;If you set SGA_TARGET, SGA_MAX_SIZE and PGA_AGGREGATE_SIZE to 0 and set MEMORY_TARGET (and optionally MEMORY_MAX_TARGET) to non zero value, Oracle will manage both SGA components and PGA together within the limit specified by you.&lt;br /&gt;&lt;br /&gt;For instance :&lt;br /&gt;If MEMORY_TARGET is set to 1024MB, Oracle will manage SGA and PGA components within itself.&lt;br /&gt;&lt;br /&gt;If MEMORY_TARGET is set to non zero value:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;SGA_TARGET, SGA_MAX_SIZE and PGA_AGGREGATE_TARGET are set to 0, 60% of memory mentioned in MEMORY_TARGET is allocated to SGA and rest 40% is kept for PGA.&lt;/li&gt;&lt;li&gt;SGA_TARGET and PGA_AGGREGATE_TARGET are set to non-zero values, these values will be considered minimum values.&lt;/li&gt;&lt;li&gt;SGA_TARGET is set to non zero value and PGA_AGGREGATE_TARGET is not set. Still these values will be autotuned and PGA_AGGREGATE_TARGET will be initialized with value of (MEMORY_TARGET-SGA_TARGET).&lt;/li&gt;&lt;li&gt;PGA_AGGREGATE_TARGET is set and SGA_TARGET is not set. Still both parameters will be autotunes. SGA_TARGET will be initialized to a value of (MEMORY_TARGET-PGA_AGGREGATE_TARGET).&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;With this version, oracle has become smart as in exchanging memory between SGA and PGAs. This is a huge achievement.&lt;br /&gt;When starting up, Oracle takes up memory equal to MEMORY_TARGET (or MEMORY_MAX_TARGET if mentioned)  from Operating System RAM and manage its reqources within itself.&lt;br /&gt;This feature helps DBA to allocate chunk of memory to a particular instance without worrying about the subcateogary allocations of different components.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I tested out few of these experiments mentioned above. Here are the results:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Test 1: When Memory_target is 1G&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;init.ora parameter&lt;br /&gt;&gt; memory_target=1073741824&lt;br /&gt;&gt; sga_max_size=0&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;SQL&gt; startup&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;Total System Global Area  640303104 bytes&lt;br /&gt;Fixed Size                  1335024 bytes&lt;br /&gt;Variable Size             226492688 bytes&lt;br /&gt;Database Buffers          406847488 bytes&lt;br /&gt;Redo Buffers                5627904 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;Database opened.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&gt;&gt; It seems around 600M is used for SGA. The decesion of using 600 MB of SGA is of Oracle itself.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;SQL&gt; sho parameter sga&lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- -------------------&lt;br /&gt;lock_sga                             boolean     FALSE&lt;br /&gt;pre_page_sga                         boolean     FALSE&lt;br /&gt;sga_max_size                         big integer 612M&lt;br /&gt;sga_target                           big integer 0&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Test 2: When MEMORY_TARGET is 2g (with no change in any other parameter)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;SQL&gt; alter system set memory_target=2048m scope=spfile;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; startup force&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;Total System Global Area 1288978432 bytes&lt;br /&gt;Fixed Size                  1339344 bytes&lt;br /&gt;Variable Size             226492464 bytes&lt;br /&gt;Database Buffers         1052770304 bytes&lt;br /&gt;Redo Buffers                8376320 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;Database opened.&lt;br /&gt;&lt;br /&gt;SQL&gt; sho parameter sga&lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- ---------------------&lt;br /&gt;lock_sga                             boolean     FALSE&lt;br /&gt;pre_page_sga                         boolean     FALSE&lt;br /&gt;sga_max_size                         big integer 1232M&lt;br /&gt;sga_target                           big integer 0&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Test 3: When sga_max_size/sga_target=700M and memory_target=1G&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;SQL&gt; startup&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;Total System Global Area  732352512 bytes&lt;br /&gt;Fixed Size                  1335696 bytes&lt;br /&gt;Variable Size             192941680 bytes&lt;br /&gt;Database Buffers          532676608 bytes&lt;br /&gt;Redo Buffers                5398528 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;Database opened.&lt;br /&gt;SQL&gt; sho parameter sga&lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- ---------------------&lt;br /&gt;lock_sga                             boolean     FALSE&lt;br /&gt;pre_page_sga                         boolean     FALSE&lt;br /&gt;sga_max_size                         big integer 700M&lt;br /&gt;sga_target                           big integer 700M&lt;br /&gt;SQL&gt;&lt;br /&gt;SQL&gt; sho parameter memory&lt;br /&gt;&lt;br /&gt;NAME                                 TYPE        VALUE&lt;br /&gt;------------------------------------ ----------- ---------------------&lt;br /&gt;hi_shared_memory_address             integer     0&lt;br /&gt;memory_max_target                    big integer 1G&lt;br /&gt;memory_target                        big integer 1G&lt;br /&gt;shared_memory_address                integer     0&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;This time, oracle has acknowledged the SGA_MAX_SIZE parameter.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-1573886790438924363?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/1573886790438924363/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=1573886790438924363' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/1573886790438924363'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/1573886790438924363'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2008/03/memory-parameters-in-11g-memorytarget.html' title='Memory parameters in 11g -  MEMORY_TARGET and MEMORY_MAX_TARGET'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>10</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-395077958117961859</id><published>2008-03-14T14:04:00.000+05:30</published><updated>2008-03-14T14:35:03.894+05:30</updated><title type='text'>Cost, selectivity and cardinality - all  changes in 10g rel2 10053 trace file</title><content type='html'>Few days back o one of the google groups, there was &lt;a href="http://groups.google.com/group/comp.databases.oracle.server/browse_thread/thread/f0371d471a3fb776/091f38e9f40e1033?hl=en&amp;amp;lnk=gst&amp;amp;q=index+selectivity#091f38e9f40e1033"&gt;issue &lt;/a&gt;posted by a gentleman about "index selectivity". Per him the "index selectivity" should be different than what is being shown by the optimizer. He was inquiring whether the procedure he followed to calculate "index selectivity" is correct or not.&lt;br /&gt;&lt;br /&gt;Here is what he had to say:&lt;br /&gt;&lt;br /&gt;I don't know how the optimizer has calculated ix_sel of the index&lt;br /&gt;IDT_FCMO_TMS.&lt;br /&gt;Oracle version: 10.2.0.3.0&lt;br /&gt;Any idea?&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;SQL Statement: &lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt; select /* PRUEBA */ count(*) FROM TDTC_CAPACIDAD_MODALIDAD WHERE &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt; CMO_CODTSG = 'HT' AND CMO_CODTMS = 'DBL&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;10053 Trace:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;***************************************&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;BASE STATISTICAL INFORMATION&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;***********************&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Table Stats::&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  Table: TDTC_CAPACIDAD_MODALIDAD  Alias: TDTC_CAPACIDAD_MODALIDAD&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    #Rows: 82240  #Blks:  1132  AvgRowLen:  82.00&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Index Stats::&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  Index: IDT_FCMO_CHA  Col#: 5&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    LVLS: 1  #LB: 170  #DK: 939  LB/K: 1.00  DB/K: 14.00  CLUF:13425.00&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  Index: IDT_FCMO_TMS  Col#: 34                                                             &lt;----- the index&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    LVLS: 1  #LB: 214  #DK: 471  LB/K: 1.00  DB/K: 26.00  CLUF:12648.00   &lt;----- the index&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  Index: IDT_FCMO_TSU  Col#: 31&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    LVLS: 0  #LB: 1  #DK: 58  LB/K: 1.00  DB/K: 6.00  CLUF: 370.00&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  Index: RDT_PCMO  Col#: 1 2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    LVLS: 1  #LB: 206  #DK: 82061  LB/K: 1.00  DB/K: 1.00  CLUF:28928.00&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;***************************************&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;SINGLE TABLE ACCESS PATH&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  Column (#3): CMO_CODTSG(VARCHAR2)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    AvgLen: 3.00 NDV: 21 Nulls: 0 Density: 0.047619       &lt;---------- first column of the index&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  Column (#4): CMO_CODTMS(VARCHAR2)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    AvgLen: 5.00 NDV: 387 Nulls: 0 Density: 0.002584     &lt;---------- second column of the index&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  Table: TDTC_CAPACIDAD_MODALIDAD  Alias:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;TDTC_CAPACIDAD_MODALIDAD&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    Card: Original: 82240  Rounded: 10  Computed: 10.12  Non Adjusted:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;10.12&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  Access Path: TableScan&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    Cost:  184.60  Resp: 184.60  Degree: 0&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      Cost_io: 181.00  Cost_cpu: 29454495&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      Resp_io: 181.00  Resp_cpu: 29454495&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  Access Path: index (index (FFS))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    Index: IDT_FCMO_TMS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    resc_io: 36.00  resc_cpu: 15484960&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    ix_sel: 0.0000e+00  ix_sel_with_filters: 1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  Access Path: index (FFS)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    Cost:  37.89  Resp: 37.89  Degree: 1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      Cost_io: 36.00  Cost_cpu: 15484960&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;      Resp_io: 36.00  Resp_cpu: 15484960&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  Access Path: index (AllEqRange)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    Index: IDT_FCMO_TMS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    resc_io: 1.00  resc_cpu: 42971&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    ix_sel: 0.0021231  ix_sel_with_filters: 0.0021231 &lt;-------------------- wrong ix_sel?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    Cost: 1.01  Resp: 1.01  Degree: 1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;  Best:: AccessPath: IndexRange  Index: IDT_FCMO_TMS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;         Cost: 1.01  Degree: 1  Resp: 1.01  Card: 10.12  Bytes: 0&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;*************************************** &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;IX_SEL should be 0.047619 * 0.002584 (which is far from what optimizer showed i.e 0.0021231)&lt;br /&gt;&lt;br /&gt;According to Jonathan lewis book "Cost-Based Oracle Fundamentals", it is well explain in Chapter-4 P 66,67 that in case of select using multiple column index, index selectivity is calculated using the multiplication of individual selectivities of columns.&lt;br /&gt;And that is precisely what the person seeking support showed.&lt;br /&gt;&lt;br /&gt;While testing this result on 10.2.0.2, I found the index selectivity never gets multiplied in case of multicolumn index. In fact optimizer calculates index selectivity based on "distinct keys" of index.In this case (per the trace shown above) it is 471.&lt;br /&gt;So the index selectivity comes out to be 1/(DK of index)=1/471=0.0021231, which is what is shown by optimizer.&lt;br /&gt;&lt;br /&gt;I think, by the time Jonathan's book was published, not all the changes were tested. In fact I visited his blog and some &lt;a href="http://jonathanlewis.wordpress.com/2008/03/11/everything-changes/"&gt;couple of finding similar to this posted there&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-395077958117961859?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/395077958117961859/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=395077958117961859' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/395077958117961859'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/395077958117961859'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2008/03/cost-selectivity-and-cardinality-all.html' title='Cost, selectivity and cardinality - all  changes in 10g rel2 10053 trace file'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-1418725338871843027</id><published>2008-03-13T11:43:00.000+05:30</published><updated>2008-03-13T15:58:31.906+05:30</updated><title type='text'>ORA-01115 and ORA-27067 during crash recovery</title><content type='html'>Yesterday, one of our development server got a power outage because of which all our databases running on that server crashed.&lt;br /&gt;&lt;br /&gt;After the server was brought up, I started these databases manually. One of the db refused to startup with normal "startup" command.&lt;br /&gt;&lt;br /&gt;Here was the front-end error.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;SQL&gt; startup&lt;br /&gt;ORACLE instance started.&lt;br /&gt;&lt;br /&gt;Total System Global Area  432013312 bytes&lt;br /&gt;Fixed Size                  2169944 bytes&lt;br /&gt;Variable Size             356115368 bytes&lt;br /&gt;Database Buffers           62914560 bytes&lt;br /&gt;Redo Buffers               10813440 bytes&lt;br /&gt;Database mounted.&lt;br /&gt;ORA-01115: IO error reading block from file 2 (block # 575701)&lt;br /&gt;ORA-01110: data file 2: '/mnt/user/oracle/data/initdb/undotbs01.dbf'&lt;br /&gt;ORA-27067: size of I/O buffer is invalid&lt;br /&gt;Additional information: 2&lt;br /&gt;Additional information: 1572864&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;And here is what I saw in alert.log&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-family:verdana;"&gt;ALTER DATABASE OPEN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Wed Mar 12 10:01:14 2008&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Beginning crash recovery of 1 threads&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt; parallel recovery started with 2 processes&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Wed Mar 12 10:01:15 2008&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Started redo scan&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Wed Mar 12 10:01:16 2008&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Completed redo scan&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt; 130874 redo blocks read, 760 data blocks need recovery&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Wed Mar 12 10:01:16 2008&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Started redo application at&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt; Thread 1: logseq 49756, block 4723&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Wed Mar 12 10:01:16 2008&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Recovery of Online Redo Log: Thread 1 Group 1 Seq 49756 Reading mem 0&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;  Mem# 0 errs 0: /mnt/filer15adapp/data/adap_dev/redo1.log&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Wed Mar 12 10:01:16 2008&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Errors in file /mnt/oracle-dev1/admin/adap_dev/bdump/adap_dev_p001_4721.trc:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ORA-01115: IO error reading block from file 2 (block # 575701)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ORA-01110: data file 2: '/mnt/filer15adapp/data/adap_dev/undotbs01.dbf'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ORA-27067: size of I/O buffer is invalid&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Additional information: 2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Additional information: 1409024&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Wed Mar 12 10:01:19 2008&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Aborting crash recovery due to slave death, attempting serial crash recovery&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Wed Mar 12 10:01:19 2008&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Beginning crash recovery of 1 threads&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Wed Mar 12 10:01:19 2008&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Started redo scan&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Wed Mar 12 10:01:20 2008&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Completed redo scan&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt; 130874 redo blocks read, 760 data blocks need recovery&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Wed Mar 12 10:01:25 2008&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Aborting crash recovery due to error 1115&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Wed Mar 12 10:01:25 2008&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Errors in file /mnt/oracle-dev1/admin/adap_dev/udump/adap_dev_ora_4717.trc:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ORA-01115: IO error reading block from file 2 (block # 575701)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ORA-01110: data file 2: '/mnt/filer15adapp/data/adap_dev/undotbs01.dbf'&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ORA-27067: size of I/O buffer is invalid&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Additional information: 2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Additional information: 1572864&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;ORA-1115 signalled during: ALTER DATABASE OPEN...&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Wed Mar 12 10:02:37 2008&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:verdana;"&gt;Shutting down instance: further logons disabled &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;This was the first time i got this error in my experience. Db being running in noarchive log mode (this being dev server) just added to my worries.&lt;br /&gt;&lt;br /&gt;Googling didnt help. After some research work, i encountered a note on metalink &lt;a href="https://metalink.oracle.com/metalink/plsql/f?p=130:14:7668690220961778056::::p14_database_id,p14_docid,p14_show_header,p14_show_help,p14_black_frame,p14_font:NOT,423128.1,1,1,1,helvetica"&gt;&lt;span style="font-family:helvetica;"&gt;&lt;strong&gt;Note:423128.1.&lt;/strong&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Though they didnt explain the cause of the problem, but suggested the workaround.&lt;br /&gt;&lt;br /&gt;i.e.&lt;br /&gt;&lt;br /&gt;1) Mount the database&lt;br /&gt;2) Issue "recover database" command&lt;br /&gt;-- Wait for "Media recovery complete"&lt;br /&gt;3) alter database open&lt;br /&gt;&lt;br /&gt;I'm s not sure about the cause as this Note on metalink refers to a &lt;a href="https://metalink.oracle.com/metalink/plsql/showdoc?db=Bug&amp;amp;id=5362935"&gt;Bug 5362935&lt;/a&gt; - "CRASH RECOVERY FAILS WITH ORA-27067 ERROR", which is closed with status "&lt;/span&gt;&lt;span style="font-family:helvetica;"&gt;&lt;span style="font-size:100%;"&gt;Suspended, Req'd Info not Avail" and lots of useful information is hidden so people like us, who are not working in Oracle Corp cant see it.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-1418725338871843027?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/1418725338871843027/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=1418725338871843027' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/1418725338871843027'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/1418725338871843027'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2008/03/ora-01115-and-ora-27067-during-crash.html' title='ORA-01115 and ORA-27067 during crash recovery'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-5928290576076377613</id><published>2008-03-05T17:29:00.000+05:30</published><updated>2008-03-05T17:35:32.742+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips'/><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>How to pass a value from Oracle to Unix shell environment variable?</title><content type='html'>Though its too trivial, but I thought its not a bad idea to put it here to help the newbies.&lt;br /&gt;Following information can be of help when you want to store a table record or some computation in a shell variable.&lt;br /&gt;&lt;br /&gt;env_variable=`sqlplus username}/{password}  &lt;&lt;&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;set echo off verify off feed off termout off pages 0&lt;/span&gt;&lt;br /&gt;{{SELECT STMT}};&lt;br /&gt;exit&lt;br /&gt;EOF`&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;-bash-3.00$ DB_USED=`sqlplus -s "/ as sysdba" &lt;&lt; EOF&lt;br /&gt;&gt; set echo off verify off feed off termout off pages 0&lt;br /&gt;&gt; select sum(tot.bytes/1024-sum(nvl(fre.bytes,0))/1024)/3.8&lt;br /&gt;&gt; from    dba_free_space fre,&lt;br /&gt;&gt; (select tablespace_name, sum(bytes) bytes&lt;br /&gt;&gt; from    dba_data_files&lt;br /&gt;&gt; group by tablespace_name) tot,&lt;br /&gt;&gt; dba_tablespaces tbs&lt;br /&gt;&gt; where   tot.tablespace_name    = tbs.tablespace_name&lt;br /&gt;&gt; and     fre.tablespace_name(+) = tbs.tablespace_name&lt;br /&gt;&gt; group by tbs.tablespace_name, tot.bytes/1024, tot.bytes&lt;br /&gt;&gt; /&lt;br /&gt;&gt; exit&lt;br /&gt;&gt; EOF`&lt;br /&gt;&lt;br /&gt;-bash-3.00$ echo $DB_USED&lt;br /&gt;4189795.79&lt;br /&gt;&lt;br /&gt;This technique can be used in various places where you need to pass a value from Oracle to Unix shell environment.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/eof&gt;&lt;/eof&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-5928290576076377613?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/5928290576076377613/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=5928290576076377613' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/5928290576076377613'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/5928290576076377613'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2008/03/how-to-pass-value-from-oracle-to-unix.html' title='How to pass a value from Oracle to Unix shell environment variable?'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-3199586579663713760</id><published>2008-02-22T12:02:00.000+05:30</published><updated>2008-02-22T12:48:50.502+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips'/><category scheme='http://www.blogger.com/atom/ns#' term='General'/><category scheme='http://www.blogger.com/atom/ns#' term='materialized view'/><title type='text'>How to rename Materialized view? ORA-32318</title><content type='html'>Now - this is what you call a long break .. almost a year. Well - The personal life has been rocking all during last year and I have good news to share, I'm a proud father of a cute little girl. We are still searching a name for her. That is some relief in Hindu religion that we can take up to some days before finalizing the name of baby.&lt;br /&gt;&lt;br /&gt;I hope to be more punctual in writing my experiences here on the blog.&lt;br /&gt;Today, I have something on materialized views. How to rename them?&lt;br /&gt;&lt;br /&gt;Last week, I had this requirement to rename a materialized view and initial search on how to the same landed me on to &lt;a href="http://ora-32318.ora-code.com/"&gt;ORA-32318&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;ORA-32318: cannot rename a materialized view&lt;br /&gt;Cause: Renaming a materialized view or its base table is not supported.&lt;br /&gt;Action: Do not rename the base table of a materialized view.&lt;br /&gt;&lt;br /&gt;Now, this is what I dont expect Oracle to do. when rename of table is possible, then why not rename of mat view possible? If any one knows a logical reason, please share.&lt;br /&gt;&lt;br /&gt;Anyways, I gave it a further thought on how to accomplish this and an idea struck me.&lt;br /&gt;&lt;br /&gt;I'm giving the information of our system but with changed names.&lt;br /&gt;DB1 - where base table exists - 10.2.0.2&lt;br /&gt;DB2 - where mview exists - 10.2.0.2&lt;br /&gt;T1  - name of the table on DB1&lt;br /&gt;M1  - name of the mview - Fast/Incremental refresh on demand&lt;br /&gt;&lt;br /&gt;Now as discussed the requirement is to convert M1 to M2, with least down-time (at least for selects).&lt;br /&gt;&lt;br /&gt;Here is some test setup scripts:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;On DB1:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; create table t1 as select * from all_objects;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter table t1 add primary key (object_id);&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; create materialized view log on t1;&lt;br /&gt;&lt;br /&gt;Materialized view log created.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;On DB2:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; create materialized view m1 refresh fast on demand as select * from t1@db1; - db1 is database link&lt;br /&gt;&lt;br /&gt;Materialized view created.&lt;br /&gt;&lt;br /&gt;SQL&gt; select count(*) from m1;&lt;br /&gt;&lt;br /&gt;COUNT(*)&lt;br /&gt;----------&lt;br /&gt;   62551&lt;br /&gt;&lt;br /&gt;Now steps to change the name:&lt;br /&gt;&lt;br /&gt;Step1: On DB1&lt;br /&gt;- Stop DML/DDL activities on the base table T1&lt;br /&gt;&lt;br /&gt;Step2: On DB2&lt;br /&gt;- Refresh the M1 mview to ensure that there are no changes in there, so we can plan to change the name.&lt;br /&gt;- Create another table with new name. This new name should be the name of mview intended.&lt;br /&gt;&lt;br /&gt;SQL&gt; create table m2 as select * from m1;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;&gt;&gt; Well this can help you in moving non-partition base-table/mview to partitioned base-table/mview&lt;br /&gt;&lt;br /&gt;Step3: On DB2&lt;br /&gt;&lt;br /&gt;Create new materialized view using "prebuilt" option.&lt;br /&gt;&lt;br /&gt;SQL&gt; create materialized view m2 ON PREBUILT TABLE REFRESH fast on demand as select * from t1@db1;&lt;br /&gt;&lt;br /&gt;Materialized view created.&lt;br /&gt;&lt;br /&gt;Step4: On DB2&lt;br /&gt;&lt;br /&gt;Drop the old materialized view.&lt;br /&gt;&lt;br /&gt;SQL&gt; drop materialized view m1;&lt;br /&gt;&lt;br /&gt;Materialized view dropped.&lt;br /&gt;&lt;br /&gt;Thats it!&lt;br /&gt;&lt;br /&gt;Now to check if thats working.&lt;br /&gt;&lt;br /&gt;Delete few rows on t1@db1&lt;br /&gt;&lt;br /&gt;SQL&gt; delete from t1 where object_id in (2,3);&lt;br /&gt;&lt;br /&gt;2 rows deleted.&lt;br /&gt;&lt;br /&gt;SQL&gt; commit;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;&gt;&gt; And now refresh the new mview.&lt;br /&gt;&lt;br /&gt;SQL&gt; exec dbms_mview.refresh('M2')&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;&gt;&gt; Check the no of rows:&lt;br /&gt;SQL&gt; select count(*) from m2;&lt;br /&gt;&lt;br /&gt;COUNT(*)&lt;br /&gt;----------&lt;br /&gt;   62549&lt;br /&gt;&lt;br /&gt;Finally check the way oracle refreshed this mview.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; select LAST_REFRESH_TYPE from user_mviews where MVIEW_NAME='M2';&lt;br /&gt;&lt;br /&gt;LAST_REF&lt;br /&gt;--------&lt;br /&gt;FAST&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Well that's just a confirmation :)&lt;br /&gt;&lt;br /&gt;Note: I havent tested other functionalities of this test. So please do a thorough testing of this code before pushing into production database system.&lt;br /&gt;BTW - we are doing the same.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-3199586579663713760?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/3199586579663713760/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=3199586579663713760' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/3199586579663713760'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/3199586579663713760'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2008/02/how-to-rename-materialized-view-ora.html' title='How to rename Materialized view? ORA-32318'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-2349543363889324124</id><published>2007-03-23T14:31:00.000+05:30</published><updated>2007-03-23T15:48:03.263+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips'/><category scheme='http://www.blogger.com/atom/ns#' term='CBO'/><category scheme='http://www.blogger.com/atom/ns#' term='Tuning'/><title type='text'>Db file sequential read while doing full table scan?</title><content type='html'>&lt;p class="MsoNormal"&gt;These days, we are working on data warehouse in which we have a master table which will have 1.5m (approx) rows inserted every half hour and we have few fast refresh materialized view based on it. These mviews have some aggregate functions on it, which makes it a bit complex. &lt;/p&gt;      &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;br /&gt;To start the experiment, each mview refreshes used to take some 18-20 mins, which is totally against the business requirement. Then we tried to figure out on why the mview refresh is taking so much time, in spite of dropping all the bitmap indexes on the mview (generally b-map indexes are not good for inserts/updates).&lt;br /&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;  &lt;/p&gt; &lt;p class="MsoNormal"&gt;The 10046 trace (level 12) highlighted that there were many &lt;i style=""&gt;“db file sequential reads”&lt;/i&gt; on mview because of optimizer using “I_SNAP$_mview” to fetch the rows from mview and merge the rows with that of master table to make the aggregated data for the mview.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;Good part of the story is access to master table was quite fast because we used direct load (using sqlldr direct=y) to insert the data in it. When you use direct load to insert the data, oracle maintains the list of rowids added to table in a view called “SYS.ALL_SUMDELTA”. So while doing fast mview refresh, news rows inserted are picked directly from table using the rowids given from ALL_SUMDELTA view and not from Mview log, so this saves time.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;Concerned part was still Oracle using I_SNAP$ index while fetching the data from mview and there were many “db file sequential read” waits and it was clearly visible that Oracle waited on sequential read the most. We figured it out that full table scan (which uses scattered read, and multi block read count) was very fast in comparison to index access by running simple test against table. Also the tables are dependent mviews are only for the day. End of the day the master table and mview’s data will be pushed to historical tables and master table and mviews will be empty post midnight.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;I gathered the stats of mview and then re-ran the mview refresh, and traced the session, and this time optimizer didn’t use the index which was good news.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;Now the challenge was to run the mview stats gathering job every half an hour or induce wrong stats to table/index to ensure mview refresh never uses index access or may be to lock the stats using DBMS_STATS.LOCK_TABLE_STATS. &lt;/p&gt;    &lt;p class="MsoNormal"&gt;But we found another solution by creating the mview with “USING NO INDEX” clause. This way “I_SNAP$” index is not created with “CREATE MATERIALIZED VIEW’ command. As per Oracle the “I_SNAP$” index is good for fast refresh but it proved to be reverse for us because our environment is different and the data changes is quite frequent.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;Now, we ran the tests again, we loaded 48 slices of data (24 hrs x 2 times within hour) and the results were above expectations. We could load the data with max 3 mins per load of data.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;This is not the end of story. In the trace we could see the mview refresh using “MERGE” command and using full table scan access to mview (which we wanted) and rowid range access to master table.&lt;/p&gt;   &lt;p class="MsoNormal"&gt;The explain plan looks like:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Rows&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Row Source Operation&lt;br /&gt;  -------&amp;nbsp;  ---------------------------------------------------&lt;br /&gt;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;  MERGE&amp;nbsp; SF_ENV_DATA_MV (cr=4598  pr=5376 pw=0 time=47493463 us)&lt;br /&gt;  &amp;nbsp;263052&amp;nbsp;&amp;nbsp;  VIEW&amp;nbsp; (cr=3703 pr=3488 pw=0  time=24390284 us)&lt;br /&gt;  &amp;nbsp;263052&amp;nbsp;&amp;nbsp;&amp;nbsp;  HASH JOIN OUTER (cr=3703 pr=3488 pw=0 time=24127224 us)&lt;br /&gt;  &amp;nbsp;263052&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  VIEW&amp;nbsp; (cr=1800 pr=1790 pw=0  time=14731732 us)&lt;br /&gt;  &amp;nbsp;263052&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  SORT GROUP BY (cr=1800 pr=1790 pw=0 time=14205624 us)&lt;br /&gt;  &amp;nbsp;784862&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  VIEW&amp;nbsp; (cr=1800 pr=1790 pw=0  time=3953958 us)&lt;br /&gt;  &amp;nbsp;784862&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  NESTED LOOPS&amp;nbsp; (cr=1800 pr=1790  pw=0 time=3169093 us)&lt;br /&gt;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  VIEW&amp;nbsp; ALL_SUMDELTA (cr=9 pr=0 pw=0  time=468 us)&lt;br /&gt;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  FILTER&amp;nbsp; (cr=9 pr=0 pw=0 time=464  us)&lt;br /&gt;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MERGE JOIN CARTESIAN (cr=9 pr=0 pw=0  time=459 us)&lt;br /&gt;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NESTED LOOPS&amp;nbsp; (cr=6 pr=0 pw=0 time=99 us)&lt;br /&gt;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TABLE ACCESS BY INDEX ROWID OBJ$  (cr=3 pr=0 pw=0 time=56 us)&lt;br /&gt;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INDEX UNIQUE SCAN I_OBJ1 (cr=2  pr=0 pw=0 time=23 us)(object id 36)&lt;br /&gt;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TABLE ACCESS CLUSTER USER$ (cr=3  pr=0 pw=0 time=40 us)&lt;br /&gt;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INDEX UNIQUE SCAN I_USER# (cr=1  pr=0 pw=0 time=7 us)(object id 11)&lt;br /&gt;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BUFFER SORT (cr=3 pr=0 pw=0  time=354 us)&lt;br /&gt;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INDEX RANGE SCAN I_SUMDELTA$ (cr=3  pr=0 pw=0 time=243 us)(object id 158)&lt;br /&gt;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NESTED LOOPS&amp;nbsp; (cr=0 pr=0 pw=0 time=0 us)&lt;br /&gt;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INDEX RANGE SCAN I_OBJAUTH1 (cr=0  pr=0 pw=0 time=0 us)(object id 103)&lt;br /&gt;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FIXED TABLE FULL X$KZSRO (cr=0 pr=0  pw=0 time=0 us)&lt;br /&gt;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FIXED TABLE FULL X$KZSPR (cr=0 pr=0  pw=0 time=0 us)&lt;br /&gt;  &amp;nbsp;784862&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  TABLE ACCESS BY ROWID RANGE SF_ENV_SLICE_DATA (cr=1791 pr=1790 pw=0  time=2383760 us)&lt;br /&gt;  &amp;nbsp;708905&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  MAT_VIEW ACCESS FULL SF_ENV_DATA_MV (cr=1903 pr=1698 pw=0 time=6387829  us)&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-size:78%;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;You can see the access pattern as above.&lt;/p&gt;   &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;   &lt;p class="MsoNormal"&gt;Interesting twist in the story is when I saw the wait events in trace file.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&amp;nbsp; Event waited on&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Times&amp;nbsp;&amp;nbsp; Max. Wait&amp;nbsp;  Total Waited&lt;br /&gt;  &amp;nbsp;  ----------------------------------------&amp;nbsp;&amp;nbsp; Waited&amp;nbsp;  ----------&amp;nbsp; ------------&lt;br /&gt;  &amp;nbsp; db file sequential  read&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2253&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  0.74&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7.73&lt;br /&gt;  &amp;nbsp; db file scattered  read&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 240&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1.05&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6.77&lt;br /&gt;  &amp;nbsp; log file switch  completion&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  0.98&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3.16&lt;br /&gt;  &amp;nbsp; log file switch &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.98&amp;nbsp;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2.47&lt;br /&gt;  &amp;nbsp; rdbms ipc reply&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00&lt;br /&gt;  &amp;nbsp; log buffer  space&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.42&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.61&lt;/p&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;Again, even when we are doing full table scan, there are “db file sequential reads”?&lt;/p&gt;   &lt;p class="MsoNormal"&gt;To confirm I opened the raw trace file (before tkprof), and checked the obj# on sequential read wait event, it was the mview (SF_ENV_DATA_MV) !! and there were many. To further investigate I checked if there were any scattered reads to mview or not. I found there were scattered reads but there were many sequential reads also on which Oracle waited more than that of scattered read which did most of the data fetching.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;After giving some thought, I realized that we created the mviews without storage clause, which means Oracle created the mview with default storage clause.&lt;/p&gt;   &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;  &lt;/p&gt; &lt;p class="MsoNormal"&gt;So assuming there are 17 blocks in an mview (container table) extent and Multi block read count is 16, Oracle will use scattered read mechanism (multiple blocks) to read the first 16 blocks and for the rest 1 it will use sequential read mechanism (one block), so you will find many sequential reads wait events sandwiched between scattered reads.&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;&lt;i style=""&gt;&lt;span style="font-weight: bold;"&gt;To overcome this we created the mview with larger extent sizes and also multiple of MBCR (multi block read count).&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;Also, another cause of sequential read is chained or migrated rows, if your mview (or table) rows are migrated, the pointer to the next row is maintained in old (original) block, which will always&lt;span style=""&gt;  &lt;/span&gt;be read by a single i/o call i.e. by sequential read.You can check the count of chained rows using DBA_TABLES.CHAIN_CNT after analysing the table .&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;&lt;i style=""&gt;&lt;span style="font-weight: bold;"&gt;So to overcome this, we created the mview with genuine pctfree so when the merge runs (as a part of mview refresh) and updates few rows, the rows are not moved to a different block and hence avoiding sequential read.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;Conclusion: &lt;/p&gt;   &lt;ol style="margin-top: 0in;" start="1" type="1"&gt; &lt;li class="MsoNormal" style=""&gt;Mview creation with “USING NO INDEX” does not create “I_SNAP$” index which sometimes help in fast refresh when the data changes are quite frequent and you cannot afford to collect stats after every few mins.&lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;Create      mview with storage clause suiting to your environment. Default extent      sizes may not be always good. &lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;PCTFREE      can be quite handy to avoid sequential reads and extra block read.&lt;/li&gt; &lt;/ol&gt;   &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-2349543363889324124?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/2349543363889324124/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=2349543363889324124' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/2349543363889324124'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/2349543363889324124'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2007/03/db-file-sequential-read-while-doing.html' title='Db file sequential read while doing full table scan?'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-6334085956222688380</id><published>2007-03-03T16:43:00.000+05:30</published><updated>2007-03-08T13:57:56.969+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='CBO'/><category scheme='http://www.blogger.com/atom/ns#' term='Tuning'/><title type='text'>Optimizer_mode – ALL_ROWS or FIRST_ROWS?</title><content type='html'>&lt;p class="MsoNormal"&gt;Out of all Oracle RDBMS modules, optimizer code is actually the most complicated code and different optimizer modes seem like jack while lifting your car in case of a puncture.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;This paper focuses on how optimizer behaves differently when you have optimizer mode set to ALL_ROWS or FIRST_ROWS.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;Possible values for optimizer_mode = choose/ all_rows/ first_rows/ first_rows[n]&lt;/p&gt;    &lt;p class="MsoNormal"&gt;By default, the value of optimizer_mode is CHOOSE which basically means ALL_ROWS (if statistics on underlying tables exist) else RULE (if there are no statistics on underlying tables). So it is very important to have statistics collected on your tables on regular intervals or else you are living in Stone Age.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;FIRST_ROWS and ALL_ROWS are both cost based optimizer features. You may use them according to their requirement.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;b style=""&gt;&lt;i style=""&gt;FIRST_ROWS/ FIRST_ROWS[n&lt;u&gt;]&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;In simple terms it ensures best response time of first few rows (n rows).&lt;/p&gt;    &lt;p class="MsoNormal"&gt;This mode is good for interactive client-server environment where server serves first few rows and by the time user scroll down for more rows, it fetches other. So user feels that he has been served the data he requested, but in reality the request is still pending and query is still fetching the data in background.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;Best example for this is toad, if you click on data tab, it instantaneously start showing you data and you feel toad is faster than sqlplus, but the fact is if you scroll down, you will see the query is still running.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;Ok, let us simulate this on SQLPLUS&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;i style=""&gt;&lt;u&gt;Create a table and index over it:&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/i&gt;&lt;/p&gt;&lt;br /&gt;SQL&gt; create table test as select * from all_objects;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;SQL&gt; create index test_in on test(object_type);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;SQL&gt; exec dbms_stats.gather_table_stats(‘SAC’,'TEST')&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; select count(*) from test;&lt;br /&gt;&lt;br /&gt;COUNT(*)&lt;br /&gt;----------&lt;br /&gt;37944&lt;br /&gt;&lt;br /&gt;SQL&gt;  select count(*) from test where object_type='JAVA CLASS';&lt;br /&gt;&lt;br /&gt;COUNT(*)&lt;br /&gt;----------&lt;br /&gt;14927&lt;br /&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;You see out of almost 38k records, 15k are of JAVA class. And now if you select the rows having object_type=’JAVA_CLASS’, it should not use index as almost half of the rows are JAVA_CLASS. It will be foolish of optimizer to read the index first and then go to table.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;i style=""&gt;&lt;u&gt;Check out the Explain plans&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/i&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; set autotrace traceonly exp&lt;br /&gt;SQL&gt; select * from test where object_type='JAVA CLASS';&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 1357081020&lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT  |      |  1001 | 94094 |    10   (0)| 00:00:01 |&lt;br /&gt;|*  1 |  TABLE ACCESS FULL| TEST |  1001 | 94094 |    10   (0)| 00:00:01 |&lt;br /&gt;--------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;As you see above, optimizer has not used Index we created on this table.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;i style=""&gt;&lt;u&gt;Now use FIRST_ROWS hint:&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/i&gt;&lt;/p&gt;&lt;br /&gt;SQL&gt; select /*+ FIRST_ROWS*/ * from test where object_type='JAVA CLASS';&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 3548301374&lt;br /&gt;&lt;br /&gt;---------------------------------------------------------------------------------------&lt;br /&gt;| Id  | Operation                   | Name    | Rows  | Bytes | Cost (%CPU)| Time     |&lt;br /&gt;---------------------------------------------------------------------------------------&lt;br /&gt;|   0 | SELECT STATEMENT            |         | 14662 |  1345K|   536   (1)| 00:00:07 |&lt;br /&gt;|   1 |  TABLE ACCESS BY INDEX ROWID| TEST    | 14662 |  1345K|   536   (1)| 00:00:07 |&lt;br /&gt;|*  2 |   INDEX RANGE SCAN          | TEST_IN | 14662 |       |    43   (3)| 00:00:01 |&lt;br /&gt;---------------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;In this case, optimizer has used the index. &lt;/p&gt;    &lt;p class="MsoNormal"&gt;Q&gt; Why?&lt;br /&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;Ans&gt; Because you wanted to see first few rows quickly. So, following your instructions oracle delivered you first few rows quickly using index and later delivering the rest.&lt;/p&gt;  &lt;p class="MsoNormal"&gt;  &lt;/p&gt; &lt;p class="MsoNormal"&gt;See the difference in cost, although the response time (partial) of second query was faster but resource consumption was high.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;But that does not mean that this optimizer mode is bad. As I said this mode may be good for interactive client-server model. In most of OLTP systems, where users want to see data fast on their screen, this mode of optimizer is very handy.&lt;/p&gt;    &lt;p style="font-style: italic;" class="MsoNormal"&gt;Important facts about FIRST_ROWS&lt;br /&gt;&lt;/p&gt; &lt;p style="font-style: italic;" class="MsoNormal"&gt;  &lt;/p&gt; &lt;ol&gt;   &lt;li&gt;It gives preference to Index scan Vs Full scan (even when index scan is not good).&lt;/li&gt;   &lt;li&gt;It prefers nested loop over hash joins because nested loop returns data as selected (&amp; compared), but hash join hashes one first input in hash table which takes time.&lt;/li&gt;   &lt;li&gt;Cost of the query is not the only criteria for choosing the execution plan. It chooses plan which helps in fetching first rows fast.&lt;/li&gt;   &lt;li&gt;It may be a good option to use this in an OLTP environment where user wants to see data as early as possible.&lt;/li&gt; &lt;/ol&gt;            &lt;p class="MsoNormal"&gt; &lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;b style=""&gt;&lt;i style=""&gt;&lt;br /&gt;ALL_ROWS&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;In simple terms, it means better throughput&lt;/p&gt;    &lt;p class="MsoNormal"&gt;While FIRST_ROWS may be good in returning first few rows, ALL_ROWS ensures the optimum resource consumption and throughput of the query. In other words, ALL_ROWS is better to retrieve the last row first.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;In above example while explaining FIRST_ROWS, you have already seen how efficient ALL_ROWS is.&lt;/p&gt;    &lt;p style="font-weight: bold; font-style: italic;" class="MsoNormal"&gt;Important facts about ALL_ROWS&lt;br /&gt;&lt;/p&gt; &lt;p style="font-weight: bold; font-style: italic;" class="MsoNormal"&gt;  &lt;/p&gt; &lt;ol&gt;   &lt;li&gt;ALL_ROWS considers both index scan and full scan and based on their contribution to the overall query, it uses them. If Selectivity of a column is low, optimizer may use index to fetch the data (for example ‘where employee_code=7712’), but if selectivity of column is quite high ('where deptno=10'), optimizer may consider doing Full table scan. With ALL_ROWS, optimizer has more freedom to its job at its best.&lt;/li&gt;   &lt;li&gt;Good for OLAP system, where work happens in batches/procedures. (While some of the report may still use FIRST_ROWS depending upon the anxiety level of report reviewers)&lt;/li&gt;   &lt;li&gt;Likes hash joins over nested loop for larger data sets.   &lt;/li&gt; &lt;/ol&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Conclusion&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Cost based optimizer gives you flexibility to choose response time or throughput. So use them based on your business requirement.&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-6334085956222688380?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/6334085956222688380/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=6334085956222688380' title='21 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/6334085956222688380'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/6334085956222688380'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2007/03/optimizermode-allrows-or-firstrows.html' title='Optimizer_mode – ALL_ROWS or FIRST_ROWS?'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>21</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-5985418838288765088</id><published>2007-03-02T20:17:00.000+05:30</published><updated>2007-03-03T17:03:53.397+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='CBO'/><category scheme='http://www.blogger.com/atom/ns#' term='Tuning'/><title type='text'>Nested loops, Hash join and Sort Merge joins – difference?</title><content type='html'>&lt;p class="MsoNormal"&gt;&lt;b style=""&gt;&lt;u&gt;Nested loop (loop over loop)&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;     &lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;In this algorithm, an outer loop is formed which consists of few entries and then for each entry, and inner loop is processed.&lt;/p&gt;     &lt;p class="MsoNormal"&gt;&lt;o:p&gt;&lt;/o:p&gt;Ex:&lt;/p&gt;   &lt;p class="MsoNormal"&gt;Select tab1.*, tab2.* from tabl, tab2 where tabl.col1=tab2.col2;&lt;/p&gt;     &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;It is processed like:&lt;/p&gt;                     &lt;p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"&gt;&lt;o:p&gt;&lt;/o:p&gt;For i in (select * from tab1) loop&lt;br /&gt;For j in (select * from tab2 where col2=i.col1) loop&lt;br /&gt;Display results;&lt;br /&gt;End loop;&lt;br /&gt;End loop;&lt;br /&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"&gt;The Steps involved in doing nested loop are:&lt;span style=""&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"&gt;&lt;span style=""&gt;a)&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;Identify outer (driving) table&lt;/p&gt;   &lt;p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;     b)&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;Assign inner (driven) table to outer table.&lt;/p&gt; &lt;p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;     c)&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;For every row of outer table, access the rows of inner table.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;In execution plan it is seen like this:&lt;/p&gt;         &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;   &lt;p class="MsoNormal"&gt;NESTED LOOPS&lt;br /&gt;outer_loop&lt;br /&gt;inner_loop&lt;/p&gt;     &lt;p style="font-style: italic;" class="MsoNormal"&gt;When optimizer uses nested loops?&lt;/p&gt;     &lt;p class="MsoNormal"&gt;Optimizer uses nested loop when we are joining tables containing small number of rows with an efficient driving condition. It is important to have an index on column of inner join table as this table is probed every time for a new value from outer table.&lt;/p&gt;     &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;Optimizer may not use nested loop in case:&lt;span style=""&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style=""&gt;&lt;span style=""&gt;&lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt; &lt;ol&gt;   &lt;li&gt;No of rows of both the table is quite high&lt;/li&gt;   &lt;li&gt;Inner query always results in same set of records&lt;/li&gt;   &lt;li&gt;The access path of inner table is independent of data coming from outer table.&lt;/li&gt; &lt;/ol&gt; &lt;!--[endif]--&gt; &lt;p class="MsoNormal"&gt;&lt;i style=""&gt;&lt;u&gt;Note&lt;/u&gt;: You will see more use of nested loop when using FIRST_ROWS optimizer mode as it works on model of showing instantaneous results to user as they are fetched. There is no need for selecting caching any data before it is returned to user. In case of hash join it is needed and is explained below.&lt;br /&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;  &lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;b style=""&gt;&lt;u&gt;Hash join&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;Hash joins are used when the joining large tables.&lt;span style=""&gt;  &lt;/span&gt;The optimizer uses smaller of the 2 tables to build a hash table in memory and the scans the large tables and compares the hash value (of rows from large table) with this hash table to find the joined rows.&lt;/p&gt;         &lt;p class="MsoNormal"&gt;The algorithm of hash join is divided in two parts&lt;/p&gt;&lt;!--[if !supportLists]--&gt;&lt;!--[endif]--&gt; &lt;ol&gt;   &lt;li&gt;&lt;b style=""&gt;Build&lt;/b&gt; a in-memory hash table on smaller of the two tables.&lt;/li&gt;   &lt;li&gt;&lt;b style=""&gt;Probe&lt;/b&gt; this hash table with hash value for each row second table&lt;/li&gt; &lt;/ol&gt;  &lt;p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"&gt;&lt;!--[endif]--&gt;&lt;/p&gt;   &lt;p class="MsoNormal"&gt;  &lt;/p&gt; &lt;p class="MsoNormal"&gt;In simpler terms it works like&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;i style=""&gt;&lt;u&gt;Build phase&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/i&gt;&lt;/p&gt;          &lt;p class="MsoNormal"&gt;For each row RW1 in small (left/build) table loop&lt;br /&gt;Calculate hash value on RW1 join key&lt;br /&gt;Insert RW1 in appropriate hash bucket.&lt;br /&gt;End loop;&lt;br /&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;  &lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;i style=""&gt;&lt;u&gt;Probe Phase&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/i&gt;&lt;/p&gt;                &lt;p class="MsoNormal"&gt;For each row RW2 in big (right/probe) table loop&lt;br /&gt;&lt;span style=""&gt;            &lt;/span&gt;    Calculate the hash value on RW2 join key&lt;br /&gt;&lt;span style=""&gt;            &lt;/span&gt;    For each row RW1 in hash table loop&lt;br /&gt;  If RW1 joins with RW2&lt;br /&gt;  Return RW1, RW2&lt;br /&gt;End loop;&lt;br /&gt;End loop;&lt;br /&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;  &lt;/p&gt; &lt;p style="font-style: italic;" class="MsoNormal"&gt;When optimizer uses hash join?&lt;br /&gt;&lt;/p&gt; &lt;p style="font-style: italic;" class="MsoNormal"&gt;  &lt;/p&gt; &lt;p class="MsoNormal"&gt;Optimizer uses has join while joining big tables or big fraction of small tables.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;Unlike nested loop, the output of hash join result is not instantaneous as hash joining is blocked on building up hash table.&lt;br /&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;  &lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;i style=""&gt;&lt;u&gt;Note: &lt;/u&gt;You may see more hash joins used with ALL_ROWS optimizer mode, because it works on model of showing results after all the rows of at least one of the tables are hashed in hash table.&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;b style=""&gt;&lt;u&gt;Sort merge join&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;Sort merge join is used to join two independent data sources. They perform better than nested loop when the volume of data is big in tables but not as good as hash joins in general.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;They perform better than hash join when the join condition columns are already sorted or there is no sorting required.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;The full operation is done in two parts:&lt;/p&gt;     &lt;ul&gt;   &lt;li&gt;&lt;!--[if !supportLists]--&gt;&lt;i style=""&gt;Sort join operation&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/li&gt; &lt;/ul&gt;                          &lt;p class="MsoNormal" style="margin-left: 0.5in;"&gt;get first row RW1 from input1&lt;br /&gt;get first row RW2 from input2.&lt;br /&gt;&lt;i style=""&gt;&lt;span style=""&gt;&lt;/span&gt;&lt;/i&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-left: 0.5in;"&gt;&lt;i style=""&gt;&lt;br /&gt;&lt;/i&gt;&lt;/p&gt; &lt;ul&gt;   &lt;li&gt;&lt;i style=""&gt;Merge join operation&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/li&gt; &lt;/ul&gt; &lt;p class="MsoNormal" style="margin-left: 0.5in;"&gt;&lt;o:p&gt;&lt;/o:p&gt;while not at the end of either input loop&lt;br /&gt;&lt;span style=""&gt;        &lt;/span&gt;    if RW1 joins with RW2&lt;br /&gt;&lt;span style=""&gt;                &lt;/span&gt;    get next row R2 from input 2&lt;br /&gt;&lt;span style=""&gt;                &lt;/span&gt;    return (RW1, RW2)&lt;br /&gt;&lt;span style=""&gt;        &lt;/span&gt;    else if RW1 &lt; style=""&gt;            get next row RW1 from input 1&lt;br /&gt;&lt;span style=""&gt;        &lt;/span&gt;    else&lt;br /&gt;get next row RW2 from input 2&lt;br /&gt;&lt;span style=""&gt; &lt;/span&gt;end loop&lt;/p&gt;     &lt;p class="MsoNormal"&gt;Note: If the data is already sorted, first step is avoided.&lt;/p&gt;    &lt;p class="MsoNormal"&gt;Important point to understand is, unlike nested loop where driven (inner) table is read as many number of times as the input from outer table, in sort merge join each of the tables involved are accessed at most once. So they prove to be better than nested loop when the data set is large.&lt;/p&gt;    &lt;p style="font-style: italic;" class="MsoNormal"&gt;When optimizer uses Sort merge join?&lt;/p&gt;     &lt;p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;a)&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;When the join condition is an inequality condition (like &lt;, &lt;=, &gt;=). This is because hash join cannot be used for inequality conditions and if the data set is large, nested loop is definitely not an option.&lt;/p&gt;   &lt;p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"&gt;&lt;!--[if !supportLists]--&gt;&lt;span style=""&gt;b)&lt;span style=""&gt;      &lt;/span&gt;&lt;/span&gt;&lt;!--[endif]--&gt;If sorting is anyways required due to some other attribute (other than join) like “order by”, optimizer prefers sort merge join over hash join as it is cheaper.&lt;br /&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"&gt;  &lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;i style=""&gt;Note: Sort merge join can be seen with both ALL_ROWS and FIRST_ROWS optimizer hint because it works on a model of first sorting both the data sources and then start returning the results. So if the data set is large and you have FIRST_ROWS as optimizer goal, optimizer may prefer sort merge join over nested loop because of large data. And if you have ALL_ROWS as optimizer goal and if any inequality condition is used the SQL, optimizer may use sort-merge join over hash join&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-5985418838288765088?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/5985418838288765088/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=5985418838288765088' title='36 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/5985418838288765088'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/5985418838288765088'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2007/03/nested-loops-hash-join-and-sort-merge.html' title='Nested loops, Hash join and Sort Merge joins – difference?'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>36</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-8422150675072915276</id><published>2007-02-27T12:28:00.000+05:30</published><updated>2007-02-27T12:38:03.950+05:30</updated><title type='text'>10g new background processes</title><content type='html'>With 10g many new background processes were introduced.&lt;br /&gt;This note highlights those.&lt;br /&gt;&lt;br /&gt;  &lt;p class="MsoNormal"&gt;&lt;u&gt;MMAN&lt;/u&gt;&lt;br /&gt;&lt;br /&gt;Memory Manager (MMAN) coordinates the sizing of different memory components within SGA. MMAN keeps a track of sizes of components and allocates/de-allocates memory based on their usage. This process is used only when you enable Automatic Shared Memory Management.&lt;/p&gt;   &lt;p class="MsoNormal"&gt;&lt;br /&gt; &lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt; &lt;!--[endif]--&gt;&lt;/p&gt;   &lt;p class="MsoNormal"&gt;&lt;u&gt;RVWR&lt;br /&gt;&lt;/u&gt;&lt;br /&gt;Process responsible for writing flashback logs which stores pre-image of data-blocks.&lt;/p&gt;   &lt;p class="MsoNormal"&gt;These logs can be used to flash back database to past point in time. It proves very handy specially in situation of logical data corruptions like an accidental drop/truncate of a table or commit of an unwanted transaction.&lt;/p&gt;   &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;   &lt;p class="MsoNormal"&gt;&lt;br /&gt;&lt;br /&gt;&lt;u&gt;CTWR &lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/p&gt;   &lt;p class="MsoNormal"&gt;Change Tracking Writer (CTWR) Process introduced in 10g to track changes to block to assist fast RMAN incremental backups.&lt;/p&gt;   &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;   &lt;p class="MsoNormal"&gt;&lt;u&gt;MMNL&lt;/u&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;u&gt; &lt;/u&gt;The Memory Monitor Light (MMNL) process introduced in 10g is responsible for writing out statistics buffer to disk as needed. It works with Automatic Workload Repository (AWR)&lt;u&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/p&gt;   &lt;p class="MsoNormal"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;u&gt;MMON&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/p&gt;     &lt;p class="MsoNormal"&gt;The memory monitor (MMON) process was introduced in 10g is responsible for gathering statistics for Automatic Workload Repository. This helps Oracle doing automatic problem detection and self tuning.&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;br /&gt;&lt;br /&gt;&lt;u&gt;M000&lt;/u&gt;&lt;/p&gt;   &lt;p class="MsoNormal"&gt;MMON background slave (m000) processes. &lt;br /&gt; &lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt; &lt;!--[endif]--&gt;&lt;/p&gt;   &lt;p class="MsoNormal"&gt;&lt;br /&gt;&lt;u&gt;RBAL&lt;br /&gt;&lt;/u&gt;&lt;br /&gt;RBAL (Re-balancer) is the ASM related process that performs rebalancing of disk resources controlled by ASM.&lt;br /&gt;&lt;br /&gt;&lt;u&gt;ARBx&lt;br /&gt;&lt;/u&gt;&lt;br /&gt;These processes are managed by the RBAL process and are used to do the actual rebalancing of ASM controlled disk resources. The number of ARBx processes invoked is directly influenced by the asm_power_limit parameter.&lt;br /&gt;&lt;br /&gt;&lt;u&gt;ASMB&lt;br /&gt;&lt;/u&gt;&lt;br /&gt;The ASMB process is used to provide information to and from the Cluster Synchronization Services used by ASM to manage the disk resources. It is also used to update statistics and provide a heartbeat mechanism.&lt;u&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/u&gt;&lt;/p&gt; &lt;br /&gt;For more detailed info check following note on metalink:&lt;br /&gt;&lt;br /&gt;&lt;small&gt;&lt;a href="https://metalink.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&amp;amp;p_id=48681.1"&gt;Server Architecture on UNIX and NT&lt;/a&gt;&lt;br /&gt;&lt;/small&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-8422150675072915276?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/8422150675072915276/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=8422150675072915276' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/8422150675072915276'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/8422150675072915276'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2007/02/10g-new-background-processes.html' title='10g new background processes'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-8852426062440054688</id><published>2007-02-15T17:14:00.000+05:30</published><updated>2007-02-19T14:05:32.353+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Space management'/><title type='text'>Size your Undo tablespace</title><content type='html'>What should be the size of UNDO tablespace? Generally this question is vaguely answered saying that sizing comes with experience (of DBA) or looking at load on server or sometimes even by the number of ORA-1555 or out of space errors.&lt;br /&gt;&lt;br /&gt;This paper is to help DBA’s in calculating the size of UNDO tablespace by using a simple formula.&lt;br /&gt;&lt;br /&gt;While designing an application, generally it is tough to know about the number of transactions and subsequently number of rows changed per second.&lt;br /&gt;So I suggest having a “big undo tablespace” to start with and based on load, after doing some calculations and resize your UNDO tablespace.&lt;br /&gt;&lt;br /&gt;In my case one of the applications was going to production (live), and I had no idea that how many transactions will happen against this database. All what I was told that there will be optimum (transactional) activity on this database. The word “optimum” itself is vague.&lt;br /&gt;&lt;br /&gt;So I started with UNDO tablespace with size of 2GB and datafiles with autoextend “on” .&lt;br /&gt;&lt;br /&gt;Note:&lt;br /&gt;In production, you must be very careful in using this (autoextend on) as the space may grow to inifinity very fast. So my advice is either dont use this option, or use with "maxsize" or continuously monitor space (which is tough).&lt;br /&gt;&lt;br /&gt;I month later, I noticed the activity from V$undostat.&lt;br /&gt;&lt;br /&gt;Here is the step by step approach:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 1: Longest running query.&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;SQL&gt; select max(maxquerylen) from v$undostat;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;MAX(MAXQUERYLEN)&lt;br /&gt;----------------&lt;br /&gt;1793&lt;br /&gt;&lt;br /&gt;This gives you ideal value for UNDO_RETENTION. To be on the safer size you should add few more seconds to get the right value. So in my case, the size of undo retention should be say 2000 secs.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 2: Size of UNDO tablespace.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Size of UNDO needed = UNDO_RETENTION x [UNDO block Generation per sec x DB_BLOCK_SIZE] + Overhead(30xDB_BLOCK_SIZE)&lt;br /&gt;&lt;br /&gt;Out of these we know UNDO_RETENTION and DB_BLOCK_SIZE&lt;br /&gt;&lt;br /&gt;All we need is to find out “UNDO Blocks per second”&lt;br /&gt;&lt;br /&gt;Which can be easily fetched from v$undostat&lt;br /&gt;&lt;br /&gt;SQL&gt; SELECT (SUM(undoblks))/ SUM ((end_time - begin_time) * 24*60*60) "UPS"&lt;br /&gt;2 FROM v$undostat;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;UPS&lt;br /&gt;------------------------------&lt;br /&gt;8.11985583&lt;br /&gt;&lt;br /&gt;V$undostat stores data for every 10 mins and begin/end times are start/end time of those intervals. We multiplied it with 24*60*60 because the difference between two dates will be in days and to get to seconds, we need it to multiply with 24hrs*60mins*60secs&lt;br /&gt;&lt;br /&gt;So now we have all the values needed.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Undo size needed = [8.12 x 2000 x 8192] + [30 x 8192] = 133283840 bytes = 127.11 MB&lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-8852426062440054688?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/8852426062440054688/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=8852426062440054688' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/8852426062440054688'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/8852426062440054688'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2007/02/size-your-undo-tablespace.html' title='Size your Undo tablespace'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-7387273832045829140</id><published>2007-02-07T13:42:00.000+05:30</published><updated>2007-02-07T14:47:37.545+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Oracle Arch'/><category scheme='http://www.blogger.com/atom/ns#' term='Space management'/><title type='text'>Identify and fix table fragmentation in Oracle 10g - how?</title><content type='html'>&lt;strong&gt;Table fragmentation – when?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;If a table is only subject to inserts, there will not be any fragmentation.&lt;br /&gt;Fragmentation comes with when we update/delete data in table.&lt;br /&gt;The space which gets freed up during non-insert DML operations is not immediately re-used (or sometimes, may not get reuse ever at all). This leaves behind holes in table which results in table fragmentation.&lt;br /&gt;&lt;br /&gt;To understand it more clearly, we need to be clear on how oracle manages space for tables.&lt;br /&gt;&lt;br /&gt;“High water mark” of table actually defines the border line between &lt;em&gt;(ever)&lt;/em&gt; used and unused &lt;em&gt;(never)&lt;/em&gt; space. While performing full table scan, Oracle will always read the data up to HWM. And if there is lot of free space with-in HWM, that is read too, and hence degrading the performance of FTS.&lt;br /&gt;&lt;br /&gt;Now lets see how to identify HWM, unused (never used) space and free space (used but deleted/updated) and then take a call whether the concerned table is candidate for a reorganization or not.&lt;br /&gt;&lt;br /&gt;SQL&gt; create table test as select * from dba_tables; -- &lt;strong&gt;Create a table&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;SQL&gt; analyze table test compute statistics; -- &lt;strong&gt;Analyze it&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Table analyzed.&lt;br /&gt;&lt;br /&gt;SQL&gt; select blocks "Ever Used", empty_blocks "Never Used", num_rows "Total rows"&lt;br /&gt;2 from user_tables where table_name='TEST'; -- &lt;strong&gt;The number of blocks used/free&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Ever Used Never Used Total rows&lt;br /&gt;---------- ---------- ----------&lt;br /&gt;49 6 1680&lt;br /&gt;&lt;br /&gt;SQL&gt; delete from test where owner='SYS'; --- &lt;strong&gt;Im deleting almost half the number of rows.&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;764 rows deleted.&lt;br /&gt;&lt;br /&gt;SQL&gt; commit;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;SQL&gt; analyze table test compute statistics; -- &lt;strong&gt;Analyze it again&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Table analyzed.&lt;br /&gt;&lt;br /&gt;SQL&gt; select blocks "Ever Used", empty_blocks "Never Used", num_rows "Total rows"&lt;br /&gt;&lt;br /&gt;2 from user_tables where table_name='TEST'; -- &lt;strong&gt;No difference in blocks usage&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Ever Used Never Used Total rows&lt;br /&gt;---------- ---------- ----------&lt;br /&gt;49 6 916&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;Even though you deleted almost half the rows, the above shows that table HWM is up to 49 blocks, and to perform any FTS, Oracle will go up to 49 blocks to search the data. If your application is so-written that there are many FTS on this table, you may consider, reorganizing this table.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Reasons to reorganization&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;a) Slower response time (from that table)&lt;br /&gt;b) High number of chained (actually migrated) rows. &lt;br /&gt;c) Table has grown many folds and the old space is not getting reused.&lt;br /&gt;&lt;br /&gt;Note: Index based queries may not get that much benefited by reorg as compared to queries which does Full table scan.&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;strong&gt;How to reorganize?&lt;/strong&gt; &lt;/u&gt;&lt;br /&gt;&lt;br /&gt;Before Oracle 10g, there were mainly 2 ways to do the reorganization of the table&lt;br /&gt;a) Export, drop, and import.&lt;br /&gt;b) Alter table &lt;name&gt;move (to another tablespace, or same tablespace).&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Oracle 10g provides us a new way of reorganizing the data.&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;Shrink command: This command is only applicable for tables which are tablespace with auto segment space management.&lt;br /&gt;&lt;br /&gt;Before using this command, you should have row movement enabled.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter table test enable row movement;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;There are 2 ways of using this command.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;1. Break in two parts&lt;/u&gt;&lt;/strong&gt;: In first part rearrange rows and in second part reset the HWM.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Part 1:&lt;/em&gt; Rearrange (All DML's can happen during this time)&lt;br /&gt;&lt;br /&gt;SQL&gt; alter table test shrink space compact;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Part 2:&lt;/em&gt; Reset HWM (No DML can happen. but this is fairly quick, infact goes unnoticed.)&lt;br /&gt;&lt;br /&gt;SQL&gt; alter table sa shrink space;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;2. Do it in one go:&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;SQL&gt; alter table sa shrink space; (Both rearrange and restting HWM happens in one statement)&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;Few advantages over the conventional methods&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;1. Unlike "alter table move ..", indexes are not in UNUSABLE state. After shrink command, indexes are updated also.&lt;br /&gt;&lt;br /&gt;2. Its an online operation, So you dont need downtime to do this reorg.&lt;br /&gt;&lt;br /&gt;3. It doesnot require any extra space for the process to complete.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Conclusion&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;Its a new 10g feature to shrink (reorg) the tables (almost) online which can be used with automatic segment space management.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-7387273832045829140?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/7387273832045829140/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=7387273832045829140' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/7387273832045829140'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/7387273832045829140'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2007/02/identify-and-fix-table-fragmentation-in.html' title='Identify and fix table fragmentation in Oracle 10g - how?'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-8828482716736940387</id><published>2007-01-31T14:17:00.000+05:30</published><updated>2007-02-01T16:56:54.793+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips'/><title type='text'>Running shell script from Oracle</title><content type='html'>It’s simple!!&lt;br /&gt;&lt;br /&gt;Especially with 10g, it is even more simpler.&lt;br /&gt;&lt;br /&gt;Here is an example:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Step 1: Create a shell script and grant execute priv to oracle user. I created a simple one:&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;bash-3.00$ cat /tmp/test.sh&lt;br /&gt;#!/usr/bin/ksh&lt;br /&gt;echo "Test succeeded `date`" &gt;&gt; /tmp/test.log&lt;br /&gt;&lt;br /&gt;Note: Do not forget to start your shell script with the shell you are using.&lt;br /&gt;&gt;&gt; #!/usr/bin/ksh should be present in your shell script otherwise, the job will fail with ORA-27369 job of type EXECUTABLE failed with &lt;exit&gt;&lt;br /&gt;&lt;br /&gt;bash-3.00$ chmod 755 /tmp/test.sh&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Step 2: Create the job:&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;Remember user doing the following should have “CREATE JOB” privilege.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; BEGIN&lt;br /&gt;2 DBMS_SCHEDULER.CREATE_JOB (&lt;br /&gt;3 job_name =&gt; 'TEST_SHELL',&lt;br /&gt;4 job_type =&gt; 'EXECUTABLE',&lt;br /&gt;5 job_action =&gt; '/tmp/test.sh',&lt;br /&gt;6 start_date =&gt; sysdate,&lt;br /&gt;7 repeat_interval =&gt; 'FREQ=MINUTELY; INTERVAL=1', /* every one hour */&lt;br /&gt;8 enabled =&gt; TRUE,&lt;br /&gt;9 comments =&gt; 'Testing shell script from Oracle');&lt;br /&gt;10 END;&lt;br /&gt;11 /&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Step 3: Check if the job is running:&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;bash-3.00$ cat /tmp/test.log&lt;br /&gt;Test succeeded Wed Jan 31 01:02:23 PST 2007&lt;br /&gt;Test succeeded Wed Jan 31 01:03:23 PST 2007&lt;br /&gt;Test succeeded Wed Jan 31 01:04:23 PST 2007&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-8828482716736940387?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/8828482716736940387/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=8828482716736940387' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/8828482716736940387'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/8828482716736940387'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2007/01/running-shell-script-from-oracle.html' title='Running shell script from Oracle'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-8780893525024719969</id><published>2007-01-30T12:39:00.000+05:30</published><updated>2007-01-31T10:46:48.602+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='CBO'/><category scheme='http://www.blogger.com/atom/ns#' term='Tuning'/><title type='text'>Index skip Scan – how?</title><content type='html'>With Oracle 9i, CBO is equipped with many more features, one of them is “Index skip scan” .This means even if you have a composite index on more than one column and you use the non-prefix column alone in your SQL, it may still use index.&lt;br /&gt;&lt;br /&gt;I said “may” because CBO will calculate the cost of using the index and if it is more than that of full table scan, then it may not use index.&lt;br /&gt;&lt;br /&gt;Index skip scan works differently from a normal index (range) scan.&lt;br /&gt;A normal range scan works from top to bottom first and then move horizontal.&lt;br /&gt;But a Skip scan includes several range scans in it. Since the query lacks the leading column it will rewrite the query into smaller queries and each doing a range scan.&lt;br /&gt;&lt;br /&gt;Ex: &lt;br /&gt;SQL&gt; create table test (a number, b number, c number);&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;SQL&gt; create index test_i on test(a,b);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;SQL&gt; begin&lt;br /&gt;  2  for i in 1 .. 100000&lt;br /&gt;  3    loop&lt;br /&gt;  4    insert into test values(mod(i, 5), i, 100);&lt;br /&gt;  5    end loop;&lt;br /&gt;  6   commit;&lt;br /&gt;  7   end;&lt;br /&gt;  8  /&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; exec dbms_stats.gather_table_stats(ownname =&gt; 'SAC', tabname =&gt; 'test', cascade =&gt; true);&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt; set autotrace trace exp&lt;br /&gt;SQL&gt; select * from test where b=95267;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;          0&lt;br /&gt;SELECT STATEMENT Optimizer=ALL_ROWS (Cost=22 Card=1 Bytes=10)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;          1                  0&lt;br /&gt;  TABLE ACCESS (BY INDEX ROWID) OF 'TEST' (TABLE) (Cost=22 Card=1 Bytes=10)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;          2                  1&lt;br /&gt;    INDEX (SKIP SCAN) OF 'TEST_I' (INDEX) (Cost=21 Card=1)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I above example, “select * from test where b=95267” was broken down to several small range scan queries. It was effectively equivalent to following &lt;br /&gt;&lt;br /&gt;Select * from test where a=0 and b=95267&lt;br /&gt;Union&lt;br /&gt;Select * from test where a=1 and b=95267&lt;br /&gt;Union&lt;br /&gt;Select * from test where a=2 and b=95267&lt;br /&gt;Union&lt;br /&gt;Select * from test where a=3 and b=95267&lt;br /&gt;Union&lt;br /&gt;Select * from test where a=4 and b=95267;&lt;br /&gt;&lt;br /&gt;In concrete, saying that skip scan is not as efficient as normal “single range scan” is correct. But yet saves some disk space and overhead of maintaining another index.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-8780893525024719969?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/8780893525024719969/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=8780893525024719969' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/8780893525024719969'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/8780893525024719969'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2007/01/index-skip-scan-how.html' title='Index skip Scan – how?'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-5158503878961920039</id><published>2007-01-24T12:08:00.000+05:30</published><updated>2007-01-24T13:49:14.367+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>External Tables - 10g</title><content type='html'>Until 9i external tables could only be used for read purposes.&lt;br /&gt;But 10g allows you to populate external tables.&lt;br /&gt;&lt;br /&gt;here is how it does:&lt;br /&gt;&lt;br /&gt;Step 1: - Create a directory&lt;br /&gt;&lt;br /&gt;SQL&gt; create directory my_dir as '/usr/test'; --- Make sure Oracle OS user has&lt;br /&gt;privilege to write on this directory.&lt;br /&gt;&lt;br /&gt;Step 2: - Grant permission to user SCOTT&lt;br /&gt;&lt;br /&gt;SQL&gt; grant read,write on directory my_dir to scott;&lt;br /&gt;&lt;br /&gt;Step 3: - Create the External Table: -&lt;br /&gt;&lt;br /&gt;SQL&gt; CREATE TABLE scott.external_emp_dept&lt;br /&gt;                      ORGANIZATION EXTERNAL&lt;br /&gt;      (TYPE ORACLE_DATAPUMP DEFAULT DIRECTORY my_dir&lt;br /&gt;        LOCATION ('emp_dept.exp')&lt;br /&gt;     ) &lt;br /&gt;   reject limit unlimited&lt;br /&gt;   AS &lt;br /&gt;   select e.ename,d.dname from emp e, dept d where &lt;br /&gt;   e.deptno=d.deptno;&lt;br /&gt;&lt;br /&gt;SQL&gt; select * from scott.external_emp_dept;&lt;br /&gt;&lt;br /&gt;ENAME      DNAME&lt;br /&gt;---------- --------------&lt;br /&gt;SMITH      RESEARCH&lt;br /&gt;ALLEN      SALES&lt;br /&gt;WARD       SALES&lt;br /&gt;JONES      RESEARCH&lt;br /&gt;MARTIN     SALES&lt;br /&gt;BLAKE      SALES&lt;br /&gt;CLARK      ACCOUNTING&lt;br /&gt;SCOTT      RESEARCH&lt;br /&gt;KING       ACCOUNTING&lt;br /&gt;TURNER     SALES&lt;br /&gt;ADAMS      RESEARCH&lt;br /&gt;&lt;br /&gt;ENAME      DNAME&lt;br /&gt;---------- --------------&lt;br /&gt;JAMES      SALES&lt;br /&gt;FORD       RESEARCH&lt;br /&gt;MILLER     ACCOUNTING&lt;br /&gt;&lt;br /&gt;And you will find a file generated i.e. 'emp_dept.exp' in /usr/test directory.&lt;br /&gt;&lt;br /&gt;Now you can take this file to the target database and create an external table &lt;br /&gt;and associate the file with that table.&lt;br /&gt;&lt;br /&gt;Step 4: - to be executed on the source database&lt;br /&gt;SQL&gt; set long 2000&lt;br /&gt;SQL&gt; Select dbms_metadata.get_ddl('TABLE','EXTERNAL_EMP_DEPT') from dual;&lt;br /&gt;&lt;br /&gt;The above command will give you the DDL command to create the table at target &lt;br /&gt;database.&lt;br /&gt;&lt;br /&gt;Similar note is also available on metalink &lt;a href=https://metalink.oracle.com/metalink/plsql/f?p=130:14:1228087276867018346::::p14_database_id,p14_docid,p14_show_header,p14_show_help,p14_black_frame,p14_font:NOT,249321.1,1,1,1,helvetica&gt;249321.1&lt;/a&gt; which was also written by me when I was with Oracle Support.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-5158503878961920039?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/5158503878961920039/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=5158503878961920039' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/5158503878961920039'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/5158503878961920039'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2007/01/external-tables-10g.html' title='External Tables - 10g'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-478919981938505984</id><published>2007-01-12T14:58:00.000+05:30</published><updated>2007-01-12T15:45:33.081+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tuning'/><title type='text'>SESSION_CACHED_CURSORS Vs CURSOR_SPACE_FOR_TIME - which, when and why?</title><content type='html'>They 2 considered to be the most important parameter for shared pool tuning, but I guess most of us generally don’t use them or sometimes use them incorrectly.&lt;br /&gt;&lt;br /&gt;The idea to put them here to understand “what they do?”, “when to use them?”, “how to use them?” and finally “see the impact”.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;SESSION_CACHED_CURSORS&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;In most of the environments, there are many SQL’s which are re-fired many a times within a session, and every time they are issued, the session searches the shared pool for the parsed state, if it doesn’t get the parsed version, it will “hard parse” it, and if it exists in shared pool, it will still do a “soft parse”.&lt;br /&gt;&lt;br /&gt;As we know “hard parse” is a costly operation, even a “soft parse” requires library cache latch and CPU overhead, which if aggregated is a significant number.&lt;br /&gt;&lt;br /&gt;This parameter if set to a non-zero value (default is 50), improves the “soft parse” performance by doing a softer soft parse.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;How?&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;If enabled, oracle maintains a local session cache which stores recently closed cursors of a session.&lt;br /&gt;&lt;br /&gt;To avoid this space getting misused or overused, oracle maintains the cursors for which there have been 3 parsed calls in the past, so all the SQL’s issued by a session are not here. Remember each cursor if pinned here, is not freeable and hence you may require more shared pool area.&lt;br /&gt;&lt;br /&gt;A normal cursor in shared pool is sum of 2 components:&lt;br /&gt;a) Heap 0 – size 1KB&lt;br /&gt;b) SQL Area – size multiple of 4k&lt;br /&gt;&lt;br /&gt;When we use session_cached_cursors only first component of cursor which is HEAP 0 is pinned in local session cache and if there is a call for re-parse for a statement, Oracle first checks the existence of the cursor in local cache and if found, it gets the address of the rest of the cursor which is in SQL Area (assuming if it is not aged out), so hereby saving CPU overhead and library cache latch contention.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;How much it is getting used ?&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; select max(value) from v$sesstat&lt;br /&gt;2 where STATISTIC# in (select STATISTIC# from v$statname where name='session cursor cache count');&lt;br /&gt;&lt;br /&gt;MAX(VALUE)&lt;br /&gt;----------&lt;br /&gt;100&lt;br /&gt;&lt;br /&gt;This shows maximum value for session_cached_cursors in past. If this value= “session_cached_cursors” (init.ora parameter), you should consider increasing it.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;If you want to see how is your session cache doing?&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; select cache/tot*100 "Session cursor cache%"&lt;br /&gt;2 from&lt;br /&gt;3 (select value tot from v$sysstat where name='parse count (total)'),&lt;br /&gt;4 ( select value cache from sys.v_$sysstat where name = 'session cursor cache hits' );&lt;br /&gt;&lt;br /&gt;Session cursor cache%&lt;br /&gt;---------------------&lt;br /&gt;106.635284&lt;br /&gt;&lt;br /&gt;A value near 100 is considered very good. But you may still consider increasing this parameter if MAX(VALUE) in query one shows you equal number of cached cursor which you have set.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;u&gt;Conclusion&lt;/u&gt;: In an OLTP application, where the same set of SQL is issued number of times, one must configure this parameter more than its default value (50).&lt;br /&gt;Also increasing this parameter will mean extra memory required for shared pool, so you must increase your shared pool when you use this parameter.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;CURSOR_SPACE_FOR_TIME&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;SQL can be aged out of shared pool in 2 cases:&lt;br /&gt;a) &lt;u&gt;When the cursor is closed&lt;/u&gt;: When the cursors are closed by application, they can still be in shared pool, until there comes a request for a new cursor and oracle needs to use LRU algorithm. SESSION_CACHED_CURSORS helps you in pinning (partial because it only pins HEAP 0) when the cursors are closed.&lt;br /&gt;&lt;br /&gt;b) &lt;u&gt;When the cursor is open&lt;/u&gt;: Oracle requires parsed state of SQL at PARSE and EXECUTE phase. If oracle parses (soft or hard) a statement, there is a likely hood that Oracle may age out your SQL out of shared pool after PARSE state if it requires to accommodate a new SQL coming its way. So in the EXECUTE state, there is a possibility that parsed information is lost and oracle parse it again.&lt;br /&gt;&lt;br /&gt;CURSOR_SPACE_FOR_TIME if set to TRUE, ensures that SQL is not aged out before the cursor is closed, so in EXECUTE phase, you will have the PARSE information.&lt;br /&gt;&lt;br /&gt;But this is generally a rare case and happens in a very highly active environment because to accommodate a new SQL, Oracle first check the free space and if it doesn’t get, it checks the closed cursors and see if any cursor can be aged out and when there is no space which can be reclaimed, Oracle comes to open cursors which are not EXECUTED.&lt;br /&gt;This generally happens when the space of shared pool is too less.&lt;br /&gt;&lt;br /&gt;I don’t suggest setting this parameter to TRUE in most of the cases.&lt;br /&gt;&lt;br /&gt;There are some other serious tradeoffs also.&lt;br /&gt;When a cursor is pinned, it cant be aged out and related memory cannot be freed for any new SQL and if you set this parameter to TRUE, you are telling Oracle to keep all the open cursors pinned and not freeable.&lt;br /&gt;If you use this parameter, you are pinning the whole cursor not just the HEAP 0 which is 1k, you are pinning HEAP 0 (1k) + SQL Area (multiple of 4k) which makes shared pool life tough because of space issues.&lt;br /&gt;&lt;br /&gt;&lt;u&gt;Conclusion:&lt;/u&gt;&lt;br /&gt;&lt;br /&gt;As I said, I don’t suggest setting this parameter to TRUE in most of the cases. An alternative to set this parameter is to increase shared pool size or/and check your code on how many numbers of cursors you are opening/closing. That will be a better approach. Setting this parameter is like taking paracetamol without knowing the cause of fever.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-478919981938505984?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/478919981938505984/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=478919981938505984' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/478919981938505984'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/478919981938505984'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2007/01/sessioncachedcursors-vs.html' title='SESSION_CACHED_CURSORS Vs CURSOR_SPACE_FOR_TIME - which, when and why?'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-5432035765850645052</id><published>2007-01-06T13:17:00.000+05:30</published><updated>2008-12-10T10:13:56.253+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Index Rebuild'/><title type='text'>Should I rebuild or coalesce my indexes ?</title><content type='html'>&lt;p&gt;Should I rebuild or coalesce my indexes ?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;My last 2 notes on this blogs were specific to rebuilding (when and to which) indexes.&lt;br /&gt;&lt;br /&gt;There is one more critical aspect which I wanted to discuss is the cost/effort related to rebuilding indexes.&lt;br /&gt;&lt;br /&gt;Rebuilding an index is quite a costly operation and you must evaluate the benefit Vs effort before rebuilding an index.&lt;br /&gt;&lt;br /&gt;Rebuilding (online) an index requires additional resources like space, cpu usage, time.&lt;br /&gt;&lt;br /&gt;Here is one more option, which is less used or probably less popular “coalesce”.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;lets&gt;Rebuild Vs Coalesce &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;strong&gt;Rebuild&lt;/strong&gt; &lt;/u&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Can move an index to a different tablespace&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Resource consuming process&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Takes more time&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Creates a new tree&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Shortens the height of an index if it was increased due to DML activities&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Rebuilding can affect future DML’s because index becomes compact and for future DML’s index has to be extend dynamically.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Coalesce&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Cannot move an index to a different tablespace&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Comparatively less resource consuming&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Takes relatively less time&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Only merge the adjacent free space between leaf blocks within a branch&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Doesn’t shorten height of index&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Since coalesce doesn’t effect the total size and only frees up the unused space, it doesn’t affect future DML’s&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_UMUqPNYoxX4/RaNM4I3eL-I/AAAAAAAAAAM/HId0mNjUnGI/s1600-h/coalesce.gif"&gt;&lt;img id="BLOGGER_PHOTO_ID_5017938937157398498" style="CURSOR: hand" alt="" src="http://4.bp.blogspot.com/_UMUqPNYoxX4/RaNM4I3eL-I/AAAAAAAAAAM/HId0mNjUnGI/s320/coalesce.gif" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Image Source: Oracle doc&lt;/em&gt;&lt;br /&gt;Coalescing the index, frees up space of adjacent leaf blocks within a branch block. This way the number of blocks or extents which an index is using will not change but there will be more number of free blocks which can be used for future inserts or updates.&lt;br /&gt;&lt;br /&gt;In an OLTP environment, where data is highly volatile, coalesce is better because it doesn’t shrink the index and the free space remains with the index segment.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-5432035765850645052?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/5432035765850645052/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=5432035765850645052' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/5432035765850645052'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/5432035765850645052'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2007/01/should-i-rebuild-or-coalesce-my-indexes.html' title='Should I rebuild or coalesce my indexes ?'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_UMUqPNYoxX4/RaNM4I3eL-I/AAAAAAAAAAM/HId0mNjUnGI/s72-c/coalesce.gif' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-486543705546193952</id><published>2007-01-04T17:29:00.000+05:30</published><updated>2007-01-12T15:28:41.165+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Index Rebuild'/><title type='text'>How to find indexes which are candidate for rebuild?</title><content type='html'>I'm writing this in response to Harvinder's comment.&lt;br /&gt;&lt;br /&gt;I know it’s a very arguable question, but let me put my words and then you can comment.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;I follow different approaches to find out indexes for rebuild&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;- Find out indexes having height(blevel+1) &gt; 4 i.e. Indexes having BLEVEL &gt; 3&lt;br /&gt;&lt;u&gt;How:&lt;/u&gt;&lt;br /&gt;SQL&gt; select owner,index_name,table_name,blevel from dba_indexes where BLEVEL&gt;3&lt;br /&gt;&lt;br /&gt;- Analyze indexes and find out ratio of (DEL_LF_ROWS/LF_ROWS*100) is &gt; 20&lt;br /&gt;&lt;u&gt;How:&lt;/u&gt;&lt;br /&gt;First "Analyze the index with validate structure option" and then,&lt;br /&gt;&lt;br /&gt;SQL&gt; SELECT name,height,lf_rows,del_lf_rows,(del_lf_rows/lf_rows)*100 as ratio FROM INDEX_STATS;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;But (a big but), the reason to rebuild should be because of poor performance of your queries using indexes. You should/must not rebuild indexes if you find both the above reason true for index if it is not coupled with poor SQL performance.&lt;br /&gt;&lt;/em&gt;&lt;br /&gt;See this example:&lt;br /&gt;&lt;br /&gt;SQL&gt; analyze index TEST_INDX validate structure; -- First analyze the suspect index&lt;br /&gt;&lt;br /&gt;Index analyzed.&lt;br /&gt;&lt;br /&gt;SQL&gt; SELECT name,height,lf_rows,lf_blks,del_lf_rows FROM INDEX_STATS;&lt;br /&gt;&lt;br /&gt;NAME HEIGHT LF_ROWS LF_BLKS DEL_LF_ROWS&lt;br /&gt;------------ ---------- ---------- ----------- -------------&lt;br /&gt;TEST_INDX 8 938752 29575 73342&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;You can see height of the index is 8 and also high number of DEL_LF_ROWS&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;SQL&gt; set autotrace on&lt;br /&gt;SQL&gt; set timing on&lt;br /&gt;SQL&gt;&lt;br /&gt;SQL&gt; select count(*) from TEST_TABLE where TEST_COL like 'http://www.hots%';&lt;br /&gt;&lt;br /&gt;COUNT(*)&lt;br /&gt;----------&lt;br /&gt;39700&lt;br /&gt;&lt;strong&gt;Elapsed: 00:00:27.25&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 870163320&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Id Operation Name Rows Bytes Cost (%CPU) Time&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;0 SELECT STATEMENT 1 117 &lt;strong&gt;10 (0)&lt;/strong&gt; 00:00:01&lt;br /&gt;&lt;br /&gt;1 SORT AGGREGATE 1 117&lt;br /&gt;&lt;br /&gt;*2 INDEX RANGE SCAN TEST_INDX 115 13455 10 (0) 00:00:01&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Statistics&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;1 recursive calls&lt;br /&gt;0 db block gets&lt;br /&gt;&lt;strong&gt;764 consistent gets&lt;br /&gt;757 physical reads&lt;/strong&gt;&lt;br /&gt;0 redo size&lt;br /&gt;516 bytes sent via SQL*Net to client&lt;br /&gt;468 bytes received via SQL*Net from client&lt;br /&gt;2 SQL*Net roundtrips to/from client&lt;br /&gt;0 sorts (memory)&lt;br /&gt;0 sorts (disk)&lt;br /&gt;1 rows processed&lt;br /&gt;&lt;br /&gt;Now you rebuild the indexes&lt;br /&gt;&lt;br /&gt;SQL&gt; alter index TEST_INDX rebuild;&lt;br /&gt;&lt;br /&gt;Index altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; select count(*) from TEST_TABLE where TEST_COL like 'http://www.hots%';&lt;br /&gt;&lt;br /&gt;COUNT(*)&lt;br /&gt;----------&lt;br /&gt;39700&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Elapsed: 00:00:06.18&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;Plan hash value: 870163320 - &lt;em&gt;&lt;strong&gt;See here although it is using the same plan but still it is faster&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Id Operation Name Rows Bytes Cost (%CPU) Time&lt;br /&gt;&lt;br /&gt;----------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;0 SELECT STATEMENT 1 117 &lt;strong&gt;6 (0)&lt;/strong&gt; 00:00:01&lt;br /&gt;&lt;br /&gt;1 SORT AGGREGATE 1 117&lt;br /&gt;&lt;br /&gt;* 2 INDEX RANGE SCAN TEST_INDX 115 13455 6 (0) 00:00:01&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Statistics&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;15 recursive calls&lt;br /&gt;0 db block gets&lt;br /&gt;&lt;strong&gt;592 consistent gets&lt;br /&gt;588 physical reads&lt;br /&gt;&lt;/strong&gt;0 redo size&lt;br /&gt;516 bytes sent via SQL*Net to client&lt;br /&gt;468 bytes received via SQL*Net from client&lt;br /&gt;2 SQL*Net roundtrips to/from client&lt;br /&gt;0 sorts (memory)&lt;br /&gt;0 sorts (disk)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; SELECT name,height,lf_rows,lf_blks,del_lf_rows,distinct_keys,used_space FROM INDEX_STATS;&lt;br /&gt;&lt;br /&gt;NAME HEIGHT LF_ROWS LF_BLKS DEL_LF_ROWS&lt;br /&gt;------------------------------ ---------- ---------- ---------- -----------&lt;br /&gt;TEST_INDX 4 865410 15434 0&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;This clearly indicates rebuild helped my query performance. The height of index is reduced to 4 and DEL_LF_ROWS is 0&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;Now coming to second of part of Harvinder's comment.&lt;br /&gt;&lt;br /&gt;Possible ways of Rebuilding.&lt;br /&gt;&lt;br /&gt;- Online/Offline.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;ONLINE Rebuild (8i onwards)&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; Alter index &lt;index_name&gt; rebuild online;&lt;br /&gt;&lt;br /&gt;This allows parallel DML to go on while Index is getting rebuild. Remember, online index requires more space, as it creates a new index before dropping the old one.&lt;br /&gt;&lt;br /&gt;Index Rebuild is primarily a 3 step process&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Prepare phase&lt;/u&gt;&lt;/strong&gt;: Oracle locks the table for a fraction of second (actually not felt) to build index structure and populate data-dictionary.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Build phase: &lt;/u&gt;&lt;/strong&gt;Most of the work is done in this phase. Oracle engine populates the index using the table and allows parallel DML's, parallel DML's uses a temporary journal table (b tree index like structure) to host the entries while the new index is getting populated.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Merge phase: &lt;/u&gt;&lt;/strong&gt;Now the final stage, Oracle merges the new index with the journal table and drops the old index. Even during the merge phase, any changes to the table are recorded in the journal table and they get merged towards end of this phase.&lt;br /&gt;&lt;br /&gt;9i onwards, online index rebuild feature includes Reverse Key, Function Based and Key Compressed indexes.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Offline Index rebuild.&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; Alter index &lt;index_name&gt; rebuild;&lt;br /&gt;&lt;br /&gt;This is conventional rebuild which was used(still available) before 8i. In this rebuild process, oracle drops the old index and creates a new one. In this process, no extra space is required, but parallel dml's are not supported.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-486543705546193952?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/486543705546193952/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=486543705546193952' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/486543705546193952'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/486543705546193952'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2007/01/how-to-find-indexes-which-are-candidate.html' title='How to find indexes which are candidate for rebuild?'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-1962965992094377868</id><published>2007-01-02T18:03:00.000+05:30</published><updated>2007-01-12T15:29:03.736+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Index Rebuild'/><title type='text'>When should I rebuild my indexes?</title><content type='html'>Need is necessary for any change. I hope all agree to this. So why many DBA’s (not all) rebuilds indexes on periodical basis without knowing the impact of it?&lt;br /&gt;&lt;br /&gt;Let’s revisit the facts stated by many Oracle experts:&lt;br /&gt;&lt;br /&gt;- B Tree indexes can never be unbalanced&lt;br /&gt;- The distance of any leaf block (which contains the index value) from the root block is always same.&lt;br /&gt;- B Tree performance is good for both small and large tables and does not degrade with the growth of table&lt;br /&gt;&lt;br /&gt;When will rebuild help?&lt;br /&gt;&lt;br /&gt;• When the data in index is sparse (lots of holes in index, due to deletes or updates) and your query is usually range based.&lt;br /&gt;&lt;br /&gt;If your SQL’s use “=” predicate, rebuilding of index may not help you at all unless the DML’s (updates/deletes) on the table are cause of increasing the height of index. Due to heavy updates/deletes on a table, the space in the index can be left unused (unless it is reused) due to which block splits and if the splitting goes beyond the level of accomodation, the height of index increases by 1.&lt;br /&gt;In simpler terms, unless you reduce the height (BLEVEL) of index, the time taken to reach the leaf block from root block will not change.&lt;br /&gt;&lt;br /&gt;As explained above, the height of index can be decreased by rebuild of an index(only if height was increased to updates/deletes).&lt;br /&gt;&lt;br /&gt;Only in case of range scan, rebuild (consider coalesce option also) may help.&lt;br /&gt;&lt;br /&gt;Select * from emp where empno between 1000 and 2000;&lt;br /&gt;&lt;br /&gt;In above case there could be lot of deleted/updated data which will also be read while reading between 1000 to 2000.  Rebuilding will reclaim any unused space and hence the select could be faster.&lt;br /&gt;&lt;br /&gt;• Index fast full scan/ Index full scan. (rare case)&lt;br /&gt;If your SQL’s are designed in a way that mostly data is selected from index (it doesn’t goes to table). In this case the whole index is read for data not for redirecting to table.&lt;br /&gt;&lt;br /&gt;Ex: &lt;br /&gt;Select count(empno) from emp; -- you have an index in empno&lt;br /&gt;Select empno from emp -- you have an index in empno&lt;br /&gt;&lt;br /&gt;Both the above SELECTs will fetch the data from Index only. Since the whole index is getting read, the space used by deleted rows is also read at the time of SELECT operation&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-1962965992094377868?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/1962965992094377868/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=1962965992094377868' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/1962965992094377868'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/1962965992094377868'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2007/01/when-should-i-rebuild-my-indexes.html' title='When should I rebuild my indexes?'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>10</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-7231282281875533605</id><published>2007-01-02T10:50:00.000+05:30</published><updated>2007-01-02T11:07:05.600+05:30</updated><title type='text'>Happy New Year - 2007</title><content type='html'>&lt;a href=http://www.icq.com/img/friendship/static/card_16961_rs.swf&gt;I wish everyone a very happy, prosperous, peaceful, joyful new year 2007.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;With this, I want to thank you for the superb response to this blob.&lt;br /&gt;I wanted to mention this earlier, but I was waiting for applauding mails to pause, so I could publish them in one go.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;jadharmadhikari no_reply@xxxx.com&lt;br /&gt;Great, Its really great, Thanks.&lt;br /&gt;&lt;br /&gt;Ajay Kumar ajaykumar21@xxxxx.com&lt;br /&gt;Nice work I must say.... Well Done and BIG WOW&lt;br /&gt;&lt;br /&gt;Mushtaque Syed mushtaquesyed@xxxxx.com&lt;br /&gt;Thanks &lt;br /&gt; &lt;br /&gt;Very nice and interesting, knowledgeable,&lt;br /&gt;I appreciate&lt;br /&gt;&lt;br /&gt;rAvi... ravirxz@xxxxx.com &lt;br /&gt;Hi Sachin,&lt;br /&gt; &lt;br /&gt;This certainly is a great blog and an excellent idea initiated. Just wanted to appreciate you of your hard work.&lt;br /&gt; &lt;br /&gt;Regards,&lt;br /&gt;~rAvi...&lt;br /&gt;&lt;br /&gt; vinodh kumar vinodh_thi@xxxxx.com &lt;br /&gt;Hi Sachin,&lt;br /&gt; &lt;br /&gt;What u have tried is a valuable thing.Thanks for taking time to prepare this blog.&lt;br /&gt;I appreciate if  u share ur knowledge more in tuning the SQL statements.But still what u have done is an excellent job.Keep going.&lt;br /&gt; &lt;br /&gt;Regards,&lt;br /&gt;Vinodhkumar V.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-7231282281875533605?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/7231282281875533605/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=7231282281875533605' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/7231282281875533605'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/7231282281875533605'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2007/01/happy-new-year-2007.html' title='Happy New Year - 2007'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-2658781857497199037</id><published>2006-12-27T17:35:00.000+05:30</published><updated>2007-01-12T15:29:22.066+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Execution Plan'/><title type='text'>Execution plan of a running SQL statement</title><content type='html'>Lot of time there is a requirement to find out the access path (execution plan) of a SQL which is currently running. Normally, we get the long running SQL from V$Sql and then simulate the execution in our environment to find the execution plan.&lt;br /&gt;&lt;br /&gt;This may (or may not) be the correct information because by that time either the statistics are changed or data is different (at the time of investigation).&lt;br /&gt;&lt;br /&gt;An ideal case would be when you can get the execution plan of the SQL which is currently running. Although this information is viewable if you see from DBA console (OEM), but you may require to write a shell script which captures all the top SQL’s with their execution plans. The following understanding will help you in finding out the execution plan using command line (SQL*Plus).&lt;br /&gt;&lt;br /&gt;Assuming a developer/user comes to you about a SQL which is running for past few hours, you first action will be to find out the session and SQL from v$session and v$sql&lt;br /&gt;&lt;br /&gt;Let’s see this:&lt;br /&gt;&lt;br /&gt;SQL&gt; select sid,serial#,status from v$session where username='VINEET';&lt;br /&gt;&lt;br /&gt;       SID    SERIAL# STATUS&lt;br /&gt;---------- ---------- --------&lt;br /&gt;       138       35417 ACTIVE&lt;br /&gt;  &lt;br /&gt;You may have multiple rows here because of many sessions using the same username. In that case you have to get the SID by using &lt;a href= http://oracle-online-help.blogspot.com/2006/12/top-sqls.html&gt; Top SQL note &lt;/a&gt; or by your own methods.&lt;br /&gt;&lt;br /&gt;Once you get the SID, lets find out the SQL.&lt;br /&gt;&lt;br /&gt;  1  select b.address,b.hash_value,b.child_number,b.plan_hash_value,b.sql_text&lt;br /&gt;  2  from v$session a, v$sql b&lt;br /&gt;  3  where a.SQL_ADDRESS=b.ADDRESS&lt;br /&gt;  4* and a.sid=138&lt;br /&gt;SQL&gt; /&lt;br /&gt;&lt;br /&gt;ADDRESS  HASH_VALUE CHILD_NUMBER PLAN_HASH_VALUE&lt;br /&gt;-------- ---------- ------------ ---------------&lt;br /&gt;SQL_TEXT&lt;br /&gt;------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;177F7178 1778505282            0      1671218824&lt;br /&gt;     DELETE   FROM TEST      WHERE ID = :1&lt;br /&gt;&lt;br /&gt;Now we have the SQL and other attributes of it.&lt;br /&gt;&lt;br /&gt;Last and final step is to find the execution plan of it. Lets see whether it is using the index on column ID or not.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;All you need to do is to put ADDRESS, HASH_VALUE, CHILD_NUMBER in the following SQL (you know those from above SQL)&lt;br /&gt;&lt;br /&gt;SQL&gt; COL id          FORMAT 999&lt;br /&gt;SQL&gt; COL parent_id   FORMAT 999 HEADING "PARENT"&lt;br /&gt;SQL&gt; COL operation   FORMAT a35 TRUNCATE&lt;br /&gt;SQL&gt; COL object_name FORMAT a30&lt;br /&gt;SQL&gt; ed&lt;br /&gt;Wrote file afiedt.buf&lt;br /&gt;&lt;br /&gt;  1  SELECT     id, parent_id, LPAD (' ', LEVEL - 1) || operation || ' ' ||&lt;br /&gt;  2             options operation, object_name&lt;br /&gt;  3  FROM       (&lt;br /&gt;  4             SELECT id, parent_id, operation, options, object_name&lt;br /&gt;  5             FROM   v$sql_plan&lt;br /&gt;  6             WHERE  address = '&amp;address'&lt;br /&gt;  7             AND    hash_value = &amp;hash_value&lt;br /&gt;  8             AND    child_number = &amp;child_number&lt;br /&gt;  9             )&lt;br /&gt; 10  START WITH id = 0&lt;br /&gt; 11* CONNECT BY PRIOR id = parent_id&lt;br /&gt;SQL&gt; /&lt;br /&gt;Enter value for address: 177F7178&lt;br /&gt;old   6:            WHERE  address = '&amp;address'&lt;br /&gt;new   6:            WHERE  address = '177F7178'&lt;br /&gt;Enter value for hash_value: 1778505282&lt;br /&gt;old   7:            AND    hash_value = &amp;hash_value&lt;br /&gt;new   7:            AND    hash_value = 1778505282&lt;br /&gt;Enter value for child_number: 0&lt;br /&gt;old   8:            AND    child_number = &amp;child_number&lt;br /&gt;new   8:            AND    child_number = 0&lt;br /&gt;&lt;br /&gt;   0        DELETE STATEMENT&lt;br /&gt;   1      0  DELETE&lt;br /&gt;   2      1   INDEX UNIQUE SCAN                 SYS_C00227769&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And there you go, The Explain plan is right here.&lt;br /&gt;&lt;br /&gt;You may want to automate this in a shell script which captures all the &lt;a href= http://oracle-online-help.blogspot.com/2006/12/top-sqls.html&gt; top sql’s &lt;/a&gt; and their respective plans and mail to you even when you are not online.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-2658781857497199037?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/2658781857497199037/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=2658781857497199037' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/2658781857497199037'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/2658781857497199037'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2006/12/execution-plan-of-running-sql-statement.html' title='Execution plan of a running SQL statement'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-453231891473706583</id><published>2006-12-26T17:29:00.000+05:30</published><updated>2007-01-12T15:30:10.354+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tuning'/><title type='text'>Index usage with LIKE operator</title><content type='html'>&lt;p&gt;I have seen many developers getting confused on index usage with like operator. Few are of the feeling that index will be used and few are against this feeling.&lt;br /&gt;&lt;br /&gt;Let’s see this with example:&lt;br /&gt;&lt;br /&gt;SQL&gt; create table sac as select * from all_objects;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;SQL&gt; create index sac_indx on sac(object_type);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;SQL&gt; set autotrace trace explain&lt;br /&gt;&lt;br /&gt;SQL&gt; select * from sac where object_type='TAB%';&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;   0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=1 Card=1 Bytes=128&lt;br /&gt;          )&lt;br /&gt;&lt;br /&gt;   1    0   TABLE ACCESS (BY INDEX ROWID) OF 'SAC' (TABLE) (Cost=1 Car&lt;br /&gt;          d=1 Bytes=128)&lt;br /&gt;&lt;br /&gt;   2    1     INDEX (RANGE SCAN) OF 'SAC_INDX' (INDEX) (Cost=1 Card=1)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Above example shows that using % wild card character towards end probe an Index search.&lt;br /&gt;&lt;br /&gt;But if it is used towards end, it will not be used. And sensibly so, because Oracle doesn’t know which data to search, it can start from ‘A to Z’ or ‘a to z’ or even 1 to any number.&lt;br /&gt;&lt;br /&gt;See this.&lt;br /&gt;SQL&gt; select * from sac where object_type like '%ABLE';&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;   0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=148 Card=1004 Byte&lt;br /&gt;          s=128512)&lt;br /&gt;&lt;br /&gt;   1    0   TABLE ACCESS (FULL) OF 'SAC' (TABLE) (Cost=148 Card=1004 B&lt;br /&gt;          ytes=128512)&lt;br /&gt;&lt;br /&gt;Now how to use the index if you are using Like operator searches. The answer is Domain Indexes.&lt;br /&gt;&lt;br /&gt;See the following example:&lt;br /&gt;&lt;br /&gt;SQL&gt; connect / as sysdba&lt;br /&gt;Connected.&lt;br /&gt;&lt;br /&gt;SQL&gt; grant execute on ctx_ddl to public;&lt;br /&gt;Grant succeeded.&lt;br /&gt;&lt;br /&gt;SQL&gt; connect sac/******&lt;br /&gt;Connected.&lt;br /&gt;SQL&gt; begin&lt;br /&gt;  2  ctx_ddl.create_preference('SUBSTRING_PREF',&lt;br /&gt;  3                            'BASIC_WORDLIST');&lt;br /&gt;  4  ctx_ddl.set_attribute('SUBSTRING_PREF',&lt;br /&gt;  5                        'SUBSTRING_INDEX','TRUE');&lt;br /&gt;  6  end;&lt;br /&gt;  7&lt;br /&gt;  8  /&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;SQL&gt; drop index sac_indx;&lt;br /&gt;Index dropped.&lt;br /&gt;&lt;br /&gt;SQL&gt; create index sac_indx on sac(object_type) indextype is ctxsys.context parameters ('wordlist SUBSTRING_PREF memory 50m');&lt;br /&gt;Index created.&lt;br /&gt; &lt;br /&gt;SQL&gt; set autotrace trace exp&lt;br /&gt;SQL&gt; select * from sac where contains (OBJECT_TYPE,'%PACK%') &gt; 0&lt;br /&gt;  2  /&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;   0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=8 Card=19 Bytes=17&lt;br /&gt;          86)&lt;br /&gt;   1    0   TABLE ACCESS (BY INDEX ROWID) OF 'SAC' (TABLE) (Cost=8 Car&lt;br /&gt;          d=19 Bytes=1786)&lt;br /&gt;&lt;strong&gt;   2    1     DOMAIN INDEX OF 'SAC_INDX' (INDEX (DOMAIN)) (Cost=4)&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;In this case the index is getting used. &lt;br /&gt;Conclusion&lt;br /&gt;=============&lt;br /&gt;For proximity, soundex and fuzzy searchs, use domain indexes.&lt;br /&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-453231891473706583?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/453231891473706583/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=453231891473706583' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/453231891473706583'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/453231891473706583'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2006/12/index-usage-with-like-operator.html' title='Index usage with LIKE operator'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-6077890178323299353</id><published>2006-12-26T15:51:00.000+05:30</published><updated>2007-01-12T15:30:53.797+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Nested table'/><title type='text'>Sparseness is what "Index By" table can offer</title><content type='html'>I received an email today (from oracle yahoo groups) asking about the reason on why index by clause is used in pl/sql tables and not for nested table?&lt;br /&gt;&lt;br /&gt;Although I replied there but I thought it is good idea to share it with you all and I’ll appreciate your comments.&lt;br /&gt;&lt;br /&gt;PL/SQL tab/index by tables use "index by BINARY_INTEGER clause" for their sparse capability.&lt;br /&gt;When I say sparse capability, it means that you can assign a value to nth member of the array.&lt;br /&gt;&lt;br /&gt;Ex:&lt;br /&gt;“INDEX BY” table&lt;br /&gt;&lt;br /&gt;SQL&gt; declare&lt;br /&gt;2     type char_array is table of varchar2(100) index by binary_integer; &lt;br /&gt;3      name char_array; &lt;br /&gt;4    begin&lt;br /&gt;5      name(15) := 'Sachin';&lt;br /&gt;6    end; &lt;br /&gt;7  /&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;“Nested table”&lt;br /&gt;&lt;br /&gt;SQL&gt; declare &lt;br /&gt;2     type char_array is table of varchar2(100); &lt;br /&gt;3      name char_array :=char_array(); &lt;br /&gt;4    begin &lt;br /&gt;5      name(15) := 'Sachin'; &lt;br /&gt;6    end; &lt;br /&gt;7  /&lt;br /&gt;declare&lt;br /&gt;*ERROR at line 1:&lt;br /&gt;ORA-06533: Subscript beyond count&lt;br /&gt;ORA-06512: at line 5&lt;br /&gt;&lt;br /&gt;And see this :-&lt;br /&gt;&lt;br /&gt;SQL&gt; ed&lt;br /&gt;Wrote file afiedt.buf&lt;br /&gt;1  declare &lt;br /&gt;2     type char_array is table of varchar2(100); &lt;br /&gt;3      name char_array :=char_array(); &lt;br /&gt;4    begin &lt;br /&gt;5      name.extend(15); &lt;br /&gt;6      name(15) := 'Sachin'; &lt;br /&gt;7*   end;SQL&gt;&lt;br /&gt;/&lt;br /&gt;PL/SQL procedure successfully completed&lt;br /&gt;&lt;br /&gt;So Nested table are not originally sparse, you have to extend them or delete the data to make them sparse.&lt;br /&gt;&lt;br /&gt;In both nested table and “index by” table, the data is referenced by index value. In case of&lt;br /&gt;“index by” table, it is BINARY_INTEGER (-2,147,483,647 to 2,147,483,647) and in case of “nested table”, it is integer value 1 to 2,147,483,647. But “index by” table offers initial sparseness which is not there in case of nested table.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-6077890178323299353?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/6077890178323299353/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=6077890178323299353' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/6077890178323299353'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/6077890178323299353'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2006/12/sparseness-is-what-index-by-table-can.html' title='Sparseness is what &quot;Index By&quot; table can offer'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-5746444992263508553</id><published>2006-12-21T16:30:00.000+05:30</published><updated>2007-01-12T15:29:48.450+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tuning'/><title type='text'>Top SQL's</title><content type='html'>&lt;p&gt;Awareness is first step towards resolution.&lt;br /&gt;I hope you will agree with me.&lt;br /&gt;&lt;br /&gt;One of the important tasks of the DBA is to know what the high CPU consuming processes on database server are.&lt;br /&gt;In my last organization, we used get number of request saying that DB server is running slow.&lt;br /&gt;Now the problem is that, this server is hosting 86 databases, and finding out which is the culprit process and database sounds a daunting task (but it isn't).&lt;br /&gt;&lt;br /&gt;See this:&lt;br /&gt;&lt;br /&gt;First find out the top CPU processes on your system:&lt;br /&gt;&lt;br /&gt;You may use TOP (or ps aux) or any other utility to find the top cpu consuming process.&lt;br /&gt;&lt;br /&gt;Here is a sample top output:&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000099;"&gt;bash-3.00$ top&lt;br /&gt;PID USERNAME LWP PRI NICE SIZE RES STATE TIME CPU COMMAND&lt;br /&gt;&lt;span style="color:#cc0000;"&gt;17480 &lt;/span&gt;oracle 11 59 0 1576M 1486M sleep 0:09 23.51% oracle&lt;br /&gt;9172 oracle 258 59 2 1576M 1476M sleep 0:43 1.33% oracle&lt;br /&gt;9176 oracle 14 59 2 1582M 1472M sleep 0:52 0.43% oracle&lt;br /&gt;17550 oracle 1 59 0 3188K 1580K cpu/1 0:00 0.04% top&lt;br /&gt;9178 oracle 13 59 2 1571M 1472M sleep 2:30 0.03% oracle&lt;/span&gt;&lt;/p&gt;&lt;p&gt;You can see the bold section. Process# 17480 is consuming 23.51 % CPU.&lt;br /&gt;&lt;br /&gt;Now this process can belong to any process out of many instances on this server.&lt;br /&gt;To find out which instance this process belongs to:&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000099;"&gt;bash-3.00$ ps -ef grep 17480 &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#000099;"&gt;oracle 17480 &lt;/span&gt;&lt;span style="color:#000099;"&gt;17479 0 03:02:03 ? 0:48 oracle&lt;span style="color:#cc0000;"&gt;orcl&lt;/span&gt; (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;The instance name is highlighted in red.&lt;br /&gt;&lt;br /&gt;Now you know which instance is holding that session.&lt;br /&gt;&lt;br /&gt;Change your environmental settings (ORACLE_SID, ORACLE_HOME) related to this database.&lt;br /&gt;and connect to the database as SYSDBA&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000099;"&gt;bash-3.00$ sqlplus "/ as sysdba"&lt;br /&gt;&lt;br /&gt;SQL*Plus: Release 10.2.0.2.0 - Production on Thu Dec 21 04:03:44 2006&lt;br /&gt;&lt;br /&gt;Copyright (c) 1982, 2005, Oracle. All Rights Reserved.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Connected to:&lt;br /&gt;Oracle Database 10g Release 10.2.0.2.0 - Production&lt;br /&gt;&lt;br /&gt;SQL&gt; select ses.sid SID,sqa.SQL_TEXT SQL from&lt;br /&gt;2 v$session ses, v$sqlarea sqa, v$process proc&lt;br /&gt;3 where ses.paddr=proc.addr&lt;br /&gt;4 and ses.sql_hash_value=sqa.hash_value&lt;br /&gt;5 and proc.spid=17480;&lt;br /&gt;&lt;br /&gt;SID SQL&lt;br /&gt;--------- -----------------&lt;br /&gt;67 delete from test&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;Now you have the responsible SQL behind 23% CPU using process.&lt;br /&gt;In my case it was a deliberate DELETE statement to induct this test but in your case it can be a query worth tuning.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;Mostly knowing what is the problem is solution of the problem. (At least you know what the issue is).&lt;br /&gt;Issue is to be addressed right away or to be taken to development team is a subjective issue which i don’t want to comment.&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-5746444992263508553?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/5746444992263508553/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=5746444992263508553' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/5746444992263508553'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/5746444992263508553'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2006/12/top-sqls.html' title='Top SQL&apos;s'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-1574526693578948687</id><published>2006-12-20T15:52:00.000+05:30</published><updated>2007-01-12T15:31:24.625+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Export/Import'/><title type='text'>Export/Import Vs Copy command</title><content type='html'>&lt;p&gt;Generally, in a support environment, when DBA gets requests like refreshing a DEV/QA table from production, they use Oracle provided utilities like export/ import. In fact i was also using the same for long time, but we realized, not only it takes more time; it is more cumbersome as well.&lt;br /&gt;&lt;br /&gt;To successfully complete the whole exercise&lt;br /&gt;&lt;/p&gt;&lt;p&gt;- You need to export table(s)&lt;br /&gt;- FTP/transfer the export dump to target location (although this can be avoided by making connection from place where the dump is lying)&lt;br /&gt;- Drop the table&lt;br /&gt;- Import the table&lt;br /&gt;&lt;br /&gt;Now this looks to me as multiple step process. (which is erroneous also)&lt;br /&gt;&lt;br /&gt;Now look at COPY command. It is much easier and provides less resolution time.&lt;/p&gt;&lt;p&gt;Truncate table (source_table);&lt;br /&gt;set arraysize 1000&lt;br /&gt;set copyc 100copy from (username/pwd)@(tns_of_remote) insert (target_table) using select /*+ parallel(a,2) */ * from (source_table);&lt;br /&gt;&lt;br /&gt;The copy command will make a connection to remote (may be prod) database and using the connection, it will populate the local table.&lt;br /&gt;Sqlplus commits after each successful “copy”. And each "copy" is n (number for copyc) number of batches where arraysize represents the size of each batch.&lt;br /&gt;&lt;br /&gt;According to the above example, SQLPLUS will perform commit after 100 (copyc - number of batches) x 1000(arraysize - size of one batch)&lt;br /&gt;&lt;br /&gt;There are several other forms in which COPY command can be used.&lt;br /&gt;You may want to read the full usage &lt;a href="http://www.lc.leidenuniv.nl/awcourse/oracle/server.920/a90842/apb.htm"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Note: COPY is a SQLPLUS utility which cannot be used for any other interface.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-1574526693578948687?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/1574526693578948687/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=1574526693578948687' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/1574526693578948687'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/1574526693578948687'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2006/12/exportimport-vs-copy-command.html' title='Export/Import Vs Copy command'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-2724396489490612599</id><published>2006-12-19T17:39:00.000+05:30</published><updated>2007-01-12T15:31:43.477+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tuning'/><title type='text'>CURSOR_SHARING - Do we use it?</title><content type='html'>&lt;p&gt;Are our cursors in shared pool shared at all?&lt;br /&gt;How many DBA’s uses this feature of 9i (introduced in 8i but enhanced in 9i?)?&lt;br /&gt;&lt;br /&gt;Actually, lot of us doesn’t use it all. Let’s first understand this feature and implement this in our systems.&lt;br /&gt;&lt;br /&gt;CURSOR_SHARING is an init.ora parameter which decides whether a SQL send from user is a candidate for fresh parsing or will use an existing plan.&lt;br /&gt;&lt;br /&gt;This parameter has 3 values.&lt;br /&gt;&lt;br /&gt;&lt;u&gt;1. CURSOR_SHARING = Exact (Default)&lt;/u&gt;&lt;br /&gt;&lt;br /&gt;Definition: Share the plan only if text of SQL matches exactly with the text of SQL lying in shared pool&lt;br /&gt;&lt;br /&gt;Let’s take an example&lt;br /&gt;&lt;br /&gt;SQL&gt; create table test1 (t1 number);&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;SQL&gt; insert into test1 values(1);&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;SQL&gt; insert into test1 values(2);&lt;br /&gt;&lt;br /&gt;1 row created.&lt;br /&gt;&lt;br /&gt;SQL&gt; commit;&lt;br /&gt;&lt;br /&gt;Commit complete.&lt;br /&gt;&lt;br /&gt;SQL&gt; select * from test1 where t1=1;&lt;br /&gt;&lt;br /&gt;T1&lt;br /&gt;----------&lt;br /&gt;1&lt;br /&gt;&lt;br /&gt;SQL&gt; select * from test1 where t1=2;&lt;br /&gt;&lt;br /&gt;T1&lt;br /&gt;----------&lt;br /&gt;2&lt;br /&gt;&lt;br /&gt;SQL&gt; select sql_text&lt;br /&gt;2 from v$sql&lt;br /&gt;3 where sql_text like 'select * from test1%'&lt;br /&gt;4 order by sql_text;&lt;br /&gt;&lt;br /&gt;SQL_TEXT&lt;br /&gt;-----------------------------------------------------&lt;br /&gt;&lt;br /&gt;select * from test1 where t1=1&lt;br /&gt;select * from test1 where t1=2&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As you see there were 2 statements in V$sql, so it generated 2 plans. Oracle had to do the same work again to generate the plan even when the difference between the two SQL was just literal value.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;u&gt;2. CURSOR_SHARING = Force (Introduced in 8.1.6)&lt;/u&gt;&lt;/p&gt;&lt;u&gt;&lt;/u&gt;&lt;p&gt;&lt;br /&gt;Definition: Share the plan (forcibly) of a SQL if the text of SQL matches (except the literal values) with text of SQL in shared pool&lt;br /&gt;&lt;br /&gt;This means if 2 SQL’s are same except their literal values, share the plan.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Let’s take an example:&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;I’m using the same table and data which is used in case of above example.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter system flush shared_pool;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter session set cursor_sharing=force;&lt;br /&gt;&lt;br /&gt;Session altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; select * from test1 where t1=1;&lt;br /&gt;&lt;br /&gt;T1&lt;br /&gt;----------&lt;br /&gt;1&lt;br /&gt;&lt;br /&gt;SQL&gt; select * from test1 where t1=2;&lt;br /&gt;&lt;br /&gt;T1&lt;br /&gt;----------&lt;br /&gt;2&lt;br /&gt;&lt;br /&gt;SQL&gt; select sql_text&lt;br /&gt;2 from v$sql&lt;br /&gt;3 where sql_text like 'select * from test1%'&lt;br /&gt;4 order by sql_text;&lt;br /&gt;&lt;br /&gt;SQL_TEXT&lt;br /&gt;---------------------------------------------------&lt;br /&gt;&lt;br /&gt;select * from test1 where t1=:"SYS_B_0"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You can see for both the statements there was only one entry in V$sql. This means for second occurrence, oracle did not generate a new plan.&lt;br /&gt;&lt;br /&gt;This not only helps in savings DB server engine time for generating the plan but also helps in reducing the number of plans shared pool can hold.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Important note:&lt;br /&gt;&lt;/em&gt;&lt;br /&gt;Cursor_sharing = force can have some flip behavior as well, so you must be careful to use this. Using this we are forcing oracle to use the same plan for 2(or more) SQL’s even when using the same plan may not be good for similar SQL’s.&lt;br /&gt;&lt;br /&gt;Example: “where t1=2” may be a good candidate for index scan while “where t1=10” should use a full table scan because 90% of the rows in the table has t1=10 (assumption).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;u&gt;3. CURSOR_SHARING = SIMILAR (Introduced in 9i)&lt;br /&gt;&lt;/u&gt;&lt;br /&gt;This is the tricky one, but most used. &lt;/p&gt;&lt;p&gt;&lt;br /&gt;Definition: SIMILAR causes statements that may differ in some literals, but are otherwise identical, to share a cursor, unless the literals affect either the meaning of the statement or the degree to which the plan is optimized. (Source: Oracle documentation)&lt;/p&gt;&lt;p&gt;&lt;br /&gt;Let’s understand this.&lt;br /&gt;Re-quoting the example above &gt; “where t1=2” may be a good candidate for index scan while “where t1=10” should use a full table scan because 90% of the rows in the table has t1=10 (assumption).&lt;br /&gt;&lt;br /&gt;To avoid 2 statements using the same plan when the same plan is not good for one of them, we have cursor_sharing=similar&lt;br /&gt;&lt;br /&gt;Let’s take an example:&lt;br /&gt;&lt;br /&gt;SQL&gt; alter system flush shared_pool;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; drop table test1;&lt;br /&gt;&lt;br /&gt;Table dropped.&lt;br /&gt;&lt;br /&gt;SQL&gt; create table test1 (t1 number,t2 number);&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;1 begin&lt;br /&gt;2 for i in 1 .. 100 loop&lt;br /&gt;3 insert into test1 values(1,i);&lt;br /&gt;4 end loop;&lt;br /&gt;5 commit;&lt;br /&gt;6 update test1 set t1=2 where rownum &lt;&gt; /&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;In this case t1 has value “2” in first row and “1” in rest 99 rows&lt;br /&gt;SQL&gt; create index tt_indx on test1(t1);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;SQL&gt; alter session set cursor_sharing=similar;&lt;br /&gt;&lt;br /&gt;Session altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; select * from test1 where t1=2;&lt;br /&gt;&lt;br /&gt;1 row selected.&lt;br /&gt;&lt;br /&gt;SQL&gt; select * from test1 where t1=1;&lt;br /&gt;&lt;br /&gt;99 rows selected.&lt;br /&gt;&lt;br /&gt;SQL&gt; select sql_text&lt;br /&gt;2 from v$sql&lt;br /&gt;3 where sql_text like 'select * from test1%'&lt;br /&gt;4 order by sql_text;&lt;br /&gt;&lt;br /&gt;SQL_TEXT&lt;br /&gt;----------------------------------------------------&lt;br /&gt;&lt;br /&gt;select * from test1 where t1=:"SYS_B_0"&lt;br /&gt;select * from test1 where t1=:"SYS_B_0"&lt;br /&gt;&lt;br /&gt;This tells us that even though the 2 statements were similar, Oracle opted for a different plan. Now even if you put t1=30 (0 rows), Oracle will create another plan.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;SQL&gt; select * from test1 where t1=30; -- (0 rows) &lt;/p&gt;&lt;p&gt;&lt;br /&gt;SQL&gt; select sql_text&lt;br /&gt;2 from v$sql&lt;br /&gt;3 where sql_text like 'select * from test1%'&lt;br /&gt;4 order by sql_text;&lt;br /&gt;&lt;br /&gt;SQL_TEXT&lt;br /&gt;---------------------------------------------------&lt;br /&gt;&lt;br /&gt;select * from test1 where t1=:"SYS_B_0"&lt;br /&gt;select * from test1 where t1=:"SYS_B_0"&lt;br /&gt;select * from test1 where t1=:"SYS_B_0"&lt;br /&gt;&lt;br /&gt;This is because the first time when the SQL ran, oracle engine found the literal value as “unsafe” because using the same literal value can cause bad plans for other similar SQL’s. So along with the PLAN, optimizer stored the literal value also. This will ensure the reusability of the plan only in case the same lieteral is provided. In case of any change, optimizer will generate a new plan.&lt;br /&gt;&lt;br /&gt;But this doesn’t mean that SIMILAR and EXACT are same.&lt;br /&gt;&lt;br /&gt;See this:&lt;br /&gt;&lt;br /&gt;SQL&gt; alter system flush shared_pool;&lt;br /&gt;&lt;br /&gt;System altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; select * from test1 where t1=2 and t1=22;&lt;br /&gt;&lt;br /&gt;no rows selected&lt;br /&gt;&lt;br /&gt;SQL&gt; select * from test1 where t1=2 and t1=23;&lt;br /&gt;&lt;br /&gt;no rows selected&lt;br /&gt;&lt;br /&gt;SQL&gt; select sql_text&lt;br /&gt;2 from v$sql&lt;br /&gt;3 where sql_text like 'select * from test1%'&lt;br /&gt;4 order by sql_text;&lt;br /&gt;&lt;br /&gt;SQL_TEXT&lt;br /&gt;--------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;select * from test1 where t1=:"SYS_B_0" and t1=:"SYS_B_1"&lt;br /&gt;&lt;br /&gt;Optimizer used single plan for both.&lt;br /&gt;&lt;br /&gt;Conclusions:&lt;br /&gt;&lt;br /&gt;1. Use CURSOR_SHARING=similar only when you have library cache misses and/or most of the SQL statements differ only in literal values&lt;/p&gt;&lt;p&gt;&lt;br /&gt;2. CURSOR_SHARING=force/similar significantly reduces the number of plans in shared pool&lt;/p&gt;&lt;br /&gt;Note:&lt;br /&gt;&lt;br /&gt;1. Oracle does not recommend setting CURSOR_SHARING to FORCE in a DSS environment or if you are using complex queries. Also, star transformation is not supported with CURSOR_SHARING set to either SIMILAR or FORCE&lt;br /&gt;&lt;br /&gt;2. Setting CURSOR_SHARING to SIMILAR or FORCE causes an increase in the maximum lengths (as returned by DESCRIBE) of any selected expressions that contain literals (in a SELECT statement). However, the actual length of the data returned does not change.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-2724396489490612599?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/2724396489490612599/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=2724396489490612599' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/2724396489490612599'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/2724396489490612599'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2006/12/cursorsharing-do-we-use-it.html' title='CURSOR_SHARING - Do we use it?'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-5839930173974920411</id><published>2006-12-19T13:50:00.000+05:30</published><updated>2007-01-12T15:32:06.101+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips'/><title type='text'>Delete in batches</title><content type='html'>One of the very important needs for DBA/developer is to delete huge data from a table.&lt;br /&gt;&lt;br /&gt;Generally Huge deletes causes rollback segment or data-files related errors.&lt;br /&gt;&lt;br /&gt;To overcome this, you may want to use this easy piece of code which deletes the data on regular intervals and commits after every 1000 rows&lt;br /&gt;&lt;br /&gt;I have taken a example with table name as GL_BALANCES and I’m deleting the data for 04 period&lt;br /&gt;&lt;br /&gt;declare &lt;br /&gt;x number :=0; &lt;br /&gt;cursor b0 is select d.rowid from gl.gl_balances d where period_name like '%-04' ; &lt;br /&gt;begin   &lt;br /&gt;for b in b0 loop      &lt;br /&gt; delete from gl.gl_balances d2 where b.rowid = d2.rowid;   &lt;br /&gt; x := x + 1;&lt;br /&gt; if x = 1000 then&lt;br /&gt;   commit;&lt;br /&gt;   x := 0;&lt;br /&gt; end if;&lt;br /&gt;end loop;&lt;br /&gt;commit;&lt;br /&gt;end;&lt;br /&gt;/&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-5839930173974920411?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/5839930173974920411/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=5839930173974920411' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/5839930173974920411'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/5839930173974920411'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2006/12/delete-in-batches.html' title='Delete in batches'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-2702783620758982988</id><published>2006-12-19T10:56:00.000+05:30</published><updated>2007-01-12T15:35:50.074+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips'/><title type='text'>SYS.Link$ stores password!</title><content type='html'>&lt;strong&gt;SYS.Link$ stores password!&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Version 10.1.0.2 (tested on 9i version also)&lt;br /&gt;OS Windows (tested on Unix versions also)&lt;br /&gt;&lt;/em&gt;&lt;br /&gt;&lt;u&gt;Let’s create a DB link:&lt;br /&gt;&lt;/u&gt;&lt;br /&gt;SQL&gt; connect / as sysdba – you may connect as different user also&lt;br /&gt;Connected.&lt;br /&gt;&lt;br /&gt;SQL&gt; create public database link test connect to sac identified by arora using&lt;br /&gt;  2  'sac';&lt;br /&gt;&lt;br /&gt;Database link created.&lt;br /&gt;&lt;br /&gt;SQL&gt; desc sys.link$ -- you need to be SYS user to select from this table&lt;br /&gt; Name                                      Null?    Type&lt;br /&gt; ----------------------------------------- -------- ----------------------------&lt;br /&gt; OWNER#                                    NOT NULL NUMBER&lt;br /&gt; NAME                                      NOT NULL VARCHAR2(128)&lt;br /&gt; CTIME                                     NOT NULL DATE&lt;br /&gt; HOST                                               VARCHAR2(2000)&lt;br /&gt; USERID                                             VARCHAR2(30)&lt;br /&gt; PASSWORD                                           VARCHAR2(30)&lt;br /&gt; FLAG                                               NUMBER&lt;br /&gt; AUTHUSR                                            VARCHAR2(30)&lt;br /&gt; AUTHPWD                                            VARCHAR2(30)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; select name,userid,password from link$ where name='TEST';&lt;br /&gt;&lt;br /&gt;NAME                           USERID     PASSWORD&lt;br /&gt;------------------------------ ---------- ------------------------------&lt;br /&gt;TEST                           SAC        ARORA&lt;br /&gt;&lt;br /&gt;Here you go. The password for SAC user is stored without encryption. This makes me feel jittery about creating db links.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-2702783620758982988?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/2702783620758982988/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=2702783620758982988' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/2702783620758982988'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/2702783620758982988'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2006/12/syslink-stores-password.html' title='SYS.Link$ stores password!'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-6406611662265447864</id><published>2006-12-15T15:54:00.000+05:30</published><updated>2007-01-12T15:35:26.021+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips'/><title type='text'>Password in Oracle is combination of username and password</title><content type='html'>I tested this intersting case and found password in Oracle stores information about user also.&lt;br /&gt;&lt;br /&gt;Lets see this: -&lt;br /&gt;Create 2 users with same passwords&lt;br /&gt;&lt;br /&gt;SQL&gt; create user sac2 identified by arora;&lt;br /&gt;&lt;br /&gt;User created.&lt;br /&gt;&lt;br /&gt;SQL&gt; create user sac3 identified by arora;&lt;br /&gt;&lt;br /&gt;User created.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;And see this. Passwords are different!&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; select username,password from dba_users where username in ('SAC2','SAC3');&lt;br /&gt;&lt;br /&gt;USERNAME                       PASSWORD&lt;br /&gt;------------------------------ ------------------------------&lt;br /&gt;SAC3                           14B4A488EC66A22B&lt;br /&gt;SAC2                           BF07E5BFF7A43D66&lt;br /&gt;&lt;br /&gt;Now lets try changing the password of SAC2 with the password of SAC3.&lt;br /&gt;&lt;br /&gt;SQL&gt;&lt;br /&gt;SQL&gt; alter user sac2 identified by values '14B4A488EC66A22B';&lt;br /&gt;&lt;br /&gt;User altered.&lt;br /&gt;&lt;br /&gt;Finally, lets try connecting&lt;br /&gt;&lt;br /&gt;SQL&gt; connect sac2/arora&lt;br /&gt;ERROR:&lt;br /&gt;ORA-01017: invalid username/password; logon denied&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;It fails ..&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now create another user in a different database by the name SAC2:&lt;br /&gt;&lt;br /&gt;SQL-DB2&gt; create user sac2 identified by arora;&lt;br /&gt;&lt;br /&gt;User created.&lt;br /&gt;&lt;br /&gt;SQL-DB2&gt; select username,password from dba_users where username='SAC2';&lt;br /&gt;&lt;br /&gt;USERNAME                       PASSWORD&lt;br /&gt;------------------------------ ------------------------------&lt;br /&gt;SAC2                           BF07E5BFF7A43D66&lt;br /&gt;&lt;br /&gt;The password matches with the password of SAC2 of first database&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Conclusion:&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt; Oracle doesnot store same passwords alike.It uses a combination of username and password. But the trick to hack the password is still unknown to me.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-6406611662265447864?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/6406611662265447864/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=6406611662265447864' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/6406611662265447864'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/6406611662265447864'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2006/12/password-in-oracle-is-combination-of.html' title='Password in Oracle is combination of username and password'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-4245755407195395687</id><published>2006-11-30T18:13:00.000+05:30</published><updated>2006-11-30T18:21:39.091+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tuning'/><title type='text'></title><content type='html'>&lt;u&gt;&lt;strong&gt;Precaution while defining data types in Oracle&lt;/strong&gt;&lt;br /&gt;&lt;/u&gt;&lt;br /&gt;I was reading a &lt;a href="http://tkyte.blogspot.com/2006/11/see-you-just-cannot-make-this-stuff-up.html"&gt;wonderful article on Tom Kyte’s blog&lt;/a&gt; on repercussion of ill defined data types.&lt;br /&gt;&lt;br /&gt;&lt;u&gt;Some of the example he mentions is:&lt;br /&gt;&lt;/u&gt;&lt;br /&gt;- Varchar2(40) Vs Varchar2(4000)&lt;br /&gt;- Date Vs varchar2&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Varchar2(40) Vs Varchar2(4000)&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Generally developers ask for this to avoid issues in the application. They always want the uppermost limit to avoid any application errors. The fact on which they argue is “varchar2” data type will not reserve 4000 character space so disk space is not an issue. But what they don’t know is how costly are these.&lt;br /&gt;&lt;br /&gt;Repercussions&lt;br /&gt;&lt;br /&gt;- Generally application does an “array fetch” from the database i.e. they select 100 (may be more) rows in one go. So if you are selecting 10 varchar2 cols. Then effective RAM (not storage) usage will be 4000(char) x 10 (cols) x 100 (rows) = 4 MB of RAM. On contrary, had this column defined with 40 char size the usage would have been 40 x 10 x 100 ~ 40KB (approx)!! See the difference; also we didn’t multiply the “number of session”. That could be another shock!!&lt;br /&gt;&lt;br /&gt;- Later on, it will be difficult to know for what the column was made. Ex: for first_name, if you define varchar2 (40000), it’s confusing for a new developer to know for what this column was made.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Date Vs varchar2&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Again lots of developers define date cols as varchar2 (or char) for their convenience. But what they forget is not only data integrity (a date could be 01/01/03 .. what was dd,mm,yy .. then u don’t know what did you defined) but also performance.&lt;br /&gt;&lt;br /&gt;While doing “Index range scans” by using “&lt;date_col&gt; between &lt;str1&gt; and &lt;str2&gt;”&lt;br /&gt;Optimizer will not be able to use the index as efficiently as in case of:&lt;br /&gt;“&lt;date_col&gt; between &lt;date1&gt; and &lt;date2&gt;”&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I suggest you to read the &lt;a href="http://tkyte.blogspot.com/2006/11/see-you-just-cannot-make-this-stuff-up.html"&gt;full article&lt;/a&gt; by maestro himself.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-4245755407195395687?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/4245755407195395687/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=4245755407195395687' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/4245755407195395687'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/4245755407195395687'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2006/11/precaution-while-defining-data-types-in.html' title=''/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-6405682055544834072</id><published>2006-11-29T12:45:00.000+05:30</published><updated>2006-11-29T16:37:22.230+05:30</updated><title type='text'>Friendly note</title><content type='html'>Friends,&lt;br /&gt;&lt;br /&gt;The present (or future) articles on this blog may not be originally mine.&lt;br /&gt;After reading some intersting article on web and books, if i feel that this could help others, i write that here.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Motive of this blog:&lt;br /&gt;&lt;br /&gt;1. Help the community using Oracle (Many others doing it, i'm just trying).&lt;br /&gt;2. Learn from others feedback. &lt;br /&gt;3. Share what i learned. Obviously so. Oracle was not written by me. Many experts have interpreted and written books. I just analyse those and put a feedback.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-6405682055544834072?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/6405682055544834072/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=6405682055544834072' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/6405682055544834072'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/6405682055544834072'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2006/11/friendly-note.html' title='Friendly note'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-5095767867564726967</id><published>2006-11-28T17:08:00.000+05:30</published><updated>2006-12-21T10:54:17.574+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tuning'/><title type='text'>Oracle table compression</title><content type='html'>&lt;strong&gt;&lt;u&gt;Compress your tables&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This feature has been introduced in 9i rel 2 and is most useful in a warehouse environment (for fact tables).&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;How to compress? Simple&lt;br /&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;SQL&gt; alter table test move compress;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;How Oracle implements compression?&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Oracle compress data by eliminating duplicate values within a data-block. Any repetitive occurrence of a value in a block is replaced by a symbol entry in a “symbol table” within the data block. So for example deptno=10 is repeated 5 times within a data block, it will be only stored once and rest 4 times a symbol entry will be stored in symbol table.&lt;br /&gt;Its very important to know that every data block is self contained and sufficient to rebuild the uncompressed form of data.&lt;br /&gt;&lt;br /&gt;&lt;a name="f1"&gt;Table compression can significantly reduce disk and buffer cache requirements for database tables while improving query performance. Compressed tables use fewer data blocks on disk, reducing disk space requirements.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;&lt;em&gt;Identifying tables to compress:&lt;/em&gt;&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;First create the following function which will get you the extent of compression&lt;br /&gt;&lt;br /&gt;create function compression_ratio (tabname varchar2)&lt;br /&gt;return number is — sample percentage&lt;br /&gt;pct number := 0.000099;&lt;br /&gt;blkcnt number := 0; blkcntc number; begin&lt;br /&gt;execute immediate ' create table TEMP$$FOR_TEST pctfree 0&lt;br /&gt;as select * from '  tabname  ' where rownum &lt; 1';&lt;br /&gt;while ((pct &lt; 100) and (blkcnt &lt; 1000)) loop&lt;br /&gt;execute immediate 'truncate table TEMP$$FOR_TEST';&lt;br /&gt;execute immediate 'insert into TEMP$$FOR_TEST select *&lt;br /&gt;from '  tabname  ' sample block ('  pct  ',10)';&lt;br /&gt;execute immediate 'select&lt;br /&gt;count(distinct(dbms_rowid.rowid_block_number(rowid)))&lt;br /&gt;from TEMP$$FOR_TEST' into blkcnt;&lt;br /&gt;pct := pct * 10;&lt;br /&gt;end loop;&lt;br /&gt;execute immediate 'alter table TEMP$$FOR_TEST move compress ';&lt;br /&gt;execute immediate 'select&lt;br /&gt;count(distinct(dbms_rowid.rowid_block_number(rowid)))&lt;br /&gt;from TEMP$$FOR_TEST' into blkcntc;&lt;br /&gt;execute immediate 'drop table TEMP$$FOR_TEST';&lt;br /&gt;return (blkcnt/blkcntc);&lt;br /&gt;end;&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1 declare&lt;br /&gt;2 a number;&lt;br /&gt;3 begin&lt;br /&gt;4 a:=compression_ratio('TEST');&lt;br /&gt;5 dbms_output.put_line(a);&lt;br /&gt;6 end&lt;br /&gt;7 ;&lt;br /&gt;8 /&lt;br /&gt;&lt;br /&gt;2.91389728096676737160120845921450151057&lt;br /&gt;&lt;br /&gt;PL/SQL procedure successfully completed.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1 select bytes/1024/1024 "Size in MB" from user_segments&lt;br /&gt;2* where segment_name='TEST'&lt;br /&gt;SQL&gt; /&lt;br /&gt;&lt;br /&gt;Size in MB&lt;br /&gt;----------&lt;br /&gt;18&lt;br /&gt;&lt;br /&gt;SQL&gt; alter table test move compress;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; select bytes/1024/1024 "Size in MB" from user_segments&lt;br /&gt;2 where segment_name='TEST';&lt;br /&gt;&lt;br /&gt;Size in MB&lt;br /&gt;----------&lt;br /&gt;6&lt;br /&gt;&lt;br /&gt;After compressing the table, you need to rebuild indexes because the rowid's have changed.&lt;br /&gt;&lt;br /&gt;Notes:&lt;br /&gt;&lt;br /&gt;- This feature can be best utilized in a warehouse environment where there are lot of duplicate values (for fact tables). Infact a larger block size is more efficient, becuase duplicate values will be only stored once within a block.&lt;br /&gt;&lt;br /&gt;- This feature has no -ve effect, infact it accelerates the performance of queries accessing large amount of data.&lt;br /&gt;&lt;br /&gt;- I suggest you to read the following white paper by Oracle which explains the whole algorithm in details along with industry recognized TPC test cases.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.vldb.org/conf/2003/papers/S28P01.pdf"&gt;http://www.vldb.org/conf/2003/papers/S28P01.pdf&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;I wrote the above article after reading the &lt;a href="http://www.oracle.com/technology/oramag/webcolumns/2003/techarticles/poess_tablecomp.html"&gt;oramag&lt;/a&gt;. I suggest you to read the full article on &lt;a href="http://www.oracle.com/technology/oramag/webcolumns/2003/techarticles/poess_tablecomp.html"&gt;Oracle site&lt;/a&gt;&lt;/b&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-5095767867564726967?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/5095767867564726967/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=5095767867564726967' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/5095767867564726967'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/5095767867564726967'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2006/11/oracle-table-compression.html' title='Oracle table compression'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-4331739596519065789</id><published>2006-11-28T14:09:00.000+05:30</published><updated>2006-11-29T12:15:42.947+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tuning'/><title type='text'>The Clustering factor</title><content type='html'>&lt;strong&gt;&lt;u&gt;The Clustering Factor&lt;br /&gt;&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;The clustering factor is a number which represent the degree to which data is randomly distributed in a table.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;In simple terms it is the number of “block switches” while reading a table using an index.&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://photos1.blogger.com/blogger2/7814/275520293397574/1600/Bad_CF.gif"&gt;&lt;img style="CURSOR: hand" alt="" src="http://photos1.blogger.com/blogger2/7814/275520293397574/320/Bad_CF.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Figure: Bad clustering factor&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;The above diagram explains that how scatter the rows of the table are. The first index entry (from left of index) points to the first data block and second index entry points to second data block. So while making index range scan or full index scan, optimizer have to switch between blocks and have to revisit the same block more than once because rows are scatter. So the number of times optimizer will make these switches is actually termed as &lt;em&gt;“Clustering factor”.&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://photos1.blogger.com/blogger2/7814/275520293397574/1600/Good_CF.gif"&gt;&lt;img style="CURSOR: hand" alt="" src="http://photos1.blogger.com/blogger2/7814/275520293397574/320/Good_CF.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Figure: Good clustering factor&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;The above image represents "Good CF”. In an event of index range scan, optimizer will not have to jump to next data block as most of the index entries points to same data block. This helps significantly in reducing the cost of your SELECT statements.&lt;br /&gt;&lt;br /&gt;Clustering factor is stored in data dictionary and can be viewed from dba_indexes (or user_indexes)&lt;br /&gt;&lt;br /&gt;SQL&gt; create table sac as select * from all_objects;&lt;br /&gt;&lt;br /&gt;Table created.&lt;br /&gt;&lt;br /&gt;SQL&gt; create index obj_id_indx on sac(object_id);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;SQL&gt; select clustering_factor from user_indexes where index_name='OBJ_ID_INDX';&lt;br /&gt;&lt;br /&gt;CLUSTERING_FACTOR&lt;br /&gt;-----------------&lt;br /&gt;545&lt;br /&gt;&lt;br /&gt;SQL&gt; select count(*) from sac;&lt;br /&gt;&lt;br /&gt;COUNT(*)&lt;br /&gt;----------&lt;br /&gt;38956&lt;br /&gt;&lt;br /&gt;SQL&gt; select blocks from user_segments where segment_name='OBJ_ID_INDX';&lt;br /&gt;&lt;br /&gt;BLOCKS&lt;br /&gt;----------&lt;br /&gt;96&lt;br /&gt;&lt;br /&gt;The above example shows that index has to jump 545 times to give you the full data had you performed full table scan using the index.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;- A good CF is equal (or near) to the values of number of blocks of table.&lt;br /&gt;&lt;br /&gt;- A bad CF is equal (or near) to the number of rows of table.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Myth:&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;- Rebuilding of index can improve the CF.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Then how to improve the CF?&lt;br /&gt;&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;- To improve the CF, it’s the table that must be rebuilt (and reordered).&lt;br /&gt;- If table has multiple indexes, careful consideration needs to be given by which index to order table.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Important point: The above is my interpretation of the subject after reading the book on Optimizer of Jonathan Lewis.&lt;/b&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-4331739596519065789?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/4331739596519065789/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=4331739596519065789' title='15 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/4331739596519065789'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/4331739596519065789'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2006/11/clustering-factor_28.html' title='The Clustering factor'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>15</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-475135802497400349</id><published>2006-11-24T17:26:00.000+05:30</published><updated>2008-12-10T10:13:56.536+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='OLAP'/><title type='text'>Star Vs Snowflake schema</title><content type='html'>&lt;strong&gt;Star Schemas&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The star schema is the simplest data warehouse schema. It is called a star schema because the diagram resembles a star, with points radiating from a center. The center of the star consists of one or more fact tables and the points of the star are the dimension tables, as shown in figure.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://photos1.blogger.com/x/blogger2/7814/275520293397574/1600/19488/Start_Schema.gif"&gt;&lt;img style="CURSOR: hand" alt="" src="http://photos1.blogger.com/x/blogger2/7814/275520293397574/320/317955/Start_Schema.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Fact Tables&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A fact table typically has two types of columns: those that contain numeric facts (often called measurements), and those that are foreign keys to dimension tables. A fact table contains either detail-level facts or facts that have been aggregated.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Dimension Tables&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;A dimension is a structure, often composed of one or more hierarchies, that categorizes data. Dimensional attributes help to describe the dimensional value. They are normally descriptive, textual values.&lt;br /&gt;Dimension tables are generally small in size as compared to fact table.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-To take an example and understand, assume this schema to be of a retail-chain (like wal-mart or  carrefour).&lt;br /&gt;&lt;br /&gt;Fact will be revenue (money). Now how do you want to see data is called a dimension.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_UMUqPNYoxX4/RbiQBnYuz5I/AAAAAAAAAAY/j4OkeXpAlL8/s1600-h/star.gif"&gt;&lt;img style="cursor:pointer; cursor:hand;" src="http://3.bp.blogspot.com/_UMUqPNYoxX4/RbiQBnYuz5I/AAAAAAAAAAY/j4OkeXpAlL8/s320/star.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5023923741758771090" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;In above figure, you can see the fact is revenue and there are many dimensions to see the same data. You may want to look at revenue based on time (what was the revenue last quarter?), or you may want to look at revenue based on a certain product (what was the revenue for chocolates?) and so on. &lt;br /&gt;In all these cases, the fact is same, however dimension changes as per the requirement.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Note:&lt;/em&gt; In an ideal Star schema, all the hierarchies of a dimension are handled within a single table.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Star Query&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A star query is a join between a fact table and a number of dimension tables. Each dimension table is joined to the fact table using a primary key to foreign key join, but the dimension tables are not joined to each other. The cost-based optimizer recognizes star queries and generates efficient execution plans for them.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Snoflake Schema&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The snowflake schema is a variation of the star schema used in a data warehouse.&lt;br /&gt;&lt;br /&gt;The snowflake schema (sometimes callled snowflake join schema) is a more complex schema than the star schema because the tables which describe the dimensions are normalized.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://photos1.blogger.com/x/blogger2/7814/275520293397574/1600/739643/snowflake_schema.gif"&gt;&lt;img style="CURSOR: hand" alt="" src="http://photos1.blogger.com/x/blogger2/7814/275520293397574/320/65119/snowflake_schema.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Flips of "snowflaking"&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;- In a data warehouse, the fact table in which data values (and its associated indexes) are stored, is typically responsible for 90% or more of the storage requirements, so the benefit here is normally insignificant.&lt;br /&gt;&lt;br /&gt;- Normalization of the dimension tables ("snowflaking") can impair the performance of a data warehouse. Whereas conventional databases can be tuned to match the regular pattern of usage, such patterns rarely exist in a data warehouse. Snowflaking will increase the time taken to perform a query, and the design goals of many data warehouse projects is to minimize these response times.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Benefits of "snowflaking"&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;- If a dimension is very sparse (i.e. most of the possible values for the dimension have no data) and/or a dimension has a very long list of attributes which may be used in a query, the dimension table may occupy a significant proportion of the database and snowflaking may be appropriate.&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;- A multidimensional view is sometimes added to an existing transactional database to aid reporting. In this case, the tables which describe the dimensions will already exist and will typically be normalised. A snowflake schema will hence be easier to implement.&lt;br /&gt;&lt;br /&gt;- A snowflake schema can sometimes reflect the way in which users think about data. Users may prefer to generate queries using a star schema in some cases, although this may or may not be reflected in the underlying organisation of the database.&lt;br /&gt;&lt;br /&gt;- Some users may wish to submit queries to the database which, using conventional multidimensional reporting tools, cannot be expressed within a simple star schema. This is particularly common in data mining of customer databases, where a common requirement is to locate common factors between customers who bought products meeting complex criteria. Some snowflaking would typically be required to permit simple query tools such as Cognos Powerplay to form such a query, especially if provision for these forms of query weren't anticpated when the data warehouse was first designed.&lt;br /&gt;&lt;br /&gt;In practice, many data warehouses will normalize some dimensions and not others, and hence use a combination of snowflake and classic star schema.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Source: Oracle documentation, wikipedia&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-475135802497400349?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/475135802497400349/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=475135802497400349' title='13 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/475135802497400349'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/475135802497400349'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2006/11/star-vs-snowflake-schema.html' title='Star Vs Snowflake schema'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_UMUqPNYoxX4/RbiQBnYuz5I/AAAAAAAAAAY/j4OkeXpAlL8/s72-c/star.gif' height='72' width='72'/><thr:total>13</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-954160730436426254</id><published>2006-11-24T16:13:00.000+05:30</published><updated>2007-01-12T15:35:00.598+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Oracle Arch'/><title type='text'>Touch-Count Algorithm</title><content type='html'>&lt;a href="http://photos1.blogger.com/x/blogger2/7814/275520293397574/1600/374960/tca.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;" src="http://photos1.blogger.com/x/blogger2/7814/275520293397574/1600/374960/tca.jpg" border="0" alt="" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Touch-Count Algorithm:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;In advancement to LRU/MRU algorithm, Oracle 8i moves towards an efficient&lt;br /&gt;algorithm of managing the Buffer cache i.e. touch-count algorithm.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;The Buffers in the Data Buffer Cache is managed as shown in the figure above. Prior to Oracle 8, when the data is fetched into data buffers from disk, the data used to&lt;br /&gt;automatically place at the head of the MRU end. However from Oracle 8 onwards the&lt;br /&gt;new data buffers are placed at the middle of block-chain. After loading the data-block, Oracle keeps the track of the “touch” count of the data.&lt;br /&gt;&lt;br /&gt;And according to the number of touches to the data, Oracle moves the data-buffers either towards MRU (hot) end or LRU (cold) end.&lt;br /&gt;This is a huge advancement to the management of the data-buffers in Oracle 8&lt;br /&gt;We have hot and cold areas in each buffer-pool (default, recycle, keep).&lt;br /&gt;The size of hot regions is configured by the following newly added parameters of init.ora&lt;br /&gt;&lt;br /&gt;a) _db_percent_hot_default.&lt;br /&gt;b) _db_percent_hot_keep&lt;br /&gt;c) _db_percent_hot_recycle&lt;br /&gt;&lt;br /&gt;Finding Hot Blocks inside the Oracle Data-Buffers&lt;br /&gt;Oracle 8i provides a internal X$BH view that shows relative performance of the databuffer pools.&lt;br /&gt;&lt;br /&gt;Following columns are more of interest :-&lt;br /&gt;&lt;br /&gt;a) tim : The tim column is related to the new _db_aging_touch_time init.ora&lt;br /&gt;parameter and governs the amount of time between touches.&lt;br /&gt;&lt;br /&gt;b) tch : represents the number of times a buffer has been touched by the user&lt;br /&gt;access. This touch relates directly to the promotion of buffers from cold region to hot region in a buffer pool&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; Select b.Object_name object, a.tch touches from x$bh a, dba_objects b&lt;br /&gt;2 Where a.obj=b.object_id and a.tch &gt; 100&lt;br /&gt;3* Order by a.tch desc;&lt;br /&gt;OBJECT TOUCHES&lt;br /&gt;----------------------------------------&lt;br /&gt;APPBROKERINFO 335&lt;br /&gt;SYS_C003474 335&lt;br /&gt;I_SYSAUTH1 278&lt;br /&gt;I_SYSAUTH1 269&lt;br /&gt;I_SYSAUTH1 268&lt;br /&gt;SYSAUTH$ 259&lt;br /&gt;PROPS$ 258&lt;br /&gt;SESSIONDATA 236&lt;br /&gt;8 rows selected.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The above advanced query can be very useful for DBA’s for tracking down those objects,&lt;br /&gt;which are perfect candidates to be moved from DEFAULT pool to KEEP pool. &lt;/div&gt;&lt;/div&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt; The above article i have written was inspired after reading a Steve Adams article for which i lost the link &lt;/b&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-954160730436426254?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/954160730436426254/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=954160730436426254' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/954160730436426254'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/954160730436426254'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2006/11/touch-count-algorithm-in-advancement-to.html' title='Touch-Count Algorithm'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-4082634722400986974</id><published>2006-11-24T12:54:00.000+05:30</published><updated>2006-11-24T12:59:31.745+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tuning'/><title type='text'>Bad SQL design</title><content type='html'>&lt;strong&gt;&lt;u&gt;Important point&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;If the statement is designed poorly, nothing much can be done by optimizer or indexes&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Few known thumb rules &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;–Avoid Cartesian joins&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;–Use UNION ALL instead of UNION – if possible&lt;br /&gt;&lt;br /&gt;–Use EXIST clause instead of IN - (Wherever appropiate)&lt;br /&gt;&lt;br /&gt;–Use order by when you really require it – Its very costly&lt;br /&gt;&lt;br /&gt;–When joining 2 views that themselves select from other views, check that the 2 views that you are using do not join the same tables!&lt;br /&gt;&lt;br /&gt;–Avoid NOT in or NOT = on indexed columns. They prevent the optimizer from using indexes. Use where amount &gt; 0 instead of where amount != 0&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;- Avoid writing where &lt;col_name&gt;is not null. nulls can prevent the optimizer from using an index&lt;br /&gt;&lt;br /&gt;- Avoid calculations on indexed columns. Write WHERE amount &gt; 26000/3 instead of WHERE approved_amt/3 &gt; 26000&lt;br /&gt;&lt;br /&gt;- The query below will return any record where bmm_code = cORE, Core, CORE, COre, etc.&lt;br /&gt;&lt;br /&gt;select appl_appl_id where upper(bmm_code) LIKE 'CORE%'&lt;br /&gt;&lt;br /&gt;But this query can be very inefficient as it results in a full table scan. It cannot make use of the index on bmm_code.&lt;br /&gt;&lt;br /&gt;Instead, write it like this:&lt;br /&gt;&lt;br /&gt;select appl_appl_id from nci_appl_elements_t where (bmm_code like 'C%' or bmm_code like 'c%') and upper(bmm_code) LIKE 'CORE%'&lt;br /&gt;&lt;br /&gt;This results in Index Range Scan.&lt;br /&gt;&lt;br /&gt;You can also make this more efficient by using 2 characters instead of just one:&lt;br /&gt;&lt;br /&gt;where ((bmm_code like 'CO%' or bmm_code like 'Co%' or bmm_code like 'cO%' or bmm_code like 'co%') and upper(bmm_code) LIKE 'CORE%')&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;strong&gt;Inviting Experts&lt;/strong&gt;&lt;/u&gt;&lt;br /&gt;&lt;u&gt;&lt;/u&gt;&lt;br /&gt;Friends, feel free to correct me. I will appreciate if you can add your comments also.&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;/u&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-4082634722400986974?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/4082634722400986974/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=4082634722400986974' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/4082634722400986974'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/4082634722400986974'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2006/11/bad-sql-design.html' title='Bad SQL design'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-393983915996653971</id><published>2006-11-24T11:52:00.000+05:30</published><updated>2007-01-12T15:33:07.541+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tuning'/><title type='text'>Consider declaring NOT NULL columns</title><content type='html'>&lt;strong&gt;&lt;u&gt;Consider declaring NOT NULL columns&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;People sometimes do not bother to define columns as NOT NULL in the data dictionary, even though these columns should not contain nulls, and indeed never do contain nulls because the application ensures that a value is always supplied. You may think that this is a matter of indifference, but it is not. The optimizer sometimes needs to know that a column is not nullable, and without that knowledge it is constrained to choose a less than optimal execution plan.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;1. An index on a nullable column cannot be used to drive access to a table unless the query contains one or more predicates against that column that exclude null values.&lt;br /&gt;&lt;/em&gt;&lt;br /&gt;Of course, it is not normally desirable to use an index based access path unless the query contains such predicates, but there are important exceptions.&lt;br /&gt;&lt;br /&gt;For example, if a full table scan would otherwise be required against the table and the query can be satisfied by a fast full scan (scan for which table data need not be read) against the index, then the latter plan will normally prove more efficient.&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;strong&gt;Test-case for the above reasoning&lt;/strong&gt;&lt;/u&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; create index color_indx on automobile(color);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;SQL&gt; select distinct color,count(*) from automobile group by color;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=4 Card=1046 Bytes=&lt;br /&gt;54392)&lt;br /&gt;&lt;br /&gt;1 0 SORT (GROUP BY) (Cost=4 Card=1046 Bytes=54392)&lt;br /&gt;2 1 &lt;strong&gt;TABLE ACCESS (FULL) OF 'AUTOMOBILE' (TABLE)&lt;/strong&gt; (Cost=3 Card&lt;br /&gt;=1046 Bytes=54392)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; alter table automobile modify color not null;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; select distinct color,count(*) from automobile group by color;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=4 Card=1046 Bytes=&lt;br /&gt;54392)&lt;br /&gt;&lt;br /&gt;1 0 SORT (GROUP BY) (Cost=4 Card=1046 Bytes=54392)&lt;br /&gt;2 1 &lt;strong&gt;INDEX (FAST FULL SCAN) OF 'COLOR_INDX' (INDEX)&lt;/strong&gt; (Cost=3 C&lt;br /&gt;ard=1046 Bytes=54392)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;2. If you are calling a sub-query in a parent query using the NOT IN predicate, the indexing on column (in where clause of parent query) will not be used.&lt;br /&gt;&lt;/em&gt;&lt;br /&gt;Because as per optimizer, results of parent query needs to be displayed only when there is no equi-matching from sub-query, And if the sub-query can potentially contain NULL value (UNKNOWN, incomparable), parent query will have no value to compare with NULL value, so it will not use the INDEX.&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;strong&gt;Test-case for the above Reasoning&lt;/strong&gt;&lt;/u&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; create index sal_indx on emp(sal);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;SQL&gt; create index ename_indx on emp(ename);&lt;br /&gt;&lt;br /&gt;Index created.&lt;br /&gt;&lt;br /&gt;SQL&gt; select * from emp where sal not in (select sal from emp where ename='JONES');&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=17 Card=13 Bytes=4&lt;br /&gt;81)&lt;br /&gt;&lt;br /&gt;1 0 FILTER&lt;br /&gt;2 1 TABLE ACCESS (FULL) OF 'EMP' (TABLE) (Cost=3 Card=14 Byt&lt;br /&gt;es=518) &lt;strong&gt;–&gt; you can see a full table scan even when index exist on SAL&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;3 1 TABLE ACCESS (BY INDEX ROWID) OF 'EMP' (TABLE) (Cost=2 C&lt;br /&gt;ard=1 Bytes=10)&lt;br /&gt;&lt;br /&gt;4 3 INDEX (RANGE SCAN) OF 'ENAME_INDX' (INDEX) (Cost=1 Car&lt;br /&gt;d=1)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SQL&gt; alter table emp modify sal not null;&lt;br /&gt;&lt;br /&gt;Table altered.&lt;br /&gt;&lt;br /&gt;SQL&gt; select * from emp where sal not in (select sal from emp where ename='JONES');&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Execution Plan&lt;br /&gt;----------------------------------------------------------&lt;br /&gt;0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=5 Card=12 Bytes=56&lt;br /&gt;4)&lt;br /&gt;&lt;br /&gt;1 0 MERGE JOIN (ANTI) (Cost=5 Card=12 Bytes=564)&lt;br /&gt;2 1 TABLE ACCESS (BY INDEX ROWID) OF 'EMP' (TABLE) (Cost=2 C&lt;br /&gt;ard=14 Bytes=518)&lt;br /&gt;&lt;br /&gt;3 2 INDEX (FULL SCAN) OF 'SAL_INDX' (INDEX) (Cost=1 Card=1&lt;br /&gt;4) &lt;strong&gt;-&gt; Here you go, your index getting used now&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;4 1 SORT (UNIQUE) (Cost=3 Card=1 Bytes=10)&lt;br /&gt;5 4 TABLE ACCESS (BY INDEX ROWID) OF 'EMP' (TABLE) (Cost=2&lt;br /&gt;Card=1 Bytes=10)&lt;br /&gt;&lt;br /&gt;6 5 INDEX (RANGE SCAN) OF 'ENAME_INDX' (INDEX) (Cost=1 C&lt;br /&gt;ard=1)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;The above article has been an inspiration after reading an article on &lt;a href=http://www.ixora.com.au/tips/not_null.htm&gt;ixora &lt;/a&gt;. The article was missing some of the testcases, so I thought of adding few for newbiews to relate to it.&lt;/b&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-393983915996653971?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/393983915996653971/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=393983915996653971' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/393983915996653971'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/393983915996653971'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2006/11/consider-declaring-not-null-columns.html' title='Consider declaring NOT NULL columns'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2257062243512934022.post-5412536138871762693</id><published>2006-11-24T11:38:00.001+05:30</published><updated>2009-01-14T19:24:46.695+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tuning'/><title type='text'>IN Vs Exist in SQL</title><content type='html'>&lt;div align="left"&gt;&lt;strong&gt;&lt;u&gt;IN Vs EXISTS&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The two are processed quite differently.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;u&gt;IN Clause&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Select * from T1 where x in ( select y from T2 )&lt;br /&gt;&lt;br /&gt;is typically processed as:&lt;br /&gt;&lt;br /&gt;select *&lt;br /&gt;from t1, ( select distinct y from t2 ) t2&lt;br /&gt;where t1.x = t2.y;&lt;br /&gt;&lt;br /&gt;The sub query is evaluated, distinct, indexed and then&lt;br /&gt;joined to the original table -- typically.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;u&gt;As opposed to "EXIST" clause&lt;br /&gt;&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;select * from t1 where exists ( select null from t2 where y = x )&lt;br /&gt;&lt;br /&gt;That is processed more like:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;for x in ( select * from t1 )&lt;br /&gt;loop&lt;br /&gt;if ( exists ( select null from t2 where y = x.x )&lt;br /&gt;then&lt;br /&gt;OUTPUT THE RECORD&lt;br /&gt;end if&lt;br /&gt;end loop&lt;br /&gt;&lt;br /&gt;It always results in a full scan of T1 whereas the first query can make use of&lt;br /&gt;an index on T1(x).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;u&gt;So, when is exists appropriate and in appropriate? &lt;/u&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;strong&gt;&lt;em&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt;Lets say the result of the subquery&lt;br /&gt;( select y from T2 )&lt;br /&gt;&lt;br /&gt;is "huge" and takes a long time. But the table T1 is relatively small and&lt;br /&gt;executing ( select null from t2 where y = x.x ) is fast (nice index on&lt;br /&gt;t2(y)). Then the exists will be faster as the time to full scan T1 and do the&lt;br /&gt;index probe into T2 could be less then the time to simply full scan T2 to build&lt;br /&gt;the subquery we need to distinct on.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Lets say the result of the subquery is small -- then IN is typicaly more&lt;br /&gt;appropriate.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If both the subquery and the outer table are huge -- either might work as well&lt;br /&gt;as the other -- depends on the indexes and other factors. &lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="left"&gt;I wrote this note after searching on same issue and found a simple explanation by Tom Kyte.&lt;/div&gt;&lt;div align="left"&gt;Here is the link of &lt;a href="http://asktom.oracle.com/pls/asktom/f?p=100:11:1455365265886235::::P11_QUESTION_ID:953229842074"&gt;original&lt;/a&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2257062243512934022-5412536138871762693?l=oracle-online-help.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oracle-online-help.blogspot.com/feeds/5412536138871762693/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2257062243512934022&amp;postID=5412536138871762693' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/5412536138871762693'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2257062243512934022/posts/default/5412536138871762693'/><link rel='alternate' type='text/html' href='http://oracle-online-help.blogspot.com/2006/11/in-vs-exist-in-sql.html' title='IN Vs Exist in SQL'/><author><name>Sachin</name><uri>http://www.blogger.com/profile/04551992629821526364</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://3.bp.blogspot.com/_UMUqPNYoxX4/SVXZ6UHakKI/AAAAAAAAB3w/K_xcdjzPL9A/S220/sac1.jpg'/></author><thr:total>8</thr:total></entry></feed>
