<?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: Multi Column indexes vs Index Merge</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2009/09/19/multi-column-indexes-vs-index-merge/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2009/09/19/multi-column-indexes-vs-index-merge/</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: Ricardo</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/19/multi-column-indexes-vs-index-merge/comment-page-1/#comment-834910</link>
		<dc:creator>Ricardo</dc:creator>
		<pubDate>Fri, 28 Oct 2011 03:41:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1206#comment-834910</guid>
		<description>I dont think the conclusion of this post is right. I have a myisam table with a primary key spanning 5 columns. I do a select using a WHERE on every of those 5 columns ANDed. Using the primary key (multicolumn index) it takes 25s, using a single index in one of the columns it takes 1 sec. I did a profiling and most of the 25s is taken in &quot;Sending data&quot; stage. The primary key has cardinality of about 7M and the single column about 80. Am i missing somehting?</description>
		<content:encoded><![CDATA[<p>I dont think the conclusion of this post is right. I have a myisam table with a primary key spanning 5 columns. I do a select using a WHERE on every of those 5 columns ANDed. Using the primary key (multicolumn index) it takes 25s, using a single index in one of the columns it takes 1 sec. I did a profiling and most of the 25s is taken in &#8220;Sending data&#8221; stage. The primary key has cardinality of about 7M and the single column about 80. Am i missing somehting?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Claudiu Filip</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/19/multi-column-indexes-vs-index-merge/comment-page-1/#comment-780312</link>
		<dc:creator>Claudiu Filip</dc:creator>
		<pubDate>Tue, 26 Oct 2010 21:46:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1206#comment-780312</guid>
		<description>Hi peter,

I have the following problem:

PLEASE EXPLAIN SELECT &#039;guys commenting above that they need to pay for support, because you are not fed by International Red Cross database department and the cheapest way to pay is buying your book. If that is too much for them, they should at least buy some bananas, rent some monkeys and start sorting their 20M rows table on plain paper.&#039;;</description>
		<content:encoded><![CDATA[<p>Hi peter,</p>
<p>I have the following problem:</p>
<p>PLEASE EXPLAIN SELECT &#8216;guys commenting above that they need to pay for support, because you are not fed by International Red Cross database department and the cheapest way to pay is buying your book. If that is too much for them, they should at least buy some bananas, rent some monkeys and start sorting their 20M rows table on plain paper.&#8217;;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wenhai</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/19/multi-column-indexes-vs-index-merge/comment-page-1/#comment-765995</link>
		<dc:creator>wenhai</dc:creator>
		<pubDate>Wed, 02 Jun 2010 02:35:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1206#comment-765995</guid>
		<description>Hi peter,

For the same query&quot;EXPLAIN  SELECT  avg(length(val)) FROM idxtest  WHERE i1=50 AND i2=50;&quot;, why the explain result is different after you set i1=i2.
I think mysql should still choose multi col index not index merge.</description>
		<content:encoded><![CDATA[<p>Hi peter,</p>
<p>For the same query&#8221;EXPLAIN  SELECT  avg(length(val)) FROM idxtest  WHERE i1=50 AND i2=50;&#8221;, why the explain result is different after you set i1=i2.<br />
I think mysql should still choose multi col index not index merge.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wenhai</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/19/multi-column-indexes-vs-index-merge/comment-page-1/#comment-765994</link>
		<dc:creator>wenhai</dc:creator>
		<pubDate>Wed, 02 Jun 2010 02:31:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1206#comment-765994</guid>
		<description>Hi Peter,

For the same query &quot; EXPLAIN SELECT avg(length(val)) FROM idxtest  WHERE i1=50 AND i2=50;&quot; ,  why there is different explain result after execute query &quot;UPDATE idxtest SET  i2=i1;&quot;. 
I was confused.


 1.
      mysql [localhost] {msandbox} (test)&gt; EXPLAIN SELECT avg(length(val)) FROM idxtest  WHERE i1=50 AND i2=50;
   2.
      +----+-------------+---------+------+----------------+----------+---------+-------------+------+-------+
   3.
      &#124; id &#124; select_type &#124; TABLE   &#124; type &#124; possible_keys  &#124; KEY      &#124; key_len &#124; ref         &#124; rows &#124; Extra &#124;
   4.
      +----+-------------+---------+------+----------------+----------+---------+-------------+------+-------+
   5.
      &#124;  1 &#124; SIMPLE      &#124; idxtest &#124; ref  &#124; i1,i2,combined &#124; combined &#124; 8       &#124; const,const &#124;  665 &#124;       &#124;
   6.
      +----+-------------+---------+------+----------------+----------+---------+-------------+------+-------+
   7.
      1 row IN SET (0.00 sec)

   1.
      mysql [localhost] {msandbox} (test)&gt; EXPLAIN SELECT avg(length(val)) FROM idxtest WHERE i1=50 AND i2=50;
   2.
      +----+-------------+---------+-------------+----------------+-------+---------+------+------+-------------------------------------+
   3.
      &#124; id &#124; select_type &#124; TABLE   &#124; type        &#124; possible_keys  &#124; KEY   &#124; key_len &#124; ref  &#124; rows &#124; Extra                               &#124;
   4.
      +----+-------------+---------+-------------+----------------+-------+---------+------+------+-------------------------------------+
   5.
      &#124;  1 &#124; SIMPLE      &#124; idxtest &#124; index_merge &#124; i1,i2,combined &#124; i2,i1 &#124; 4,4     &#124; NULL &#124;  959 &#124; USING intersect(i2,i1); USING WHERE &#124;
   6.
      +----+-------------+---------+-------------+----------------+-------+---------+------+------+-------------------------------------+
   7.
      1 row IN SET (0.00 sec)</description>
		<content:encoded><![CDATA[<p>Hi Peter,</p>
<p>For the same query &#8221; EXPLAIN SELECT avg(length(val)) FROM idxtest  WHERE i1=50 AND i2=50;&#8221; ,  why there is different explain result after execute query &#8220;UPDATE idxtest SET  i2=i1;&#8221;.<br />
I was confused.</p>
<p> 1.<br />
      mysql [localhost] {msandbox} (test)&gt; EXPLAIN SELECT avg(length(val)) FROM idxtest  WHERE i1=50 AND i2=50;<br />
   2.<br />
      +&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;-+<br />
   3.<br />
      | id | select_type | TABLE   | type | possible_keys  | KEY      | key_len | ref         | rows | Extra |<br />
   4.<br />
      +&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;-+<br />
   5.<br />
      |  1 | SIMPLE      | idxtest | ref  | i1,i2,combined | combined | 8       | const,const |  665 |       |<br />
   6.<br />
      +&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;-+<br />
   7.<br />
      1 row IN SET (0.00 sec)</p>
<p>   1.<br />
      mysql [localhost] {msandbox} (test)&gt; EXPLAIN SELECT avg(length(val)) FROM idxtest WHERE i1=50 AND i2=50;<br />
   2.<br />
      +&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
   3.<br />
      | id | select_type | TABLE   | type        | possible_keys  | KEY   | key_len | ref  | rows | Extra                               |<br />
   4.<br />
      +&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
   5.<br />
      |  1 | SIMPLE      | idxtest | index_merge | i1,i2,combined | i2,i1 | 4,4     | NULL |  959 | USING intersect(i2,i1); USING WHERE |<br />
   6.<br />
      +&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
   7.<br />
      1 row IN SET (0.00 sec)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rulix</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/19/multi-column-indexes-vs-index-merge/comment-page-1/#comment-735284</link>
		<dc:creator>rulix</dc:creator>
		<pubDate>Fri, 12 Mar 2010 21:40:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1206#comment-735284</guid>
		<description>Hi Peter,

I have a scenario here on multiple column keys. I created an partial index for person table of 2M+ records:

CREATE INDEX firstlastname_idx ON person(firstname(2), lastname(2));

The requirement is for wildcard searching on the first character on the firstname and lastname.

select firstname, lastname from person where firstname like &#039;p%&#039; and lastname like &#039;s%&#039;;

It&#039;s working fine but I also notice that when the server is idle for some time and then execute a query it takes more than a minute to finished the query. All subsequent query is a snap. So the problem is on the first query execution.

I do run explain and it using the partial index. I know there is a issue about mysql on warming up but I haven&#039;t found any concrete solution/advice to this.

The issue in my application is I am getting &quot;504 Gateway Time-out&quot; error because of this slow first query.

Any thoughts about myqsl warm up? and how to improve it. 

Thanks

Rulix</description>
		<content:encoded><![CDATA[<p>Hi Peter,</p>
<p>I have a scenario here on multiple column keys. I created an partial index for person table of 2M+ records:</p>
<p>CREATE INDEX firstlastname_idx ON person(firstname(2), lastname(2));</p>
<p>The requirement is for wildcard searching on the first character on the firstname and lastname.</p>
<p>select firstname, lastname from person where firstname like &#8216;p%&#8217; and lastname like &#8216;s%&#8217;;</p>
<p>It&#8217;s working fine but I also notice that when the server is idle for some time and then execute a query it takes more than a minute to finished the query. All subsequent query is a snap. So the problem is on the first query execution.</p>
<p>I do run explain and it using the partial index. I know there is a issue about mysql on warming up but I haven&#8217;t found any concrete solution/advice to this.</p>
<p>The issue in my application is I am getting &#8220;504 Gateway Time-out&#8221; error because of this slow first query.</p>
<p>Any thoughts about myqsl warm up? and how to improve it. </p>
<p>Thanks</p>
<p>Rulix</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manik</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/19/multi-column-indexes-vs-index-merge/comment-page-1/#comment-729158</link>
		<dc:creator>Manik</dc:creator>
		<pubDate>Wed, 24 Feb 2010 17:32:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1206#comment-729158</guid>
		<description>Hi Peter,

I have a similar question as to what Chad asked about having multiple column keys. We need to build up queries based on columns a,b,c,d and in those queries the column &#039;a&#039; will always be there.

So the queries can be like 

WHERE a= AND b= AND c= AND d=
OR
WHERE a= AND c= AND d=
OR
WHERE a= AND b= AND d=

Would you recommend one composite index like KEY &#039;my_key(&#039;a&#039;,&#039;b&#039;,&#039;c&#039;,&#039;d&#039;) which can server my purpose efficiently?

Thanks in Advance
Manik</description>
		<content:encoded><![CDATA[<p>Hi Peter,</p>
<p>I have a similar question as to what Chad asked about having multiple column keys. We need to build up queries based on columns a,b,c,d and in those queries the column &#8216;a&#8217; will always be there.</p>
<p>So the queries can be like </p>
<p>WHERE a= AND b= AND c= AND d=<br />
OR<br />
WHERE a= AND c= AND d=<br />
OR<br />
WHERE a= AND b= AND d=</p>
<p>Would you recommend one composite index like KEY &#8216;my_key(&#8216;a&#8217;,'b&#8217;,'c&#8217;,'d&#8217;) which can server my purpose efficiently?</p>
<p>Thanks in Advance<br />
Manik</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Blackhurst</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/19/multi-column-indexes-vs-index-merge/comment-page-1/#comment-666919</link>
		<dc:creator>Daniel Blackhurst</dc:creator>
		<pubDate>Tue, 20 Oct 2009 16:38:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1206#comment-666919</guid>
		<description>Hi,

I have a table with over 80,000,000 rows containing GPS information latitude, longitude, date_time, vehicle_id and a few more columns.

I can&#039;t seem to find a good index combination for a query bringing back around 7 days of results for a vehicle. Tried (date_time,vehicle_id) and MYSQL won&#039;t use it, (date_time) and its bringing back thousands of rows under explain. Using innodb. Inserting up to 100 per second. 

Query 

select 
	g.date_time, g.speed, 
	g.odometer, gl.building_number_name, 
	gl.street, gl.town_city, gl.region, gl.postcode, io.high, i.id as is_idle, m.id as is_moving, o.id as over_speed,
	l.name as location_name 
from gps_positions g 

	inner join geocoded_locations gl on g.geocoded_location_id = gl.id 
	left join io_events io on g.id = io.gps_position_id 
	left join idling_events i on g.id = i.gps_position_id 
	left join moving_events m on g.id = m.gps_position_id 
	left join overspeed_events o on g.id = o.gps_position_id 
	left join locations l on l.id = gl.location_id               
	left join ios on io.io_id = ios.id 

where 
	g.date_time between &#039;2009-10-15 00:00:00&#039; and &#039;2009-10-15 23:59:58&#039; 
	and g.vehicle_id = 6261  
	and ( (io.high is not null and ios.gpio = 8) or i.id is not null or m.id is not null or o.id is not null )  
order by g.date_time;

Thanks, Dan</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I have a table with over 80,000,000 rows containing GPS information latitude, longitude, date_time, vehicle_id and a few more columns.</p>
<p>I can&#8217;t seem to find a good index combination for a query bringing back around 7 days of results for a vehicle. Tried (date_time,vehicle_id) and MYSQL won&#8217;t use it, (date_time) and its bringing back thousands of rows under explain. Using innodb. Inserting up to 100 per second. </p>
<p>Query </p>
<p>select<br />
	g.date_time, g.speed,<br />
	g.odometer, gl.building_number_name,<br />
	gl.street, gl.town_city, gl.region, gl.postcode, io.high, i.id as is_idle, m.id as is_moving, o.id as over_speed,<br />
	l.name as location_name<br />
from gps_positions g </p>
<p>	inner join geocoded_locations gl on g.geocoded_location_id = gl.id<br />
	left join io_events io on g.id = io.gps_position_id<br />
	left join idling_events i on g.id = i.gps_position_id<br />
	left join moving_events m on g.id = m.gps_position_id<br />
	left join overspeed_events o on g.id = o.gps_position_id<br />
	left join locations l on l.id = gl.location_id<br />
	left join ios on io.io_id = ios.id </p>
<p>where<br />
	g.date_time between &#8217;2009-10-15 00:00:00&#8242; and &#8217;2009-10-15 23:59:58&#8242;<br />
	and g.vehicle_id = 6261<br />
	and ( (io.high is not null and ios.gpio = <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> or i.id is not null or m.id is not null or o.id is not null )<br />
order by g.date_time;</p>
<p>Thanks, Dan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/19/multi-column-indexes-vs-index-merge/comment-page-1/#comment-665296</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Thu, 15 Oct 2009 17:28:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1206#comment-665296</guid>
		<description>Chad,

Indeed this is a hard choice. You may end up having a lot of indexes if you need to have a lot of different search combinations.  Some of them (for example double ranges) may not be handled effectively by MySQL at all.

One of solutions we used when indexes can&#039;t be constructed is using Sphinx (www.sphinxsearch.com) which can be thrown on the cluster easily and which can serve queries very fast even without having perfect indexes.</description>
		<content:encoded><![CDATA[<p>Chad,</p>
<p>Indeed this is a hard choice. You may end up having a lot of indexes if you need to have a lot of different search combinations.  Some of them (for example double ranges) may not be handled effectively by MySQL at all.</p>
<p>One of solutions we used when indexes can&#8217;t be constructed is using Sphinx (www.sphinxsearch.com) which can be thrown on the cluster easily and which can serve queries very fast even without having perfect indexes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chad</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/19/multi-column-indexes-vs-index-merge/comment-page-1/#comment-665238</link>
		<dc:creator>chad</dc:creator>
		<pubDate>Thu, 15 Oct 2009 13:15:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1206#comment-665238</guid>
		<description>I have an issue that I can&#039;t figure out. I have a huge query that is like: where a,b,c,d,e,f pulling from a DB of nearly 5 million records. I can make a multi column index on a,b,c,d,e,f but the query is dynamic. It may search on a,b,e,f or b,d,f. The amount of indexes I would need to create for this would probably be 36 (because of the leftmost prefix rule). I know that is rather absurd. So, how can I make sure everything is indexed so searches are fast on this large query and I don&#039;t have to make all the indexes?</description>
		<content:encoded><![CDATA[<p>I have an issue that I can&#8217;t figure out. I have a huge query that is like: where a,b,c,d,e,f pulling from a DB of nearly 5 million records. I can make a multi column index on a,b,c,d,e,f but the query is dynamic. It may search on a,b,e,f or b,d,f. The amount of indexes I would need to create for this would probably be 36 (because of the leftmost prefix rule). I know that is rather absurd. So, how can I make sure everything is indexed so searches are fast on this large query and I don&#8217;t have to make all the indexes?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Danny</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/19/multi-column-indexes-vs-index-merge/comment-page-1/#comment-660257</link>
		<dc:creator>Danny</dc:creator>
		<pubDate>Wed, 30 Sep 2009 14:37:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1206#comment-660257</guid>
		<description>Oke thank you. Few minutes ago I recieved your book &#039;High Perfomance MySQL&#039;. So I can start reading this weekend and hope all about the indexes becomes clear to me.</description>
		<content:encoded><![CDATA[<p>Oke thank you. Few minutes ago I recieved your book &#8216;High Perfomance MySQL&#8217;. So I can start reading this weekend and hope all about the indexes becomes clear to me.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

