<?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: Can MySQL temporary tables be made safe for statement-based replication?</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2008/05/26/mysql-temporary-tables-safe-for-statement-based-replication/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2008/05/26/mysql-temporary-tables-safe-for-statement-based-replication/</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: Gregory Haase</title>
		<link>http://www.mysqlperformanceblog.com/2008/05/26/mysql-temporary-tables-safe-for-statement-based-replication/comment-page-1/#comment-306831</link>
		<dc:creator>Gregory Haase</dc:creator>
		<pubDate>Fri, 30 May 2008 13:31:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=404#comment-306831</guid>
		<description>Actually, I did submit a bug: &lt;a href=&quot;http://bugs.mysql.com/bug.php?id=37011&quot; rel=&quot;nofollow&quot;&gt;Bug #37011&lt;/a&gt;: creating temporary table inside a transaction may result in incorrect binlog.</description>
		<content:encoded><![CDATA[<p>Actually, I did submit a bug: <a href="http://bugs.mysql.com/bug.php?id=37011" rel="nofollow">Bug #37011</a>: creating temporary table inside a transaction may result in incorrect binlog.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Baron Schwartz</title>
		<link>http://www.mysqlperformanceblog.com/2008/05/26/mysql-temporary-tables-safe-for-statement-based-replication/comment-page-1/#comment-306646</link>
		<dc:creator>Baron Schwartz</dc:creator>
		<pubDate>Thu, 29 May 2008 22:17:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=404#comment-306646</guid>
		<description>Gregory, thanks for writing in with these interesting findings.  I think a good bug report is lurking in here, and you seem qualified to submit it :-)</description>
		<content:encoded><![CDATA[<p>Gregory, thanks for writing in with these interesting findings.  I think a good bug report is lurking in here, and you seem qualified to submit it <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Parvesh</title>
		<link>http://www.mysqlperformanceblog.com/2008/05/26/mysql-temporary-tables-safe-for-statement-based-replication/comment-page-1/#comment-306060</link>
		<dc:creator>Parvesh</dc:creator>
		<pubDate>Wed, 28 May 2008 09:50:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=404#comment-306060</guid>
		<description>Baron,

1. Against creating *scratch tables*: Running DDL statements in production can screw you up a big time. And anyhow my doing a create table won&#039;t be transaction safe if it is MyISAM and if InnoDB, I will be messing up with the common tablespace which I don&#039;t want to do in production. This puts me into a trade-off of saving data in replication and risk of losing everything one bad morning.

2. Against row based replication: My last resort is row based replication that goes against the very first reason of using temporary tables. Most of us use temporary tables (there are more reasons also) because we want to replace multiple inserts with one bulk in the main table. Now if I enable RBR, I go back to stone age as far as my slaves are concerned.

I&#039;m in a complete deadlock situation of Reliability vs Performance. And to top it all, I want both.</description>
		<content:encoded><![CDATA[<p>Baron,</p>
<p>1. Against creating *scratch tables*: Running DDL statements in production can screw you up a big time. And anyhow my doing a create table won&#8217;t be transaction safe if it is MyISAM and if InnoDB, I will be messing up with the common tablespace which I don&#8217;t want to do in production. This puts me into a trade-off of saving data in replication and risk of losing everything one bad morning.</p>
<p>2. Against row based replication: My last resort is row based replication that goes against the very first reason of using temporary tables. Most of us use temporary tables (there are more reasons also) because we want to replace multiple inserts with one bulk in the main table. Now if I enable RBR, I go back to stone age as far as my slaves are concerned.</p>
<p>I&#8217;m in a complete deadlock situation of Reliability vs Performance. And to top it all, I want both.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gregory Haase</title>
		<link>http://www.mysqlperformanceblog.com/2008/05/26/mysql-temporary-tables-safe-for-statement-based-replication/comment-page-1/#comment-305688</link>
		<dc:creator>Gregory Haase</dc:creator>
		<pubDate>Tue, 27 May 2008 15:55:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=404#comment-305688</guid>
		<description>So I dug even deeper, and I found out that you basically need to perform some kind of action to initiate the transaction before creating your temp table. It seems that merely issuing a &quot;START TRANSACTION&quot; is not enough.

For example, if you create a table with 1 column:
CREATE TABLE `test`.`ints` (id int(1));

And your procedure looks like this:
START TRANSACTION;
INSERT INTO `test`.`ints` VALUES (1);
CREATE TEMPORARY TABLE...
...
COMMIT;

... then the temporary table will be created inside the transaction.  

I&#039;ve never looked at the internals, but if you just issue START TRANSACTION; COMMIT; with nothing in between, nothing shows up in the binlog. I&#039;m assuming then there is a list of &quot;events&quot; that can occur that cause a transaction to start in the binlog. It seems to me right now that this is simply a case of &quot;create temporary table&quot; is left out of this set of events. I suspect that the word temporary has nothing to do with it... that a simple &quot;CREATE TABLE&quot; does not cause a transaction to start, but that &quot;CREATE TABLE AS SELECT&quot; does.

I logged a bug - #37011</description>
		<content:encoded><![CDATA[<p>So I dug even deeper, and I found out that you basically need to perform some kind of action to initiate the transaction before creating your temp table. It seems that merely issuing a &#8220;START TRANSACTION&#8221; is not enough.</p>
<p>For example, if you create a table with 1 column:<br />
CREATE TABLE `test`.`ints` (id int(1));</p>
<p>And your procedure looks like this:<br />
START TRANSACTION;<br />
INSERT INTO `test`.`ints` VALUES (1);<br />
CREATE TEMPORARY TABLE&#8230;<br />
&#8230;<br />
COMMIT;</p>
<p>&#8230; then the temporary table will be created inside the transaction.  </p>
<p>I&#8217;ve never looked at the internals, but if you just issue START TRANSACTION; COMMIT; with nothing in between, nothing shows up in the binlog. I&#8217;m assuming then there is a list of &#8220;events&#8221; that can occur that cause a transaction to start in the binlog. It seems to me right now that this is simply a case of &#8220;create temporary table&#8221; is left out of this set of events. I suspect that the word temporary has nothing to do with it&#8230; that a simple &#8220;CREATE TABLE&#8221; does not cause a transaction to start, but that &#8220;CREATE TABLE AS SELECT&#8221; does.</p>
<p>I logged a bug &#8211; #37011</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gregory Haase</title>
		<link>http://www.mysqlperformanceblog.com/2008/05/26/mysql-temporary-tables-safe-for-statement-based-replication/comment-page-1/#comment-305672</link>
		<dc:creator>Gregory Haase</dc:creator>
		<pubDate>Tue, 27 May 2008 14:22:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=404#comment-305672</guid>
		<description>Ooops...  I spoke too soon!

You can completely disregard the previous post because I just figured out that the real difference is the &quot;CREATE TEMPORARY TABLE ... AS SELECT&quot; syntax. If I take that out and try to make a normal temporary table, it puts the table creation _before_ the transaction starts.

The plot thickens...  you can do the following, and everything will be inside the transaction:

START TRANSACTION;
CREATE TEMPORARY TABLE `test`.`test2` AS SELECT 1;
CREATE TEMPORARY TABLE `test`.`temporary_table`
( `id` int(11) NOT NULL,
  `value_1` varchar(10) default NULL,
  `value_2` varchar(10) default NULL,
  `value_3` varchar(10) default NULL
) ENGINE=InnoDB;
</description>
		<content:encoded><![CDATA[<p>Ooops&#8230;  I spoke too soon!</p>
<p>You can completely disregard the previous post because I just figured out that the real difference is the &#8220;CREATE TEMPORARY TABLE &#8230; AS SELECT&#8221; syntax. If I take that out and try to make a normal temporary table, it puts the table creation _before_ the transaction starts.</p>
<p>The plot thickens&#8230;  you can do the following, and everything will be inside the transaction:</p>
<p>START TRANSACTION;<br />
CREATE TEMPORARY TABLE `test`.`test2` AS SELECT 1;<br />
CREATE TEMPORARY TABLE `test`.`temporary_table`<br />
( `id` int(11) NOT NULL,<br />
  `value_1` varchar(10) default NULL,<br />
  `value_2` varchar(10) default NULL,<br />
  `value_3` varchar(10) default NULL<br />
) ENGINE=InnoDB;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gregory Haase</title>
		<link>http://www.mysqlperformanceblog.com/2008/05/26/mysql-temporary-tables-safe-for-statement-based-replication/comment-page-1/#comment-305665</link>
		<dc:creator>Gregory Haase</dc:creator>
		<pubDate>Tue, 27 May 2008 14:08:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=404#comment-305665</guid>
		<description>I thought I had figured this one out, so I was pretty shocked to see your post that it doesn&#039;t work. I was about to go back to the drawing board, but I realized that you were looking directly at the binlogs and I was actually crash-testing my slaves. So I took a look at my bin-logs and I see a very surprising difference.

Note that I am using a stored procedure and that I have my code surrounded by START TRANSACTION; COMMIT;


mysql&gt; SHOW binlog events IN &#039;bin-logs.000440&#039;\G
*************************** 1. row ***************************
   Log_name: bin-logs.000440
        Pos: 4
 Event_type: Format_desc
  Server_id: 1
End_log_pos: 98
       Info: Server ver: 5.0.27-standard-log, Binlog ver: 4
*************************** 2. row ***************************
   Log_name: bin-logs.000440
        Pos: 98
 Event_type: Query
  Server_id: 1
End_log_pos: 224
       Info: use `test`; DROP TEMPORARY TABLE IF EXISTS `test`.`temporary_table`
*************************** 3. row ***************************
   Log_name: bin-logs.000440
        Pos: 224
 Event_type: Query
  Server_id: 1
End_log_pos: 300
       Info: use `test`; BEGIN
*************************** 4. row ***************************
   Log_name: bin-logs.000440
        Pos: 300
 Event_type: Query
  Server_id: 1
End_log_pos: 272
       Info: use `test`; CREATE TEMPORARY TABLE `test`.`temporary_table` 
  ENGINE = InnoDB
      AS SELECT id,
                value_1,
                value_2,
                value_3
           FROM `test`.`permanent_table`


I was including a drop temporary table statement because if this worked, I was going to create a process that could potentially run this multiple times per session. Interestingly enough, we don&#039;t care if the drop table statement isn&#039;t rolled back in a crash - because a crash would drop the tmp table anyway.

Then I decided to check a new version, so I ran this in 5.1.24-rc and I got the same results. 

So at first glance, we suspect that its a bug where the very first temporary table transaction is not included. I ran several additional tests, and I can&#039;t really find any consistency. If I create two temp tables, the BEGIN occurs between the two, however if I do create temp table, drop temp table, create temp table, the BEGIN occurs before the last create.</description>
		<content:encoded><![CDATA[<p>I thought I had figured this one out, so I was pretty shocked to see your post that it doesn&#8217;t work. I was about to go back to the drawing board, but I realized that you were looking directly at the binlogs and I was actually crash-testing my slaves. So I took a look at my bin-logs and I see a very surprising difference.</p>
<p>Note that I am using a stored procedure and that I have my code surrounded by START TRANSACTION; COMMIT;</p>
<p>mysql&gt; SHOW binlog events IN &#8216;bin-logs.000440&#8242;\G<br />
*************************** 1. row ***************************<br />
   Log_name: bin-logs.000440<br />
        Pos: 4<br />
 Event_type: Format_desc<br />
  Server_id: 1<br />
End_log_pos: 98<br />
       Info: Server ver: 5.0.27-standard-log, Binlog ver: 4<br />
*************************** 2. row ***************************<br />
   Log_name: bin-logs.000440<br />
        Pos: 98<br />
 Event_type: Query<br />
  Server_id: 1<br />
End_log_pos: 224<br />
       Info: use `test`; DROP TEMPORARY TABLE IF EXISTS `test`.`temporary_table`<br />
*************************** 3. row ***************************<br />
   Log_name: bin-logs.000440<br />
        Pos: 224<br />
 Event_type: Query<br />
  Server_id: 1<br />
End_log_pos: 300<br />
       Info: use `test`; BEGIN<br />
*************************** 4. row ***************************<br />
   Log_name: bin-logs.000440<br />
        Pos: 300<br />
 Event_type: Query<br />
  Server_id: 1<br />
End_log_pos: 272<br />
       Info: use `test`; CREATE TEMPORARY TABLE `test`.`temporary_table`<br />
  ENGINE = InnoDB<br />
      AS SELECT id,<br />
                value_1,<br />
                value_2,<br />
                value_3<br />
           FROM `test`.`permanent_table`</p>
<p>I was including a drop temporary table statement because if this worked, I was going to create a process that could potentially run this multiple times per session. Interestingly enough, we don&#8217;t care if the drop table statement isn&#8217;t rolled back in a crash &#8211; because a crash would drop the tmp table anyway.</p>
<p>Then I decided to check a new version, so I ran this in 5.1.24-rc and I got the same results. </p>
<p>So at first glance, we suspect that its a bug where the very first temporary table transaction is not included. I ran several additional tests, and I can&#8217;t really find any consistency. If I create two temp tables, the BEGIN occurs between the two, however if I do create temp table, drop temp table, create temp table, the BEGIN occurs before the last create.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Baron Schwartz</title>
		<link>http://www.mysqlperformanceblog.com/2008/05/26/mysql-temporary-tables-safe-for-statement-based-replication/comment-page-1/#comment-305609</link>
		<dc:creator>Baron Schwartz</dc:creator>
		<pubDate>Tue, 27 May 2008 10:59:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=404#comment-305609</guid>
		<description>Michael, actually I knew about all these things already, and that&#039;s not what&#039;s happening.  There is NOT an implicit commit, which I proved to myself by examining SHOW INNODB STATUS carefuly.  But commit or no commit, the CREATE TEMPORARY TABLE statement is logged right away to the binlog. This is not the same thing as implicit commit.</description>
		<content:encoded><![CDATA[<p>Michael, actually I knew about all these things already, and that&#8217;s not what&#8217;s happening.  There is NOT an implicit commit, which I proved to myself by examining SHOW INNODB STATUS carefuly.  But commit or no commit, the CREATE TEMPORARY TABLE statement is logged right away to the binlog. This is not the same thing as implicit commit.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Renner</title>
		<link>http://www.mysqlperformanceblog.com/2008/05/26/mysql-temporary-tables-safe-for-statement-based-replication/comment-page-1/#comment-305596</link>
		<dc:creator>Michael Renner</dc:creator>
		<pubDate>Tue, 27 May 2008 09:07:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=404#comment-305596</guid>
		<description>Oh, it&#039;s even worse than you thought.

See http://dev.mysql.com/doc/refman/5.1/en/innodb-implicit-commit.html , http://dev.mysql.com/doc/refman/5.1/en/innodb-error-handling.html and http://dev.mysql.com/doc/refman/5.1/en/implicit-commit.html . 

But there&#039;s a slim chance that it&#039;ll get better in the future - see http://www.scribd.com/doc/2575733/The-future-of-MySQL-The-Project .</description>
		<content:encoded><![CDATA[<p>Oh, it&#8217;s even worse than you thought.</p>
<p>See <a href="http://dev.mysql.com/doc/refman/5.1/en/innodb-implicit-commit.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.1/en/innodb-implicit-commit.html</a> , <a href="http://dev.mysql.com/doc/refman/5.1/en/innodb-error-handling.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.1/en/innodb-error-handling.html</a> and <a href="http://dev.mysql.com/doc/refman/5.1/en/implicit-commit.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.1/en/implicit-commit.html</a> . </p>
<p>But there&#8217;s a slim chance that it&#8217;ll get better in the future &#8211; see <a href="http://www.scribd.com/doc/2575733/The-future-of-MySQL-The-Project" rel="nofollow">http://www.scribd.com/doc/2575733/The-future-of-MySQL-The-Project</a> .</p>
]]></content:encoded>
	</item>
</channel>
</rss>
