<?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: Long PRIMARY KEY for Innodb tables</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2006/10/03/long-primary-key-for-innodb-tables/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2006/10/03/long-primary-key-for-innodb-tables/</link>
	<description>Everything about MySQL Performance</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:23:57 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jaka Jancar</title>
		<link>http://www.mysqlperformanceblog.com/2006/10/03/long-primary-key-for-innodb-tables/comment-page-1/#comment-571517</link>
		<dc:creator>Jaka Jancar</dc:creator>
		<pubDate>Mon, 01 Jun 2009 14:52:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/10/03/long-primary-key-for-innodb-tables/#comment-571517</guid>
		<description>Thanks Peter!</description>
		<content:encoded><![CDATA[<p>Thanks Peter!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2006/10/03/long-primary-key-for-innodb-tables/comment-page-1/#comment-569309</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Fri, 29 May 2009 22:19:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/10/03/long-primary-key-for-innodb-tables/#comment-569309</guid>
		<description>Jaka,

In this case (because bar1 can be NULL) innodb will create its internal primary key which is not exposed on the top level. That primary key will be when used for reference from unique keys.
If bar1 would be NOT NULL the first unique key would be in fact primary key.</description>
		<content:encoded><![CDATA[<p>Jaka,</p>
<p>In this case (because bar1 can be NULL) innodb will create its internal primary key which is not exposed on the top level. That primary key will be when used for reference from unique keys.<br />
If bar1 would be NOT NULL the first unique key would be in fact primary key.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jaka Jancar</title>
		<link>http://www.mysqlperformanceblog.com/2006/10/03/long-primary-key-for-innodb-tables/comment-page-1/#comment-569004</link>
		<dc:creator>Jaka Jancar</dc:creator>
		<pubDate>Fri, 29 May 2009 08:50:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/10/03/long-primary-key-for-innodb-tables/#comment-569004</guid>
		<description>Peter,

you say that all other keys will refer to the rows by primary key.

What about if the table doesn&#039;t have a primary key, e.g. a table with columns:
 - foo NOT NULL
 - bar1 NULL
 - bar2 NULL
UNIQUE (foo, bar1)
UNIQUE (foo, bar2)
?</description>
		<content:encoded><![CDATA[<p>Peter,</p>
<p>you say that all other keys will refer to the rows by primary key.</p>
<p>What about if the table doesn&#8217;t have a primary key, e.g. a table with columns:<br />
 &#8211; foo NOT NULL<br />
 &#8211; bar1 NULL<br />
 &#8211; bar2 NULL<br />
UNIQUE (foo, bar1)<br />
UNIQUE (foo, bar2)<br />
?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.mysqlperformanceblog.com/2006/10/03/long-primary-key-for-innodb-tables/comment-page-1/#comment-534964</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Fri, 10 Apr 2009 20:23:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/10/03/long-primary-key-for-innodb-tables/#comment-534964</guid>
		<description>I think we figured it out.  There&#039;s a secondary index on the table (updatedTimestamp bigint), and the results are ordered by it.  Strange that the query optimizer chooses it.

These methods fix it, but I&#039;m not entirely sure of the repercussions:

1) select id from view.MediumTextView order by id limit 10
2) select id from view.MediumTextView force index (primary) limit 10
3) select id from view.MediumTextView where id &gt; &#039;&#039;

Perhaps the optimizer is finding the most compact storage location of primary keys?  If it uses the clustered index, it has to load all the leaf data pages (avg ~1kb in this table), and parse out the ids.  But if it uses the secondary index, it&#039;s much fewer data pages to parse through.

Is there a good method for creating a secondary index that&#039;s optimized for selecting large ranges of ids?  Theoretically, you could make a zero-field b-tree index, which would then just be a huge list of primary keys, but i&#039;m not sure you can do that.  What about an index on a bit field where all rows have the same bit value?

It would be interesting to see your thoughts on low cardinality indexes and short-prefix indexes resulting in low cardinality.  What happens if I have a 5 million row table with an index on a true/false column?  Does it form two large trees of primary keys?  Or is it some inefficient list structure.

I guess i better stop now... thanks</description>
		<content:encoded><![CDATA[<p>I think we figured it out.  There&#8217;s a secondary index on the table (updatedTimestamp bigint), and the results are ordered by it.  Strange that the query optimizer chooses it.</p>
<p>These methods fix it, but I&#8217;m not entirely sure of the repercussions:</p>
<p>1) select id from view.MediumTextView order by id limit 10<br />
2) select id from view.MediumTextView force index (primary) limit 10<br />
3) select id from view.MediumTextView where id &gt; &#8221;</p>
<p>Perhaps the optimizer is finding the most compact storage location of primary keys?  If it uses the clustered index, it has to load all the leaf data pages (avg ~1kb in this table), and parse out the ids.  But if it uses the secondary index, it&#8217;s much fewer data pages to parse through.</p>
<p>Is there a good method for creating a secondary index that&#8217;s optimized for selecting large ranges of ids?  Theoretically, you could make a zero-field b-tree index, which would then just be a huge list of primary keys, but i&#8217;m not sure you can do that.  What about an index on a bit field where all rows have the same bit value?</p>
<p>It would be interesting to see your thoughts on low cardinality indexes and short-prefix indexes resulting in low cardinality.  What happens if I have a 5 million row table with an index on a true/false column?  Does it form two large trees of primary keys?  Or is it some inefficient list structure.</p>
<p>I guess i better stop now&#8230; thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.mysqlperformanceblog.com/2006/10/03/long-primary-key-for-innodb-tables/comment-page-1/#comment-534955</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Fri, 10 Apr 2009 19:55:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/10/03/long-primary-key-for-innodb-tables/#comment-534955</guid>
		<description>I have an InnoDB table with a long varchar primary key, and when I do a &quot;select id...&quot; query, the results do not return ordered by id.  I can think of 2 possible reasons:

1) this table has previously been converted to MyISAM and back to InnoDB, but has been modified much since then

2) the primary keys all start with the same 18 latin1 characters, and maybe the primary key is only indexed to 10 characters?  If this is the case, what does the internal data storage structure look like?

