<?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: Why InnoDB index cardinality varies strangely</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2009/09/28/why-innodb-index-cardinality-varies-strangely/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2009/09/28/why-innodb-index-cardinality-varies-strangely/</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: Deepika Maddali</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/28/why-innodb-index-cardinality-varies-strangely/comment-page-1/#comment-662918</link>
		<dc:creator>Deepika Maddali</dc:creator>
		<pubDate>Thu, 08 Oct 2009 17:42:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=386#comment-662918</guid>
		<description>Hi Morgon,

I think i was the one who asked you the question in the SFO training.

Thanks</description>
		<content:encoded><![CDATA[<p>Hi Morgon,</p>
<p>I think i was the one who asked you the question in the SFO training.</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Deepika Maddali</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/28/why-innodb-index-cardinality-varies-strangely/comment-page-1/#comment-662917</link>
		<dc:creator>Deepika Maddali</dc:creator>
		<pubDate>Thu, 08 Oct 2009 17:40:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=386#comment-662917</guid>
		<description>Hi,

I had the same problem with the various indexes on tables. The query would not use the same execution plan for each execution with Index Hints, but when we analyze the table the execution plan is as per the Index hints. I am not sure why is this possible, due to data fragmentation on the datafile and the estimates are not the most recent.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I had the same problem with the various indexes on tables. The query would not use the same execution plan for each execution with Index Hints, but when we analyze the table the execution plan is as per the Index hints. I am not sure why is this possible, due to data fragmentation on the datafile and the estimates are not the most recent.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vadim</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/28/why-innodb-index-cardinality-varies-strangely/comment-page-1/#comment-659341</link>
		<dc:creator>Vadim</dc:creator>
		<pubDate>Mon, 28 Sep 2009 17:09:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=386#comment-659341</guid>
		<description>The story is much worse than it is sounds. For single-column indexes we get variations. For multi-column indexes we have problems.

Lets consider 

CREATE TABLE T (
  A int NOT NULL,
  B int NOT NULL,
  C int NOT NULL,
  S varchar(80) NOT NULL,
  KEY ix_a_b (A, B),
  KEY ix_a_c (A, C)
) ENGINE=InnoDB

Our typical queries are 

select S from T where A = ? and B = ?;
select S from T where A = ? and C = ?;

Well, here sampling comes to the play. We will get cardinalities
ix_a_b (1)  x1
ix_a_b (2)  x2
ix_a_c (3)  y1
ix_a_c (4)  y2

Because of sampling x1 is never equal to y1. So, for our queries it will always prefer one index over another. It means that one of the queries is always executed using wrong index!!!

I talked to Percona people. In their opinion the behavior is inherent, as sampling of indexes happen independently. I guess, expectations of optimizer are:
1) x1 = y1
2) x1 &lt;= x2 &lt;= rowcount &amp;&amp; y1 &lt;= y2 &lt;= rowcount</description>
		<content:encoded><![CDATA[<p>The story is much worse than it is sounds. For single-column indexes we get variations. For multi-column indexes we have problems.</p>
<p>Lets consider </p>
<p>CREATE TABLE T (<br />
  A int NOT NULL,<br />
  B int NOT NULL,<br />
  C int NOT NULL,<br />
  S varchar(80) NOT NULL,<br />
  KEY ix_a_b (A, B),<br />
  KEY ix_a_c (A, C)<br />
) ENGINE=InnoDB</p>
<p>Our typical queries are </p>
<p>select S from T where A = ? and B = ?;<br />
select S from T where A = ? and C = ?;</p>
<p>Well, here sampling comes to the play. We will get cardinalities<br />
ix_a_b (1)  x1<br />
ix_a_b (2)  x2<br />
ix_a_c (3)  y1<br />
ix_a_c (4)  y2</p>
<p>Because of sampling x1 is never equal to y1. So, for our queries it will always prefer one index over another. It means that one of the queries is always executed using wrong index!!!</p>
<p>I talked to Percona people. In their opinion the behavior is inherent, as sampling of indexes happen independently. I guess, expectations of optimizer are:<br />
1) x1 = y1<br />
2) x1 &lt;= x2 &lt;= rowcount &amp;&amp; y1 &lt;= y2 &lt;= rowcount</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Baron Schwartz</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/28/why-innodb-index-cardinality-varies-strangely/comment-page-1/#comment-659269</link>
		<dc:creator>Baron Schwartz</dc:creator>
		<pubDate>Mon, 28 Sep 2009 14:04:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=386#comment-659269</guid>
		<description>Oh, I should have linked my bug report: http://bugs.mysql.com/bug.php?id=41133</description>
		<content:encoded><![CDATA[<p>Oh, I should have linked my bug report: <a href="http://bugs.mysql.com/bug.php?id=41133" rel="nofollow">http://bugs.mysql.com/bug.php?id=41133</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Morgan Tocker</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/28/why-innodb-index-cardinality-varies-strangely/comment-page-1/#comment-659264</link>
		<dc:creator>Morgan Tocker</dc:creator>
		<pubDate>Mon, 28 Sep 2009 13:59:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=386#comment-659264</guid>
		<description>Excellent!  I had a training student ask me this question in San Francisco.  It&#039;s great to see such a thorough analysis in Vasil&#039;s post.</description>
		<content:encoded><![CDATA[<p>Excellent!  I had a training student ask me this question in San Francisco.  It&#8217;s great to see such a thorough analysis in Vasil&#8217;s post.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

