<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Alexander Rubin&#039;s Blog on MySQL &#187; dtrace</title>
	<atom:link href="http://www.arubin.org/blog/category/dtrace/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.arubin.org/blog</link>
	<description>MySQL, FullText Search, Performance, High Availability</description>
	<lastBuildDate>Sat, 30 Jul 2011 00:18:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using Dtrace to find queries creating disk temporary tables</title>
		<link>http://www.arubin.org/blog/2009/10/02/using-dtrace-to-find-queries-creating-disk-temporary-tables/</link>
		<comments>http://www.arubin.org/blog/2009/10/02/using-dtrace-to-find-queries-creating-disk-temporary-tables/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 18:44:52 +0000</pubDate>
		<dc:creator>arubin</dc:creator>
				<category><![CDATA[dtrace]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[performance tuning]]></category>
		<category><![CDATA[temporary tables]]></category>

		<guid isPermaLink="false">http://www.arubin.org/blog/?p=36</guid>
		<description><![CDATA[Showed script with Dtrace to find queries creating disk temporary tables [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes we have a lots of small and rather fast queries which use group by/order by, thus creating temporary tables. Some of those queries are retrieving text fields and mysql have to use disk (myisam) temporary tables. Those queries usually run for less than 1-2 seconds, so they did not get into slow query log, however, they sometimes add serious load on the system.</p>
<p>Here is the stat example:</p>
<pre>
bash-3.00$  /usr/local/mysql/bin/mysqladmin -uroot -p -i 2 -r extended-status|grep tmp_disk
...
| Created_tmp_disk_tables           | 109           |
| Created_tmp_disk_tables           | 101           |
| Created_tmp_disk_tables           | 122           |
...
</pre>
<p>40-50 tmp_disk_tables created per second</p>
<p>So, how can we grab those queries? Usually we have to temporary enable general log, filter out queries with &#8220;group by/order by&#8221; and profile them all. On solaris/mac we can use dtrace instead.</p>
<p>Here is the simple script, which will find the list of queries creating tmp_disk_tables:</p>
<pre>
#pragma D option quiet
dtrace:::BEGIN
{
printf("Tracing... Hit Ctrl-C to end.\n");
}

pid$target::*mysql_parse*:entry
{
self->query = copyinstr(arg1);
}

pid$target::*create_myisam_tmp_table*:return
{
@query[self->query] = count();
}
</pre>
<p>put it into tmpdisktable.d, chmod +x tmpdisktable.d and run it with<br />
./tmpdisktable.d -p `pgrep -x mysqld`</p>
<p>Ctrl+C after 5 seconds whatever and you will see the queries:</p>
<pre>
# ./tmpdisktable.d -p `pgrep -x mysqld`
Tracing... Hit Ctrl-C to end.
^C
</pre>
<p>Queries are stripped by the &#8220;strsize&#8221;, which is can be tweaked:</p>
<pre>#pragma D option strsize=N</pre>
<p>We can increase the &#8220;strsize&#8221; length now and run the script again to get the real queries examples.</p>
<p>Please note: running dtrace for a while can decrease performance, so do not run it for more than couple minutes on production systems. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.arubin.org/blog/2009/10/02/using-dtrace-to-find-queries-creating-disk-temporary-tables/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