The problem is that the table is about 3.6 million rows, and I do range selects that pull about 300,000 ids at a time.  If they&#039;re not in order, I&#039;m not sure I&#039;ll get the correct id&#039;s, and I can&#039;t add an &quot;order by id&quot; clause because that will hurt performance too much.

Further, I can&#039;t find any way to assert an index&#039;s prefix length on MySQL 5.1.  It does not display in a &quot;show create table&quot; statement nor a &quot;show index from&quot; nor a &quot;describe table&quot; statement!

Here is example output without and with an &quot;order by id&quot; clause:

---------------------------------------

select id from view.MediumTextView limit 10

modelQuadTokens_1_030233102111321211233320001_23260356_RealtyTrac
modelQuadTokens_1_021333011030113102211010101_23264578_RealtyTrac
modelQuadTokens_1_023101030110202002021310021_23265168_RealtyTrac
modelQuadTokens_1_023012311310002011100033022_23258199_RealtyTrac
modelQuadTokens_1_023012311312130313023213020_23265583_RealtyTrac
modelQuadTokens_1_023012311103021221232131110_23258157_RealtyTrac
modelQuadTokens_1_023013210320212220101012001_23256624_RealtyTrac
modelQuadTokens_1_023012130130003202121231312_23256294_RealtyTrac
modelQuadTokens_1_023012130102300210002011120_23256413_RealtyTrac
modelQuadTokens_1_023010203333201133300002301_23266647_RealtyTrac


select id from view.MediumTextView order by id limit 10

modelQuadTokens_1_002231332112003321210202031_1279355_LandWatch
modelQuadTokens_1_002231332112003321210202031_253830_LandWatch
modelQuadTokens_1_002302203000032102223033220_GZ14768_Worldspan
modelQuadTokens_1_003222003112121300202000120_WV0932_Worldspan
modelQuadTokens_1_020010301121310313312101300_2266695_Point2
modelQuadTokens_1_020010301221110133133221233_1733075_Point2
modelQuadTokens_1_020010301221110133133221233_1809187_Point2
modelQuadTokens_1_020010301221110133133221233_1863296_Point2
modelQuadTokens_1_020010301221110133133223011_1477083_Point2
modelQuadTokens_1_020010320312133200303333333_1698538_Point2
-------------------------

