<?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: Copying to tmp table</title>
	<atom:link href="http://danosipov.com/blog/?feed=rss2&#038;p=75" rel="self" type="application/rss+xml" />
	<link>http://danosipov.com/blog/?p=75</link>
	<description>I will be posting my latest photos, as well as code snippets, useful tricks &#38; techniques, and whatever else is on my mind on a particular day.</description>
	<lastBuildDate>Thu, 12 Aug 2010 15:41:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Mike</title>
		<link>http://danosipov.com/blog/?p=75&#038;cpage=1#comment-2038</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Sun, 23 Aug 2009 19:54:10 +0000</pubDate>
		<guid isPermaLink="false">http://danosipov.com/blog/?p=75#comment-2038</guid>
		<description>Dan, that last comment is not true.  I have plenty of queries that use group by or order by, and are saved in memory and say &#039;copying to tmp table&#039; not &#039;copying to tmp table on disk&#039; within profiler.  I don&#039;t know the exact conditions that determine when something is stored on disk, but I know it&#039;s not true that everything that uses order by or group by is...</description>
		<content:encoded><![CDATA[<p>Dan, that last comment is not true.  I have plenty of queries that use group by or order by, and are saved in memory and say &#8216;copying to tmp table&#8217; not &#8216;copying to tmp table on disk&#8217; within profiler.  I don&#8217;t know the exact conditions that determine when something is stored on disk, but I know it&#8217;s not true that everything that uses order by or group by is&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Osipov</title>
		<link>http://danosipov.com/blog/?p=75&#038;cpage=1#comment-820</link>
		<dc:creator>Dan Osipov</dc:creator>
		<pubDate>Mon, 16 Mar 2009 20:48:26 +0000</pubDate>
		<guid isPermaLink="false">http://danosipov.com/blog/?p=75#comment-820</guid>
		<description>Good point Dave - it doesn&#039;t, but like I said, if the table contains a TEXT/BLOB field, or there is GROUP BY/ORDER BY clause in the query, the table will have to be written to disk.

To be sure, you can check the process list while running a query, and you will see the query enter into the &quot;Copying to tmp table on disk&quot; state.</description>
		<content:encoded><![CDATA[<p>Good point Dave &#8211; it doesn&#8217;t, but like I said, if the table contains a TEXT/BLOB field, or there is GROUP BY/ORDER BY clause in the query, the table will have to be written to disk.</p>
<p>To be sure, you can check the process list while running a query, and you will see the query enter into the &#8220;Copying to tmp table on disk&#8221; state.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Abdemoulaie</title>
		<link>http://danosipov.com/blog/?p=75&#038;cpage=1#comment-819</link>
		<dc:creator>David Abdemoulaie</dc:creator>
		<pubDate>Mon, 16 Mar 2009 19:26:43 +0000</pubDate>
		<guid isPermaLink="false">http://danosipov.com/blog/?p=75#comment-819</guid>
		<description>In fact, here&#039;s an article that puts it much better than I have:

http://www.mysqlperformanceblog.com/2009/03/05/what-does-using-filesort-mean-in-mysql/</description>
		<content:encoded><![CDATA[<p>In fact, here&#8217;s an article that puts it much better than I have:</p>
<p><a href="http://www.mysqlperformanceblog.com/2009/03/05/what-does-using-filesort-mean-in-mysql/" rel="nofollow">http://www.mysqlperformanceblog.com/2009/03/05/what-does-using-filesort-mean-in-mysql/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Abdemoulaie</title>
		<link>http://danosipov.com/blog/?p=75&#038;cpage=1#comment-818</link>
		<dc:creator>David Abdemoulaie</dc:creator>
		<pubDate>Mon, 16 Mar 2009 19:25:20 +0000</pubDate>
		<guid isPermaLink="false">http://danosipov.com/blog/?p=75#comment-818</guid>
		<description>Dan,

&quot;Using where; Using temporary; Using filesort&quot;

does *not* mean that the temporary table was written to disk. In fact, nothing in EXPLAIN can give you that information. It seems like you&#039;re working under the common assumption that &#039;filesort&#039; means it was written to a file on disk, and then sorted. This is not necessarily the case, filesort is simply the name of the sorting algorithm used, and occurs for in-memory tables as well. It means that the results could not be sorted by an index alone, thus the data was copied to a temporary table, and then the &quot;filesort&quot; algorithm was applied to sort the results.</description>
		<content:encoded><![CDATA[<p>Dan,</p>
<p>&#8220;Using where; Using temporary; Using filesort&#8221;</p>
<p>does *not* mean that the temporary table was written to disk. In fact, nothing in EXPLAIN can give you that information. It seems like you&#8217;re working under the common assumption that &#8216;filesort&#8217; means it was written to a file on disk, and then sorted. This is not necessarily the case, filesort is simply the name of the sorting algorithm used, and occurs for in-memory tables as well. It means that the results could not be sorted by an index alone, thus the data was copied to a temporary table, and then the &#8220;filesort&#8221; algorithm was applied to sort the results.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Osipov</title>
		<link>http://danosipov.com/blog/?p=75&#038;cpage=1#comment-542</link>
		<dc:creator>Dan Osipov</dc:creator>
		<pubDate>Sat, 21 Feb 2009 18:13:32 +0000</pubDate>
		<guid isPermaLink="false">http://danosipov.com/blog/?p=75#comment-542</guid>
		<description>I see your point, but interestingly enough the DB is configured to use all the available memory - it just chooses not to for some reason...</description>
		<content:encoded><![CDATA[<p>I see your point, but interestingly enough the DB is configured to use all the available memory &#8211; it just chooses not to for some reason&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ries</title>
		<link>http://danosipov.com/blog/?p=75&#038;cpage=1#comment-541</link>
		<dc:creator>Ries</dc:creator>
		<pubDate>Sat, 21 Feb 2009 17:58:04 +0000</pubDate>
		<guid isPermaLink="false">http://danosipov.com/blog/?p=75#comment-541</guid>
		<description>Dan,

it is still very dangerous to let a DB write that stuff to a limited Disk space because you will never know what happens next. It&#039;s also a bit of a shame that if that ram disk is &#039;to large&#039; you have a lot of memory in use you really don&#039;t use for the DB.

Ries</description>
		<content:encoded><![CDATA[<p>Dan,</p>
<p>it is still very dangerous to let a DB write that stuff to a limited Disk space because you will never know what happens next. It&#8217;s also a bit of a shame that if that ram disk is &#8216;to large&#8217; you have a lot of memory in use you really don&#8217;t use for the DB.</p>
<p>Ries</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Osipov</title>
		<link>http://danosipov.com/blog/?p=75&#038;cpage=1#comment-403</link>
		<dc:creator>Dan Osipov</dc:creator>
		<pubDate>Tue, 03 Feb 2009 21:15:22 +0000</pubDate>
		<guid isPermaLink="false">http://danosipov.com/blog/?p=75#comment-403</guid>
		<description>Ries,

It depends on the Linux kernel version you&#039;re using. Older kernels will freeze when space runs out, but newer kernels are more safe.

As for giving the DB all the memory it can use - sure, but in the case of a filesort MySQL will create a disk based table no matter what - and that&#039;s slow even if the table is small.

You can also limit the size of a tmpfs partition to make sure it never goes into swap.

FYI - we&#039;ve been running it on a high traffic DB server with 8Gb of RAM, and usage never went into swap space so far.</description>
		<content:encoded><![CDATA[<p>Ries,</p>
<p>It depends on the Linux kernel version you&#8217;re using. Older kernels will freeze when space runs out, but newer kernels are more safe.</p>
<p>As for giving the DB all the memory it can use &#8211; sure, but in the case of a filesort MySQL will create a disk based table no matter what &#8211; and that&#8217;s slow even if the table is small.</p>
<p>You can also limit the size of a tmpfs partition to make sure it never goes into swap.</p>
<p>FYI &#8211; we&#8217;ve been running it on a high traffic DB server with 8Gb of RAM, and usage never went into swap space so far.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ries</title>
		<link>http://danosipov.com/blog/?p=75&#038;cpage=1#comment-400</link>
		<dc:creator>Ries</dc:creator>
		<pubDate>Tue, 03 Feb 2009 14:49:19 +0000</pubDate>
		<guid isPermaLink="false">http://danosipov.com/blog/?p=75#comment-400</guid>
		<description>I agree that the on disk temporary storage is bad for performance and the first thing to look at is to &#039;filter&#039; data as soon a possible so MySQL has less reason to create such a tmp table.

However your solution posted is very dangerous on buzy databases because what if people run all queries in memory? Then you might end up with out of memory or usage of swap space which slows that down again. Also the solution you provided to store these temp tables on a separate memory HD is dangerous for the similar reasons, what if that space runs out? Will MySQL crash, or happily keep on running and give incorrect or no results back, does anybody know that
behavior?

Usually it&#039;s best to give the RDBM all the memory it can get from the system and let the OS handle disk caching which is more save then create your own tricks.

Ries</description>
		<content:encoded><![CDATA[<p>I agree that the on disk temporary storage is bad for performance and the first thing to look at is to &#8216;filter&#8217; data as soon a possible so MySQL has less reason to create such a tmp table.</p>
<p>However your solution posted is very dangerous on buzy databases because what if people run all queries in memory? Then you might end up with out of memory or usage of swap space which slows that down again. Also the solution you provided to store these temp tables on a separate memory HD is dangerous for the similar reasons, what if that space runs out? Will MySQL crash, or happily keep on running and give incorrect or no results back, does anybody know that<br />
behavior?</p>
<p>Usually it&#8217;s best to give the RDBM all the memory it can get from the system and let the OS handle disk caching which is more save then create your own tricks.</p>
<p>Ries</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frank</title>
		<link>http://danosipov.com/blog/?p=75&#038;cpage=1#comment-375</link>
		<dc:creator>Frank</dc:creator>
		<pubDate>Mon, 26 Jan 2009 21:43:15 +0000</pubDate>
		<guid isPermaLink="false">http://danosipov.com/blog/?p=75#comment-375</guid>
		<description>Good to know!</description>
		<content:encoded><![CDATA[<p>Good to know!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
