<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: A little-known way to cause a database deadlock</title>
	<link>http://www.xaprb.com/blog/2006/08/03/a-little-known-way-to-cause-a-database-deadlock/</link>
	<description>Stay curious!</description>
	<pubDate>Thu, 24 Jul 2008 00:14:24 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.2</generator>

	<item>
		<title>By: Xaprb</title>
		<link>http://www.xaprb.com/blog/2006/08/03/a-little-known-way-to-cause-a-database-deadlock/#comment-1394</link>
		<author>Xaprb</author>
		<pubDate>Tue, 08 Aug 2006 19:17:52 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/08/03/a-little-known-way-to-cause-a-database-deadlock/#comment-1394</guid>
		<description>&lt;p&gt;Peter of MySQL Performance Blog wrote a very informative article on &lt;a href="http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/"&gt;how locking and transaction isolation levels work in InnoDB&lt;/a&gt;.  Then I asked questions in the comments and he replied.  It is well worth reading the article and the comments!&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Peter of MySQL Performance Blog wrote a very informative article on <a href="http://www.mysqlperformanceblog.com/2006/08/06/select-lock-in-share-mode-and-for-update/">how locking and transaction isolation levels work in InnoDB</a>.  Then I asked questions in the comments and he replied.  It is well worth reading the article and the comments!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Callaghan</title>
		<link>http://www.xaprb.com/blog/2006/08/03/a-little-known-way-to-cause-a-database-deadlock/#comment-1343</link>
		<author>Mark Callaghan</author>
		<pubDate>Sat, 05 Aug 2006 17:35:53 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/08/03/a-little-known-way-to-cause-a-database-deadlock/#comment-1343</guid>
		<description>&lt;p&gt;InnoDB gets share locks on rows read from the selected table for statements of the form (create&#124;update&#124;delete&#124;insert) .... select ... from ....
This is done so that a replica will read the same values as the master for the select. Unfortunately, these share locks are taken when the binlog is disabled, and the set of statements for which the locks are taken has changed from 4.0.20 to 4.0.26 to 4.1 to 5.x (thus the apparent 'randomness'). Depending on the version that you use, innodb_locks_unsafe_for_binlog may prevent the locks from being taken.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>InnoDB gets share locks on rows read from the selected table for statements of the form (create|update|delete|insert) &#8230;. select &#8230; from &#8230;.<br />
This is done so that a replica will read the same values as the master for the select. Unfortunately, these share locks are taken when the binlog is disabled, and the set of statements for which the locks are taken has changed from 4.0.20 to 4.0.26 to 4.1 to 5.x (thus the apparent &#8216;randomness&#8217;). Depending on the version that you use, innodb_locks_unsafe_for_binlog may prevent the locks from being taken.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy Cole</title>
		<link>http://www.xaprb.com/blog/2006/08/03/a-little-known-way-to-cause-a-database-deadlock/#comment-1337</link>
		<author>Jeremy Cole</author>
		<pubDate>Sat, 05 Aug 2006 03:36:58 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/08/03/a-little-known-way-to-cause-a-database-deadlock/#comment-1337</guid>
		<description>&lt;p&gt;Hi Baron,&lt;/p&gt;

&lt;p&gt;Fair enough, but mucking with the core server's locking in order to make replication (decidedly, an add-on) work correctly seems like the wrong approach.  Perhaps the right approach would be to (at least optionally) allow you to have the INSERT ... SELECT converted into either plain INSERT or optimally LOAD DATA INFILE with the file in-lined in the binlog.&lt;/p&gt;

&lt;p&gt;Ugliness...&lt;/p&gt;

&lt;p&gt;Regards,&lt;/p&gt;

&lt;p&gt;Jeremy&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Hi Baron,</p>
<p>Fair enough, but mucking with the core server&#8217;s locking in order to make replication (decidedly, an add-on) work correctly seems like the wrong approach.  Perhaps the right approach would be to (at least optionally) allow you to have the INSERT &#8230; SELECT converted into either plain INSERT or optimally LOAD DATA INFILE with the file in-lined in the binlog.</p>
<p>Ugliness&#8230;</p>
<p>Regards,</p>
<p>Jeremy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xaprb</title>
		<link>http://www.xaprb.com/blog/2006/08/03/a-little-known-way-to-cause-a-database-deadlock/#comment-1334</link>
		<author>Xaprb</author>
		<pubDate>Fri, 04 Aug 2006 17:24:56 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/08/03/a-little-known-way-to-cause-a-database-deadlock/#comment-1334</guid>
		<description>&lt;p&gt;Hi Jeremy, you're correct that the "select for insert" or "select for update" type of statement is what's acquiring locks.  This is necessary for statement-based replication to work correctly, though.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Hi Jeremy, you&#8217;re correct that the &#8220;select for insert&#8221; or &#8220;select for update&#8221; type of statement is what&#8217;s acquiring locks.  This is necessary for statement-based replication to work correctly, though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy Cole</title>
		<link>http://www.xaprb.com/blog/2006/08/03/a-little-known-way-to-cause-a-database-deadlock/#comment-1332</link>
		<author>Jeremy Cole</author>
		<pubDate>Fri, 04 Aug 2006 16:32:02 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/08/03/a-little-known-way-to-cause-a-database-deadlock/#comment-1332</guid>
		<description>&lt;p&gt;Hi Baron,&lt;/p&gt;

&lt;p&gt;An interesting but missed point in this discussion is that the only reason that InnoDB is trying to acquire a shared read lock is that the CREATE TEMPORARY TABLE upgraded the locking used by that SELECT.  If you run the same SELECT, without the CREATE TEMPORARY TABLE, it does not deadlock.&lt;/p&gt;

&lt;p&gt;I've noticed this before, and in fact complained about it before (at the Users Conference) that InnoDB somewhat "randomly" decides what locking to use for INSERT ... SELECT and CREATE ... SELECT.  As far as I can tell, there's no reason that your CREATE ... SELECT should require a shared read lock... multiversioning should allow it to be executed with no locks.&lt;/p&gt;

&lt;p&gt;Regards,&lt;/p&gt;

&lt;p&gt;Jeremy&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Hi Baron,</p>
<p>An interesting but missed point in this discussion is that the only reason that InnoDB is trying to acquire a shared read lock is that the CREATE TEMPORARY TABLE upgraded the locking used by that SELECT.  If you run the same SELECT, without the CREATE TEMPORARY TABLE, it does not deadlock.</p>
<p>I&#8217;ve noticed this before, and in fact complained about it before (at the Users Conference) that InnoDB somewhat &#8220;randomly&#8221; decides what locking to use for INSERT &#8230; SELECT and CREATE &#8230; SELECT.  As far as I can tell, there&#8217;s no reason that your CREATE &#8230; SELECT should require a shared read lock&#8230; multiversioning should allow it to be executed with no locks.</p>
<p>Regards,</p>
<p>Jeremy</p>
]]></content:encoded>
	</item>
</channel>
</rss>