I have some workarounds, but It&#039;s strange that I can&#039;t find many others having a similar problem.

Have you ever encountered this?

Matt</description>
		<content:encoded><![CDATA[<p>I have an InnoDB table with a long varchar primary key, and when I do a &#8220;select id&#8230;&#8221; query, the results do not return ordered by id.  I can think of 2 possible reasons:</p>
<p>1) this table has previously been converted to MyISAM and back to InnoDB, but has been modified much since then</p>
<p>2) the primary keys all start with the same 18 latin1 characters, and maybe the primary key is only indexed to 10 characters?  If this is the case, what does the internal data storage structure look like?</p>
<p>The problem is that the table is about 3.6 million rows, and I do range selects that pull about 300,000 ids at a time.  If they&#8217;re not in order, I&#8217;m not sure I&#8217;ll get the correct id&#8217;s, and I can&#8217;t add an &#8220;order by id&#8221; clause because that will hurt performance too much.</p>
<p>Further, I can&#8217;t find any way to assert an index&#8217;s prefix length on MySQL 5.1.  It does not display in a &#8220;show create table&#8221; statement nor a &#8220;show index from&#8221; nor a &#8220;describe table&#8221; statement!</p>
<p>Here is example output without and with an &#8220;order by id&#8221; clause:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>select id from view.MediumTextView limit 10</p>
<p>modelQuadTokens_1_030233102111321211233320001_23260356_RealtyTrac<br />
modelQuadTokens_1_021333011030113102211010101_23264578_RealtyTrac<br />
modelQuadTokens_1_023101030110202002021310021_23265168_RealtyTrac<br />
modelQuadTokens_1_023012311310002011100033022_23258199_RealtyTrac<br />
modelQuadTokens_1_023012311312130313023213020_23265583_RealtyTrac<br />
modelQuadTokens_1_023012311103021221232131110_23258157_RealtyTrac<br />
modelQuadTokens_1_023013210320212220101012001_23256624_RealtyTrac<br />
modelQuadTokens_1_023012130130003202121231312_23256294_RealtyTrac<br />
modelQuadTokens_1_023012130102300210002011120_23256413_RealtyTrac<br />
modelQuadTokens_1_023010203333201133300002301_23266647_RealtyTrac</p>
<p>select id from view.MediumTextView order by id limit 10</p>
<p>modelQuadTokens_1_002231332112003321210202031_1279355_LandWatch<br />
modelQuadTokens_1_002231332112003321210202031_253830_LandWatch<br />
modelQuadTokens_1_002302203000032102223033220_GZ14768_Worldspan<br />
modelQuadTokens_1_003222003112121300202000120_WV0932_Worldspan<br />
modelQuadTokens_1_020010301121310313312101300_2266695_Point2<br />
modelQuadTokens_1_020010301221110133133221233_1733075_Point2<br />
modelQuadTokens_1_020010301221110133133221233_1809187_Point2<br />
modelQuadTokens_1_020010301221110133133221233_1863296_Point2<br />
modelQuadTokens_1_020010301221110133133223011_1477083_Point2<br />
modelQuadTokens_1_020010320312133200303333333_1698538_Point2<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>I have some workarounds, but It&#8217;s strange that I can&#8217;t find many others having a similar problem.</p>
<p>Have you ever encountered this?</p>
<p>Matt</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rangi</title>
		<link>http://www.mysqlperformanceblog.com/2006/10/03/long-primary-key-for-innodb-tables/comment-page-1/#comment-32495</link>
		<dc:creator>rangi</dc:creator>
		<pubDate>Fri, 19 Jan 2007 05:50:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/10/03/long-primary-key-for-innodb-tables/#comment-32495</guid>
		<description>in what purpose we are using primary key?</description>
		<content:encoded><![CDATA[<p>in what purpose we are using primary key?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
