<?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: How to eliminate temporary tables in MySQL</title>
	<link>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/</link>
	<description>Stay curious!</description>
	<pubDate>Fri, 29 Aug 2008 04:58:29 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.2</generator>

	<item>
		<title>By: Xaprb</title>
		<link>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-14498</link>
		<author>Xaprb</author>
		<pubDate>Thu, 01 May 2008 21:21:37 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-14498</guid>
		<description>Gregory, I have not tested that to the point of exhaustion, but I don't think your scenario is safe either.  I know at least one other person doing the same workaround for a workaround, for the same reason :-)</description>
		<content:encoded><![CDATA[<p>Gregory, I have not tested that to the point of exhaustion, but I don&#8217;t think your scenario is safe either.  I know at least one other person doing the same workaround for a workaround, for the same reason :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gregory Haase</title>
		<link>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-14497</link>
		<author>Gregory Haase</author>
		<pubDate>Thu, 01 May 2008 20:09:55 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-14497</guid>
		<description>Sorry to circle back to an old post but...

What happens if you wrap your entire process inside of an explicit transaction, e.g. start transaction; create temporary table; populate it using various methods; further manipulate the data; use the data to update a real table; commit;

If your slave crashes for some reason or another during the middle of this transaction, will it roll back correctly; and more importantly, when you restart the slave, where will it pick up?

I'm looking at this from a difficult angle because I want to "manufacture" a result set inside of a stored procedure. The answer I keep getting as a replacement for Oracle's varray is "use a temp table" and because I'm using replication I'm now looking at a work-around for a a work-around.</description>
		<content:encoded><![CDATA[<p>Sorry to circle back to an old post but&#8230;</p>
<p>What happens if you wrap your entire process inside of an explicit transaction, e.g. start transaction; create temporary table; populate it using various methods; further manipulate the data; use the data to update a real table; commit;</p>
<p>If your slave crashes for some reason or another during the middle of this transaction, will it roll back correctly; and more importantly, when you restart the slave, where will it pick up?</p>
<p>I&#8217;m looking at this from a difficult angle because I want to &#8220;manufacture&#8221; a result set inside of a stored procedure. The answer I keep getting as a replacement for Oracle&#8217;s varray is &#8220;use a temp table&#8221; and because I&#8217;m using replication I&#8217;m now looking at a work-around for a a work-around.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xaprb</title>
		<link>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-14146</link>
		<author>Xaprb</author>
		<pubDate>Thu, 10 Jan 2008 23:15:55 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-14146</guid>
		<description>That won't work if there are any multi-table updates or deletes, or an INSERT...SELECT query.  If you do that, then the following queries will still cause trouble:

&lt;pre&gt;
create temporary table temp_prefix.foo as
   select * from main_db.bar;

insert into main_db.fizzle
   select * from temp_prefix.foo;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>That won&#8217;t work if there are any multi-table updates or deletes, or an INSERT&#8230;SELECT query.  If you do that, then the following queries will still cause trouble:</p>
<pre>
create temporary table temp_prefix.foo as
   select * from main_db.bar;

insert into main_db.fizzle
   select * from temp_prefix.foo;</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: eDawg</title>
		<link>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-14145</link>
		<author>eDawg</author>
		<pubDate>Thu, 10 Jan 2008 22:49:05 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-14145</guid>
		<description>why not just use --Replicate-Wild-Ignore-Table=DBNAME.TEMP_PREFIX%

and force the scripts to use the TEMP_PREFIX you specify?

e</description>
		<content:encoded><![CDATA[<p>why not just use &#8211;Replicate-Wild-Ignore-Table=DBNAME.TEMP_PREFIX%</p>
<p>and force the scripts to use the TEMP_PREFIX you specify?</p>
<p>e</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xaprb</title>
		<link>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-14024</link>
		<author>Xaprb</author>
		<pubDate>Sun, 09 Dec 2007 14:39:14 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-14024</guid>
		<description>I'm glad I figured out what you meant.  It should not be a problem, because the connection dies when the server dies, so there will never be more than one connection with a given ID.  Now, there may be more than one program that thinks its magical suffix should be 1, if the code is bad and the program doesn't quit when the server bounces.  But any program that thinks it can keep going when the server bounces is a problem.  It should either die, or throw away its work and begin again.  Certainly using "real" temporary tables wouldn't avoid this issue either, because they won't survive the restart either.</description>
		<content:encoded><![CDATA[<p>I&#8217;m glad I figured out what you meant.  It should not be a problem, because the connection dies when the server dies, so there will never be more than one connection with a given ID.  Now, there may be more than one program that thinks its magical suffix should be 1, if the code is bad and the program doesn&#8217;t quit when the server bounces.  But any program that thinks it can keep going when the server bounces is a problem.  It should either die, or throw away its work and begin again.  Certainly using &#8220;real&#8221; temporary tables wouldn&#8217;t avoid this issue either, because they won&#8217;t survive the restart either.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard Edward Horner</title>
		<link>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-13979</link>
		<author>Richard Edward Horner</author>
		<pubDate>Sat, 08 Dec 2007 22:06:14 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-13979</guid>
		<description>Yeah, that's what I was saying.

The situation I had occur frequently on one install (still a mystery to this day) was the server had a forum using InnoDB tables and it had some index table that liked to corrupt. Ppl were always on this forum and thus always accessing the index so whenever it corrupted (which was about once a week), the server rarely got it's connection count over 2.

My "solution" was to ditch all the transactional code (only a handful of changes) and change all the tables to MyISAM.</description>
		<content:encoded><![CDATA[<p>Yeah, that&#8217;s what I was saying.</p>
<p>The situation I had occur frequently on one install (still a mystery to this day) was the server had a forum using InnoDB tables and it had some index table that liked to corrupt. Ppl were always on this forum and thus always accessing the index so whenever it corrupted (which was about once a week), the server rarely got it&#8217;s connection count over 2.</p>
<p>My &#8220;solution&#8221; was to ditch all the transactional code (only a handful of changes) and change all the tables to MyISAM.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xaprb</title>
		<link>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-13978</link>
		<author>Xaprb</author>
		<pubDate>Sat, 08 Dec 2007 21:56:59 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-13978</guid>
		<description>Sure, I understand the paranoia.  I've seen bad problems too.

I still feel that I'm missing your point though.  Are you saying that my program might connect to the server, get connection ID 1, create table_1, and then there's a crash?  And then that another program would also get connection ID 1 and the two programs would conflict?

Just to clarify what I'm using these tables for: it's things like rolling up large amounts of performance data into summary tables, holding short lists of things to work on (like client numbers), generating reports, etc.  Many of these would go to disk anyway because they'd exceed the size limit on in-memory tables.  So no, I haven't seen a performance hit; I'm much happier with the data on disk anyway, where it will survive a crash.</description>
		<content:encoded><![CDATA[<p>Sure, I understand the paranoia.  I&#8217;ve seen bad problems too.</p>
<p>I still feel that I&#8217;m missing your point though.  Are you saying that my program might connect to the server, get connection ID 1, create table_1, and then there&#8217;s a crash?  And then that another program would also get connection ID 1 and the two programs would conflict?</p>
<p>Just to clarify what I&#8217;m using these tables for: it&#8217;s things like rolling up large amounts of performance data into summary tables, holding short lists of things to work on (like client numbers), generating reports, etc.  Many of these would go to disk anyway because they&#8217;d exceed the size limit on in-memory tables.  So no, I haven&#8217;t seen a performance hit; I&#8217;m much happier with the data on disk anyway, where it will survive a crash.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard Edward Horner</title>
		<link>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-13929</link>
		<author>Richard Edward Horner</author>
		<pubDate>Sat, 08 Dec 2007 13:53:35 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-13929</guid>
		<description>I think you missed the point of what I was saying. When the angel process respawns the server, the connection number resets to zero so if the process keeps respawning, you'll see a lot of connections with id 1. Yes, the IF EXISTS thing helps but maybe doing foo_$serverid_$timestamp_$connectionid would be even better.

I'm probably just being overly paranoid here from some of the production disasters I've seen with MySQL, particularly involving InnoDB and/or replication. When things go bad, they go real bad...and quickly.

Have you seen a performance hit using this scheme though? I wouldn't want to writing to disk for temp tables.</description>
		<content:encoded><![CDATA[<p>I think you missed the point of what I was saying. When the angel process respawns the server, the connection number resets to zero so if the process keeps respawning, you&#8217;ll see a lot of connections with id 1. Yes, the IF EXISTS thing helps but maybe doing foo_$serverid_$timestamp_$connectionid would be even better.</p>
<p>I&#8217;m probably just being overly paranoid here from some of the production disasters I&#8217;ve seen with MySQL, particularly involving InnoDB and/or replication. When things go bad, they go real bad&#8230;and quickly.</p>
<p>Have you seen a performance hit using this scheme though? I wouldn&#8217;t want to writing to disk for temp tables.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xaprb</title>
		<link>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-13888</link>
		<author>Xaprb</author>
		<pubDate>Fri, 07 Dec 2007 21:54:35 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-13888</guid>
		<description>Oh -- I meant to say, I'm in agreement with you that InnoDB corruption can cause major pain in general (though thankfully InnoDB is very reliable in general, bless Heikki and team), but I don't understand why  the issue you're raising isn't just as much of a concern for non-temporary tables.</description>
		<content:encoded><![CDATA[<p>Oh &#8212; I meant to say, I&#8217;m in agreement with you that InnoDB corruption can cause major pain in general (though thankfully InnoDB is very reliable in general, bless Heikki and team), but I don&#8217;t understand why  the issue you&#8217;re raising isn&#8217;t just as much of a concern for non-temporary tables.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xaprb</title>
		<link>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-13887</link>
		<author>Xaprb</author>
		<pubDate>Fri, 07 Dec 2007 21:52:21 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2007/05/11/how-to-eliminate-temporary-tables-in-mysql/#comment-13887</guid>
		<description>Hi Richard,

The changes I'm referring to are row-based replication, which you can read about in the manual.

I partially disagree with some of your points.  However, I can see your point of view, and I strongly agree with your view that fixing problems in replication is better than using workarounds.

Some notes:

Queries to corrupted InnoDB tables don't always crash MySQL.  It depends on the corruption.

I'm not sure exactly what you mean by "have the id of 1... major problems."  I think you mean "crash, write to the same table again, crash, ad infinitum."  However, this won't be a problem with the way I'm advocating using the tables.  They are truly meant to be temporary and used only by one connection, so I do something like "drop table if exists foo_1, create table foo_1(a int), ... drop table if exists foo1."  Dropping the table before using it should avoid the problems I think you're worried about.

Finally, an add-on to the original article.  I now add both the connection's ID and the server's ID to the table name.  This way it's easy to know whether the table was created on the server I'm looking at (in case I'm looking at a slave).  So my tables are now named like this: foo_21_198282.  This is also integrated into mk-find (in Maatkit).</description>
		<content:encoded><![CDATA[<p>Hi Richard,</p>
<p>The changes I&#8217;m referring to are row-based replication, which you can read about in the manual.</p>
<p>I partially disagree with some of your points.  However, I can see your point of view, and I strongly agree with your view that fixing problems in replication is better than using workarounds.</p>
<p>Some notes:</p>
<p>Queries to corrupted InnoDB tables don&#8217;t always crash MySQL.  It depends on the corruption.</p>
<p>I&#8217;m not sure exactly what you mean by &#8220;have the id of 1&#8230; major problems.&#8221;  I think you mean &#8220;crash, write to the same table again, crash, ad infinitum.&#8221;  However, this won&#8217;t be a problem with the way I&#8217;m advocating using the tables.  They are truly meant to be temporary and used only by one connection, so I do something like &#8220;drop table if exists foo_1, create table foo_1(a int), &#8230; drop table if exists foo1.&#8221;  Dropping the table before using it should avoid the problems I think you&#8217;re worried about.</p>
<p>Finally, an add-on to the original article.  I now add both the connection&#8217;s ID and the server&#8217;s ID to the table name.  This way it&#8217;s easy to know whether the table was created on the server I&#8217;m looking at (in case I&#8217;m looking at a slave).  So my tables are now named like this: foo_21_198282.  This is also integrated into mk-find (in Maatkit).</p>
]]></content:encoded>
	</item>
</channel>
</rss>
