<?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"
	>
<channel>
	<title>Comments on: SELECT LOCK IN SHARE MODE  and FOR UPDATE</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/</link>
	<description>Everything about MySQL Performance</description>
	<pubDate>Fri, 04 Jul 2008 15:12:49 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Victor</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-286478</link>
		<dc:creator>Victor</dc:creator>
		<pubDate>Wed, 23 Apr 2008 12:38:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-286478</guid>
		<description>Problem solved with mysql 5.0.56.</description>
		<content:encoded><![CDATA[<p>Problem solved with mysql 5.0.56.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-286128</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Wed, 23 Apr 2008 00:49:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-286128</guid>
		<description>Victor,

I would suggest to try it with recent MySQL 5.0 version and if it still happens report it at bugs.mysql.com</description>
		<content:encoded><![CDATA[<p>Victor,</p>
<p>I would suggest to try it with recent MySQL 5.0 version and if it still happens report it at bugs.mysql.com</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Victor</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-284896</link>
		<dc:creator>Victor</dc:creator>
		<pubDate>Tue, 22 Apr 2008 06:40:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-284896</guid>
		<description>Darseq&#62; I have tested from two console boxes with mysql 5.0.21 on freebsd6 and linux. I also thought that update should succeed, but it does not! It waits for some table level locks which were made by second SELECT FOR UPDATE which in turn waits for X lock. That is why undetectable deadlock happens. But my opinion that that is a bug. Just try yourself (may be i missed something) - start 2 transactions from two consoles and make any SELECT FOR UPDATE for the SAME ROW in both transactions. Second transaction will wait for the lock, then from the first transaction try to UPDATE that row. In my case it blocks both transaction until timeout and it is very very strange! Can anyone explain me why? Or tell me that it is not working just for me because of my stupidness.</description>
		<content:encoded><![CDATA[<p>Darseq&gt; I have tested from two console boxes with mysql 5.0.21 on freebsd6 and linux. I also thought that update should succeed, but it does not! It waits for some table level locks which were made by second SELECT FOR UPDATE which in turn waits for X lock. That is why undetectable deadlock happens. But my opinion that that is a bug. Just try yourself (may be i missed something) - start 2 transactions from two consoles and make any SELECT FOR UPDATE for the SAME ROW in both transactions. Second transaction will wait for the lock, then from the first transaction try to UPDATE that row. In my case it blocks both transaction until timeout and it is very very strange! Can anyone explain me why? Or tell me that it is not working just for me because of my stupidness.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: darseq</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-284632</link>
		<dc:creator>darseq</dc:creator>
		<pubDate>Mon, 21 Apr 2008 21:02:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-284632</guid>
		<description>Interesting, but I think the update should actually succeed.
Did you test with mysql.exe in two console (dos?) boxes?
Using mysql ensures that you operate directly on the server
with no other software layers in between. Also I find the
syntax is_active=is_active rather odd. Always test using the
most simple case. So do something like is_active='0' or so.

I don't know about GET_LOCK/RELEASE_LOCK.

p.s: did you know that a
'SELECT id into tmp from mf_banners where id=192 LOCK IN SHARE MODE'
together with 'REPEATABLE_READ' suffices to get serializability?</description>
		<content:encoded><![CDATA[<p>Interesting, but I think the update should actually succeed.<br />
Did you test with mysql.exe in two console (dos?) boxes?<br />
Using mysql ensures that you operate directly on the server<br />
with no other software layers in between. Also I find the<br />
syntax is_active=is_active rather odd. Always test using the<br />
most simple case. So do something like is_active=&#8217;0&#8242; or so.</p>
<p>I don&#8217;t know about GET_LOCK/RELEASE_LOCK.</p>
<p>p.s: did you know that a<br />
&#8216;SELECT id into tmp from mf_banners where id=192 LOCK IN SHARE MODE&#8217;<br />
together with &#8216;REPEATABLE_READ&#8217; suffices to get serializability?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Victor</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-284409</link>
		<dc:creator>Victor</dc:creator>
		<pubDate>Mon, 21 Apr 2008 13:11:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-284409</guid>
		<description>Following code cause an undetectable deadlock when run simultaneously. (Lock wait timeout exceeded;)
START TRANSACTION;
SELECT id into tmp from mf_banners where id=192 FOR UPDATE;
UPDATE mf_banners set is_active=is_active where id=192;
COMMIT;

And I can't understand why. 
Transaction 1 takes X lock for record 192, then Transaction 2 try to take the same lock and can't, so T2 waits for X lock. Then T1 tries to update record (It holds X lock for that record) and it can't! Why???
I have serialized access with GET_LOCK and RELEASE_LOCK and that helped to avoid lock wait timeouts, but i'am not sure that they are replication safe. Are they replication safe, especially when used inside stored procedures?
Thank you for help.</description>
		<content:encoded><![CDATA[<p>Following code cause an undetectable deadlock when run simultaneously. (Lock wait timeout exceeded;)<br />
START TRANSACTION;<br />
SELECT id into tmp from mf_banners where id=192 FOR UPDATE;<br />
UPDATE mf_banners set is_active=is_active where id=192;<br />
COMMIT;</p>
<p>And I can&#8217;t understand why.<br />
Transaction 1 takes X lock for record 192, then Transaction 2 try to take the same lock and can&#8217;t, so T2 waits for X lock. Then T1 tries to update record (It holds X lock for that record) and it can&#8217;t! Why???<br />
I have serialized access with GET_LOCK and RELEASE_LOCK and that helped to avoid lock wait timeouts, but i&#8217;am not sure that they are replication safe. Are they replication safe, especially when used inside stored procedures?<br />
Thank you for help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: darseq</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-253941</link>
		<dc:creator>darseq</dc:creator>
		<pubDate>Tue, 18 Mar 2008 11:54:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-253941</guid>
		<description>Oh yeah, and before I forget: A lock only becomes active when
the statement is actually EXECUTED, so a PREPARE does not
necessarily lock until the point of actually EXECUTING the
statement.</description>
		<content:encoded><![CDATA[<p>Oh yeah, and before I forget: A lock only becomes active when<br />
the statement is actually EXECUTED, so a PREPARE does not<br />
necessarily lock until the point of actually EXECUTING the<br />
statement.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: darseq</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-253940</link>
		<dc:creator>darseq</dc:creator>
		<pubDate>Tue, 18 Mar 2008 11:47:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-253940</guid>
		<description>Hi Pratab,

Check the following:

- Is the transaction isolation level properly set?
  For ODBC use the ODBC API and something like:
  SQLSetConnectAttr(dbc_h,
  SQL_ATTR_TXN_ISOLATION,
  (SQLPOINTER) isolation,
  SQL_IS_INTEGER);

- Is AUTOCOMMIT set to false?
  For ODBC use the ODBC API and something like:
  SQLSetConnectAttr(dbc_h,
  SQL_ATTR_AUTOCOMMIT,
  (SQLPOINTER)autocommit,
  SQL_IS_UINTEGER);

- When using ODBC you do not need to specify BEGIN statements. A new transaction start automatically
after the previous transaction commits.
  To commit a transaction in ODBC, use the API:
  SQLEndTran(SQL_HANDLE_DBC,dbc_h,SQL_COMMIT);
  If you choose to use a 'sql passthrough' COMMIT
  statement however, the ODBC driver itself may not
  know about your transaction ending and may not
  automatically start a new one so beware of this.</description>
		<content:encoded><![CDATA[<p>Hi Pratab,</p>
<p>Check the following:</p>
<p>- Is the transaction isolation level properly set?<br />
  For ODBC use the ODBC API and something like:<br />
  SQLSetConnectAttr(dbc_h,<br />
  SQL_ATTR_TXN_ISOLATION,<br />
  (SQLPOINTER) isolation,<br />
  SQL_IS_INTEGER);</p>
<p>- Is AUTOCOMMIT set to false?<br />
  For ODBC use the ODBC API and something like:<br />
  SQLSetConnectAttr(dbc_h,<br />
  SQL_ATTR_AUTOCOMMIT,<br />
  (SQLPOINTER)autocommit,<br />
  SQL_IS_UINTEGER);</p>
<p>- When using ODBC you do not need to specify BEGIN statements. A new transaction start automatically<br />
after the previous transaction commits.<br />
  To commit a transaction in ODBC, use the API:<br />
  SQLEndTran(SQL_HANDLE_DBC,dbc_h,SQL_COMMIT);<br />
  If you choose to use a &#8217;sql passthrough&#8217; COMMIT<br />
  statement however, the ODBC driver itself may not<br />
  know about your transaction ending and may not<br />
  automatically start a new one so beware of this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-253627</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Mon, 17 Mar 2008 15:26:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-253627</guid>
		<description>Pratap, you would do better of asking question on forum and providing complete SQL example.

Most typical the problem is you do not have transaction open.</description>
		<content:encoded><![CDATA[<p>Pratap, you would do better of asking question on forum and providing complete SQL example.</p>
<p>Most typical the problem is you do not have transaction open.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pratap</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-253562</link>
		<dc:creator>pratap</dc:creator>
		<pubDate>Mon, 17 Mar 2008 08:17:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-253562</guid>
		<description>In an ODBC based application, I need to lock a row while selecting it. For this
I did use SELECT FOR UPDATE in SQLPREPARE()  odbc primitive. But it is not working.
WHat may be the reason, Ia m working on Linux.</description>
		<content:encoded><![CDATA[<p>In an ODBC based application, I need to lock a row while selecting it. For this<br />
I did use SELECT FOR UPDATE in SQLPREPARE()  odbc primitive. But it is not working.<br />
WHat may be the reason, Ia m working on Linux.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pavel</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-223115</link>
		<dc:creator>pavel</dc:creator>
		<pubDate>Mon, 24 Dec 2007 20:47:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-223115</guid>
		<description>DO NOT EVER DO THIS:

update SOMETABLE as fn set fn.counter = (select count(*) from SOMEOTHERTABLE as p where p.X = fn.X LOCK IN share mode);

Good luck with your locked mysql</description>
		<content:encoded><![CDATA[<p>DO NOT EVER DO THIS:</p>
<p>update SOMETABLE as fn set fn.counter = (select count(*) from SOMEOTHERTABLE as p where p.X = fn.X LOCK IN share mode);</p>
<p>Good luck with your locked mysql</p>
]]></content:encoded>
	</item>
</channel>
</rss>
