<?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: When the subselect runs faster</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2010/03/18/when-the-subselect-runs-faster/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2010/03/18/when-the-subselect-runs-faster/</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: Istvan Podor</title>
		<link>http://www.mysqlperformanceblog.com/2010/03/18/when-the-subselect-runs-faster/comment-page-1/#comment-750459</link>
		<dc:creator>Istvan Podor</dc:creator>
		<pubDate>Tue, 20 Apr 2010 06:03:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=2271#comment-750459</guid>
		<description>Nikolay:

If you would give me the explain I could give an exact answer. Now it&#039;s looks like because the joins are slow/slower in the subquery. As I mentioned in the post, the subquery will be executed for each result of the main query. So in this case each query like this means 20 joins :)</description>
		<content:encoded><![CDATA[<p>Nikolay:</p>
<p>If you would give me the explain I could give an exact answer. Now it&#8217;s looks like because the joins are slow/slower in the subquery. As I mentioned in the post, the subquery will be executed for each result of the main query. So in this case each query like this means 20 joins <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nikolay Mihaylov</title>
		<link>http://www.mysqlperformanceblog.com/2010/03/18/when-the-subselect-runs-faster/comment-page-1/#comment-749094</link>
		<dc:creator>Nikolay Mihaylov</dc:creator>
		<pubDate>Sat, 17 Apr 2010 10:41:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=2271#comment-749094</guid>
		<description>Why not something with union / join?

select * from table where id in (
select id from table where col1=&#039;a&#039;
union
select id from table where col1=&#039;b&#039;
)ORDER BY id DESC LIMIT 20 

or even:

select t1.* from table t1, (
select id from table where col1=&#039;a&#039;
union
select id from table where col1=&#039;b&#039;
) t2
where t1.id = t2.id
ORDER BY id DESC LIMIT 20</description>
		<content:encoded><![CDATA[<p>Why not something with union / join?</p>
<p>select * from table where id in (<br />
select id from table where col1=&#8217;a&#8217;<br />
union<br />
select id from table where col1=&#8217;b&#8217;<br />
)ORDER BY id DESC LIMIT 20 </p>
<p>or even:</p>
<p>select t1.* from table t1, (<br />
select id from table where col1=&#8217;a&#8217;<br />
union<br />
select id from table where col1=&#8217;b&#8217;<br />
) t2<br />
where t1.id = t2.id<br />
ORDER BY id DESC LIMIT 20</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zhangll</title>
		<link>http://www.mysqlperformanceblog.com/2010/03/18/when-the-subselect-runs-faster/comment-page-1/#comment-741025</link>
		<dc:creator>zhangll</dc:creator>
		<pubDate>Mon, 29 Mar 2010 05:44:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=2271#comment-741025</guid>
		<description>Nice! :)</description>
		<content:encoded><![CDATA[<p>Nice! <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: varzosu</title>
		<link>http://www.mysqlperformanceblog.com/2010/03/18/when-the-subselect-runs-faster/comment-page-1/#comment-739976</link>
		<dc:creator>varzosu</dc:creator>
		<pubDate>Thu, 25 Mar 2010 22:45:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=2271#comment-739976</guid>
		<description>I suggest to also run the queries in a different order, to make sure that the caching of blocks by the kernel does not happen in favor or the second query.
The most useful would be the have a col1,id index so definitely the index would be used by default.</description>
		<content:encoded><![CDATA[<p>I suggest to also run the queries in a different order, to make sure that the caching of blocks by the kernel does not happen in favor or the second query.<br />
The most useful would be the have a col1,id index so definitely the index would be used by default.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jpgerek</title>
		<link>http://www.mysqlperformanceblog.com/2010/03/18/when-the-subselect-runs-faster/comment-page-1/#comment-739298</link>
		<dc:creator>jpgerek</dc:creator>
		<pubDate>Tue, 23 Mar 2010 09:29:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=2271#comment-739298</guid>
		<description>I think that the real problem is having an index in col1, it&#039;s not optimal at all having and index in a field with just 9 different possible values, and index is as efficient as its cardinality. I would try removing the index in col1, moreover you would save memory and the index creation when inserting rows.</description>
		<content:encoded><![CDATA[<p>I think that the real problem is having an index in col1, it&#8217;s not optimal at all having and index in a field with just 9 different possible values, and index is as efficient as its cardinality. I would try removing the index in col1, moreover you would save memory and the index creation when inserting rows.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick Casey</title>
		<link>http://www.mysqlperformanceblog.com/2010/03/18/when-the-subselect-runs-faster/comment-page-1/#comment-739009</link>
		<dc:creator>Patrick Casey</dc:creator>
		<pubDate>Mon, 22 Mar 2010 01:05:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=2271#comment-739009</guid>
		<description>Seems like this is really just a workaround for a weakness in the optimizer. Properly handling limit clauses in the optimizer is definitely something I&#039;d like to see tackled.</description>
		<content:encoded><![CDATA[<p>Seems like this is really just a workaround for a weakness in the optimizer. Properly handling limit clauses in the optimizer is definitely something I&#8217;d like to see tackled.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2010/03/18/when-the-subselect-runs-faster/comment-page-1/#comment-738554</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Sat, 20 Mar 2010 04:19:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=2271#comment-738554</guid>
		<description>zerkms,

Yes estimation may give different value.  Regarding PRIMARY KEY this is because MySQL does primary key lookups for rows as it retrieves them in the order and after fetching row by primary key checks if it matches WHERE clause.</description>
		<content:encoded><![CDATA[<p>zerkms,</p>
<p>Yes estimation may give different value.  Regarding PRIMARY KEY this is because MySQL does primary key lookups for rows as it retrieves them in the order and after fetching row by primary key checks if it matches WHERE clause.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zerkms</title>
		<link>http://www.mysqlperformanceblog.com/2010/03/18/when-the-subselect-runs-faster/comment-page-1/#comment-738048</link>
		<dc:creator>zerkms</dc:creator>
		<pubDate>Thu, 18 Mar 2010 16:50:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=2271#comment-738048</guid>
		<description>ah, about first question: seems like the optimizer get a projected number of possible affected index records aproximately due to it&#039;s measured before real query was executed</description>
		<content:encoded><![CDATA[<p>ah, about first question: seems like the optimizer get a projected number of possible affected index records aproximately due to it&#8217;s measured before real query was executed</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zerkms</title>
		<link>http://www.mysqlperformanceblog.com/2010/03/18/when-the-subselect-runs-faster/comment-page-1/#comment-738046</link>
		<dc:creator>zerkms</dc:creator>
		<pubDate>Thu, 18 Mar 2010 16:48:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=2271#comment-738046</guid>
		<description>why it is differen number of rows in cases (606920 vs 765105)?
and why it is PRIMARY as key for DEPENDENT SUBQUERY in second case?</description>
		<content:encoded><![CDATA[<p>why it is differen number of rows in cases (606920 vs 765105)?<br />
and why it is PRIMARY as key for DEPENDENT SUBQUERY in second case?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

