<?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: Using UNION to implement loose index scan in MySQL</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/</link>
	<description>Percona&#039;s MySQL &#38; InnoDB performance and scalability blog</description>
	<lastBuildDate>Sat, 11 Feb 2012 16:45:54 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Spyd</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/comment-page-1/#comment-887289</link>
		<dc:creator>Spyd</dc:creator>
		<pubDate>Fri, 10 Feb 2012 15:53:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/#comment-887289</guid>
		<description>Hey, i found this page while googling for more information after i implemented something exactly like this! I thought i had done something &quot;dirty&quot; but now i&#039;m happy that this &quot;tricky&quot; method is suggested by you! My queries went from 0,6 to 0,01 :) :) :)</description>
		<content:encoded><![CDATA[<p>Hey, i found this page while googling for more information after i implemented something exactly like this! I thought i had done something &#8220;dirty&#8221; but now i&#8217;m happy that this &#8220;tricky&#8221; method is suggested by you! My queries went from 0,6 to 0,01 <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jindra</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/comment-page-1/#comment-712729</link>
		<dc:creator>Jindra</dc:creator>
		<pubDate>Thu, 21 Jan 2010 17:38:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/#comment-712729</guid>
		<description>Thanks, helped me to optimize query with agregate function on table with multiple key:

table:
Create table tabData (
  channel_id Int NOT NULL,
  date_time Datetime NOT NULL,
  value Double NOT NULL,
 Primary Key (channel_id, date_time)
);

too slow (more then a few seconds when thousands of records):

select min(date_time) from tabData where id_virtual_channel in (1, 2, 3)

optimized - query returns immediately:

select min(m)
from (
  select min(date_time) as m from tabData where channel_id = 1
  union
  select min(date_time) from tabData where channel_id = 2
  union
  select min(date_time) from tabData where channel_id = 3
) as min_datetimes</description>
		<content:encoded><![CDATA[<p>Thanks, helped me to optimize query with agregate function on table with multiple key:</p>
<p>table:<br />
Create table tabData (<br />
  channel_id Int NOT NULL,<br />
  date_time Datetime NOT NULL,<br />
  value Double NOT NULL,<br />
 Primary Key (channel_id, date_time)<br />
);</p>
<p>too slow (more then a few seconds when thousands of records):</p>
<p>select min(date_time) from tabData where id_virtual_channel in (1, 2, 3)</p>
<p>optimized &#8211; query returns immediately:</p>
<p>select min(m)<br />
from (<br />
  select min(date_time) as m from tabData where channel_id = 1<br />
  union<br />
  select min(date_time) from tabData where channel_id = 2<br />
  union<br />
  select min(date_time) from tabData where channel_id = 3<br />
) as min_datetimes</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: How to select the first/least/max row per group in SQL &#124; Wilson80s</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/comment-page-1/#comment-675729</link>
		<dc:creator>How to select the first/least/max row per group in SQL &#124; Wilson80s</dc:creator>
		<pubDate>Wed, 11 Nov 2009 20:15:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/#comment-675729</guid>
		<description>[...] Peter Zaitsev has written in detail about this technique, so I wonâ€™t go into it too much more here. If it suits your purposes, it can be a very good solution. [...]</description>
		<content:encoded><![CDATA[<p>[...] Peter Zaitsev has written in detail about this technique, so I wonâ€™t go into it too much more here. If it suits your purposes, it can be a very good solution. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/comment-page-1/#comment-665078</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Thu, 15 Oct 2009 00:34:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/#comment-665078</guid>
		<description>Its 3 years later, has this been fixed?  If so, in what version of MySQL?

Thanks!</description>
		<content:encoded><![CDATA[<p>Its 3 years later, has this been fixed?  If so, in what version of MySQL?</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: How to select the first/least/max row per group in SQL at Xaprb</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/comment-page-1/#comment-342483</link>
		<dc:creator>How to select the first/least/max row per group in SQL at Xaprb</dc:creator>
		<pubDate>Fri, 08 Aug 2008 15:39:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/#comment-342483</guid>
		<description>[...] Peter Zaitsev has written in detail about this technique, so I won&#8217;t go into it too much more here. If it suits your purposes, it can be a very good solution. [...]</description>
		<content:encoded><![CDATA[<p>[...] Peter Zaitsev has written in detail about this technique, so I won&#8217;t go into it too much more here. If it suits your purposes, it can be a very good solution. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: How adding another table to JOIN can improve performance ? &#124; MySQL Performance Blog</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/comment-page-1/#comment-338958</link>
		<dc:creator>How adding another table to JOIN can improve performance ? &#124; MySQL Performance Blog</dc:creator>
		<pubDate>Sat, 02 Aug 2008 05:10:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/#comment-338958</guid>
		<description>[...] have described  couple of solutions to this problem - using IN list instead of range or UNION which however require [...]</description>
		<content:encoded><![CDATA[<p>[...] have described  couple of solutions to this problem &#8211; using IN list instead of range or UNION which however require [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Day</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/comment-page-1/#comment-1829</link>
		<dc:creator>James Day</dc:creator>
		<pubDate>Wed, 16 Aug 2006 18:30:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/#comment-1829</guid>
		<description>Apachez, one of many areas where it&#039;s known that the optimizer can be improved. They are gradually being done, no particular schedule for when each one is done. Other than more slowly than we&#039;d all like. :)

James Day
Support Engineer, MySQL AB</description>
		<content:encoded><![CDATA[<p>Apachez, one of many areas where it&#8217;s known that the optimizer can be improved. They are gradually being done, no particular schedule for when each one is done. Other than more slowly than we&#8217;d all like. <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>James Day<br />
Support Engineer, MySQL AB</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MySQL Performance Blog &#187; MySQL: Followup on UNION for query optimization, Query profiling</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/comment-page-1/#comment-1775</link>
		<dc:creator>MySQL Performance Blog &#187; MySQL: Followup on UNION for query optimization, Query profiling</dc:creator>
		<pubDate>Mon, 14 Aug 2006 20:46:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/#comment-1775</guid>
		<description>[...] Few days ago I wrote  an article about using UNION to implement loose index scan. [...]</description>
		<content:encoded><![CDATA[<p>[...] Few days ago I wrote  an article about using UNION to implement loose index scan. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Apachez</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/comment-page-1/#comment-1768</link>
		<dc:creator>Apachez</dc:creator>
		<pubDate>Mon, 14 Aug 2006 18:32:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/#comment-1768</guid>
		<description>Is this a MySQL Optimizer bug (which we could expect to be fixed in near future) or is this &quot;by design&quot; for the next couple of years ?

I mean the UNION is a nice workaround but needs more code and logic where just writing a &quot;WHERE col BETWEEN 19 AND 22&quot; is so much easier :-)</description>
		<content:encoded><![CDATA[<p>Is this a MySQL Optimizer bug (which we could expect to be fixed in near future) or is this &#8220;by design&#8221; for the next couple of years ?</p>
<p>I mean the UNION is a nice workaround but needs more code and logic where just writing a &#8220;WHERE col BETWEEN 19 AND 22&#8243; is so much easier <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/comment-page-1/#comment-1724</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Sun, 13 Aug 2006 15:52:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/10/using-union-to-implement-loose-index-scan-to-mysql/#comment-1724</guid>
		<description>Yuan WANG,

If query with where clause &quot;age=19 and zip in (...)&quot; is executed what really is performed is sequence of lookups 
age=19 and zip=const.   Key length=4 is missleading in this case. It seems to be EXPLAIN bug in this case. 

For query with &quot;age between 19 and 22 and zip in (...)&quot;  what you have described is happening -  index range lookup is performend on age condition and zip condition only checked after row is read. 

You can use FLUSH STATUS;  &lt;run query&gt;  SHOW STATUS;   and check Handler_XXX stats to see how query execution was performed.</description>
		<content:encoded><![CDATA[<p>Yuan WANG,</p>
<p>If query with where clause &#8220;age=19 and zip in (&#8230;)&#8221; is executed what really is performed is sequence of lookups<br />
age=19 and zip=const.   Key length=4 is missleading in this case. It seems to be EXPLAIN bug in this case. </p>
<p>For query with &#8220;age between 19 and 22 and zip in (&#8230;)&#8221;  what you have described is happening &#8211;  index range lookup is performend on age condition and zip condition only checked after row is read. </p>
<p>You can use FLUSH STATUS;  <run query>  SHOW STATUS;   and check Handler_XXX stats to see how query execution was performed.</run></p>
]]></content:encoded>
	</item>
</channel>
</rss>

