<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Upgrade Whoa</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2011/03/20/upgrade-whoa/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2011/03/20/upgrade-whoa/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Thu, 23 May 2013 12:47:17 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2011/03/20/upgrade-whoa/#comment-52386</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Sat, 29 Dec 2012 15:33:27 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=5969#comment-52386</guid>
		<description><![CDATA[Valentin,

I&#039;m not totally surprised that /*+ precompute subquery */ should produce contradictory results - especially when it appears in a cursor that&#039;s pinned by the pl/sql cursor cache. Strangely, though, my results are different from yours despite running your test on 11.2.0.3. 

I get 0 as the first result, then 1 for the next 9 results, before getting 10 - 19. The 10053 trace shows that I re-optimise the hinted SQL, getting two different plans (although the first one disappears from the library cache very promptly).  The first plan is:

[sourcecode gutter=&quot;false&quot;]
---------------------------------------+-----------------------------------+
&#124; Id  &#124; Operation            &#124; Name    &#124; Rows  &#124; Bytes &#124; Cost  &#124; Time      &#124;
---------------------------------------+-----------------------------------+
&#124; 0   &#124; SELECT STATEMENT     &#124;         &#124;       &#124;       &#124;     1 &#124;           &#124;
&#124; 1   &#124;  SORT AGGREGATE      &#124;         &#124;     1 &#124;       &#124;       &#124;           &#124;
&#124; 2   &#124;   FILTER             &#124;         &#124;       &#124;       &#124;       &#124;           &#124;
&#124; 3   &#124;    TABLE ACCESS FULL &#124; T0001   &#124;     1 &#124;       &#124;     2 &#124;  00:00:01 &#124;
---------------------------------------+-----------------------------------+
Predicate Information:
----------------------
2 - filter(NULL IS NOT NULL)

[/sourcecode]

The second plan, that appears after &lt;b&gt;two&lt;/b&gt; inserts is:

[sourcecode gutter=&quot;false&quot;]
--------------------------------------+-----------------------------------+
&#124; Id  &#124; Operation           &#124; Name    &#124; Rows  &#124; Bytes &#124; Cost  &#124; Time      &#124;
--------------------------------------+-----------------------------------+
&#124; 0   &#124; SELECT STATEMENT    &#124;         &#124;       &#124;       &#124;     2 &#124;           &#124;
&#124; 1   &#124;  SORT AGGREGATE     &#124;         &#124;     1 &#124;    13 &#124;       &#124;           &#124;
&#124; 2   &#124;   TABLE ACCESS FULL &#124; T0001   &#124;     1 &#124;    13 &#124;     2 &#124;  00:00:01 &#124;
--------------------------------------+-----------------------------------+
Predicate Information:
----------------------
2 - filter(&quot;ID&quot;=1)

[/sourcecode]

Possibly we have some differences in dynamic sampling or cardinality feedback settings.]]></description>
		<content:encoded><![CDATA[<p>Valentin,</p>
<p>I&#8217;m not totally surprised that /*+ precompute subquery */ should produce contradictory results &#8211; especially when it appears in a cursor that&#8217;s pinned by the pl/sql cursor cache. Strangely, though, my results are different from yours despite running your test on 11.2.0.3. </p>
<p>I get 0 as the first result, then 1 for the next 9 results, before getting 10 &#8211; 19. The 10053 trace shows that I re-optimise the hinted SQL, getting two different plans (although the first one disappears from the library cache very promptly).  The first plan is:</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
---------------------------------------+-----------------------------------+
| Id  | Operation            | Name    | Rows  | Bytes | Cost  | Time      |
---------------------------------------+-----------------------------------+
| 0   | SELECT STATEMENT     |         |       |       |     1 |           |
| 1   |  SORT AGGREGATE      |         |     1 |       |       |           |
| 2   |   FILTER             |         |       |       |       |           |
| 3   |    TABLE ACCESS FULL | T0001   |     1 |       |     2 |  00:00:01 |
---------------------------------------+-----------------------------------+
Predicate Information:
----------------------
2 - filter(NULL IS NOT NULL)

</pre>
<p>The second plan, that appears after <b>two</b> inserts is:</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
--------------------------------------+-----------------------------------+
| Id  | Operation           | Name    | Rows  | Bytes | Cost  | Time      |
--------------------------------------+-----------------------------------+
| 0   | SELECT STATEMENT    |         |       |       |     2 |           |
| 1   |  SORT AGGREGATE     |         |     1 |    13 |       |           |
| 2   |   TABLE ACCESS FULL | T0001   |     1 |    13 |     2 |  00:00:01 |
--------------------------------------+-----------------------------------+
Predicate Information:
----------------------
2 - filter(&quot;ID&quot;=1)

</pre>
<p>Possibly we have some differences in dynamic sampling or cardinality feedback settings.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Valentin Nikotin</title>
		<link>http://jonathanlewis.wordpress.com/2011/03/20/upgrade-whoa/#comment-52368</link>
		<dc:creator><![CDATA[Valentin Nikotin]]></dc:creator>
		<pubDate>Fri, 28 Dec 2012 22:52:14 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=5969#comment-52368</guid>
		<description><![CDATA[Another example of inconsistency related to undocumented hint PRECOMPUTE_SUBQUERY in 11.2 :

[sourcecode language=&quot;SQL&quot; collapse=&quot;true&quot;]
[oracle@SB1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Sat Dec 29 02:20:02 2012

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options

SQL&gt; @sql
SQL&gt; drop table t0001 purge;

Table dropped.

SQL&gt; create table t0001 (id number);

Table created.

SQL&gt; declare
  2    c number;
  3  begin
  4    for i in 1 .. 10 loop
  5      select count(*) into c from t0001 where id in (select /*+ PRECOMPUTE_SUBQUERY */ * from t0001);
  6      dbms_output.put_line(c);
  7      insert into t0001 values (1);
  8      commit;
  9    end loop;
 10    for i in 1 .. 10 loop
 11      select count(*) into c from t0001 where id in (select * from t0001);
 12      dbms_output.put_line(c);
 13      insert into t0001 values (1);
 14      commit;
 15    end loop;
 16  end;
 17  /
0
0
0
0
0
0
0
0
0
0
10
11
12
13
14
15
16
17
18
19

PL/SQL procedure successfully completed.
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>Another example of inconsistency related to undocumented hint PRECOMPUTE_SUBQUERY in 11.2 :</p>
<pre class="brush: sql; collapse: true; light: false; title: ; toolbar: true; notranslate">
[oracle@SB1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Sat Dec 29 02:20:02 2012

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options

SQL&gt; @sql
SQL&gt; drop table t0001 purge;

Table dropped.

SQL&gt; create table t0001 (id number);

Table created.

SQL&gt; declare
  2    c number;
  3  begin
  4    for i in 1 .. 10 loop
  5      select count(*) into c from t0001 where id in (select /*+ PRECOMPUTE_SUBQUERY */ * from t0001);
  6      dbms_output.put_line(c);
  7      insert into t0001 values (1);
  8      commit;
  9    end loop;
 10    for i in 1 .. 10 loop
 11      select count(*) into c from t0001 where id in (select * from t0001);
 12      dbms_output.put_line(c);
 13      insert into t0001 values (1);
 14      commit;
 15    end loop;
 16  end;
 17  /
0
0
0
0
0
0
0
0
0
0
10
11
12
13
14
15
16
17
18
19

PL/SQL procedure successfully completed.
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2011/03/20/upgrade-whoa/#comment-52102</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Thu, 13 Dec 2012 21:49:23 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=5969#comment-52102</guid>
		<description><![CDATA[Vladimir,

Thanks for the update.]]></description>
		<content:encoded><![CDATA[<p>Vladimir,</p>
<p>Thanks for the update.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vladimir Jelinek</title>
		<link>http://jonathanlewis.wordpress.com/2011/03/20/upgrade-whoa/#comment-51818</link>
		<dc:creator><![CDATA[Vladimir Jelinek]]></dc:creator>
		<pubDate>Wed, 05 Dec 2012 13:41:14 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=5969#comment-51818</guid>
		<description><![CDATA[FYI: Our problem with &quot;select for update when FBI is used&quot; has been approved as a bug by Oracle development after 3 months. 
So this expected behaviour will be fixed in 12c:
Bug 14605021 : SELECT FOR UPDATE RETURNS WRONG RESULT WHEN FUNCTION BASED INDEX USED]]></description>
		<content:encoded><![CDATA[<p>FYI: Our problem with &#8220;select for update when FBI is used&#8221; has been approved as a bug by Oracle development after 3 months.<br />
So this expected behaviour will be fixed in 12c:<br />
Bug 14605021 : SELECT FOR UPDATE RETURNS WRONG RESULT WHEN FUNCTION BASED INDEX USED</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vladimir Jelinek</title>
		<link>http://jonathanlewis.wordpress.com/2011/03/20/upgrade-whoa/#comment-50329</link>
		<dc:creator><![CDATA[Vladimir Jelinek]]></dc:creator>
		<pubDate>Wed, 19 Sep 2012 15:46:51 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=5969#comment-50329</guid>
		<description><![CDATA[I&#039;ve tried usage of virtual column instead of fbi (based on Valentin&#039;s suggestion).
I&#039;ve done 5 testcases. Each testcase has the same beginning:

[sourcecode language=&quot;sql&quot;]
drop table aaa;
create table aaa (n number, state char(1), s char(300), snew char(1) GENERATED ALWAYS AS (NVL(state,&#039;N&#039;)) VIRTUAL);
create index aaa_i on aaa(snew);

insert into aaa(n,state,s) values(1,null,&#039;row 1&#039;);
insert into aaa(n,state,s) values(2,null,&#039;row 2&#039;);
commit;
[/sourcecode]


Column &quot;snew&quot; is new virtual column with index.
I did the same locking scenario as in my previous example:

[sourcecode language=&quot;sql&quot;]
-- SESSION1:
select /*+ INDEX(aaa) */ n from aaa where NVL(state,&#039;N&#039;) = &#039;N&#039; and rownum&lt;=1 for update;
-- SESSION2:
select /*+ INDEX(aaa) */ n from aaa where NVL(state,&#039;N&#039;) = &#039;N&#039; and rownum&lt;=1 for update;
-- SESSION1:
update aaa set state=&#039;Y&#039; where n=1;
commit;
[/sourcecode]


In each scenario, I used different &quot;select for update&quot; command. They are here, together with their results:

[sourcecode language=&quot;sql&quot;]
-- scen 1
select /*+ INDEX(aaa) */ n            from aaa where NVL(state,&#039;N&#039;) = &#039;N&#039; and rownum&lt;=1 for update;
-- result is: row 1

-- scen 2
select /*+ INDEX(aaa) */ n,state      from aaa where NVL(state,&#039;N&#039;) = &#039;N&#039; and rownum&lt;=1 for update;
-- result is: row 2

-- scen 3
select /*+ INDEX(aaa) */ n            from aaa where snew = &#039;N&#039;           and rownum&lt;=1 for update;
-- result is: row 1

-- scen 4
select /*+ INDEX(aaa) */ n,snew       from aaa where snew = &#039;N&#039;           and rownum&lt;=1 for update;
-- result is: row 1

-- scen 5
select /*+ INDEX(aaa) */ n,snew,state from aaa where snew = &#039;N&#039;           and rownum&lt;=1 for update;
-- result is: row 2
[/sourcecode]

Scenario 1 and 2 is in fact the same as FBI usage, with the same results.
Result in scenario 5 is little surprise, because the column state is not in the where clause, but it presence in select clause cause different result.
It seems, that when Oracle is forced to read this column from table, then it&#039;s value is used to reevaluate the where clause (directly in scenario 2 and indirectly in scenario 5 by recalculationof the virtual column value).]]></description>
		<content:encoded><![CDATA[<p>I&#8217;ve tried usage of virtual column instead of fbi (based on Valentin&#8217;s suggestion).<br />
I&#8217;ve done 5 testcases. Each testcase has the same beginning:</p>
<pre class="brush: sql; title: ; notranslate">
drop table aaa;
create table aaa (n number, state char(1), s char(300), snew char(1) GENERATED ALWAYS AS (NVL(state,'N')) VIRTUAL);
create index aaa_i on aaa(snew);

insert into aaa(n,state,s) values(1,null,'row 1');
insert into aaa(n,state,s) values(2,null,'row 2');
commit;
</pre>
<p>Column &#8220;snew&#8221; is new virtual column with index.<br />
I did the same locking scenario as in my previous example:</p>
<pre class="brush: sql; title: ; notranslate">
-- SESSION1:
select /*+ INDEX(aaa) */ n from aaa where NVL(state,'N') = 'N' and rownum&lt;=1 for update;
-- SESSION2:
select /*+ INDEX(aaa) */ n from aaa where NVL(state,'N') = 'N' and rownum&lt;=1 for update;
-- SESSION1:
update aaa set state='Y' where n=1;
commit;
</pre>
<p>In each scenario, I used different &#8220;select for update&#8221; command. They are here, together with their results:</p>
<pre class="brush: sql; title: ; notranslate">
-- scen 1
select /*+ INDEX(aaa) */ n            from aaa where NVL(state,'N') = 'N' and rownum&lt;=1 for update;
-- result is: row 1

-- scen 2
select /*+ INDEX(aaa) */ n,state      from aaa where NVL(state,'N') = 'N' and rownum&lt;=1 for update;
-- result is: row 2

-- scen 3
select /*+ INDEX(aaa) */ n            from aaa where snew = 'N'           and rownum&lt;=1 for update;
-- result is: row 1

-- scen 4
select /*+ INDEX(aaa) */ n,snew       from aaa where snew = 'N'           and rownum&lt;=1 for update;
-- result is: row 1

-- scen 5
select /*+ INDEX(aaa) */ n,snew,state from aaa where snew = 'N'           and rownum&lt;=1 for update;
-- result is: row 2
</pre>
<p>Scenario 1 and 2 is in fact the same as FBI usage, with the same results.<br />
Result in scenario 5 is little surprise, because the column state is not in the where clause, but it presence in select clause cause different result.<br />
It seems, that when Oracle is forced to read this column from table, then it&#8217;s value is used to reevaluate the where clause (directly in scenario 2 and indirectly in scenario 5 by recalculationof the virtual column value).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pavol Babel</title>
		<link>http://jonathanlewis.wordpress.com/2011/03/20/upgrade-whoa/#comment-50310</link>
		<dc:creator><![CDATA[Pavol Babel]]></dc:creator>
		<pubDate>Wed, 19 Sep 2012 07:16:49 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=5969#comment-50310</guid>
		<description><![CDATA[Hermant, 

I don&#039;t think it has anything to do with row updating (when size of row is increasing), nor CHOOSE/ALL_ROWS

1. we were not using CHOOSE in 9.2.0.8
2. the FBI was used in hint in our application in 9.2.0.8 (but Vladimir didn&#039;t add hints to synthetic testcace), so CBO was used to generate execution plan even in 9.2.0.8

Sure, row will be copied to block free space and pointer in row directory will be changed. But if you drop FBI and create classic B-tree index, session 2 will select row number 2 as well.

It seems oracle forgets to restart SELECT FOR UPDATE statement in this specific situation. Statement generates less consistent and current gets as it should

Regards 
Pavol Babel]]></description>
		<content:encoded><![CDATA[<p>Hermant, </p>
<p>I don&#8217;t think it has anything to do with row updating (when size of row is increasing), nor CHOOSE/ALL_ROWS</p>
<p>1. we were not using CHOOSE in 9.2.0.8<br />
2. the FBI was used in hint in our application in 9.2.0.8 (but Vladimir didn&#8217;t add hints to synthetic testcace), so CBO was used to generate execution plan even in 9.2.0.8</p>
<p>Sure, row will be copied to block free space and pointer in row directory will be changed. But if you drop FBI and create classic B-tree index, session 2 will select row number 2 as well.</p>
<p>It seems oracle forgets to restart SELECT FOR UPDATE statement in this specific situation. Statement generates less consistent and current gets as it should</p>
<p>Regards<br />
Pavol Babel</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://jonathanlewis.wordpress.com/2011/03/20/upgrade-whoa/#comment-50305</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Wed, 19 Sep 2012 01:57:48 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=5969#comment-50305</guid>
		<description><![CDATA[The second to the last paragraph on page 7 of &quot;Oracle Core&quot; is what I am referencing at the end of my previous comment.]]></description>
		<content:encoded><![CDATA[<p>The second to the last paragraph on page 7 of &#8220;Oracle Core&#8221; is what I am referencing at the end of my previous comment.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://jonathanlewis.wordpress.com/2011/03/20/upgrade-whoa/#comment-50303</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Wed, 19 Sep 2012 01:51:27 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=5969#comment-50303</guid>
		<description><![CDATA[Vladimir,

That is an interesting test case.  I experimented with it for a bit over an hour using Oracle Database 11.2.0.2.

* Setting the OPTIMIZER_FEATURES_ENABLE parameter at the session level in session 2 to a value of less than or equal to 9.2.0.8 results in session 2 selecting the number 2 (rather than 1):
ALTER SESSION SET OPTIMIZER_FEATURES_ENABLE=&#039;9.2.0.8&#039;;

* Setting the OPTIMIZER_FEATURES_ENABLE parameter back to 11.2.0.2, and changing the OPTIMIZER_MODE from the 11.2.0.2 default of ALL_ROWS to CHOOSE in session 2 results in session 2 selecting the number 2 (rather than 1):
ALTER SESSION SET OPTIMIZER_FEATURES_ENABLE=&#039;11.2.0.2&#039;;
ALTER SESSION SET OPTIMIZER_MODE=&#039;CHOOSE&#039;;

* Setting the OPTIMIZER_MODE from ALL_ROWS to CHOOSE in both sessions, results in session 1 selecting the number 1, while session 2 selects the number 2 (rather than 1).

* Collecting the table statistics using DBMS_STATS.GATHER_TABLE_STATS with OPTIMIZER_MODE set to CHOOSE results in both sessions selecting the number 1.

The execution plan with the OPTIMIZER_MODE set to CHOOSE (the same seen with OPTIMIZER_FEATURES_ENABLE=&#039;9.2.0.8&#039; and no statistics for table AAA) (the RULE based optimizer cannot use function based indexes, if I recall correctly):
[sourcecode]
Plan hash value: 2311360649
 
-------------------------------------
&#124; Id  &#124; Operation            &#124; Name &#124;
-------------------------------------
&#124;   0 &#124; SELECT STATEMENT     &#124;      &#124;
&#124;   1 &#124;  FOR UPDATE          &#124;      &#124;
&#124;   2 &#124;   BUFFER SORT        &#124;      &#124;
&#124;*  3 &#124;    COUNT STOPKEY     &#124;      &#124;
&#124;*  4 &#124;     TABLE ACCESS FULL&#124; AAA  &#124;
-------------------------------------
 
Predicate Information (identified by operation id):
---------------------------------------------------
   3 - filter(ROWNUM&lt;=1)
   4 - filter(NVL(&quot;STATE&quot;,&#039;N&#039;)=&#039;N&#039;)
 
Note
-----
   - rule based optimizer used (consider using cbo)
[/sourcecode]

The execution plan with OPTIMIZER_MODE set to ALL_ROWS:
[sourcecode]
Plan hash value: 3492588397
 
----------------------------------------------------------------------------------------
&#124; Id  &#124; Operation                      &#124; Name  &#124; Rows  &#124; Bytes &#124; Cost (%CPU)&#124; Time     &#124;
----------------------------------------------------------------------------------------
&#124;   0 &#124; SELECT STATEMENT               &#124;       &#124;       &#124;       &#124;     1 (100)&#124;          &#124;
&#124;   1 &#124;  FOR UPDATE                    &#124;       &#124;       &#124;       &#124;            &#124;          &#124;
&#124;   2 &#124;   BUFFER SORT                  &#124;       &#124;       &#124;       &#124;            &#124;          &#124;
&#124;*  3 &#124;    COUNT STOPKEY               &#124;       &#124;       &#124;       &#124;            &#124;          &#124;
&#124;   4 &#124;     TABLE ACCESS BY INDEX ROWID&#124; AAA   &#124;     1 &#124;    15 &#124;     1   (0)&#124; 00:00:01 &#124;
&#124;*  5 &#124;      INDEX RANGE SCAN          &#124; AAA_I &#124;     1 &#124;       &#124;     1   (0)&#124; 00:00:01 &#124;
----------------------------------------------------------------------------------------
 
Predicate Information (identified by operation id):
---------------------------------------------------
   3 - filter(ROWNUM&lt;=1)
   5 - access(&quot;AAA&quot;.&quot;SYS_NC00004$&quot;=&#039;N&#039;)
 
Note
-----
   - dynamic sampling used for this statement (level=2)
[/sourcecode]

So, it appears that the switch of the OPTIMIZER_MODE from CHOOSE to ALL_ROWS resulted in a change of the execution plan - rather than the rows being access in index order, the rows are accessed in the order in which the rows appear in the table&#039;s blocks.

Jonathan, could this change in which row is selected be caused by the row moving its physical location in the block because the row is now longer than before (a NULL was set to a value of &#039;Y&#039;)?  I am having trouble remembering if your latest book mentioned something along the lines that if there is sufficient free space in the block, that the row could be moved within the block with only a pointer change needed, thus saving the work of relocating the other rows in that block (I could very well be incorrectly remembering this concept).]]></description>
		<content:encoded><![CDATA[<p>Vladimir,</p>
<p>That is an interesting test case.  I experimented with it for a bit over an hour using Oracle Database 11.2.0.2.</p>
<p>* Setting the OPTIMIZER_FEATURES_ENABLE parameter at the session level in session 2 to a value of less than or equal to 9.2.0.8 results in session 2 selecting the number 2 (rather than 1):<br />
ALTER SESSION SET OPTIMIZER_FEATURES_ENABLE=&#8217;9.2.0.8&#8242;;</p>
<p>* Setting the OPTIMIZER_FEATURES_ENABLE parameter back to 11.2.0.2, and changing the OPTIMIZER_MODE from the 11.2.0.2 default of ALL_ROWS to CHOOSE in session 2 results in session 2 selecting the number 2 (rather than 1):<br />
ALTER SESSION SET OPTIMIZER_FEATURES_ENABLE=&#8217;11.2.0.2&#8242;;<br />
ALTER SESSION SET OPTIMIZER_MODE=&#8217;CHOOSE&#8217;;</p>
<p>* Setting the OPTIMIZER_MODE from ALL_ROWS to CHOOSE in both sessions, results in session 1 selecting the number 1, while session 2 selects the number 2 (rather than 1).</p>
<p>* Collecting the table statistics using DBMS_STATS.GATHER_TABLE_STATS with OPTIMIZER_MODE set to CHOOSE results in both sessions selecting the number 1.</p>
<p>The execution plan with the OPTIMIZER_MODE set to CHOOSE (the same seen with OPTIMIZER_FEATURES_ENABLE=&#8217;9.2.0.8&#8242; and no statistics for table AAA) (the RULE based optimizer cannot use function based indexes, if I recall correctly):</p>
<pre class="brush: plain; title: ; notranslate">
Plan hash value: 2311360649
 
-------------------------------------
| Id  | Operation            | Name |
-------------------------------------
|   0 | SELECT STATEMENT     |      |
|   1 |  FOR UPDATE          |      |
|   2 |   BUFFER SORT        |      |
|*  3 |    COUNT STOPKEY     |      |
|*  4 |     TABLE ACCESS FULL| AAA  |
-------------------------------------
 
Predicate Information (identified by operation id):
---------------------------------------------------
   3 - filter(ROWNUM&lt;=1)
   4 - filter(NVL(&quot;STATE&quot;,'N')='N')
 
Note
-----
   - rule based optimizer used (consider using cbo)
</pre>
<p>The execution plan with OPTIMIZER_MODE set to ALL_ROWS:</p>
<pre class="brush: plain; title: ; notranslate">
Plan hash value: 3492588397
 
----------------------------------------------------------------------------------------
| Id  | Operation                      | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT               |       |       |       |     1 (100)|          |
|   1 |  FOR UPDATE                    |       |       |       |            |          |
|   2 |   BUFFER SORT                  |       |       |       |            |          |
|*  3 |    COUNT STOPKEY               |       |       |       |            |          |
|   4 |     TABLE ACCESS BY INDEX ROWID| AAA   |     1 |    15 |     1   (0)| 00:00:01 |
|*  5 |      INDEX RANGE SCAN          | AAA_I |     1 |       |     1   (0)| 00:00:01 |
----------------------------------------------------------------------------------------
 
Predicate Information (identified by operation id):
---------------------------------------------------
   3 - filter(ROWNUM&lt;=1)
   5 - access(&quot;AAA&quot;.&quot;SYS_NC00004$&quot;='N')
 
Note
-----
   - dynamic sampling used for this statement (level=2)
</pre>
<p>So, it appears that the switch of the OPTIMIZER_MODE from CHOOSE to ALL_ROWS resulted in a change of the execution plan &#8211; rather than the rows being access in index order, the rows are accessed in the order in which the rows appear in the table&#8217;s blocks.</p>
<p>Jonathan, could this change in which row is selected be caused by the row moving its physical location in the block because the row is now longer than before (a NULL was set to a value of &#8216;Y&#8217;)?  I am having trouble remembering if your latest book mentioned something along the lines that if there is sufficient free space in the block, that the row could be moved within the block with only a pointer change needed, thus saving the work of relocating the other rows in that block (I could very well be incorrectly remembering this concept).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pavol Babel</title>
		<link>http://jonathanlewis.wordpress.com/2011/03/20/upgrade-whoa/#comment-50302</link>
		<dc:creator><![CDATA[Pavol Babel]]></dc:creator>
		<pubDate>Tue, 18 Sep 2012 23:27:42 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=5969#comment-50302</guid>
		<description><![CDATA[We should raise severity level 1 bug only because of productional system outage etc. We &quot;fixed&quot; code exactly in way you suggested and it works. But maybe you are right, oracle is cheating regarding &quot;expected behaviour&quot;, so ... :)

[sourcecode language=&quot;css&quot;]
select n, state from aaa where NVL(state,&#039;N&#039;) = &#039;N&#039; and rownum&lt;=1 for update;
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>We should raise severity level 1 bug only because of productional system outage etc. We &#8220;fixed&#8221; code exactly in way you suggested and it works. But maybe you are right, oracle is cheating regarding &#8220;expected behaviour&#8221;, so &#8230; :)</p>
<pre class="brush: css; title: ; notranslate">
select n, state from aaa where NVL(state,'N') = 'N' and rownum&lt;=1 for update;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://jonathanlewis.wordpress.com/2011/03/20/upgrade-whoa/#comment-50299</link>
		<dc:creator><![CDATA[Andy]]></dc:creator>
		<pubDate>Tue, 18 Sep 2012 20:50:27 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=5969#comment-50299</guid>
		<description><![CDATA[From experience, you will have to push past MOS level 1 support to get anything done. Some of the answers I got from their level 1 support are really amusing :)]]></description>
		<content:encoded><![CDATA[<p>From experience, you will have to push past MOS level 1 support to get anything done. Some of the answers I got from their level 1 support are really amusing :)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
