<?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: MySQL Optimizer and  Innodb Primary Key</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/</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: peter</title>
		<link>http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/comment-page-1/#comment-334581</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Fri, 25 Jul 2008 17:44:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/#comment-334581</guid>
		<description>Cyril,

Thank you for update.  Indeed problems are getting fixed so you have to look at the old posts with care. 
In particular as developers often read this blog it is not a surprise :)</description>
		<content:encoded><![CDATA[<p>Cyril,</p>
<p>Thank you for update.  Indeed problems are getting fixed so you have to look at the old posts with care.<br />
In particular as developers often read this blog it is not a surprise <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cyril Scetbon</title>
		<link>http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/comment-page-1/#comment-334503</link>
		<dc:creator>Cyril Scetbon</dc:creator>
		<pubDate>Fri, 25 Jul 2008 13:44:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/#comment-334503</guid>
		<description>It seems to be not the case anymore in 5.1 :

mysql&gt; EXPLAIN SELECT id FROM innodb WHERE a=3 ORDER BY id \G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: innodb
         type: ref
possible_keys: a
          key: a
      key_len: 5
          ref: const
         rows: 3
        Extra: Using where; Using index
1 row in set (0.51 sec)</description>
		<content:encoded><![CDATA[<p>It seems to be not the case anymore in 5.1 :</p>
<p>mysql&gt; EXPLAIN SELECT id FROM innodb WHERE a=3 ORDER BY id \G<br />
*************************** 1. row ***************************<br />
           id: 1<br />
  select_type: SIMPLE<br />
        table: innodb<br />
         type: ref<br />
possible_keys: a<br />
          key: a<br />
      key_len: 5<br />
          ref: const<br />
         rows: 3<br />
        Extra: Using where; Using index<br />
1 row in set (0.51 sec)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/comment-page-1/#comment-256432</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Sun, 23 Mar 2008 20:52:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/#comment-256432</guid>
		<description>What is fixed ? 

This seems to be similar to my example:

#
mysql&gt; EXPLAIN SELECT id FROM innodb WHERE a=3 \G
#
*************************** 1. row ***************************
#
           id: 1
#
  select_type: SIMPLE
#
        TABLE: innodb
#
         type: ref
#
possible_keys: a
#
          KEY: a
#
      key_len: 5
#
          ref: const
#
         rows: 1
#
        Extra: USING WHERE; USING INDEX
#
1 row IN SET (0.00 sec)


Which already had using index.</description>
		<content:encoded><![CDATA[<p>What is fixed ? </p>
<p>This seems to be similar to my example:</p>
<p>#<br />
mysql> EXPLAIN SELECT id FROM innodb WHERE a=3 \G<br />
#<br />
*************************** 1. row ***************************<br />
#<br />
           id: 1<br />
#<br />
  select_type: SIMPLE<br />
#<br />
        TABLE: innodb<br />
#<br />
         type: ref<br />
#<br />
possible_keys: a<br />
#<br />
          KEY: a<br />
#<br />
      key_len: 5<br />
#<br />
          ref: const<br />
#<br />
         rows: 1<br />
#<br />
        Extra: USING WHERE; USING INDEX<br />
#<br />
1 row IN SET (0.00 sec)</p>
<p>Which already had using index.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geo</title>
		<link>http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/comment-page-1/#comment-256369</link>
		<dc:creator>Geo</dc:creator>
		<pubDate>Sun, 23 Mar 2008 18:44:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/#comment-256369</guid>
		<description>This is now fixed, at least my tests show so

CREATE TABLE `pricesbig_inno` (
  `id` int(10) unsigned NOT NULL,
  `url_id` int(10) unsigned NOT NULL,
  `product_id` int(10) unsigned NOT NULL,
  PRIMARY KEY  (`product_id`,`id`),
  KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


mysql&gt; EXPLAIN SELECT id, product_id FROM `pricesbig_inno` WHERE id =1515;
+----+-------------+----------------+------+---------------+------+---------+-------+------+-------------+
&#124; id &#124; select_type &#124; table          &#124; type &#124; possible_keys &#124; key  &#124; key_len &#124; ref   &#124; rows &#124; Extra       &#124;
+----+-------------+----------------+------+---------------+------+---------+-------+------+-------------+
&#124;  1 &#124; SIMPLE      &#124; pricesbig_inno &#124; ref  &#124; id            &#124; id   &#124; 4       &#124; const &#124;    1 &#124; Using index &#124;
+----+-------------+----------------+------+---------------+------+---------+-------+------+-------------+
1 row in set (0.00 sec)</description>
		<content:encoded><![CDATA[<p>This is now fixed, at least my tests show so</p>
<p>CREATE TABLE `pricesbig_inno` (<br />
  `id` int(10) unsigned NOT NULL,<br />
  `url_id` int(10) unsigned NOT NULL,<br />
  `product_id` int(10) unsigned NOT NULL,<br />
  PRIMARY KEY  (`product_id`,`id`),<br />
  KEY `id` (`id`)<br />
) ENGINE=InnoDB DEFAULT CHARSET=utf8;</p>
<p>mysql&gt; EXPLAIN SELECT id, product_id FROM `pricesbig_inno` WHERE id =1515;<br />
+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| id | select_type | table          | type | possible_keys | key  | key_len | ref   | rows | Extra       |<br />
+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
|  1 | SIMPLE      | pricesbig_inno | ref  | id            | id   | 4       | const |    1 | Using index |<br />
+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
1 row in set (0.00 sec)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raj</title>
		<link>http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/comment-page-1/#comment-178637</link>
		<dc:creator>Raj</dc:creator>
		<pubDate>Thu, 18 Oct 2007 13:12:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/#comment-178637</guid>
		<description>Will Primary key improve performance ?</description>
		<content:encoded><![CDATA[<p>Will Primary key improve performance ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/comment-page-1/#comment-5455</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Sat, 28 Oct 2006 08:38:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/#comment-5455</guid>
		<description>Why is that ? 

The choice is basically if you access data by primary key and send it  or you access data by primary key to sort it and return back to the client ? 

Innodb full table scan will be reading via Innodb key and the data comes sorted already so it will be just overhead to sort it again.</description>
		<content:encoded><![CDATA[<p>Why is that ? </p>
<p>The choice is basically if you access data by primary key and send it  or you access data by primary key to sort it and return back to the client ? </p>
<p>Innodb full table scan will be reading via Innodb key and the data comes sorted already so it will be just overhead to sort it again.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: grantsucceeded</title>
		<link>http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/comment-page-1/#comment-5451</link>
		<dc:creator>grantsucceeded</dc:creator>
		<pubDate>Sat, 28 Oct 2006 06:50:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/#comment-5451</guid>
		<description>Peter:
It is not true that primary key lookup is faster than filesort, or at least should not be true.

If one is sorting a significant number of rows, sort is faster because it can do sequential IOs then O(logN) sort instead of random IOs.</description>
		<content:encoded><![CDATA[<p>Peter:<br />
It is not true that primary key lookup is faster than filesort, or at least should not be true.</p>
<p>If one is sorting a significant number of rows, sort is faster because it can do sequential IOs then O(logN) sort instead of random IOs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/comment-page-1/#comment-4773</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Thu, 05 Oct 2006 07:30:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/#comment-4773</guid>
		<description>Roland yes.  The solution you&#039;re mentioning does work and it is a way to get such behavior for non-Innodb tables. 
My point is simply it could be done for Innodb with given index structure but it is not. 

Also quite curious if key (a,id) is used is Innodb is smart enough to notice it already had id in the end so it does not have to be added second time.</description>
		<content:encoded><![CDATA[<p>Roland yes.  The solution you&#8217;re mentioning does work and it is a way to get such behavior for non-Innodb tables.<br />
My point is simply it could be done for Innodb with given index structure but it is not. </p>
<p>Also quite curious if key (a,id) is used is Innodb is smart enough to notice it already had id in the end so it does not have to be added second time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roland Volkmann</title>
		<link>http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/comment-page-1/#comment-4766</link>
		<dc:creator>Roland Volkmann</dc:creator>
		<pubDate>Wed, 04 Oct 2006 22:07:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/10/03/mysql-optimizer-and-innodb-primary-key/#comment-4766</guid>
		<description>Hello Peter,

as long as the bug is not fixed, you can define key a as  &quot;KEY `a` (`a`,`id`)&quot;  to avoid filesort. I did so in my projects.


With best regards

Roland</description>
		<content:encoded><![CDATA[<p>Hello Peter,</p>
<p>as long as the bug is not fixed, you can define key a as  &#8220;KEY `a` (`a`,`id`)&#8221;  to avoid filesort. I did so in my projects.</p>
<p>With best regards</p>
<p>Roland</p>
]]></content:encoded>
	</item>
</channel>
</rss>
