<?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"
	>
<channel>
	<title>Comments on: MySQL:  Followup on UNION for query optimization,  Query profiling</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2006/08/14/mysql-followup-on-union-for-query-optimization-query-profiling/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2006/08/14/mysql-followup-on-union-for-query-optimization-query-profiling/</link>
	<description>Everything about MySQL Performance</description>
	<pubDate>Mon, 08 Sep 2008 04:38:10 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/14/mysql-followup-on-union-for-query-optimization-query-profiling/#comment-313019</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Fri, 13 Jun 2008 16:57:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/14/mysql-followup-on-union-for-query-optimization-query-profiling/#comment-313019</guid>
		<description>Tobias,

UNION generally has larger overhead than IN or OR.  It is faster in the cases when it allows better execution plan - avoiding full table scan with OR on different columns (before 5.0) or avoiding filesort.</description>
		<content:encoded><![CDATA[<p>Tobias,</p>
<p>UNION generally has larger overhead than IN or OR.  It is faster in the cases when it allows better execution plan - avoiding full table scan with OR on different columns (before 5.0) or avoiding filesort.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/14/mysql-followup-on-union-for-query-optimization-query-profiling/#comment-313018</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Fri, 13 Jun 2008 16:55:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/14/mysql-followup-on-union-for-query-optimization-query-profiling/#comment-313018</guid>
		<description>Brian,

You would need to test large IN vs BETWEEN this likely to be rather workload dependent.
Note very large IN sets (especially cascaded) may cause MySQL to abandon full range optimization - in this case there is it should become slower than BETWEEN.</description>
		<content:encoded><![CDATA[<p>Brian,</p>
<p>You would need to test large IN vs BETWEEN this likely to be rather workload dependent.<br />
Note very large IN sets (especially cascaded) may cause MySQL to abandon full range optimization - in this case there is it should become slower than BETWEEN.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tobias</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/14/mysql-followup-on-union-for-query-optimization-query-profiling/#comment-312978</link>
		<dc:creator>Tobias</dc:creator>
		<pubDate>Fri, 13 Jun 2008 14:44:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/14/mysql-followup-on-union-for-query-optimization-query-profiling/#comment-312978</guid>
		<description>Peter,

one question on UNION vers. IN : Is it a general rule that UNION is faster then IN? Another thing I experienced is a serious speed-advantage when using UNION instead of long OR-Statements. Is this correct?

Thank You!</description>
		<content:encoded><![CDATA[<p>Peter,</p>
<p>one question on UNION vers. IN : Is it a general rule that UNION is faster then IN? Another thing I experienced is a serious speed-advantage when using UNION instead of long OR-Statements. Is this correct?</p>
<p>Thank You!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brian</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/14/mysql-followup-on-union-for-query-optimization-query-profiling/#comment-271184</link>
		<dc:creator>brian</dc:creator>
		<pubDate>Wed, 09 Apr 2008 00:52:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/14/mysql-followup-on-union-for-query-optimization-query-profiling/#comment-271184</guid>
		<description>Hi Peter, 

I wonder if you might be able to expand on the limitations of using "IN" vs. "BETWEEN" in terms of a point of decreasing returns? (e.g., at what point do the number of values in "IN" become large enough that there is no performance difference between using "IN" and "BETWEEN"?)

Also, does the performance increase involved in using "IN" apply to JOIN queries as well? Is there a difference in how "IN" is treated when the query in question utilizes a JOIN? 

Of course, one thing I love about this site is that often times you tell us how we can measure for ourselves. I can see if one query is faster than the other, but am still not so awesome at unwrapping things to determine why. 
Thanks.</description>
		<content:encoded><![CDATA[<p>Hi Peter, </p>
<p>I wonder if you might be able to expand on the limitations of using &#8220;IN&#8221; vs. &#8220;BETWEEN&#8221; in terms of a point of decreasing returns? (e.g., at what point do the number of values in &#8220;IN&#8221; become large enough that there is no performance difference between using &#8220;IN&#8221; and &#8220;BETWEEN&#8221;?)</p>
<p>Also, does the performance increase involved in using &#8220;IN&#8221; apply to JOIN queries as well? Is there a difference in how &#8220;IN&#8221; is treated when the query in question utilizes a JOIN? </p>
<p>Of course, one thing I love about this site is that often times you tell us how we can measure for ourselves. I can see if one query is faster than the other, but am still not so awesome at unwrapping things to determine why.<br />
Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jorje</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/14/mysql-followup-on-union-for-query-optimization-query-profiling/#comment-182508</link>
		<dc:creator>Jorje</dc:creator>
		<pubDate>Tue, 30 Oct 2007 04:29:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/14/mysql-followup-on-union-for-query-optimization-query-profiling/#comment-182508</guid>
		<description>Great article...One quaestion : Can I use UNION, if I don't have certain values for a field ( like age=18, age=19 ) ?? What if I have a query like :

SELECT * from table WHERE type = 1 and value &#62;= 150.4 and value  31 order by score desc limit 20 ???

How can I avoid "using filesort", in this case ???

Thanx</description>
		<content:encoded><![CDATA[<p>Great article&#8230;One quaestion : Can I use UNION, if I don&#8217;t have certain values for a field ( like age=18, age=19 ) ?? What if I have a query like :</p>
<p>SELECT * from table WHERE type = 1 and value &gt;= 150.4 and value  31 order by score desc limit 20 ???</p>
<p>How can I avoid &#8220;using filesort&#8221;, in this case ???</p>
<p>Thanx</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/14/mysql-followup-on-union-for-query-optimization-query-profiling/#comment-24535</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Fri, 15 Dec 2006 10:24:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/14/mysql-followup-on-union-for-query-optimization-query-profiling/#comment-24535</guid>
		<description>Mocanu, 

Nope there is a serious difference.   Assuming you have query which matches 50.000 rows  and you want to get and display only 10 of them - a way most search applications work.      In case you're using simply IN you will get 50.000 rows stored in temporary table and sorted by filesort - going to be quite slow.

If you're using UNION - each of the queries in the UNION will produce only 10 rows, using index for sorting not filesort.  If you have 5 queries in the UNION you will have 50 rows in the temporary table which you still need to do filesort for. 

Sorting 50.000 rows vs 50 rows is the difference here, now avoiding filesort completely :)</description>
		<content:encoded><![CDATA[<p>Mocanu, </p>
<p>Nope there is a serious difference.   Assuming you have query which matches 50.000 rows  and you want to get and display only 10 of them - a way most search applications work.      In case you&#8217;re using simply IN you will get 50.000 rows stored in temporary table and sorted by filesort - going to be quite slow.</p>
<p>If you&#8217;re using UNION - each of the queries in the UNION will produce only 10 rows, using index for sorting not filesort.  If you have 5 queries in the UNION you will have 50 rows in the temporary table which you still need to do filesort for. </p>
<p>Sorting 50.000 rows vs 50 rows is the difference here, now avoiding filesort completely <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sorin Mocanu</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/14/mysql-followup-on-union-for-query-optimization-query-profiling/#comment-24532</link>
		<dc:creator>Sorin Mocanu</dc:creator>
		<pubDate>Fri, 15 Dec 2006 10:00:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/14/mysql-followup-on-union-for-query-optimization-query-profiling/#comment-24532</guid>
		<description>Peter, I think you are making a mistake regarding the filesort - in both cases (when using "IN (18,19,20)" and when using "UNION") mysql makes a temporary table of about the same size on which it does a filesort. Basically, in the first version the results are filtered by age and then a temporary table is created with the *filtered* records.</description>
		<content:encoded><![CDATA[<p>Peter, I think you are making a mistake regarding the filesort - in both cases (when using &#8220;IN (18,19,20)&#8221; and when using &#8220;UNION&#8221;) mysql makes a temporary table of about the same size on which it does a filesort. Basically, in the first version the results are filtered by age and then a temporary table is created with the *filtered* records.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MySQL Performance Blog &#187; ORDER BY &#8230; LIMIT Performance Optimization</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/14/mysql-followup-on-union-for-query-optimization-query-profiling/#comment-2147</link>
		<dc:creator>MySQL Performance Blog &#187; ORDER BY &#8230; LIMIT Performance Optimization</dc:creator>
		<pubDate>Fri, 01 Sep 2006 16:37:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/14/mysql-followup-on-union-for-query-optimization-query-profiling/#comment-2147</guid>
		<description>[...] Even though it looks quite similar to previous one it is a lot different as there are multiple category_id values in the list now so index on (category_id, date_created) can't be used directly. Index on date_created separately would still work. The good from performance standpoint (even though a bit ugly) will be UNION workaround I already wrote about. [...]</description>
		<content:encoded><![CDATA[<p>[...] Even though it looks quite similar to previous one it is a lot different as there are multiple category_id values in the list now so index on (category_id, date_created) can&#8217;t be used directly. Index on date_created separately would still work. The good from performance standpoint (even though a bit ugly) will be UNION workaround I already wrote about. [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
