<?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: Lock Horror</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2010/02/15/lock-horror/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2010/02/15/lock-horror/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Sun, 26 May 2013 02:13:39 +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/2010/02/15/lock-horror/#comment-43546</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Fri, 23 Dec 2011 10:13:01 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3118#comment-43546</guid>
		<description><![CDATA[Thepisas,

This is expected behaviour since, as you point our in your follow-up comment, you&#039;ve declared your foreign key constraint to be &quot;on delete cascade&quot;. This means that &quot;delete from parent&quot; start with a recursive &quot;delete from child&quot; - which has to take the mode 3 lock.]]></description>
		<content:encoded><![CDATA[<p>Thepisas,</p>
<p>This is expected behaviour since, as you point our in your follow-up comment, you&#8217;ve declared your foreign key constraint to be &#8220;on delete cascade&#8221;. This means that &#8220;delete from parent&#8221; start with a recursive &#8220;delete from child&#8221; &#8211; which has to take the mode 3 lock.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thepisas</title>
		<link>http://jonathanlewis.wordpress.com/2010/02/15/lock-horror/#comment-43437</link>
		<dc:creator><![CDATA[thepisas]]></dc:creator>
		<pubDate>Wed, 21 Dec 2011 02:47:52 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3118#comment-43437</guid>
		<description><![CDATA[test case 3: insert
3a. insert into parent takes mode 3 lock on parent and mode 2 on all child(ren)
3b.insert  into child takes mode 3 on child and mode 2 on parent .]]></description>
		<content:encoded><![CDATA[<p>test case 3: insert<br />
3a. insert into parent takes mode 3 lock on parent and mode 2 on all child(ren)<br />
3b.insert  into child takes mode 3 on child and mode 2 on parent .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thepisas</title>
		<link>http://jonathanlewis.wordpress.com/2010/02/15/lock-horror/#comment-43436</link>
		<dc:creator><![CDATA[thepisas]]></dc:creator>
		<pubDate>Wed, 21 Dec 2011 02:45:24 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3118#comment-43436</guid>
		<description><![CDATA[I need to qualify my previous comment about observing mode 3 locking in 10.2.0.3 as well.

The following tests were performed on 10.2.0.3

test case 1:        1 parent table and 1 child table ; the FK is indexed and on delete cascade is defined.

1a. delete on parent  takes mode 3 lock on parent and mode 3 on child which is apparently not expected in 10.2.0.3 .
 1b. delete on child takes mode 3 on child and mode  2 on parent which is expected.


test case 2:     1 parent table and  2 child tables referencing it; the FKs are indexed and on delete cascade is defined.

1a. delete on parent  takes mode 3 lock on parent and mode 3 on child1 and mode 2 on child 2 !!
1b. delete on child takes mode 3 on child and mode  2 on parent.]]></description>
		<content:encoded><![CDATA[<p>I need to qualify my previous comment about observing mode 3 locking in 10.2.0.3 as well.</p>
<p>The following tests were performed on 10.2.0.3</p>
<p>test case 1:        1 parent table and 1 child table ; the FK is indexed and on delete cascade is defined.</p>
<p>1a. delete on parent  takes mode 3 lock on parent and mode 3 on child which is apparently not expected in 10.2.0.3 .<br />
 1b. delete on child takes mode 3 on child and mode  2 on parent which is expected.</p>
<p>test case 2:     1 parent table and  2 child tables referencing it; the FKs are indexed and on delete cascade is defined.</p>
<p>1a. delete on parent  takes mode 3 lock on parent and mode 3 on child1 and mode 2 on child 2 !!<br />
1b. delete on child takes mode 3 on child and mode  2 on parent.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thepisas</title>
		<link>http://jonathanlewis.wordpress.com/2010/02/15/lock-horror/#comment-43428</link>
		<dc:creator><![CDATA[thepisas]]></dc:creator>
		<pubDate>Tue, 20 Dec 2011 23:26:58 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3118#comment-43428</guid>
		<description><![CDATA[I just wanted to mention that I have a  10.2.0.3 and I see LMODE=3  (not 2)  on the child table in 10.2.0.3 as well.]]></description>
		<content:encoded><![CDATA[<p>I just wanted to mention that I have a  10.2.0.3 and I see LMODE=3  (not 2)  on the child table in 10.2.0.3 as well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Book Review: Oracle Database 11g Performance Tuning Recipes &#171; Charles Hooper&#039;s Oracle Notes</title>
		<link>http://jonathanlewis.wordpress.com/2010/02/15/lock-horror/#comment-41677</link>
		<dc:creator><![CDATA[Book Review: Oracle Database 11g Performance Tuning Recipes &#171; Charles Hooper&#039;s Oracle Notes]]></dc:creator>
		<pubDate>Sat, 10 Sep 2011 21:14:13 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3118#comment-41677</guid>
		<description><![CDATA[[...] from issuing a DDL statement to alter the table&#8217;s structure.” (pages 163-165 reference reference2 [...]]]></description>
		<content:encoded><![CDATA[<p>[...] from issuing a DDL statement to alter the table&#8217;s structure.” (pages 163-165 reference reference2 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2010/02/15/lock-horror/#comment-40641</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Sun, 05 Jun 2011 20:30:09 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3118#comment-40641</guid>
		<description><![CDATA[Thiago,

I wasn&#039;t aware of the down-up-down either until your demonstration prompted me to run a 10704 trace to see exactly what the locking sequence was. 

I think the comment I made on the &lt;a href=&quot;http://jonathanlewis.wordpress.com/2011/06/03/merge-argh/#comment-40630&quot; rel=&quot;nofollow&quot;&gt;&lt;em&gt;&lt;strong&gt;&quot;merge - argh!&quot;&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt; note applies here: the example is just far enough outside the obvious list of tests that it wouldn&#039;t be surprising if this side effect of the mode 2 / mode 3 change hadn&#039;t been noticed. After all, I think you have to have a &quot;missing&quot; index and an insert that queues on delete or update that is already queueing on an uncommitted delete or update; I would imagine any test suite that defines a foreign key as &quot;on delete cascade&quot; would automatically include the foreign key index.
]]></description>
		<content:encoded><![CDATA[<p>Thiago,</p>
<p>I wasn&#8217;t aware of the down-up-down either until your demonstration prompted me to run a 10704 trace to see exactly what the locking sequence was. </p>
<p>I think the comment I made on the <a href="http://jonathanlewis.wordpress.com/2011/06/03/merge-argh/#comment-40630" rel="nofollow"><em><strong>&#8220;merge &#8211; argh!&#8221;</strong></em></a> note applies here: the example is just far enough outside the obvious list of tests that it wouldn&#8217;t be surprising if this side effect of the mode 2 / mode 3 change hadn&#8217;t been noticed. After all, I think you have to have a &#8220;missing&#8221; index and an insert that queues on delete or update that is already queueing on an uncommitted delete or update; I would imagine any test suite that defines a foreign key as &#8220;on delete cascade&#8221; would automatically include the foreign key index.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thiago Maciel</title>
		<link>http://jonathanlewis.wordpress.com/2010/02/15/lock-horror/#comment-40640</link>
		<dc:creator><![CDATA[Thiago Maciel]]></dc:creator>
		<pubDate>Sun, 05 Jun 2011 15:53:31 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3118#comment-40640</guid>
		<description><![CDATA[I was not aware of the way that Oracle down-converts from 5 to 3 immediately.

This was a demo that i made to a jr performance analyst to show him the concepts (performance impact) of not having an index on the foreign key. So, when i was saying that insert on the parent table should not get blocked on this specific case, i made &quot;oops, this is odd&quot;. Now i can explain thanks to you.

Moral of the story: Bad application design can stay even worse on 11g releases :)]]></description>
		<content:encoded><![CDATA[<p>I was not aware of the way that Oracle down-converts from 5 to 3 immediately.</p>
<p>This was a demo that i made to a jr performance analyst to show him the concepts (performance impact) of not having an index on the foreign key. So, when i was saying that insert on the parent table should not get blocked on this specific case, i made &#8220;oops, this is odd&#8221;. Now i can explain thanks to you.</p>
<p>Moral of the story: Bad application design can stay even worse on 11g releases :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2010/02/15/lock-horror/#comment-40639</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Sun, 05 Jun 2011 12:03:23 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3118#comment-40639</guid>
		<description><![CDATA[Thiago,

That&#039;s a lot easier to deal with. Forget all the stuff about write-consistency, I was fooled by the repetition of the &#039;X&#039;s in your original comment into thinking that you were deleting and re-inserting the same thing all the time. The example you&#039;ve supplied arises through a combination of two things: (a) absence of a foreign key index when deleting parent keys (especially with &quot;on delete cascade&quot; on the foreign key, and (b) the change in 11g results in a mode 3 lock at the opposite end of a parent/child relationship rather than the mode 2 that used to be used in 9i and 10g.

The sequence is as follows:
&lt;ul&gt;
Session 1 deletes from parent - gets mode 3 on parent, gets mode 5 on child because of absence of &quot;foreign key&quot; index, but ends up down-converting to mode 3.
Session 2 locks parent in mode 3, attempts to lock child in mode 5 - gets blocked by session 1
Session 3 locks parent in mode 3, attempts to lock child in mode 3 - gets blocked by session 2

Session 1 commits

Session 2 gets mode 5, and &lt;strong&gt;immediately&lt;/strong&gt; down-converts to mode 3 (that&#039;s just the way it works)
Session 3 is no longer blocked and gets mode 3 on the child, does the insert on the parent
Session 2 prepares to do the delete on the child and tries to up-convert to mode 5 - and gets blocked by session 3.
&lt;/ul&gt;
The oddity (or rather, the behaviour that I can&#039;t think of an explanation for yet) is the way that Oracle down-converts from 5 to 3 when it does, forcing it to up-convert to do the delete. You could raise this with Oracle in an SR, but I suspect they would simply tell you to create an index on the foreign key.

The reason you don&#039;t see the &lt;strong&gt;apparent&lt;/strong&gt;  breaking of FIFO in earlier versions of Oracle is that session 3 only takes out a mode 2 on the child in 9i and 10g when inserting on the parent, and session 2 is allowed to hold a mode 5 when other sessions are holding mode 2.
]]></description>
		<content:encoded><![CDATA[<p>Thiago,</p>
<p>That&#8217;s a lot easier to deal with. Forget all the stuff about write-consistency, I was fooled by the repetition of the &#8216;X&#8217;s in your original comment into thinking that you were deleting and re-inserting the same thing all the time. The example you&#8217;ve supplied arises through a combination of two things: (a) absence of a foreign key index when deleting parent keys (especially with &#8220;on delete cascade&#8221; on the foreign key, and (b) the change in 11g results in a mode 3 lock at the opposite end of a parent/child relationship rather than the mode 2 that used to be used in 9i and 10g.</p>
<p>The sequence is as follows:</p>
<ul>
Session 1 deletes from parent &#8211; gets mode 3 on parent, gets mode 5 on child because of absence of &#8220;foreign key&#8221; index, but ends up down-converting to mode 3.<br />
Session 2 locks parent in mode 3, attempts to lock child in mode 5 &#8211; gets blocked by session 1<br />
Session 3 locks parent in mode 3, attempts to lock child in mode 3 &#8211; gets blocked by session 2</p>
<p>Session 1 commits</p>
<p>Session 2 gets mode 5, and <strong>immediately</strong> down-converts to mode 3 (that&#8217;s just the way it works)<br />
Session 3 is no longer blocked and gets mode 3 on the child, does the insert on the parent<br />
Session 2 prepares to do the delete on the child and tries to up-convert to mode 5 &#8211; and gets blocked by session 3.
</ul>
<p>The oddity (or rather, the behaviour that I can&#8217;t think of an explanation for yet) is the way that Oracle down-converts from 5 to 3 when it does, forcing it to up-convert to do the delete. You could raise this with Oracle in an SR, but I suspect they would simply tell you to create an index on the foreign key.</p>
<p>The reason you don&#8217;t see the <strong>apparent</strong>  breaking of FIFO in earlier versions of Oracle is that session 3 only takes out a mode 2 on the child in 9i and 10g when inserting on the parent, and session 2 is allowed to hold a mode 5 when other sessions are holding mode 2.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thiago Maciel</title>
		<link>http://jonathanlewis.wordpress.com/2010/02/15/lock-horror/#comment-40635</link>
		<dc:creator><![CDATA[Thiago Maciel]]></dc:creator>
		<pubDate>Sat, 04 Jun 2011 16:55:02 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3118#comment-40635</guid>
		<description><![CDATA[Hi Jonathan, thanks for the feedback. Yes, the answer is B, but I m still confused because of the FIFO implementation. My demonstration include &quot;on delete cascade&quot; on the child table, sorry i forgot to mention that. Below you can see the complete demonstration:
[sourcecode]
CREATE TABLE SUPPLIER
  (
    &quot;SUPPLIER_ID&quot;   NUMBER(10,0) NOT NULL ENABLE,
    &quot;SUPPLIER_NAME&quot; VARCHAR2(50 BYTE) NOT NULL ENABLE,
    &quot;CONTACT_NAME&quot;  VARCHAR2(50 BYTE),
    CONSTRAINT &quot;SUPPLIER_PK&quot; PRIMARY KEY (&quot;SUPPLIER_ID&quot;) 
  );  
  
CREATE TABLE PRODUCT
  (
    &quot;PRODUCT_ID&quot;   NUMBER(10,0) NOT NULL ENABLE,
    &quot;PRODUCT_NAME&quot; VARCHAR2(50 BYTE) NOT NULL ENABLE,
    &quot;SUPPLIER_ID&quot;  NUMBER(10,0) NOT NULL ENABLE,
    CONSTRAINT &quot;FK_SUPPLIER&quot; FOREIGN KEY (&quot;SUPPLIER_ID&quot;) REFERENCES .&quot;SUPPLIER&quot; (&quot;SUPPLIER_ID&quot;) ON
  DELETE CASCADE ENABLE
  );
  
insert into SUPPLIER values (1,&#039;Thiago Maciel&#039;,&#039;email&#039;);
insert into SUPPLIER values (2,&#039;Jonathan Lewis&#039;,&#039;Blog - lock-horror&#039;);
commit;
insert into PRODUCT values(1,&#039;Oracle&#039;,1);
insert into PRODUCT values(1,&#039;Enqueue Kernel&#039;,2);
commit;
[/sourcecode]

Session 1: DELETE SUPPLIER WHERE SUPPLIER_ID = 1;
Session 2: DELETE SUPPLIER WHERE SUPPLIER_ID = 2;
Session 3: INSERT INTO SUPPLIER VALUES (3,&#039;lock Behavior 11gR2&#039;,&#039;Oracle Support&#039;);

Wait Chains: Session 2 is being blocked by the session 1, and session 3 is being blocked by the session 2.

Session 1: commit;
Session 2: still blocked
Session 3: got the lock, and complete the insert command.

Wait Chains: Now, session 2 is being blocked by the session 3

Session 3: commit;
Session 2: got the lock, and complete the delete command.
Session 2: commit;

[sourcecode]
Session 1: select * from supplier;
SUPPLIER_ID SUPPLIER_NAME       CONTACT_NAME
----------- ------------------- --------------
          3 lock Behavior 11gR2 Oracle Support
[/sourcecode]
]]></description>
		<content:encoded><![CDATA[<p>Hi Jonathan, thanks for the feedback. Yes, the answer is B, but I m still confused because of the FIFO implementation. My demonstration include &#8220;on delete cascade&#8221; on the child table, sorry i forgot to mention that. Below you can see the complete demonstration:</p>
<pre class="brush: plain; title: ; notranslate">
CREATE TABLE SUPPLIER
  (
    &quot;SUPPLIER_ID&quot;   NUMBER(10,0) NOT NULL ENABLE,
    &quot;SUPPLIER_NAME&quot; VARCHAR2(50 BYTE) NOT NULL ENABLE,
    &quot;CONTACT_NAME&quot;  VARCHAR2(50 BYTE),
    CONSTRAINT &quot;SUPPLIER_PK&quot; PRIMARY KEY (&quot;SUPPLIER_ID&quot;) 
  );  
  
CREATE TABLE PRODUCT
  (
    &quot;PRODUCT_ID&quot;   NUMBER(10,0) NOT NULL ENABLE,
    &quot;PRODUCT_NAME&quot; VARCHAR2(50 BYTE) NOT NULL ENABLE,
    &quot;SUPPLIER_ID&quot;  NUMBER(10,0) NOT NULL ENABLE,
    CONSTRAINT &quot;FK_SUPPLIER&quot; FOREIGN KEY (&quot;SUPPLIER_ID&quot;) REFERENCES .&quot;SUPPLIER&quot; (&quot;SUPPLIER_ID&quot;) ON
  DELETE CASCADE ENABLE
  );
  
insert into SUPPLIER values (1,'Thiago Maciel','email');
insert into SUPPLIER values (2,'Jonathan Lewis','Blog - lock-horror');
commit;
insert into PRODUCT values(1,'Oracle',1);
insert into PRODUCT values(1,'Enqueue Kernel',2);
commit;
</pre>
<p>Session 1: DELETE SUPPLIER WHERE SUPPLIER_ID = 1;<br />
Session 2: DELETE SUPPLIER WHERE SUPPLIER_ID = 2;<br />
Session 3: INSERT INTO SUPPLIER VALUES (3,&#8217;lock Behavior 11gR2&#8242;,&#8217;Oracle Support&#8217;);</p>
<p>Wait Chains: Session 2 is being blocked by the session 1, and session 3 is being blocked by the session 2.</p>
<p>Session 1: commit;<br />
Session 2: still blocked<br />
Session 3: got the lock, and complete the insert command.</p>
<p>Wait Chains: Now, session 2 is being blocked by the session 3</p>
<p>Session 3: commit;<br />
Session 2: got the lock, and complete the delete command.<br />
Session 2: commit;</p>
<pre class="brush: plain; title: ; notranslate">
Session 1: select * from supplier;
SUPPLIER_ID SUPPLIER_NAME       CONTACT_NAME
----------- ------------------- --------------
          3 lock Behavior 11gR2 Oracle Support
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2010/02/15/lock-horror/#comment-40631</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Sat, 04 Jun 2011 10:56:27 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3118#comment-40631</guid>
		<description><![CDATA[Thiago,

There are lots of places where the manuals (and notes on Metalink) have not changed to reflect the way the software has changed. From time to time I use the &quot;feedback&quot; option to point out errors or omissions. You could do the same in this case.

I can&#039;t comment on your question on locking because I didn&#039;t see anything anomalous when I tried to emulate your code path on 11.2.0.2. (It behaved the same way on 9.2.0.8 and 10.2.0.3)

It seems to me, though, that there are two possible legal outcomes - although one of them is counter-intuitive.

a) Session 2 reports no rows deleted and session 3 inserts a row
b) Session 3 inserts a row and session 2 waits on session 3 to commit (actually, I&#039;ve changed my mind about that, at least for the simplest cases - although if there is a child table involved I might want to re-think the issue).

Option (a) is the intuitively obvious one.

Option (b) could occur, in some circumstances perhaps, but is highly dependent on timing - if you are seeing it then it may be a legal example of &quot;write-consistency&quot;. Session 2 has to rollback and restart because the data it is supposed to modify has changed since the start of statement; this being the case it is possible for session 3 to be released to insert the new row.  (It&#039;s also possible that you&#039;ve found a bug, of course.)

I haven&#039;t been able to make (b) appear on 11.2.0.2.

Have you got a complete demonstration showing how to create the table, and listing every step along the way. Have you checked that you don&#039;t have some setting (e.g. related to isolation level) that confuses the issue ?]]></description>
		<content:encoded><![CDATA[<p>Thiago,</p>
<p>There are lots of places where the manuals (and notes on Metalink) have not changed to reflect the way the software has changed. From time to time I use the &#8220;feedback&#8221; option to point out errors or omissions. You could do the same in this case.</p>
<p>I can&#8217;t comment on your question on locking because I didn&#8217;t see anything anomalous when I tried to emulate your code path on 11.2.0.2. (It behaved the same way on 9.2.0.8 and 10.2.0.3)</p>
<p>It seems to me, though, that there are two possible legal outcomes &#8211; although one of them is counter-intuitive.</p>
<p>a) Session 2 reports no rows deleted and session 3 inserts a row<br />
b) Session 3 inserts a row and session 2 waits on session 3 to commit (actually, I&#8217;ve changed my mind about that, at least for the simplest cases &#8211; although if there is a child table involved I might want to re-think the issue).</p>
<p>Option (a) is the intuitively obvious one.</p>
<p>Option (b) could occur, in some circumstances perhaps, but is highly dependent on timing &#8211; if you are seeing it then it may be a legal example of &#8220;write-consistency&#8221;. Session 2 has to rollback and restart because the data it is supposed to modify has changed since the start of statement; this being the case it is possible for session 3 to be released to insert the new row.  (It&#8217;s also possible that you&#8217;ve found a bug, of course.)</p>
<p>I haven&#8217;t been able to make (b) appear on 11.2.0.2.</p>
<p>Have you got a complete demonstration showing how to create the table, and listing every step along the way. Have you checked that you don&#8217;t have some setting (e.g. related to isolation level) that confuses the issue ?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
