<?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: Skip Locked</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2010/05/31/skip-locked/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2010/05/31/skip-locked/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Sat, 18 May 2013 11:04:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Sriram K</title>
		<link>http://jonathanlewis.wordpress.com/2010/05/31/skip-locked/#comment-46790</link>
		<dc:creator><![CDATA[Sriram K]]></dc:creator>
		<pubDate>Wed, 30 May 2012 05:53:29 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3863#comment-46790</guid>
		<description><![CDATA[Hi,

if we move the locking in the example at a record level in pl/sql then we are able to process 99 records in the second session. 

try this code in the second session.
[sourcecode]
create or replace procedure pr_prcess_first_row
as

cursor c2 
is select 
rowid
from t1
where 
rownum &lt; 100;

l_rowid rowid;

type typ_2 is table of c2%rowtype index by binary_integer;

tab_2 typ_2;

begin

    open c2;
    fetch c2 bulk collect into tab_2 ;
    for i in tab_2.first..tab_2.last
    loop
	begin 
		select rowid 
        	into l_rowid
		from
		t1 
	        where rowid = tab_2(i).rowid 
		for update skip locked; 

		dbms_output.put_line(&#039; i is &#039; &#124;&#124; i &#124;&#124; &#039; row id &#039; &#124;&#124; l_rowid);	
	exception
		when no_data_found
		then 
			null;
	end;
	

    end loop;
end;
[/sourcecode]
]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>if we move the locking in the example at a record level in pl/sql then we are able to process 99 records in the second session. </p>
<p>try this code in the second session.</p>
<pre class="brush: plain; title: ; notranslate">
create or replace procedure pr_prcess_first_row
as

cursor c2 
is select 
rowid
from t1
where 
rownum &lt; 100;

l_rowid rowid;

type typ_2 is table of c2%rowtype index by binary_integer;

tab_2 typ_2;

begin

    open c2;
    fetch c2 bulk collect into tab_2 ;
    for i in tab_2.first..tab_2.last
    loop
	begin 
		select rowid 
        	into l_rowid
		from
		t1 
	        where rowid = tab_2(i).rowid 
		for update skip locked; 

		dbms_output.put_line(' i is ' || i || ' row id ' || l_rowid);	
	exception
		when no_data_found
		then 
			null;
	end;
	

    end loop;
end;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Select For Update &#8211; In What Order are the Rows Locked? &#171; Charles Hooper&#039;s Oracle Notes</title>
		<link>http://jonathanlewis.wordpress.com/2010/05/31/skip-locked/#comment-42483</link>
		<dc:creator><![CDATA[Select For Update &#8211; In What Order are the Rows Locked? &#171; Charles Hooper&#039;s Oracle Notes]]></dc:creator>
		<pubDate>Mon, 21 Nov 2011 16:58:51 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3863#comment-42483</guid>
		<description><![CDATA[[...] specified by the ORDER BY clause.  Why might this be an important question?  Possibly if the SKIP LOCKED clause is implemented in the SELECT FOR UPDATE statement?  Possibly if a procedure is hanging, and [...]]]></description>
		<content:encoded><![CDATA[<p>[...] specified by the ORDER BY clause.  Why might this be an important question?  Possibly if the SKIP LOCKED clause is implemented in the SELECT FOR UPDATE statement?  Possibly if a procedure is hanging, and [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Force Oracle to return TOP N rows with SKIP LOCKED</title>
		<link>http://jonathanlewis.wordpress.com/2010/05/31/skip-locked/#comment-42163</link>
		<dc:creator><![CDATA[Force Oracle to return TOP N rows with SKIP LOCKED]]></dc:creator>
		<pubDate>Sun, 23 Oct 2011 06:32:50 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3863#comment-42163</guid>
		<description><![CDATA[[...] two interesting articles here and [...]]]></description>
		<content:encoded><![CDATA[<p>[...] two interesting articles here and [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2010/05/31/skip-locked/#comment-41604</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Thu, 01 Sep 2011 22:04:40 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3863#comment-41604</guid>
		<description><![CDATA[rogflies,

Interesting side effect. That was an optimisation introduced in 10g for implicit cursor loops in pl/sql. You can disable the feature by setting plsql_optimize_level to 1 (or possibly zero) from the default of 2, then you will really fetch 1 row at a time.

The level is stored with the object when you recompile it, so future recompile (but not &quot;create or replace&quot; should continue to use the lower level.]]></description>
		<content:encoded><![CDATA[<p>rogflies,</p>
<p>Interesting side effect. That was an optimisation introduced in 10g for implicit cursor loops in pl/sql. You can disable the feature by setting plsql_optimize_level to 1 (or possibly zero) from the default of 2, then you will really fetch 1 row at a time.</p>
<p>The level is stored with the object when you recompile it, so future recompile (but not &#8220;create or replace&#8221; should continue to use the lower level.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rogflies</title>
		<link>http://jonathanlewis.wordpress.com/2010/05/31/skip-locked/#comment-41603</link>
		<dc:creator><![CDATA[rogflies]]></dc:creator>
		<pubDate>Thu, 01 Sep 2011 21:23:02 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3863#comment-41603</guid>
		<description><![CDATA[We seem to be running into a different problem that possibly some of the others above are also running into.  We fetch the rows using skip locked from within a PL/SQL procedure using a bulk collect with a limit.  Our limit needs to be on the small size, i.e., 20 rows.  However, PL/SQL seems to be &quot;helping&quot; us by pre-fetching 100 rows, causing them to be locked and unavailable to other threads calling this same procedure.  But, since our limit is 20, we don&#039;t see the other 80 rows, either.  They are eventually unlocked at the commit, but they are still unprocessed, lowering our overall throughput.

Is there any way to lower the amount PL/SQL prefetches for us or turn it off altogether?

Thanks,
-Roger]]></description>
		<content:encoded><![CDATA[<p>We seem to be running into a different problem that possibly some of the others above are also running into.  We fetch the rows using skip locked from within a PL/SQL procedure using a bulk collect with a limit.  Our limit needs to be on the small size, i.e., 20 rows.  However, PL/SQL seems to be &#8220;helping&#8221; us by pre-fetching 100 rows, causing them to be locked and unavailable to other threads calling this same procedure.  But, since our limit is 20, we don&#8217;t see the other 80 rows, either.  They are eventually unlocked at the commit, but they are still unprocessed, lowering our overall throughput.</p>
<p>Is there any way to lower the amount PL/SQL prefetches for us or turn it off altogether?</p>
<p>Thanks,<br />
-Roger</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DS</title>
		<link>http://jonathanlewis.wordpress.com/2010/05/31/skip-locked/#comment-41164</link>
		<dc:creator><![CDATA[DS]]></dc:creator>
		<pubDate>Tue, 02 Aug 2011 18:09:52 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3863#comment-41164</guid>
		<description><![CDATA[Hi Jonathan,

We are using the same skip locked with rownum &lt;= 30 rows. This is a single table select with two indexes. The table size is around 25M and indexes less than 10M.

There are 20 sessions running the same sql. I understand from the blog that we can get less than 30 rows on each execution. I see different issue, that the buffer gets per execution is around 1-3 Million. All this cause 100% cpu on the box.

Our DB version is 10.2.0.4.0. 

I am not able to understand how come it is using 1-3M buffer gets per exec. It happens only when there is some data in the table otherwise buffer gets arr less than 900/exec.]]></description>
		<content:encoded><![CDATA[<p>Hi Jonathan,</p>
<p>We are using the same skip locked with rownum &lt;= 30 rows. This is a single table select with two indexes. The table size is around 25M and indexes less than 10M.</p>
<p>There are 20 sessions running the same sql. I understand from the blog that we can get less than 30 rows on each execution. I see different issue, that the buffer gets per execution is around 1-3 Million. All this cause 100% cpu on the box.</p>
<p>Our DB version is 10.2.0.4.0. </p>
<p>I am not able to understand how come it is using 1-3M buffer gets per exec. It happens only when there is some data in the table otherwise buffer gets arr less than 900/exec.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2010/05/31/skip-locked/#comment-38896</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Tue, 28 Dec 2010 15:31:09 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3863#comment-38896</guid>
		<description><![CDATA[Amy,

Insufficient information to be certain - but since you have concurrency 6 and initrans 8 it seems unlikely. It&#039;s possible, of course, that someone changed the initrans after the table was created and put into service, leaving some older blocks with too few ITL slots, and no space to grow them.

The first guess, though, would simply be that your six sessions have overlapping requests as described by Chen Shapira in her comment.]]></description>
		<content:encoded><![CDATA[<p>Amy,</p>
<p>Insufficient information to be certain &#8211; but since you have concurrency 6 and initrans 8 it seems unlikely. It&#8217;s possible, of course, that someone changed the initrans after the table was created and put into service, leaving some older blocks with too few ITL slots, and no space to grow them.</p>
<p>The first guess, though, would simply be that your six sessions have overlapping requests as described by Chen Shapira in her comment.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Amy</title>
		<link>http://jonathanlewis.wordpress.com/2010/05/31/skip-locked/#comment-38887</link>
		<dc:creator><![CDATA[Amy]]></dc:creator>
		<pubDate>Mon, 27 Dec 2010 21:20:19 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3863#comment-38887</guid>
		<description><![CDATA[Hi,

I am facing similar problem. SKIP LOCKED query is not returning specified number of records, but returns random number of records each time when multiple threads are run.
In my scenario,
Number of concurrent threads = 6
DB Block size = 8K
INITRANS = 8
PCTFREE = 10
Average row length (according to dba_tab_statistics.avg_row_len) = 260

Do you think that INITRANS value should be increased ?

Thanks.]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I am facing similar problem. SKIP LOCKED query is not returning specified number of records, but returns random number of records each time when multiple threads are run.<br />
In my scenario,<br />
Number of concurrent threads = 6<br />
DB Block size = 8K<br />
INITRANS = 8<br />
PCTFREE = 10<br />
Average row length (according to dba_tab_statistics.avg_row_len) = 260</p>
<p>Do you think that INITRANS value should be increased ?</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2010/05/31/skip-locked/#comment-36449</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Tue, 08 Jun 2010 22:03:35 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3863#comment-36449</guid>
		<description><![CDATA[Henish,

The clue is in Gwen&#039;s comment (repeated in the opening line of my comment). The &quot;rownum &lt;= 100&quot; predicate takes precedence over the locking. Oracle stops after attempting to lock 100 rows, not after locking 100 rows. It&#039;s just the way it behaves - maybe at some point release it will just change.]]></description>
		<content:encoded><![CDATA[<p>Henish,</p>
<p>The clue is in Gwen&#8217;s comment (repeated in the opening line of my comment). The &#8220;rownum &lt;= 100&quot; predicate takes precedence over the locking. Oracle stops after attempting to lock 100 rows, not after locking 100 rows. It&#039;s just the way it behaves &#8211; maybe at some point release it will just change.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Henish</title>
		<link>http://jonathanlewis.wordpress.com/2010/05/31/skip-locked/#comment-36427</link>
		<dc:creator><![CDATA[Henish]]></dc:creator>
		<pubDate>Fri, 04 Jun 2010 16:31:49 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=3863#comment-36427</guid>
		<description><![CDATA[Hello Sir,

&quot;The first two sessions will return 100 rows, the third session will (should) return no rows – even though there are no locked rows for the given value of modded – but the first hundred rows that will be scanned cannot be locked because an ITL entry cannot be acquired....&quot;

As per your example theree are 693 rows in the first block and I assume the same for the rest of the blocks so there will be 231 rows per modded value

so why not oracle goes to another block where it could find rows where modded=2  since the intent is to return 100 rows matching the condition also we donot have any order by clause?  


could please clarify 

Many Thanks]]></description>
		<content:encoded><![CDATA[<p>Hello Sir,</p>
<p>&#8220;The first two sessions will return 100 rows, the third session will (should) return no rows – even though there are no locked rows for the given value of modded – but the first hundred rows that will be scanned cannot be locked because an ITL entry cannot be acquired&#8230;.&#8221;</p>
<p>As per your example theree are 693 rows in the first block and I assume the same for the rest of the blocks so there will be 231 rows per modded value</p>
<p>so why not oracle goes to another block where it could find rows where modded=2  since the intent is to return 100 rows matching the condition also we donot have any order by clause?  </p>
<p>could please clarify </p>
<p>Many Thanks</p>
]]></content:encoded>
	</item>
</channel>
</rss>
