<?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/"
		>
<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>
	<lastBuildDate>Sat, 21 Nov 2009 05:23:57 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: darseq</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/comment-page-1/#comment-622788</link>
		<dc:creator>darseq</dc:creator>
		<pubDate>Sun, 02 Aug 2009 08:32:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-622788</guid>
		<description>The first update statement results in a lock for other transactions.
Since these update statements are in the same transaction, the second
update statement does not block. However because the row was already
updated with the first update statement, an identical update will
affect zero rows because the update has already been made.</description>
		<content:encoded><![CDATA[<p>The first update statement results in a lock for other transactions.<br />
Since these update statements are in the same transaction, the second<br />
update statement does not block. However because the row was already<br />
updated with the first update statement, an identical update will<br />
affect zero rows because the update has already been made.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gaditano</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/comment-page-1/#comment-622339</link>
		<dc:creator>Gaditano</dc:creator>
		<pubDate>Sat, 01 Aug 2009 16:58:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-622339</guid>
		<description>Hi everybody,

I have an a problem and I cannot resolve.

I don&#039;t know how I can resolve this:

Transaction 1

START TRANSACTION;

UPDATE `sginfra_actas` SET `act_estado_id` = &#039;9&#039; WHERE `act_id` = &#039;3713&#039;
(Affected Row = 1)

Other statments....


UPDATE `sginfra_actas` SET `act_estado_id` = &#039;9&#039; WHERE `act_id` = &#039;3713&#039;
(Affected Row = 0)

I&#039;m in the same transactions.
Why there is a lock?

Thansk

Gaditano</description>
		<content:encoded><![CDATA[<p>Hi everybody,</p>
<p>I have an a problem and I cannot resolve.</p>
<p>I don&#8217;t know how I can resolve this:</p>
<p>Transaction 1</p>
<p>START TRANSACTION;</p>
<p>UPDATE `sginfra_actas` SET `act_estado_id` = &#8216;9&#8242; WHERE `act_id` = &#8216;3713&#8242;<br />
(Affected Row = 1)</p>
<p>Other statments&#8230;.</p>
<p>UPDATE `sginfra_actas` SET `act_estado_id` = &#8216;9&#8242; WHERE `act_id` = &#8216;3713&#8242;<br />
(Affected Row = 0)</p>
<p>I&#8217;m in the same transactions.<br />
Why there is a lock?</p>
<p>Thansk</p>
<p>Gaditano</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-page-1/#comment-344626</link>
		<dc:creator>darseq</dc:creator>
		<pubDate>Thu, 14 Aug 2008 11:13:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-344626</guid>
		<description>Ben, just to clarify some things, copied from the mysql manual:

The correct way to use LOCK TABLES and UNLOCK TABLES with transactional tables, such as InnoDB tables, is to begin a transaction with SET AUTOCOMMIT = 0 (not START TRANSACTION) followed by LOCK TABLES, and to not call UNLOCK TABLES until you commit the transaction explicitly. When you call LOCK TABLES, InnoDB internally takes its own table lock, and MySQL takes its own table lock. InnoDB releases its internal table lock at the next commit, but for MySQL to release its table lock, you have to call UNLOCK TABLES. You should not have AUTOCOMMIT = 1, because then InnoDB releases its internal table lock immediately after the call of LOCK TABLES, and deadlocks can very easily happen. InnoDB does not acquire the internal table lock at all if AUTOCOMMIT=1, to help old applications avoid unnecessary deadlocks.</description>
		<content:encoded><![CDATA[<p>Ben, just to clarify some things, copied from the mysql manual:</p>
<p>The correct way to use LOCK TABLES and UNLOCK TABLES with transactional tables, such as InnoDB tables, is to begin a transaction with SET AUTOCOMMIT = 0 (not START TRANSACTION) followed by LOCK TABLES, and to not call UNLOCK TABLES until you commit the transaction explicitly. When you call LOCK TABLES, InnoDB internally takes its own table lock, and MySQL takes its own table lock. InnoDB releases its internal table lock at the next commit, but for MySQL to release its table lock, you have to call UNLOCK TABLES. You should not have AUTOCOMMIT = 1, because then InnoDB releases its internal table lock immediately after the call of LOCK TABLES, and deadlocks can very easily happen. InnoDB does not acquire the internal table lock at all if AUTOCOMMIT=1, to help old applications avoid unnecessary deadlocks.</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-page-1/#comment-344624</link>
		<dc:creator>darseq</dc:creator>
		<pubDate>Thu, 14 Aug 2008 10:53:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-344624</guid>
		<description>Ben, 

A deadlock is like Peter explains, but basically you are saying the same.
So to combine both explanations just consider two transactions A en B and
one table with rows r1 and r2 in it. Transactions A locks r1, and
transaction B locks r2, then transaction A wants to lock r2 but has to
wait to get it, and finally transaction B wants to lock r1 but also has
to wait. In this scenario transaction A and B are waiting for eachother
and neither one can ever proceed which is called a deadlock.

As to why table locks are more efficient is because of this:
When a transaction wants to access a table it first checks if there is
a table lock sitting on it. Only after doing this check, row locks come
into play. So there are actually two levels of locking, first the table
lock, only then the row locks. Checking only a single table lock is
less overhead then having to check multiple row locks.</description>
		<content:encoded><![CDATA[<p>Ben, </p>
<p>A deadlock is like Peter explains, but basically you are saying the same.<br />
So to combine both explanations just consider two transactions A en B and<br />
one table with rows r1 and r2 in it. Transactions A locks r1, and<br />
transaction B locks r2, then transaction A wants to lock r2 but has to<br />
wait to get it, and finally transaction B wants to lock r1 but also has<br />
to wait. In this scenario transaction A and B are waiting for eachother<br />
and neither one can ever proceed which is called a deadlock.</p>
<p>As to why table locks are more efficient is because of this:<br />
When a transaction wants to access a table it first checks if there is<br />
a table lock sitting on it. Only after doing this check, row locks come<br />
into play. So there are actually two levels of locking, first the table<br />
lock, only then the row locks. Checking only a single table lock is<br />
less overhead then having to check multiple row locks.</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-page-1/#comment-344579</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Thu, 14 Aug 2008 04:40:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-344579</guid>
		<description>Ben,

If one thread just tries to lock the resouce which is already locked lock wait happens.   If however the locking thread holds resources other threads is waiting for (most simple case) wait would happen forever and it is called deadlock.

Why Innodb locks row level locks always is because it is designed this way :)</description>
		<content:encoded><![CDATA[<p>Ben,</p>
<p>If one thread just tries to lock the resouce which is already locked lock wait happens.   If however the locking thread holds resources other threads is waiting for (most simple case) wait would happen forever and it is called deadlock.</p>
<p>Why Innodb locks row level locks always is because it is designed this way <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/comment-page-1/#comment-344578</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Thu, 14 Aug 2008 04:01:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/#comment-344578</guid>
		<description>I don&#039;t think I understand.  I thought a deadlock was when two tasks wanted access to a resource that the other had already locked.  When something asks for a lock and can not get it because something else has the lock was called lock contention.

Also, when you say: &quot;Lock table Innodb can lock tables but it will still need to set row level locks which is memory and CPU overhead. For some bulk operations it would be more efficient to use table locks.&quot;, I am curious as to why, if the whole table is locked, row level locks are still needed.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t think I understand.  I thought a deadlock was when two tasks wanted access to a resource that the other had already locked.  When something asks for a lock and can not get it because something else has the lock was called lock contention.</p>
<p>Also, when you say: &#8220;Lock table Innodb can lock tables but it will still need to set row level locks which is memory and CPU overhead. For some bulk operations it would be more efficient to use table locks.&#8221;, I am curious as to why, if the whole table is locked, row level locks are still needed.</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-page-1/#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-page-1/#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-page-1/#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&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.</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) &#8211; 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-page-1/#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=&#039;0&#039; or so.

I don&#039;t know about GET_LOCK/RELEASE_LOCK.

p.s: did you know that a
&#039;SELECT id into tmp from mf_banners where id=192 LOCK IN SHARE MODE&#039;
together with &#039;REPEATABLE_READ&#039; 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>
</channel>
</rss>
