<?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 FORCE INDEX with Rails</title>
	<atom:link href="http://involution.com/2010/04/04/using-force-index-with-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://involution.com/2010/04/04/using-force-index-with-rails/</link>
	<description>Tony Perrie&#039;s Weblog</description>
	<lastBuildDate>Tue, 15 May 2012 22:43:17 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Tony Perrie</title>
		<link>http://involution.com/2010/04/04/using-force-index-with-rails/comment-page-1/#comment-387838</link>
		<dc:creator>Tony Perrie</dc:creator>
		<pubDate>Mon, 03 Oct 2011 23:08:13 +0000</pubDate>
		<guid isPermaLink="false">http://involution.com/?p=1277#comment-387838</guid>
		<description>Thanks.  I didn&#039;t know that.</description>
		<content:encoded><![CDATA[<p>Thanks.  I didn&#8217;t know that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Edward Rudd</title>
		<link>http://involution.com/2010/04/04/using-force-index-with-rails/comment-page-1/#comment-387835</link>
		<dc:creator>Edward Rudd</dc:creator>
		<pubDate>Mon, 03 Oct 2011 22:52:24 +0000</pubDate>
		<guid isPermaLink="false">http://involution.com/?p=1277#comment-387835</guid>
		<description>The reason why MySQL won&#039;t use the index is because the index is sorted ASC, and you are requesting it be sorted DESC.   For some reason rails lacks the ability to specify the sort direction when creating indexes.

Creating an index thusly would solve your issue AND increase performance over what you are currently doing.

CREATE INDEX posts_created_at_and_blog_id ON posts (create_at DESC, blog_id)

though probably you want to do

CREATE INDEX posts_blog_id_and_created_at ON posts (blog_id, created_at DESC)

As I&#039;m assuming your queries are like this.

SELECT posts.* from posts where blog_id = 23 ORDER BY created_at DESC</description>
		<content:encoded><![CDATA[<p>The reason why MySQL won&#8217;t use the index is because the index is sorted ASC, and you are requesting it be sorted DESC.   For some reason rails lacks the ability to specify the sort direction when creating indexes.</p>
<p>Creating an index thusly would solve your issue AND increase performance over what you are currently doing.</p>
<p>CREATE INDEX posts_created_at_and_blog_id ON posts (create_at DESC, blog_id)</p>
<p>though probably you want to do</p>
<p>CREATE INDEX posts_blog_id_and_created_at ON posts (blog_id, created_at DESC)</p>
<p>As I&#8217;m assuming your queries are like this.</p>
<p>SELECT posts.* from posts where blog_id = 23 ORDER BY created_at DESC</p>
]]></content:encoded>
	</item>
</channel>
</rss>

