<?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: 7 ways to convince MySQL to use the right index</title>
	<atom:link href="http://code.openark.org/blog/mysql/7-ways-to-convince-mysql-to-use-the-right-index/feed" rel="self" type="application/rss+xml" />
	<link>http://code.openark.org/blog/mysql/7-ways-to-convince-mysql-to-use-the-right-index</link>
	<description>Blog by Shlomi Noach</description>
	<lastBuildDate>Sat, 13 Mar 2010 09:46:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jim</title>
		<link>http://code.openark.org/blog/mysql/7-ways-to-convince-mysql-to-use-the-right-index/comment-page-1#comment-3222</link>
		<dc:creator>Jim</dc:creator>
		<pubDate>Thu, 13 Aug 2009 22:15:38 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=695#comment-3222</guid>
		<description>This bug may be fixed in 5.1.37: http://dev.mysql.com/doc/refman/5.1/en/news-5-1-37.html

We had EXACTLY the same problem as described in this blog, and upgrading to 5.1.32 seems to have fixed it.</description>
		<content:encoded><![CDATA[<p>This bug may be fixed in 5.1.37: <a href="http://dev.mysql.com/doc/refman/5.1/en/news-5-1-37.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.1/en/news-5-1-37.html</a></p>
<p>We had EXACTLY the same problem as described in this blog, and upgrading to 5.1.32 seems to have fixed it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Artículos destacados de Abril 2009 &#124; cambrico.net</title>
		<link>http://code.openark.org/blog/mysql/7-ways-to-convince-mysql-to-use-the-right-index/comment-page-1#comment-1819</link>
		<dc:creator>Artículos destacados de Abril 2009 &#124; cambrico.net</dc:creator>
		<pubDate>Thu, 07 May 2009 07:48:44 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=695#comment-1819</guid>
		<description>[...] formas de forzar el uso de un índice determinado, en openark.org. (en [...]</description>
		<content:encoded><![CDATA[<p>[...] formas de forzar el uso de un índice determinado, en openark.org. (en [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Interesting Items - April 27, 2009 &#124; Oxidiser techblog</title>
		<link>http://code.openark.org/blog/mysql/7-ways-to-convince-mysql-to-use-the-right-index/comment-page-1#comment-1705</link>
		<dc:creator>Interesting Items - April 27, 2009 &#124; Oxidiser techblog</dc:creator>
		<pubDate>Mon, 27 Apr 2009 10:07:11 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=695#comment-1705</guid>
		<description>[...] 7 ways to convince MySQL to use the right index [...]</description>
		<content:encoded><![CDATA[<p>[...] 7 ways to convince MySQL to use the right index [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shlomi</title>
		<link>http://code.openark.org/blog/mysql/7-ways-to-convince-mysql-to-use-the-right-index/comment-page-1#comment-1588</link>
		<dc:creator>shlomi</dc:creator>
		<pubDate>Fri, 17 Apr 2009 02:50:16 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=695#comment-1588</guid>
		<description>Hi nolan,

Yes, I think this should work also. Since I don&#039;t have that DB available to me anymore, and since I cannot reproduce the problem, I can&#039;t test...
If indeed it works (and if EJB supports it) - I like it better than any of the above solutions.

Thanks</description>
		<content:encoded><![CDATA[<p>Hi nolan,</p>
<p>Yes, I think this should work also. Since I don&#8217;t have that DB available to me anymore, and since I cannot reproduce the problem, I can&#8217;t test&#8230;<br />
If indeed it works (and if EJB supports it) &#8211; I like it better than any of the above solutions.</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nolan</title>
		<link>http://code.openark.org/blog/mysql/7-ways-to-convince-mysql-to-use-the-right-index/comment-page-1#comment-1586</link>
		<dc:creator>nolan</dc:creator>
		<pubDate>Thu, 16 Apr 2009 20:39:40 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=695#comment-1586</guid>
		<description>What if you broke it into a query and subquery?  i.e.:

SELECT id from (SELECT id FROM data
WHERE type=12345 AND level &gt; 3)
ORDER BY id

This should make MySQL ignore the primary key in the subquery.  I guess you&#039;ll also lose the primary key in the main query, but that just means sorting a list of ~100 entries, so it&#039;s not so bad.</description>
		<content:encoded><![CDATA[<p>What if you broke it into a query and subquery?  i.e.:</p>
<p>SELECT id from (SELECT id FROM data<br />
WHERE type=12345 AND level &gt; 3)<br />
ORDER BY id</p>
<p>This should make MySQL ignore the primary key in the subquery.  I guess you&#8217;ll also lose the primary key in the main query, but that just means sorting a list of ~100 entries, so it&#8217;s not so bad.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Suggs</title>
		<link>http://code.openark.org/blog/mysql/7-ways-to-convince-mysql-to-use-the-right-index/comment-page-1#comment-1492</link>
		<dc:creator>Aaron Suggs</dc:creator>
		<pubDate>Mon, 06 Apr 2009 21:29:39 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=695#comment-1492</guid>
		<description>Ah, you&#039;re right. Putting the primary key as the last column in a multicolumn index is redundant. I hadn&#039;t thought of that.</description>
		<content:encoded><![CDATA[<p>Ah, you&#8217;re right. Putting the primary key as the last column in a multicolumn index is redundant. I hadn&#8217;t thought of that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shlomi</title>
		<link>http://code.openark.org/blog/mysql/7-ways-to-convince-mysql-to-use-the-right-index/comment-page-1#comment-1487</link>
		<dc:creator>shlomi</dc:creator>
		<pubDate>Mon, 06 Apr 2009 16:26:31 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=695#comment-1487</guid>
		<description>Hi Aaron,

Please see my previous comment: on InnoDB tables, and when the PRIMARY KEY is `id`, the `type` index is implicitly an index on (`type`, `id`). This is because of the implementation InnoDB does for secondary indexes, which point to PRIMARY key values.</description>
		<content:encoded><![CDATA[<p>Hi Aaron,</p>
<p>Please see my previous comment: on InnoDB tables, and when the PRIMARY KEY is `id`, the `type` index is implicitly an index on (`type`, `id`). This is because of the implementation InnoDB does for secondary indexes, which point to PRIMARY key values.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Suggs</title>
		<link>http://code.openark.org/blog/mysql/7-ways-to-convince-mysql-to-use-the-right-index/comment-page-1#comment-1485</link>
		<dc:creator>Aaron Suggs</dc:creator>
		<pubDate>Mon, 06 Apr 2009 12:34:44 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=695#comment-1485</guid>
		<description>Another option is to get rid of the `type` index and add a multicolumn index on `type` and `id` (in that order, not `id` then `type`).

With a multicolumn index, the plan for the original offending query would expect 110 rows, and wouldn&#039;t use filesort (since the index contains the sorted values).</description>
		<content:encoded><![CDATA[<p>Another option is to get rid of the `type` index and add a multicolumn index on `type` and `id` (in that order, not `id` then `type`).</p>
<p>With a multicolumn index, the plan for the original offending query would expect 110 rows, and wouldn&#8217;t use filesort (since the index contains the sorted values).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shlomi</title>
		<link>http://code.openark.org/blog/mysql/7-ways-to-convince-mysql-to-use-the-right-index/comment-page-1#comment-1479</link>
		<dc:creator>shlomi</dc:creator>
		<pubDate>Sun, 05 Apr 2009 17:38:11 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=695#comment-1479</guid>
		<description>Hi Hannes,

I did try it, but the query plan still went for the PRIMARY key only.
It&#039;s interesting to note that, on InnoDB tables, the key on &#039;type&#039; actually includes the &#039;id&#039; column implicitly, since secondary indexes contains the value of the primary keys. 
If the optimizer chooses to use the &#039;type&#039; index on &quot;ORDER BY type, id&quot;, it can do so using index only (however, in our case we also had a filter on the &#039;level&#039; column, which negates this optimization)</description>
		<content:encoded><![CDATA[<p>Hi Hannes,</p>
<p>I did try it, but the query plan still went for the PRIMARY key only.<br />
It&#8217;s interesting to note that, on InnoDB tables, the key on &#8216;type&#8217; actually includes the &#8216;id&#8217; column implicitly, since secondary indexes contains the value of the primary keys.<br />
If the optimizer chooses to use the &#8216;type&#8217; index on &#8220;ORDER BY type, id&#8221;, it can do so using index only (however, in our case we also had a filter on the &#8216;level&#8217; column, which negates this optimization)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hannes</title>
		<link>http://code.openark.org/blog/mysql/7-ways-to-convince-mysql-to-use-the-right-index/comment-page-1#comment-1478</link>
		<dc:creator>Hannes</dc:creator>
		<pubDate>Sun, 05 Apr 2009 16:59:14 +0000</pubDate>
		<guid isPermaLink="false">http://code.openark.org/blog/?p=695#comment-1478</guid>
		<description>My first guess would have been:

ORDER BY type, id

Have you tried this?</description>
		<content:encoded><![CDATA[<p>My first guess would have been:</p>
<p>ORDER BY type, id</p>
<p>Have you tried this?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
