<?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: 3 ways MySQL uses indexes</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2009/09/12/3-ways-mysql-uses-indexes/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2009/09/12/3-ways-mysql-uses-indexes/</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: Pavel Cibulka</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/12/3-ways-mysql-uses-indexes/comment-page-1/#comment-821831</link>
		<dc:creator>Pavel Cibulka</dc:creator>
		<pubDate>Mon, 12 Sep 2011 09:26:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1097#comment-821831</guid>
		<description>Peter,

thanks for response. Percona blog is really great source of knowledge with many helpful people. I hope we will see 3rd edition of &quot;High Performance MySQL&quot; book soon.</description>
		<content:encoded><![CDATA[<p>Peter,</p>
<p>thanks for response. Percona blog is really great source of knowledge with many helpful people. I hope we will see 3rd edition of &#8220;High Performance MySQL&#8221; book soon.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Zaitsev</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/12/3-ways-mysql-uses-indexes/comment-page-1/#comment-821779</link>
		<dc:creator>Peter Zaitsev</dc:creator>
		<pubDate>Mon, 12 Sep 2011 02:31:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1097#comment-821779</guid>
		<description>Pavel,

It is not the same as  sex in (&#039;M&#039;,&#039;F&#039;) is enumerated range while  A&gt;=0 is not.   MySQL would only use full index when leading parts are enumerated as soon as it is non enumerated range (as &gt; &lt; BETWEEN etc)  this will be last key part to use.</description>
		<content:encoded><![CDATA[<p>Pavel,</p>
<p>It is not the same as  sex in (&#8216;M&#8217;,'F&#8217;) is enumerated range while  A>=0 is not.   MySQL would only use full index when leading parts are enumerated as soon as it is non enumerated range (as > < BETWEEN etc)  this will be last key part to use.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pavel Cibulka</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/12/3-ways-mysql-uses-indexes/comment-page-1/#comment-821603</link>
		<dc:creator>Pavel Cibulka</dc:creator>
		<pubDate>Sat, 10 Sep 2011 16:02:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1097#comment-821603</guid>
		<description>Hi Peter,
I&#039;ve been thinking about your example with index (A,B) and WHERE B BETWEEN 5 AND 10. What about rewrite it as WHERE A&gt;=0 AND B BETWEEN 5 AND 10? It is similar to the example in your book (AND sex IN(&#039;m&#039;, &#039;f&#039;)).

This will use index. It would be ok, if A have few different values. But could become slow, if A has many different values.</description>
		<content:encoded><![CDATA[<p>Hi Peter,<br />
I&#8217;ve been thinking about your example with index (A,B) and WHERE B BETWEEN 5 AND 10. What about rewrite it as WHERE A&gt;=0 AND B BETWEEN 5 AND 10? It is similar to the example in your book (AND sex IN(&#8216;m&#8217;, &#8216;f&#8217;)).</p>
<p>This will use index. It would be ok, if A have few different values. But could become slow, if A has many different values.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jay</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/12/3-ways-mysql-uses-indexes/comment-page-1/#comment-769735</link>
		<dc:creator>jay</dc:creator>
		<pubDate>Wed, 21 Jul 2010 05:02:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1097#comment-769735</guid>
		<description>that you see more of it, I created 2 new indexes (on production data, not testing or random).
(sizes are different in production data. Type is int (4Bytes) not smallint and vector is varchar 255+2)

  KEY `ty_fr` (`tree_type`,`date_from`),
  KEY `ty_fr_to` (`tree_type`,`date_from`,`date_to`),
  KEY `ty_fr_to_ve_de` (`tree_type`,`date_from`,`date_to`,`tree_vector`,`tree_depth`), - the real key used in app

FROM tree FORCE INDEX (ty_fr) :
key ty_fr
key_len 7
rows 11410

FROM tree FORCE INDEX (ty_fr_to) :
key ty_fr_to
key_len 10
rows 8492

FROM tree FORCE INDEX (ty_fr_to_ve_de) :
key ty_fr_to_ve_de
key_len 267
rows 7128</description>
		<content:encoded><![CDATA[<p>that you see more of it, I created 2 new indexes (on production data, not testing or random).<br />
(sizes are different in production data. Type is int (4Bytes) not smallint and vector is varchar 255+2)</p>
<p>  KEY `ty_fr` (`tree_type`,`date_from`),<br />
  KEY `ty_fr_to` (`tree_type`,`date_from`,`date_to`),<br />
  KEY `ty_fr_to_ve_de` (`tree_type`,`date_from`,`date_to`,`tree_vector`,`tree_depth`), &#8211; the real key used in app</p>
<p>FROM tree FORCE INDEX (ty_fr) :<br />
key ty_fr<br />
key_len 7<br />
rows 11410</p>
<p>FROM tree FORCE INDEX (ty_fr_to) :<br />
key ty_fr_to<br />
key_len 10<br />
rows 8492</p>
<p>FROM tree FORCE INDEX (ty_fr_to_ve_de) :<br />
key ty_fr_to_ve_de<br />
key_len 267<br />
rows 7128</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jay</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/12/3-ways-mysql-uses-indexes/comment-page-1/#comment-769731</link>
		<dc:creator>jay</dc:creator>
		<pubDate>Wed, 21 Jul 2010 04:25:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1097#comment-769731</guid>
		<description>sizes of parts of the key in Bytes:
tree_type = 2B
tree_vector = 200B (ascii char)
date_from = 3B
date_to = 3B

From Explain in the article:
type : range
possible_keys : type_vector_to_from,type_vector_from_to,type_from_...
key : type_from_to_vector
key_len : 208

testing on different keys (also in the article) confirms the key lenght.</description>
		<content:encoded><![CDATA[<p>sizes of parts of the key in Bytes:<br />
tree_type = 2B<br />
tree_vector = 200B (ascii char)<br />
date_from = 3B<br />
date_to = 3B</p>
<p>From Explain in the article:<br />
type : range<br />
possible_keys : type_vector_to_from,type_vector_from_to,type_from_&#8230;<br />
key : type_from_to_vector<br />
key_len : 208</p>
<p>testing on different keys (also in the article) confirms the key lenght.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/12/3-ways-mysql-uses-indexes/comment-page-1/#comment-769730</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Wed, 21 Jul 2010 04:20:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1097#comment-769730</guid>
		<description>Jay,

So the question remains. How do you KNOW all key parts are actually used ?</description>
		<content:encoded><![CDATA[<p>Jay,</p>
<p>So the question remains. How do you KNOW all key parts are actually used ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jay</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/12/3-ways-mysql-uses-indexes/comment-page-1/#comment-769728</link>
		<dc:creator>jay</dc:creator>
		<pubDate>Wed, 21 Jul 2010 04:05:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1097#comment-769728</guid>
		<description>Someone who aproved my comment changed the query. (propably symbols &quot;more&quot; and &quot;less&quot; made problems)
Look at the link, at the end of the article is the correct query.

date_from and date_to are true ranges.
And vector LIKE &quot;0001%&quot; is changed by optimizer to another range - vector &gt;= &quot;0001&quot; AND vector &lt; &quot;0002&quot;.</description>
		<content:encoded><![CDATA[<p>Someone who aproved my comment changed the query. (propably symbols &#8220;more&#8221; and &#8220;less&#8221; made problems)<br />
Look at the link, at the end of the article is the correct query.</p>
<p>date_from and date_to are true ranges.<br />
And vector LIKE &#8220;0001%&#8221; is changed by optimizer to another range &#8211; vector &gt;= &#8220;0001&#8243; AND vector &lt; &quot;0002&quot;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/12/3-ways-mysql-uses-indexes/comment-page-1/#comment-769726</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Wed, 21 Jul 2010 03:03:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1097#comment-769726</guid>
		<description>Jay,

In your case you have 4 clauses.  2 of them are EQ clauses and clauses on date_to and tree_vector are ranges.    This query should use 3 key parts of this index hence only one range.  If you think it is different can you explain why do you think so ?</description>
		<content:encoded><![CDATA[<p>Jay,</p>
<p>In your case you have 4 clauses.  2 of them are EQ clauses and clauses on date_to and tree_vector are ranges.    This query should use 3 key parts of this index hence only one range.  If you think it is different can you explain why do you think so ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jay</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/12/3-ways-mysql-uses-indexes/comment-page-1/#comment-769685</link>
		<dc:creator>jay</dc:creator>
		<pubDate>Tue, 20 Jul 2010 12:51:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1097#comment-769685</guid>
		<description>Quote: &quot;once MySQL runs into the interval range it will not use any further index parts.&quot;
WRONG!

Triple range lookup:

EXPLAIN SELECT *
FROM tree
WHERE 1
AND tree_type = &quot;2220&quot;
AND date_from = &quot;0000-00-00&quot;
AND date_to &gt; &quot;2010-06-01&quot;
AND date_to &lt;= &quot;9999-12-31&quot;
AND tree_vector LIKE &quot;0001%&quot;

The WHOLE key is used.
KEY `type_from_to_vector` (`tree_type`,`date_to`,`date_from`,`tree_vector`)

more in Slovak language :
http://kyberia.sk/id/5396760

In app, I&#039;m already using multiple range lookups with speeds in miliseconds.
It&#039;s maybe difficult to make it work the first time, to make the correct index, and the correct WHERE, but it&#039;s worth it.</description>
		<content:encoded><![CDATA[<p>Quote: &#8220;once MySQL runs into the interval range it will not use any further index parts.&#8221;<br />
WRONG!</p>
<p>Triple range lookup:</p>
<p>EXPLAIN SELECT *<br />
FROM tree<br />
WHERE 1<br />
AND tree_type = &#8220;2220&#8243;<br />
AND date_from = &#8220;0000-00-00&#8243;<br />
AND date_to &gt; &#8220;2010-06-01&#8243;<br />
AND date_to &lt;= &quot;9999-12-31&quot;<br />
AND tree_vector LIKE &quot;0001%&quot;</p>
<p>The WHOLE key is used.<br />
KEY `type_from_to_vector` (`tree_type`,`date_to`,`date_from`,`tree_vector`)</p>
<p>more in Slovak language :<br />
<a href="http://kyberia.sk/id/5396760" rel="nofollow">http://kyberia.sk/id/5396760</a></p>
<p>In app, I&#039;m already using multiple range lookups with speeds in miliseconds.<br />
It&#039;s maybe difficult to make it work the first time, to make the correct index, and the correct WHERE, but it&#039;s worth it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ted Naleid &#187; Batch Import Performance with Grails and MySQL</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/12/3-ways-mysql-uses-indexes/comment-page-1/#comment-660550</link>
		<dc:creator>Ted Naleid &#187; Batch Import Performance with Grails and MySQL</dc:creator>
		<pubDate>Thu, 01 Oct 2009 05:54:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1097#comment-660550</guid>
		<description>[...] you haven&#8217;t created many indexes before, I highly suggest reading this post on indexes on the mysql high performance blog. The executive summary is that multi-key indexes tailored to your query have a performance edge [...]</description>
		<content:encoded><![CDATA[<p>[...] you haven&#8217;t created many indexes before, I highly suggest reading this post on indexes on the mysql high performance blog. The executive summary is that multi-key indexes tailored to your query have a performance edge [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

