<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MySQL Performance Blog &#187; myisam</title>
	<atom:link href="http://www.mysqlperformanceblog.com/category/myisam/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com</link>
	<description>Everything about MySQL Performance</description>
	<lastBuildDate>Sat, 21 Nov 2009 03:11:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>table_cache negative scalability</title>
		<link>http://www.mysqlperformanceblog.com/2009/11/16/table_cache-negative-scalability/</link>
		<comments>http://www.mysqlperformanceblog.com/2009/11/16/table_cache-negative-scalability/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 02:18:00 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[benchmarks]]></category>
		<category><![CDATA[myisam]]></category>

		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1754</guid>
		<description><![CDATA[Couple of months ago there was a post by FreshBooks on getting great performance improvements by lowering table_cache variable.    So I decided to investigate what is really happening here.
The &#8220;common sense&#8221; approach to tuning caches is to get them as large as you can if you have enough resources (such as memory). [...]]]></description>
			<content:encoded><![CDATA[<p>Couple of months ago there was a <a href="http://www.freshbooks.com/blog/2008/09/09/now-were-flying/">post</a> by FreshBooks on getting great performance improvements by lowering <strong>table_cache</strong> variable.    So I decided to investigate what is really happening here.</p>
<p>The &#8220;common sense&#8221; approach to tuning caches is to get them as large as you can if you have enough resources (such as memory).  With MySQL common sense however does not always works &#8211; we&#8217;ve seen performance issues with large <strong>query_cache_size</strong> also <a href="http://www.mysqlperformanceblog.com/2007/08/18/how-fast-can-you-sort-data-with-mysql/">sort_buffer_size</a> and <a href="http://www.mysqlperformanceblog.com/2007/09/17/mysql-what-read_buffer_size-value-is-optimal/">read_buffer_size</a> may not give you better performance if you increase them. I found this also applies to <a href="http://www.mysqlperformanceblog.com/2006/06/06/are-larger-buffers-always-better/">some other buffers</a>.</p>
<p>Even though having previous experience of surprised behavior I did not expect such a <strong>table_cache</strong> issue &#8211; the LRU for cache management is classics and there are scalable algorithms to deal with it.  I would expect Monty to implement one of them.</p>
<p>To do the test I have created 100.000 empty tables containing single integer column and no indexes and when ran <strong>SELECT * FROM tableN</strong> in the loop.    Each table in such case is accessed only once and on any but first run each access would require table replacement in table cache based on LRU logic.<br />
<a href="http://mysqlsandbox.net/">MySQL Sandbox</a> helped me to test this with different servers easily.</p>
<p>I did test on CentOS 5.3,  Xeon E5405,  16GB RAM and EXT3 file system on the SATA hard drive. </p>
<p><strong>MySQL 5.0.85</strong>  Created 100.000 tables in around 3min 40 sec which is about <strong>450 tables/sec </strong> &#8211; This indicates the &#8220;fsync&#8221; is lying on this test system as  default sync_frm option is used.</p>
<p>With default <strong>table_cache=64</strong>   accessing all tables take 12 sec which is almost <strong>8500 tables/sec </strong>   which is a great speed.    We can note significant writes to the disk during this read-only benchmark. Why ?  Because for MyISAM tables table header has to be modified each time the table is opened.   In this case the performance was so great because all 100.000 tables data (first block of index) was placed close by on disk as well as fully cached which made updates to headers very slow.  In the production systems with table headers not in OS cache you often will see significantly low numbers &#8211; 100 or less.</p>
<p>With significantly larger<strong> table_cache=16384</strong> (and appropriately adjusted number of open files)  the same operation takes 660 seconds which is <strong>151 tables/sec</strong>  which is around 50 times slower.  Wow. This is the slow down.  We can see the load becomes very CPU bound in this case and it looks like some of the table_cache algorithms do not scale well.</p>
<p>The absolute numbers are also very interesting &#8211; 151 tables/sec is not that bad if you look at it as an absolute number.   So if you tune table cache is &#8220;normal&#8221; case and is able to bring down your miss rate (<strong>opened_tables</strong>) to 10/sec or less by using large <strong>table_cache </strong> you should do so.   However if you have so many tables you still see 100+ misses/sec  while your data (at least table headers)  is well cached so the cost of table cache miss is not very high, you may be better of with significantly reduced table cache size. </p>
<p>The next step for me was to see if the problem was fixed in MySQL 5.1 &#8211;  in this version table_cache was significantly redone and split in <strong>table_open_cache</strong> and  <strong>table_definition_cache</strong> and I assumed the behavior may be different as well.</p>
<p><strong>MySQL 5.1.40</strong><br />
I started testing with default <strong>table_open_cache=64</strong> and <strong>table_definition_cache=256</strong> &#8211; the read took about 12 seconds very close to MySQL 5.0.85.<br />
As I increased <strong>table_definition_cache</strong> to 16384 result remained the same so this variable is not causing the bottleneck.   However increasing <strong>table_open_cache</strong>  to 16384 causes scan to take about 780 sec which is a bit worse than MySQL 5.0.85. So the problem is not fixed in MySQL 5.1, lets see how MySQL 5.4 behaves.</p>
<p><strong>MySQL 5.4.2</strong><br />
MySQL 5.4.2  has higher default <strong>table_open_cache</strong> so I took it down to 64 so we can compare apples to apples.   It performs same as MySQL 5.0 and MySQL 5.1 with small table cache.<br />
With <strong>table_open_cache</strong> increased  to 16384 the test took  750 seconds  so the problem exists in MySQL 5.4 as well.</p>
<p>So the problem is real and it is not fixed even in Performance focused MySQL 5.4.  As we can see large table_cache (or table_open_cache_ values indeed can cause significant performance problems.  Interesting enough  Innodb has a very similar task of managing its own cache of file descriptors (set by <strong>innodb_open_files</strong>)  As the time allows I should test if Heikki knows how to implement LRU properly so it does not have problem with large number.  We&#8217;ll see.</p>
    <hr noshade style="margin:0;height:1px" />
    <p>Entry posted by peter |
      <a href="http://www.mysqlperformanceblog.com/2009/11/16/table_cache-negative-scalability/#comments">13 comments</a></p>
    <p>Add to: <a href="http://del.icio.us/post?url=http://www.mysqlperformanceblog.com/2009/11/16/table_cache-negative-scalability/&amp;title=table_cache negative scalability" title="Bookmark this post on del.icio.us"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/delicious.png" alt="delicious" /></a> | <a href="http://digg.com/submit?phase=2&amp;url=http://www.mysqlperformanceblog.com/2009/11/16/table_cache-negative-scalability/&amp;title=table_cache negative scalability" title="Digg this post on Digg.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/digg.png" alt="digg" /></a> | <a href="http://reddit.com/submit?url=http://www.mysqlperformanceblog.com/2009/11/16/table_cache-negative-scalability/&amp;title=table_cache negative scalability" title="Submit this post on reddit.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/reddit.png" alt="reddit" /></a> | <a href="http://www.netscape.com/submit/?U=http://www.mysqlperformanceblog.com/2009/11/16/table_cache-negative-scalability/&amp;T=table_cache negative scalability" title="Vote for this article on Netscape"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/netscape.gif" alt="netscape" /></a> | <a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.mysqlperformanceblog.com/2009/11/16/table_cache-negative-scalability/&amp;title=table_cache negative scalability" title="Add to Google Bookmarks"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/google.png" alt="Google Bookmarks" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlperformanceblog.com/2009/11/16/table_cache-negative-scalability/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Quick comparison of MyISAM, Infobright, and MonetDB</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/29/quick-comparison-of-myisam-infobright-and-monetdb/</link>
		<comments>http://www.mysqlperformanceblog.com/2009/09/29/quick-comparison-of-myisam-infobright-and-monetdb/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 02:56:58 +0000</pubDate>
		<dc:creator>Baron Schwartz</dc:creator>
				<category><![CDATA[myisam]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[optimizer]]></category>
		<category><![CDATA[Infobright]]></category>
		<category><![CDATA[MonetDB]]></category>

		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1258</guid>
		<description><![CDATA[Recently I was doing a little work for a client who has MyISAM tables with many columns (the same one Peter wrote about recently).  The client's performance is suffering in part because of the number of columns, which is over 200.  The queries are generally pretty simple (sums of columns), but they're ad-hoc [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was doing a little work for a client who has MyISAM tables with many columns (the same one <a href="http://www.mysqlperformanceblog.com/2009/09/28/how-number-of-columns-affects-performance/">Peter wrote about recently</a>).  The client's performance is suffering in part because of the number of columns, which is over 200.  The queries are generally pretty simple (sums of columns), but they're ad-hoc (can access any columns) and it seems tailor-made for a column-oriented database.</p>
<p>I decided it was time to actually give <a href="http://www.infobright.org/">Infobright</a> a try.  They have an open-source community edition, which is crippled but not enough to matter for this test.  The "Knowledge Grid" architecture seems ideal for the types of queries the client runs.  But hey, why not also try <a href="http://monetdb.cwi.nl/">MonetDB</a>, another open-source column-oriented database I've been meaning to take a look at?</p>
<p>What follows is not a realistic benchmark, it's not scientific, it's just some quick and dirty tinkering.  I threw up an Ubuntu 9.04 small server on Amazon.  (I used this version because there's a .deb of MonetDB for it).  I created a table with 200 integer columns and loaded it with random numbers between 0 and 10000.  Initially I wanted to try with 4 million rows, but I had trouble with MonetDB -- there was not enough memory for this.  I didn't do anything fancy with the Amazon server -- I didn't fill up the /mnt disk to claim the bits, for example.  I used default tuning, out of the box, for all three databases.</p>
<p>The first thing I tried doing was loading the data with SQL statements.  I wanted to see how fast MyISAM vs. MonetDB would interpret really large INSERT statements, the kind produced by mysqldump.  But MonetDB choked and told me the number of columns mismatched.  I found reference to this on the mailing list, and skipped that.  I used LOAD DATA INFILE instead (MonetDB's version of that is COPY INTO).  This is the only way to get data into Infobright, anyway.</p>
<h3>The tests</h3>
<p>I loaded 1 million rows into the table.  Here's a graph of the times (smaller is better):</p>
<p><img class="alignnone size-full wp-image-1259" title="Load Time" src="http://www.mysqlperformanceblog.com/wp-content/uploads/2009/09/load_time.png" alt="Load Time" width="450" height="320" /></p>
<p>MyISAM took 88 seconds, MonetDB took 200, and Infobright took 486.  Here's the size of the resulting table on disk (smaller is better):</p>
<p><img src="http://www.mysqlperformanceblog.com/wp-content/uploads/2009/09/table_size_bytes.png" alt="Table Size in Bytes" title="Table Size in Bytes" width="450" height="320" class="alignnone size-full wp-image-1270" /></p>
<p>MyISAM is 787MB, MonetDB is 791MB, and Infobright is 317MB.  Next I ran three queries:</p>
<div class="igBar"><span id="lsql-2"><a href="#" onclick="javascript:showPlainTxt('sql-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-2">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">SELECT</span> sum<span style="color:#006600; font-weight:bold;">&#40;</span>c19<span style="color:#006600; font-weight:bold;">&#41;</span>, sum<span style="color:#006600; font-weight:bold;">&#40;</span>c89<span style="color:#006600; font-weight:bold;">&#41;</span>, sum<span style="color:#006600; font-weight:bold;">&#40;</span>c129<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> t;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">SELECT</span> sum<span style="color:#006600; font-weight:bold;">&#40;</span>c19<span style="color:#006600; font-weight:bold;">&#41;</span>, sum<span style="color:#006600; font-weight:bold;">&#40;</span>c89<span style="color:#006600; font-weight:bold;">&#41;</span>, sum<span style="color:#006600; font-weight:bold;">&#40;</span>c129<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> t <span style="color: #993333; font-weight: bold;">WHERE</span> c11&gt; <span style="color: #cc66cc;color:#800000;">5</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">SELECT</span> sum<span style="color:#006600; font-weight:bold;">&#40;</span>c19<span style="color:#006600; font-weight:bold;">&#41;</span>, sum<span style="color:#006600; font-weight:bold;">&#40;</span>c89<span style="color:#006600; font-weight:bold;">&#41;</span>, sum<span style="color:#006600; font-weight:bold;">&#40;</span>c129<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> t <span style="color: #993333; font-weight: bold;">WHERE</span> c11 &lt;<span style="color: #cc66cc;color:#800000;">5</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Graphs of query performance time for all three databases are really not very helpful, because MyISAM is so much slower that you can't see the graphs for the others.  So I'll give the numbers and then omit MyISAM from the graphs.  Here are the numbers for everything I measured:</p>
<table borders="1">
<thead>
<tr>
<td></td>
<th>myisam</th>
<th>monetdb</th>
<th>infobright</th>
</tr>
</thead>
<tr>
<th>size (bytes)    </th>
<td>826000000    </td>
<td>829946723</td>
<td>332497242</td>
</tr>
<tr>
<th>load time (seconds)    </th>
<td>88    </td>
<td>200    </td>
<td>486</td>
</tr>
<tr>
<th>query1 time    </th>
<td>3.4    </td>
<td>0.012    </td>
<td>0.0007</td>
</tr>
<tr>
<th>query2 time    </th>
<td>3.4    </td>
<td>0.15    </td>
<td>1.2</td>
</tr>
<tr>
<th>query3 time    </th>
<td>2.5    </td>
<td>0.076    </td>
<td>0.15</td>
</tr>
</table>
<p>And here is a graph of Infobright duking it out with MonetDB on the three queries I tested (shorter bar is better):</p>
<p><img src="http://www.mysqlperformanceblog.com/wp-content/uploads/2009/09/monetdb_infobright_query_time1.png" alt="MonetDB vs Infobright Query Time" title="MonetDB vs Infobright Query Time" width="492" height="320" class="alignnone size-full wp-image-1265" /></p>
<p>I ran each query a few times, discarded the first run, and averaged the next three together.</p>
<h3>Notes on Infobright</h3>
<p>A few miscellaneous notes: don't forget that Infobright is <em>not</em> just a storage engine plugged into MySQL.  It's a complete server with a different optimizer, etc.  This point was hammered home during the LOAD DATA INFILE, when I looked to see what was taking so long (I was tempted to use oprofile and see if there are sleep() statements).  What did I see in 'top' but a program called bhloader.  This bhloader program was the only thing doing anything; mysqld wasn't doing a thing.  LOAD DATA INFILE in Infobright isn't what it seems to be.  Otherwise, Infobright behaved about as I expected it to; it seemed pretty normal to a MySQL guy.</p>
<h3>Notes on MonetDB</h3>
<p>MonetDB was a bit different.  I had to be a bit resourceful to get everything going.  The documentation was for an old version, and was pretty sparse.  I had to go to the mailing lists to find the correct COPY syntax -- it wasn't that listed in the online manual.  And there were funny things like a "merovingian" process (think "angel") that had to be started before the server would start, and I had to destroy the demo database and recreate it before I could start it as shown in the tutorials.</p>
<p>MonetDB has some unexpected properties; it is not a regular RDBMS.  Still, I'm quite impressed by it in some ways.  For example, it seems quite nicely put together, and it's not at all hard to learn.</p>
<p>It doesn't really "speak SQL" -- it speaks relational algebra, and the SQL is just a front-end to it.  You can talk XQuery to it, too.  I'm not sure if you can talk dirty to it, but you can sure talk nerdy to it: you can, should you choose to, give it instructions in MonetDB Assembly Language (MAL), the underlying language.  An abstracted front-end is a great idea; MySQL abstracts the storage backend, but why not do both?  Last I checked, Drizzle is going this direction, hurrah!</p>
<p>EXPLAIN is enlightening and frightening!  You get to see the intermediate code from the compiler.  <a href="http://monetdb.cwi.nl/projects/monetdb/SQL/Documentation/EXPLAIN-Statement.html">The goggles, they do nothing!</a></p>
<p>From what I was able to learn about MonetDB in an hour, I believe it uses memory-mapped files to hold the data in-memory.  If this is true, it explains why I couldn't load 4 million rows into it (this was a 32-bit Amazon machine).</p>
<p>The SQL implementation is impressive.  It's a really solid subset of SQL:2003, much more than I expected.  It even has CTEs, although not recursive ones.  (No, there is no REPLACE, and there is no INSERT/ON DUPLICATE KEY UPDATE.)  I didn't try the XQuery interface.</p>
<p>Although I didn't try it out, there are what looks like pretty useful instrumentation interfaces for profiling, debugging and the like.  The query timer is in milliseconds (why doesn't mysql show query times in microseconds?  I had to resort to Perl + Time::HiRes for timing the Infobright queries).</p>
<p>I think it can be quite useful.  However, I'm not quite sure it's useful for "general-purpose" database use -- there are a number of limitations (concurrency, for one) and it looks like it's still fairly experimental.</p>
    <hr noshade style="margin:0;height:1px" />
    <p>Entry posted by Baron Schwartz |
      <a href="http://www.mysqlperformanceblog.com/2009/09/29/quick-comparison-of-myisam-infobright-and-monetdb/#comments">26 comments</a></p>
    <p>Add to: <a href="http://del.icio.us/post?url=http://www.mysqlperformanceblog.com/2009/09/29/quick-comparison-of-myisam-infobright-and-monetdb/&amp;title=Quick comparison of MyISAM, Infobright, and MonetDB" title="Bookmark this post on del.icio.us"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/delicious.png" alt="delicious" /></a> | <a href="http://digg.com/submit?phase=2&amp;url=http://www.mysqlperformanceblog.com/2009/09/29/quick-comparison-of-myisam-infobright-and-monetdb/&amp;title=Quick comparison of MyISAM, Infobright, and MonetDB" title="Digg this post on Digg.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/digg.png" alt="digg" /></a> | <a href="http://reddit.com/submit?url=http://www.mysqlperformanceblog.com/2009/09/29/quick-comparison-of-myisam-infobright-and-monetdb/&amp;title=Quick comparison of MyISAM, Infobright, and MonetDB" title="Submit this post on reddit.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/reddit.png" alt="reddit" /></a> | <a href="http://www.netscape.com/submit/?U=http://www.mysqlperformanceblog.com/2009/09/29/quick-comparison-of-myisam-infobright-and-monetdb/&amp;T=Quick comparison of MyISAM, Infobright, and MonetDB" title="Vote for this article on Netscape"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/netscape.gif" alt="netscape" /></a> | <a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.mysqlperformanceblog.com/2009/09/29/quick-comparison-of-myisam-infobright-and-monetdb/&amp;title=Quick comparison of MyISAM, Infobright, and MonetDB" title="Add to Google Bookmarks"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/google.png" alt="Google Bookmarks" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlperformanceblog.com/2009/09/29/quick-comparison-of-myisam-infobright-and-monetdb/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>How number of columns affects performance ?</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/28/how-number-of-columns-affects-performance/</link>
		<comments>http://www.mysqlperformanceblog.com/2009/09/28/how-number-of-columns-affects-performance/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 01:39:04 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[Innodb]]></category>
		<category><![CDATA[benchmarks]]></category>
		<category><![CDATA[myisam]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1244</guid>
		<description><![CDATA[It is pretty understood the tables which have long rows tend to be slower than tables with short rows.   I was interested to check if the row length is the only thing what matters or if number of columns we have to work with also have an important role.    I [...]]]></description>
			<content:encoded><![CDATA[<p>It is pretty understood the tables which have long rows tend to be slower than tables with short rows.   I was interested to check if the row length is the only thing what matters or if number of columns we have to work with also have an important role.    I was interested in peak row processing speed so I looked at full table scan in case data fits in OS cache completely.   I created 3 tables -  First containing single tinyint column which is almost shortest type possible (CHAR(0) could be taking less space),  table with 1 tinyint column and char(99) column and table with 100 tinyint columns.    The former two tables have the same row length but have number of column different 50 times. Finally I have created 4th table which is also 100 columns but one of them is VARCHAR causes raw format to be dynamic.</p>
<p>More specially:</p>
<div class="igBar"><span id="lsql-9"><a href="#" onclick="javascript:showPlainTxt('sql-9'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-9">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`t1`</span> <span style="color:#006600; font-weight:bold;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`t1`</span> tinyint<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#41;</span> ENGINE=MyISAM <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET=latin1 </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<div class="igBar"><span id="lsql-10"><a href="#" onclick="javascript:showPlainTxt('sql-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-10">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`t1c99`</span> <span style="color:#006600; font-weight:bold;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`t1`</span> tinyint<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`c99`</span> char<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">99</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#41;</span> ENGINE=MyISAM <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET=latin1 </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<div class="igBar"><span id="lsql-11"><a href="#" onclick="javascript:showPlainTxt('sql-11'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-11">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`t100`</span> <span style="color:#006600; font-weight:bold;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`t1`</span> tinyint<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`t2`</span> tinyint<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">...</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`t99`</span> tinyint<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`t100`</span> tinyint<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#41;</span> ENGINE=MyISAM <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET=latin1 </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<div class="igBar"><span id="lsql-12"><a href="#" onclick="javascript:showPlainTxt('sql-12'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-12">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`t99v1`</span> <span style="color:#006600; font-weight:bold;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`t1`</span> tinyint<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`t2`</span> tinyint<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">...</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`t99`</span> tinyint<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`v1`</span> varchar<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#41;</span> ENGINE=MyISAM <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET=latin1 </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>I populated each of the tables with 12M rows. Getting  7 bytes row size for first table  and 101 byte for second and third.<br />
I used simple scan query: <strong>select max(t1) from t100;</strong>  for the test.</p>
<p>The result was as follows:<br />
t1            -   1.00 sec      (12M rows/sec  ;  80MB/sec)<br />
t1c99       -   1.71 sec      (7M rows/sec ;    676MB/sec)<br />
t100        -   1.77 sec      (7M rows/sec ;    653MB/sec)<br />
t99v1       -  12.36 sec      (1M rows/sec  ;   93MB/sec)</p>
<p>This shows there is surely the problem with dynamic row format table with many columns.   But is it because of large number of columns or dynamic format on its own is slave ?<br />
I have tested yet another table structure:</p>
<div class="igBar"><span id="lsql-13"><a href="#" onclick="javascript:showPlainTxt('sql-13'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-13">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`t1v1`</span> <span style="color:#006600; font-weight:bold;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`t1`</span> tinyint<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`v`</span> varchar<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#41;</span> ENGINE=MyISAM <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET=latin1 </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This table has row length of 20 (which was a bit of surprise to me) and it has:</p>
<p>t1v1           - 1.83 sec  (6.5M rows/sec;  125M/sec)</p>
<p>So there is surely the penalty for dynamic rows, however it is not very significant if number of columns is small.   For large number of columns dynamic rows become very expensive and you have to watch out.<br />
I have not looked at the code and would appreciate any developers comments but I guess for dynamic rows tables certain conversion has to take place when internal data structures are populated (everything but TEXTs/BLOBs  is fixed length when it is being processed).   This conversion process depends on number of columns while for fixed rows the MyISAM storage format matches internal one so you can basically do memory copy which does not depends on number of columns. </p>
<p>Another interesting observation  is access speed to different columns.    the max(t1) and max(t99) were taking the same time which means there is no penalty for accessing column which is in the end of the table rather than at the start when it comes to MyISAM.</p>
<p>The common workaround working with such wide tables is to use covering indexes.  I added one to t99v1 table  and repeated the query:</p>
<div class="igBar"><span id="lsql-14"><a href="#" onclick="javascript:showPlainTxt('sql-14'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-14">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql <span style="color:#006600; font-weight:bold;">&#91;</span>localhost<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>msandbox<span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#40;</span>test<span style="color:#006600; font-weight:bold;">&#41;</span>&gt; <span style="color: #993333; font-weight: bold;">SELECT</span> max<span style="color:#006600; font-weight:bold;">&#40;</span>t1+<span style="color: #cc66cc;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> t99v1;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-----------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| max<span style="color:#006600; font-weight:bold;">&#40;</span>t1+<span style="color: #cc66cc;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-----------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">0</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-----------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">1</span> row <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">3</span>.<span style="color: #cc66cc;color:#800000;">26</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql <span style="color:#006600; font-weight:bold;">&#91;</span>localhost<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>msandbox<span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#40;</span>test<span style="color:#006600; font-weight:bold;">&#41;</span>&gt; <span style="color: #993333; font-weight: bold;">EXPLAIN</span> <span style="color: #993333; font-weight: bold;">SELECT</span> max<span style="color:#006600; font-weight:bold;">&#40;</span>t1+<span style="color: #cc66cc;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> t99v1;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">----+-------------+-------+-------+---------------+------+---------+------+----------+-------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| id | select_type | <span style="color: #993333; font-weight: bold;">TABLE</span> | type&nbsp; | possible_keys | <span style="color: #993333; font-weight: bold;">KEY</span>&nbsp; | key_len | ref&nbsp; | rows&nbsp; &nbsp; &nbsp;| Extra&nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">----+-------------+-------+-------+---------------+------+---------+------+----------+-------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">|&nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | SIMPLE&nbsp; &nbsp; &nbsp; | t99v1 | <span style="color: #993333; font-weight: bold;">INDEX</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | t1&nbsp; &nbsp;| <span style="color: #cc66cc;color:#800000;">1</span>&nbsp; &nbsp; &nbsp; &nbsp;| <span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #cc66cc;color:#800000;">12000000</span> | <span style="color: #993333; font-weight: bold;">USING</span> <span style="color: #993333; font-weight: bold;">INDEX</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">----+-------------+-------+-------+---------------+------+---------+------+----------+-------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">1</span> row <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>As you can see the index scan is not as fast as table scan scanning about 3.7M rows/sec but which is still pretty fast. </p>
<p>So this is all about MyISAM, what is about Innodb ?  Here are results for Innodb with all data in buffer pool, to measure peak speed as well</p>
<p>The results for Innodb were:<br />
t1                          -    5.11 sec      (2.3M rows/sec)<br />
t1c99                     -    5.74 sec      (2.1M rows/sec)<br />
t100                       -   15.16 sec     (0.8M rows/sec)<br />
t99v1                      -  14.93 sec      (0.8M rows/sec)<br />
t1v1                        -  5.26 sec       (2.3M rows/sec)<br />
t99v1 (covering idx)   -  5.62 sec       (2.1M rows/sec)</p>
<p>As you can see Innodb is a lot slower and has behavior similar to Dynamic Row tables in both cases.  This is because Innodb does not store data in native MyISAM format and conversion is needed in all cases. We can also see the table scan speed can be up to 5 times slower, for very short rows - some of this goes back to the fact Innodb rows have a lot of transaction control overhead attached to them.</p>
<p>Also note the covering index scan speed is very similar to full table scan speed - this is rather expected as table data is stored in BTREE index  very similarly to how indexes are stored. </p>
<p><strong>Summary:</strong>  Beware of dynamic row format tables with many columns they might bite you with surprise slowdown.   MyISAM is much faster than Innodb when it comes to in memory full table scan. </p>
<p>P.S Tests were done on MySQL 5.4.2  on Intel(R) Xeon(R) CPU           E5405  @ 2.00GHz CPU. </p>
    <hr noshade style="margin:0;height:1px" />
    <p>Entry posted by peter |
      <a href="http://www.mysqlperformanceblog.com/2009/09/28/how-number-of-columns-affects-performance/#comments">9 comments</a></p>
    <p>Add to: <a href="http://del.icio.us/post?url=http://www.mysqlperformanceblog.com/2009/09/28/how-number-of-columns-affects-performance/&amp;title=How number of columns affects performance ?" title="Bookmark this post on del.icio.us"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/delicious.png" alt="delicious" /></a> | <a href="http://digg.com/submit?phase=2&amp;url=http://www.mysqlperformanceblog.com/2009/09/28/how-number-of-columns-affects-performance/&amp;title=How number of columns affects performance ?" title="Digg this post on Digg.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/digg.png" alt="digg" /></a> | <a href="http://reddit.com/submit?url=http://www.mysqlperformanceblog.com/2009/09/28/how-number-of-columns-affects-performance/&amp;title=How number of columns affects performance ?" title="Submit this post on reddit.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/reddit.png" alt="reddit" /></a> | <a href="http://www.netscape.com/submit/?U=http://www.mysqlperformanceblog.com/2009/09/28/how-number-of-columns-affects-performance/&amp;T=How number of columns affects performance ?" title="Vote for this article on Netscape"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/netscape.gif" alt="netscape" /></a> | <a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.mysqlperformanceblog.com/2009/09/28/how-number-of-columns-affects-performance/&amp;title=How number of columns affects performance ?" title="Add to Google Bookmarks"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/google.png" alt="Google Bookmarks" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlperformanceblog.com/2009/09/28/how-number-of-columns-affects-performance/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>What to do with MySQL Full Text Search while migrating to Innodb ?</title>
		<link>http://www.mysqlperformanceblog.com/2009/09/10/what-to-do-with-mysql-full-text-search-while-migrating-to-innodb/</link>
		<comments>http://www.mysqlperformanceblog.com/2009/09/10/what-to-do-with-mysql-full-text-search-while-migrating-to-innodb/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 20:45:19 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[Innodb]]></category>
		<category><![CDATA[myisam]]></category>

		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=1093</guid>
		<description><![CDATA[It is rather typical for systems to start as MyISAM but  as system growths to move to Innodb.    The reason of the move could be just desire for better data consistency guaranty or being bitten repairing multiple GB MyISAM table few times, though Table Locks is probably the most important issue [...]]]></description>
			<content:encoded><![CDATA[<p>It is rather typical for systems to start as MyISAM but  as system growths to <a href="http://www.mysqlperformanceblog.com/2009/01/12/should-you-move-from-myisam-to-innodb/">move to Innodb</a>.    The reason of the move could be just desire for better data consistency guaranty or being bitten repairing multiple GB MyISAM table few times, though Table Locks is probably the most important issue -  with modern multi core servers not only the fact you can't well mix SELECTs and UPDATEs but also the fact only one update can be happening at the time can be the problem, not to mention <a href="http://www.mysqlperformanceblog.com/2008/08/12/beware-of-myisam-key-cache-mutex-contention/">Key Cache</a> which  often becomes serious contention issue.</p>
<p>The problem we often run into during migration is Full Text Search indexes which are not supported for Innodb tables. So what can you do ? </p>
<p><strong>Leave Tables as MyISAM</strong>  The beauty of MySQL storage engines is you do not have to convert all tables at once.  In some cases full text search is used on secondary small tables which do not cause problems with contention or anything else. So this can be valid choice.  Unfortunately in many cases the tables you want to do full text search on  are intensively used and this may not be the option.</p>
<p><strong>Use MyISAM Slaves</strong>   In some cases it may be justified to keep table as MyISAM on one or several of slaves and use it for full text search queries. This approach is helpful if migration has to be performed very quickly and it takes a lot of time to implement any significant changes to schema or queries.    In general cross storage engine replication is not my favorite approach but sometimes it is less of the evils.</p>
<p><strong>Use "Shadow" MyISAM Table</strong>   You can keep main data in Innodb but build a "shadow" MyISAM table which is used for full text search. In certain cases you can just use MySQL triggers to maintain such table, in other cases this would not work as this would add a lot of contention on the writes. In this case you can just rebuild the table from Innodb source on regular basics.  In case you can afford to have stale data in search results it can work pretty well.</p>
<p><strong>Use Sphinx or other external full text search engine</strong>   This is what we use a lot especially if performance of full text search is an issue to.  This eliminates the need to have MyISAM table anywhere. We use <a href="http://www.sphinxsearch.com">Sphinx</a> in a lot of cases as it is very easy to get going.  For simple applications it often takes just couple of hours to get the full text search running Sphinx instead of build in full text search.</p>
    <hr noshade style="margin:0;height:1px" />
    <p>Entry posted by peter |
      <a href="http://www.mysqlperformanceblog.com/2009/09/10/what-to-do-with-mysql-full-text-search-while-migrating-to-innodb/#comments">9 comments</a></p>
    <p>Add to: <a href="http://del.icio.us/post?url=http://www.mysqlperformanceblog.com/2009/09/10/what-to-do-with-mysql-full-text-search-while-migrating-to-innodb/&amp;title=What to do with MySQL Full Text Search while migrating to Innodb ?" title="Bookmark this post on del.icio.us"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/delicious.png" alt="delicious" /></a> | <a href="http://digg.com/submit?phase=2&amp;url=http://www.mysqlperformanceblog.com/2009/09/10/what-to-do-with-mysql-full-text-search-while-migrating-to-innodb/&amp;title=What to do with MySQL Full Text Search while migrating to Innodb ?" title="Digg this post on Digg.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/digg.png" alt="digg" /></a> | <a href="http://reddit.com/submit?url=http://www.mysqlperformanceblog.com/2009/09/10/what-to-do-with-mysql-full-text-search-while-migrating-to-innodb/&amp;title=What to do with MySQL Full Text Search while migrating to Innodb ?" title="Submit this post on reddit.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/reddit.png" alt="reddit" /></a> | <a href="http://www.netscape.com/submit/?U=http://www.mysqlperformanceblog.com/2009/09/10/what-to-do-with-mysql-full-text-search-while-migrating-to-innodb/&amp;T=What to do with MySQL Full Text Search while migrating to Innodb ?" title="Vote for this article on Netscape"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/netscape.gif" alt="netscape" /></a> | <a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.mysqlperformanceblog.com/2009/09/10/what-to-do-with-mysql-full-text-search-while-migrating-to-innodb/&amp;title=What to do with MySQL Full Text Search while migrating to Innodb ?" title="Add to Google Bookmarks"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/google.png" alt="Google Bookmarks" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlperformanceblog.com/2009/09/10/what-to-do-with-mysql-full-text-search-while-migrating-to-innodb/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Getting annoyed with MyISAM multiple key caches.</title>
		<link>http://www.mysqlperformanceblog.com/2009/05/01/getting-annoyed-with-myisam-multiple-key-caches/</link>
		<comments>http://www.mysqlperformanceblog.com/2009/05/01/getting-annoyed-with-myisam-multiple-key-caches/#comments</comments>
		<pubDate>Sat, 02 May 2009 03:27:02 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[myisam]]></category>

		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=679</guid>
		<description><![CDATA[As I've wrote few times using multiple key caches is a great way to get CPU scalability if you're using MyISAM.  It is however very annoying -  this feature really looks half baked to me.  
The problem with multiple key caches and mapping of tables to the different files is - there [...]]]></description>
			<content:encoded><![CDATA[<p>As I've <a href="http://www.mysqlperformanceblog.com/2008/11/26/using-multiple-key-caches-for-myisam-scalability/">wrote</a> few times using multiple key caches is a great way to get CPU scalability if you're using MyISAM.  It is however very annoying -  this feature really looks half baked to me.  </p>
<p>The problem with multiple key caches and mapping of tables to the different files is - there is no way to see the existing key caches, their mapping and stats.  The only thing you can access is key cache parameters - via <a href="http://dev.mysql.com/doc/refman/6.0/en/structured-system-variables.html">structured variables</a></p>
<p>In particular I would like to:</p>
<p><strong>See the list of created caches</strong>  Right now I can create key caches with random names causing invisible resource consumption.  It is possible to make an error in key cache creation but it is not possible to later find out such key cache exists.  This in my opinion violates fundamental design principle - if you can create something you should be able to also list what you have created.</p>
<p><strong>See the mappings </strong>  I can now map tables to be cached in different key caches but there is no way to see the current mappings or to see where each given table is cached.</p>
<p><strong>See other key cache stats </strong>  To tune the caches I need to see number of accesses, blocks used, number of misses.  Such basic feature either does not exist or is not documented. </p>
<p>I'm not sure how relevant is MyISAM with MariaDB on a way but this is surely sad to see the feature of multiple key caches first introduced in MySQL 4.1 was newer quite polished in terms of usability.</p>
    <hr noshade style="margin:0;height:1px" />
    <p>Entry posted by peter |
      <a href="http://www.mysqlperformanceblog.com/2009/05/01/getting-annoyed-with-myisam-multiple-key-caches/#comments">10 comments</a></p>
    <p>Add to: <a href="http://del.icio.us/post?url=http://www.mysqlperformanceblog.com/2009/05/01/getting-annoyed-with-myisam-multiple-key-caches/&amp;title=Getting annoyed with MyISAM multiple key caches." title="Bookmark this post on del.icio.us"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/delicious.png" alt="delicious" /></a> | <a href="http://digg.com/submit?phase=2&amp;url=http://www.mysqlperformanceblog.com/2009/05/01/getting-annoyed-with-myisam-multiple-key-caches/&amp;title=Getting annoyed with MyISAM multiple key caches." title="Digg this post on Digg.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/digg.png" alt="digg" /></a> | <a href="http://reddit.com/submit?url=http://www.mysqlperformanceblog.com/2009/05/01/getting-annoyed-with-myisam-multiple-key-caches/&amp;title=Getting annoyed with MyISAM multiple key caches." title="Submit this post on reddit.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/reddit.png" alt="reddit" /></a> | <a href="http://www.netscape.com/submit/?U=http://www.mysqlperformanceblog.com/2009/05/01/getting-annoyed-with-myisam-multiple-key-caches/&amp;T=Getting annoyed with MyISAM multiple key caches." title="Vote for this article on Netscape"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/netscape.gif" alt="netscape" /></a> | <a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.mysqlperformanceblog.com/2009/05/01/getting-annoyed-with-myisam-multiple-key-caches/&amp;title=Getting annoyed with MyISAM multiple key caches." title="Add to Google Bookmarks"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/google.png" alt="Google Bookmarks" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlperformanceblog.com/2009/05/01/getting-annoyed-with-myisam-multiple-key-caches/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Should you move from MyISAM to Innodb ?</title>
		<link>http://www.mysqlperformanceblog.com/2009/01/12/should-you-move-from-myisam-to-innodb/</link>
		<comments>http://www.mysqlperformanceblog.com/2009/01/12/should-you-move-from-myisam-to-innodb/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 20:49:56 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[Innodb]]></category>
		<category><![CDATA[myisam]]></category>
		<category><![CDATA[production]]></category>

		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=586</guid>
		<description><![CDATA[There is significant portion of customers which are still using MyISAM when they come to us, so one of the big questions is when it is feasible to move to Innodb and when staying on MyISAM is preferred ?
I generally prefer to see Innodb as the main storage engine because it makes life much simpler [...]]]></description>
			<content:encoded><![CDATA[<p>There is significant portion of customers which are still using MyISAM when they come to us, so one of the big questions is when it is feasible to move to Innodb and when staying on MyISAM is preferred ?</p>
<p>I generally prefer to see Innodb as the main storage engine because it makes life much simpler in the end for most users - you do not get to deal with recovering tables on the crash or partially  executed statements.  Table locks is no more problem,  hot backups are easy, though there are some important things which we have to consider on case by case basics before recommending the move. </p>
<p><strong>Is MyISAM used as default or as a choice ? </strong>  This is the most important question to ask upfront.  Sometimes MyISAM is there just because it is default, in other cases this is deliberate choice with system being optimized to deal with MyISAM limits, for example there is a dedicated slave available for all long reporting queries.   In case MyISAM was chosen not just happened to be it is important to build the good argument to suggest Innodb.</p>
<p><strong>Application Readiness</strong>  Application should be ready to work with Innodb, for example be ready to deal with deadlocks which can happen with Innodb even if you do not use transactions, but which are not existent with MyISAM.     QA has to be performed as part of the move.</p>
<p><strong>Performance</strong>  Innodb has a lot to offer in terms of performance - Performance benefits and drawbacks.  On the benefits side we usually see clustering by primary key, caching data, higher concurrency,  background flushes while on the drawbacks side we see significantly large table size (especially if data size is close to memory size),  generally slower writes, slower blob handling, concurrency issues, problems dealing with very large number of tables, slow data load and ALTER TABLE and others.  Another big one is COUNT(*)  without where clause which is often the show stopper for them move until it is worked around.</p>
<p><strong>Operations</strong>   What is good for MyISAM kills Innodb,  such as copying binary tables between the servers.   It is important the team understands Innodb and knows how to handle it, or be able to learn it.  It is also important to adjust processes as required to work with Innodb.  For example binary copy of one of the databases from the Slave to the dev envinronment works great for MyISAM but does not work with Innodb.   Backup tools like "mysqlhotcopy" does not work etc.  Note Performance also affects Operations aspects a lot - for example using mysqldump as a backup may well work for MyISAM but will start taking way too much time to do restore for Innodb.  On large scale installations mysqldump does not work anyway but it may still work for you when you're running MyISAM but instantly break upon upgrading to Innodb.</p>
<p><strong>Features</strong>  The MyISAM features which forbid moving to Innodb are typically Full Text Search and RTREE indexes/GIS with Full Text  being much more common.     There are workarounds for both of them, including dedicated MyISAM slave or shadow table but it is important to consider them.</p>
<p><strong>How about Mixing Storage Engines ?</strong>  Sure you can mix storage engines but I suggest you doing is wisely.  It complicates operations tasks (backups, balancing, performance analyzes)  as well as it exercises not so common paths in the MySQL server - in particular Optimizer may have harder time because costs between storage engines may not be well balanced or replication of mixed table types which is quite complicated. </p>
<p>I prefer to pick one storage engine (typically Innodb) and when use other tables when it really gives substantial gains.  I would not switch table to MyISAM because it gives 5% performance improvement but I can perfectly use MyISAM (or Archive) for logging.</p>
<p><strong>Innodb Needs Tuning</strong>  As a final note about MyISAM to Innodb migration  I should mention about Innodb tuning.  Innodb needs tuning. Really.  MyISAM for many applications can work well with defaults.  I've seen hundreds of GB databases ran with MyISAM with default  settings and it worked reasonably.  Innodb needs resources and it will not work well with defaults a lot.   Tuning MyISAM from defaults rarely gives more than 2-3 times gain while it can be as much as 10-50 times for Innodb tables in particular for write intensive workloads.  Check <a href="http://www.mysqlperformanceblog.com/2007/11/01/innodb-performance-optimization-basics/">here</a> for details.</p>
<p><strong>Note:</strong>  As Few people questioned me, I indeed forgot to clarify the scope here - I'm mainly speaking about OLTP/ Traditional web applications.  for Analytics things are a lot different.</p>
    <hr noshade style="margin:0;height:1px" />
    <p>Entry posted by peter |
      <a href="http://www.mysqlperformanceblog.com/2009/01/12/should-you-move-from-myisam-to-innodb/#comments">34 comments</a></p>
    <p>Add to: <a href="http://del.icio.us/post?url=http://www.mysqlperformanceblog.com/2009/01/12/should-you-move-from-myisam-to-innodb/&amp;title=Should you move from MyISAM to Innodb ?" title="Bookmark this post on del.icio.us"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/delicious.png" alt="delicious" /></a> | <a href="http://digg.com/submit?phase=2&amp;url=http://www.mysqlperformanceblog.com/2009/01/12/should-you-move-from-myisam-to-innodb/&amp;title=Should you move from MyISAM to Innodb ?" title="Digg this post on Digg.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/digg.png" alt="digg" /></a> | <a href="http://reddit.com/submit?url=http://www.mysqlperformanceblog.com/2009/01/12/should-you-move-from-myisam-to-innodb/&amp;title=Should you move from MyISAM to Innodb ?" title="Submit this post on reddit.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/reddit.png" alt="reddit" /></a> | <a href="http://www.netscape.com/submit/?U=http://www.mysqlperformanceblog.com/2009/01/12/should-you-move-from-myisam-to-innodb/&amp;T=Should you move from MyISAM to Innodb ?" title="Vote for this article on Netscape"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/netscape.gif" alt="netscape" /></a> | <a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.mysqlperformanceblog.com/2009/01/12/should-you-move-from-myisam-to-innodb/&amp;title=Should you move from MyISAM to Innodb ?" title="Add to Google Bookmarks"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/google.png" alt="Google Bookmarks" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlperformanceblog.com/2009/01/12/should-you-move-from-myisam-to-innodb/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>Recovering CREATE TABLE statement from .frm file</title>
		<link>http://www.mysqlperformanceblog.com/2008/12/17/recovering-create-table-statement-from-frm-file/</link>
		<comments>http://www.mysqlperformanceblog.com/2008/12/17/recovering-create-table-statement-from-frm-file/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 00:22:13 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[Innodb]]></category>
		<category><![CDATA[myisam]]></category>
		<category><![CDATA[production]]></category>

		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=565</guid>
		<description><![CDATA[So lets say you have .frm file for the table and you need to recover CREATE TABLE statement for this table.  In particular when we do  Innodb Recovery we often get .frm files and some mess in the Innodb tablespace from which we have to get data from.    Of course [...]]]></description>
			<content:encoded><![CDATA[<p>So lets say you have .frm file for the table and you need to recover CREATE TABLE statement for this table.  In particular when we do  <a href="http://www.percona.com/services/data-recovery-services-mysql.html">Innodb Recovery</a> we often get .frm files and some mess in the Innodb tablespace from which we have to get data from.    Of course we could relay on old backups (and we do ask for them for a different reason anyway) but there is never guaranty there were no schema changes in between.</p>
<p>So how to recover CREATE TABLE from .frm file ?</p>
<p><strong>Recovering from .frm for Innodb Table</strong></p>
<p>If we simply copy .frm file back to the database we will see the following MySQL creative error message:</p>
<div class="igBar"><span id="lsql-19"><a href="#" onclick="javascript:showPlainTxt('sql-19'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-19">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">TABLES</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">----------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| Tables_in_test |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">----------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| queue&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| test_innodb&nbsp; &nbsp; |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">----------------+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">2</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> test_innodb;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ERROR <span style="color: #cc66cc;color:#800000;">1146</span> <span style="color:#006600; font-weight:bold;">&#40;</span>42S02<span style="color:#006600; font-weight:bold;">&#41;</span>: <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">'test.test_innodb'</span> doesn<span style="color: #ff0000;">'t exist </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>With more elaborate details in error log:</p>
<blockquote><p>
081217 15:59:11 [ERROR] Cannot find or open table test/test_innodb from<br />
the internal data dictionary of InnoDB though the .frm file for the<br />
table exists. Maybe you have deleted and recreated InnoDB data<br />
files but have forgotten to delete the corresponding .frm files<br />
of InnoDB tables, or you have moved .frm files to another database?<br />
or, the table contains indexes that this version of the engine<br />
doesn't support.<br />
See http://dev.mysql.com/doc/refman/5.1/en/innodb-troubleshooting.html<br />
how you can resolve the problem.
</p></blockquote>
<p>I would much rather see MySQL to report some more reasonable error message, something like Storage Engine could not open table or something like it. </p>
<p>So what we can do is to make sure Innodb has something in its data dictionary so it allows MySQL to succeed displaying .frm file contents:</p>
<blockquote><p>
mysql> create table test_innodb(i int) engine=innodb;<br />
Query OK, 0 rows affected (0.06 sec)</p>
<p>mysql> Aborted<br />
[root@test3 test]# cp /tmp/test_innodb.frm .<br />
cp: overwrite `./test_innodb.frm'? y<br />
[root@test3 test]# mysql test;<br />
Reading table information for completion of table and column names<br />
You can turn off this feature to get a quicker startup with -A</p>
<p>Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 17<br />
Server version: 5.1.30-community-log MySQL Community Server (GPL)</p>
<p>Type 'help;' or '\h' for help. Type '\c' to clear the buffer.</p>
<p>mysql> show create table test_innodb;<br />
+-------------+----------------------------------------------------------------------------------------------------------------------------+<br />
| Table       | Create Table                                                                                                               |<br />
+-------------+----------------------------------------------------------------------------------------------------------------------------+<br />
| test_innodb | CREATE TABLE `test_innodb` (<br />
  `a` int(11) DEFAULT NULL,<br />
  `b` int(11) DEFAULT NULL<br />
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |<br />
+-------------+----------------------------------------------------------------------------------------------------------------------------+<br />
1 row in set (0.00 sec)
</p></blockquote>
<p>Note:  I have created the table which have a different definition from original table.  It is good enough to get SHOW CREATE TABLE but do not try to use it any other way, as nasty things may happen:</p>
<div class="igBar"><span id="lsql-20"><a href="#" onclick="javascript:showPlainTxt('sql-20'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-20">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> test_innodb <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">1</span>,<span style="color: #cc66cc;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">1</span> row affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SELECT</span> * <span style="color: #993333; font-weight: bold;">FROM</span> test_innodb;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ERROR <span style="color: #cc66cc;color:#800000;">2013</span> <span style="color:#006600; font-weight:bold;">&#40;</span>HY000<span style="color:#006600; font-weight:bold;">&#41;</span>: Lost connection <span style="color: #993333; font-weight: bold;">TO</span> MySQL server during query </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><strong>Recovering CREATE TABLE from  .frm file for MyISAM Table</strong></p>
<p>We do not really need this that frequently but I decided to cover this for completeness anyway.</p>
<p>With MyISAM table MySQL comes with another creative error message if .frm is the only file which exists:</p>
<div class="igBar"><span id="lsql-21"><a href="#" onclick="javascript:showPlainTxt('sql-21'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-21">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> test_myisam;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ERROR <span style="color: #cc66cc;color:#800000;">1017</span> <span style="color:#006600; font-weight:bold;">&#40;</span>HY000<span style="color:#006600; font-weight:bold;">&#41;</span>: Can<span style="color: #ff0000;">'t find file: '</span>test_myisam<span style="color: #ff0000;">' (errno: 2) </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This is closer to the truth though file name is wrong - there should be  test_myisam.MYI or test_myisam.MYD  in the error message.  The file with name "test_myisam"  does not need to be exist.</p>
<p>The intuitive way to rebuild MyISAM table would be <strong>REPAIR TABLE test_myisam USE_FRM</strong>, however it does not work... just yet. </p>
<p>You need to create the .MYI and .MYD files for the table to make it work:</p>
<blockquote><p>
[root@test3 test]# touch test_myisam.MYI<br />
[root@test3 test]# touch test_myisam.MYD<br />
[root@test3 test]# chown mysql:mysql *
</p></blockquote>
<div class="igBar"><span id="lsql-22"><a href="#" onclick="javascript:showPlainTxt('sql-22'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-22">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; repair <span style="color: #993333; font-weight: bold;">TABLE</span> test_myisam USE_FRM;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">------------------+--------+----------+----------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #993333; font-weight: bold;">TABLE</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Op&nbsp; &nbsp; &nbsp;| Msg_type | Msg_text |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">------------------+--------+----------+----------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| test.test_myisam | repair | <span style="color: #993333; font-weight: bold;">STATUS</span>&nbsp; &nbsp;| OK&nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">------------------+--------+----------+----------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">1</span> row <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> test_myisam;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-------------+----------------------------------------------------------------------------------------------------------------------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #993333; font-weight: bold;">TABLE</span>&nbsp; &nbsp; &nbsp; &nbsp;| <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-------------+----------------------------------------------------------------------------------------------------------------------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| test_myisam | <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`test_myisam`</span> <span style="color:#006600; font-weight:bold;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`a`</span> int<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">11</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`b`</span> int<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">11</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#41;</span> ENGINE=MyISAM <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET=latin1 |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-------------+----------------------------------------------------------------------------------------------------------------------------+ </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>So it is not at all that complicated.</p>
    <hr noshade style="margin:0;height:1px" />
    <p>Entry posted by peter |
      <a href="http://www.mysqlperformanceblog.com/2008/12/17/recovering-create-table-statement-from-frm-file/#comments">2 comments</a></p>
    <p>Add to: <a href="http://del.icio.us/post?url=http://www.mysqlperformanceblog.com/2008/12/17/recovering-create-table-statement-from-frm-file/&amp;title=Recovering CREATE TABLE statement from .frm file" title="Bookmark this post on del.icio.us"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/delicious.png" alt="delicious" /></a> | <a href="http://digg.com/submit?phase=2&amp;url=http://www.mysqlperformanceblog.com/2008/12/17/recovering-create-table-statement-from-frm-file/&amp;title=Recovering CREATE TABLE statement from .frm file" title="Digg this post on Digg.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/digg.png" alt="digg" /></a> | <a href="http://reddit.com/submit?url=http://www.mysqlperformanceblog.com/2008/12/17/recovering-create-table-statement-from-frm-file/&amp;title=Recovering CREATE TABLE statement from .frm file" title="Submit this post on reddit.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/reddit.png" alt="reddit" /></a> | <a href="http://www.netscape.com/submit/?U=http://www.mysqlperformanceblog.com/2008/12/17/recovering-create-table-statement-from-frm-file/&amp;T=Recovering CREATE TABLE statement from .frm file" title="Vote for this article on Netscape"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/netscape.gif" alt="netscape" /></a> | <a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.mysqlperformanceblog.com/2008/12/17/recovering-create-table-statement-from-frm-file/&amp;title=Recovering CREATE TABLE statement from .frm file" title="Add to Google Bookmarks"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/google.png" alt="Google Bookmarks" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlperformanceblog.com/2008/12/17/recovering-create-table-statement-from-frm-file/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>AUTO_INCREMENT and MERGE TABLES</title>
		<link>http://www.mysqlperformanceblog.com/2008/09/11/auto_increment-and-merge-tables/</link>
		<comments>http://www.mysqlperformanceblog.com/2008/09/11/auto_increment-and-merge-tables/#comments</comments>
		<pubDate>Fri, 12 Sep 2008 00:15:59 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[bugs]]></category>
		<category><![CDATA[myisam]]></category>

		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=498</guid>
		<description><![CDATA[How would you expect AUTO_INCREMENT to work with MERGE tables ?  Assuming INSERT_METHOD=LAST is used I would expect it to work same as in case insertion happens to the last table... which does not seems to be the case.  Alternatively I would expect AUTO_INCREMENT to be based off the maximum value across all [...]]]></description>
			<content:encoded><![CDATA[<p>How would you expect <strong>AUTO_INCREMENT</strong> to work with <strong>MERGE</strong> tables ?  Assuming INSERT_METHOD=LAST is used I would expect it to work same as in case insertion happens to the last table... which does not seems to be the case.  Alternatively I would expect AUTO_INCREMENT to be based off the maximum value across all tables, respecting AUTO_INCREMENT set for the Merge Table itself.    Neither of these expectations really true:</p>
<div class="igBar"><span id="lsql-28"><a href="#" onclick="javascript:showPlainTxt('sql-28'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-28">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> a1<span style="color:#006600; font-weight:bold;">&#40;</span>i int <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">0</span> rows affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">01</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> a2 <span style="color: #993333; font-weight: bold;">LIKE</span> a1;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">0</span> rows affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> a1 <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">1</span> row affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> a2 <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">1</span> row affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> am<span style="color:#006600; font-weight:bold;">&#40;</span>i int <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color:#006600; font-weight:bold;">&#41;</span> type=merge union<span style="color:#006600; font-weight:bold;">&#40;</span>a1,a2<span style="color:#006600; font-weight:bold;">&#41;</span> insert_method=last;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">0</span> rows affected, <span style="color: #cc66cc;color:#800000;">1</span> warning <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> am <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">1</span> row affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SELECT</span> * <span style="color: #993333; font-weight: bold;">FROM</span> am;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| i |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">1</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">2</span> |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">3</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">3</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>So you can see merge table behaves quite smart.  Even though the maximum value in table a2 was 1 it finds out what other subtable  had value 2 and assigns the value 3 to the new row.</p>
<p>Let us see how stable merge table auto_increment values are by truncating the table we just inserted data to:</p>
<div class="igBar"><span id="lsql-29"><a href="#" onclick="javascript:showPlainTxt('sql-29'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-29">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">TRUNCATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> a2;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ERROR <span style="color: #cc66cc;color:#800000;">1105</span> <span style="color:#006600; font-weight:bold;">&#40;</span>HY000<span style="color:#006600; font-weight:bold;">&#41;</span>: MyISAM <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">'a2'</span> <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">USE</span> <span style="color:#006600; font-weight:bold;">&#40;</span>most likely <span style="color: #993333; font-weight: bold;">BY</span> a MERGE <span style="color: #993333; font-weight: bold;">TABLE</span><span style="color:#006600; font-weight:bold;">&#41;</span>. Try <span style="color: #993333; font-weight: bold;">FLUSH</span> <span style="color: #993333; font-weight: bold;">TABLES</span>.</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">FLUSH</span> <span style="color: #993333; font-weight: bold;">TABLES</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">0</span> rows affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">01</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">TRUNCATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> a2;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">0</span> rows affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> am <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">1</span> row affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SELECT</span> * <span style="color: #993333; font-weight: bold;">FROM</span> am;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| i |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">2</span> |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">3</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">2</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>As you see newly inserted row got value 3, which is maximum value which remained in the table plus 1. So auto_increment values are reusable just as with old ISAM tables.   Such behavior does not only corresponds to TRUNCATE - deleting last row will cause auto_increment value to be reused too.</p>
<p>Can you use AUTO_INCREMENT clause in CREATE TABLE to get different auto_increment values ? I guess not:</p>
<div class="igBar"><span id="lsql-30"><a href="#" onclick="javascript:showPlainTxt('sql-30'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-30">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> am <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span>=<span style="color: #cc66cc;color:#800000;">1000</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">0</span> rows affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Records: <span style="color: #cc66cc;color:#800000;">0</span>&nbsp; Duplicates: <span style="color: #cc66cc;color:#800000;">0</span>&nbsp; Warnings: <span style="color: #cc66cc;color:#800000;">0</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> am;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #993333; font-weight: bold;">TABLE</span> | <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| am&nbsp; &nbsp; | <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`am`</span> <span style="color:#006600; font-weight:bold;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`i`</span> int<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>&nbsp; <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">`i`</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#41;</span> ENGINE=MRG_MyISAM <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET=utf8 INSERT_METHOD=LAST UNION=<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">`a1`</span>,<span style="color: #ff0000;">`a2`</span><span style="color:#006600; font-weight:bold;">&#41;</span> |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>As you can see Merge table does not even stores auto_increment value (and of course does it without any warnings)  </p>
<p>Neither setting auto_increment value for underlying MyISAM tables works:</p>
<div class="igBar"><span id="lsql-31"><a href="#" onclick="javascript:showPlainTxt('sql-31'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-31">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> a1 <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span>=<span style="color: #cc66cc;color:#800000;">100</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">1</span> row affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Records: <span style="color: #cc66cc;color:#800000;">1</span>&nbsp; Duplicates: <span style="color: #cc66cc;color:#800000;">0</span>&nbsp; Warnings: <span style="color: #cc66cc;color:#800000;">0</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> a2 <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span>=<span style="color: #cc66cc;color:#800000;">100</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">1</span> row affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Records: <span style="color: #cc66cc;color:#800000;">1</span>&nbsp; Duplicates: <span style="color: #cc66cc;color:#800000;">0</span>&nbsp; Warnings: <span style="color: #cc66cc;color:#800000;">0</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> am <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">1</span> row affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SELECT</span> * <span style="color: #993333; font-weight: bold;">FROM</span> am;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| i |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">2</span> |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">3</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">4</span> |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">3</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>So for bad or for good you should remember auto_increment for Merge Tables works differently from both MyISAM and Innodb tables and being similar to what ISAM tables used to have.  As the side effect of this - if you're using auto_increment columns inserting into Merge Table and in the last table directly will have different results.</p>
<p>Another thing I should remind you should be very careful while running ALTER TABLE for underlying tables. Unlike with TRUNCATE TABLE there is no warning displayed but the MERGE TABLE may continue having old file descriptors open not seeing changes done to original table:</p>
<div class="igBar"><span id="lsql-32"><a href="#" onclick="javascript:showPlainTxt('sql-32'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-32">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SELECT</span> * <span style="color: #993333; font-weight: bold;">FROM</span> am;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-----+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| i&nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-----+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">|&nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">2</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">|&nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">3</span> |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">|&nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">5</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">|&nbsp; <span style="color: #cc66cc;color:#800000;">10</span> |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">100</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">101</span> |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">102</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">103</span> |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">104</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">105</span> |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-----+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">10</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">01</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> a2 <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span>=<span style="color: #cc66cc;color:#800000;">5000</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">9</span> rows affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Records: <span style="color: #cc66cc;color:#800000;">9</span>&nbsp; Duplicates: <span style="color: #cc66cc;color:#800000;">0</span>&nbsp; Warnings: <span style="color: #cc66cc;color:#800000;">0</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">FROM</span> a2 <span style="color: #993333; font-weight: bold;">WHERE</span> i&gt;<span style="color: #cc66cc;color:#800000;">2</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">9</span> rows affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SELECT</span> * <span style="color: #993333; font-weight: bold;">FROM</span> am;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-----+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| i&nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-----+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">|&nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">2</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">|&nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">3</span> |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">|&nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">5</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">|&nbsp; <span style="color: #cc66cc;color:#800000;">10</span> |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">100</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">101</span> |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">102</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">103</span> |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">104</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">105</span> |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-----+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">10</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SELECT</span> * <span style="color: #993333; font-weight: bold;">FROM</span> a2;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Empty <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">FLUSH</span> <span style="color: #993333; font-weight: bold;">TABLES</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">0</span> rows affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SELECT</span> * <span style="color: #993333; font-weight: bold;">FROM</span> am;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| i |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">2</span> |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">1</span> row <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>As you can see delete is invisible in the merge table after we did alter table until we have run flush tables. </p>
<p>I've done my tests with MySQL 5.0.62.</p>
    <hr noshade style="margin:0;height:1px" />
    <p>Entry posted by peter |
      <a href="http://www.mysqlperformanceblog.com/2008/09/11/auto_increment-and-merge-tables/#comments">No comment</a></p>
    <p>Add to: <a href="http://del.icio.us/post?url=http://www.mysqlperformanceblog.com/2008/09/11/auto_increment-and-merge-tables/&amp;title=AUTO_INCREMENT and MERGE TABLES" title="Bookmark this post on del.icio.us"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/delicious.png" alt="delicious" /></a> | <a href="http://digg.com/submit?phase=2&amp;url=http://www.mysqlperformanceblog.com/2008/09/11/auto_increment-and-merge-tables/&amp;title=AUTO_INCREMENT and MERGE TABLES" title="Digg this post on Digg.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/digg.png" alt="digg" /></a> | <a href="http://reddit.com/submit?url=http://www.mysqlperformanceblog.com/2008/09/11/auto_increment-and-merge-tables/&amp;title=AUTO_INCREMENT and MERGE TABLES" title="Submit this post on reddit.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/reddit.png" alt="reddit" /></a> | <a href="http://www.netscape.com/submit/?U=http://www.mysqlperformanceblog.com/2008/09/11/auto_increment-and-merge-tables/&amp;T=AUTO_INCREMENT and MERGE TABLES" title="Vote for this article on Netscape"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/netscape.gif" alt="netscape" /></a> | <a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.mysqlperformanceblog.com/2008/09/11/auto_increment-and-merge-tables/&amp;title=AUTO_INCREMENT and MERGE TABLES" title="Add to Google Bookmarks"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/google.png" alt="Google Bookmarks" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlperformanceblog.com/2008/09/11/auto_increment-and-merge-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Can you Trust CHECK TABLE ?</title>
		<link>http://www.mysqlperformanceblog.com/2008/09/11/can-you-trust-check-table/</link>
		<comments>http://www.mysqlperformanceblog.com/2008/09/11/can-you-trust-check-table/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 23:24:54 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[myisam]]></category>

		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=497</guid>
		<description><![CDATA[Take a look at this:
PLAIN TEXT
SQL:




mysql&#62; repair TABLE a3;


+---------+--------+----------+----------+


&#124; TABLE&#160; &#160;&#124; Op&#160; &#160; &#160;&#124; Msg_type &#124; Msg_text &#124;


+---------+--------+----------+----------+


&#124; test.a3 &#124; repair &#124; STATUS&#160; &#160;&#124; OK&#160; &#160; &#160; &#160;&#124;


+---------+--------+----------+----------+


1 row IN SET &#40;0.10 sec&#41;


&#160;


mysql&#62; SELECT * FROM a3 ORDER BY i;


+------------+


&#124; i&#160; &#160; &#160; &#160; &#160; &#124;


+------------+


&#124; 2147483648 &#124;


&#124;&#160; &#160; &#160; &#160; &#160;11 &#124;


&#124;&#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Take a look at this:</p>
<div class="igBar"><span id="lsql-34"><a href="#" onclick="javascript:showPlainTxt('sql-34'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-34">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; repair <span style="color: #993333; font-weight: bold;">TABLE</span> a3;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------+--------+----------+----------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #993333; font-weight: bold;">TABLE</span>&nbsp; &nbsp;| Op&nbsp; &nbsp; &nbsp;| Msg_type | Msg_text |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------+--------+----------+----------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| test.a3 | repair | <span style="color: #993333; font-weight: bold;">STATUS</span>&nbsp; &nbsp;| OK&nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------+--------+----------+----------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">1</span> row <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">10</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SELECT</span> * <span style="color: #993333; font-weight: bold;">FROM</span> a3 <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> i;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">2147483648</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">11</span> |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">13</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">14</span> |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #cc66cc;color:#800000;">2147483647</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">5</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The sort order is obviously wrong while <strong>CHECK TABLE</strong> is not reporting any error</p>
<p>Why ?  Because <strong>CHECK TABLE</strong> only looks at  MyISAM data and Index files and it does not compare information in these to  table definition (.frm file)</p>
<p>In this particular case I replaced .frm file for the table from different one changing  INT to UNSIGNED INT to see what effect it will give - as you can see  you get quite funny table which is considered OK by CHECK TABLE, which does store values larger than max signed int but which sorts them as unsigned ints.  Quite fun.</p>
<p>I hope the task of fixing this is somewhere on MySQL roadmap <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
    <hr noshade style="margin:0;height:1px" />
    <p>Entry posted by peter |
      <a href="http://www.mysqlperformanceblog.com/2008/09/11/can-you-trust-check-table/#comments">5 comments</a></p>
    <p>Add to: <a href="http://del.icio.us/post?url=http://www.mysqlperformanceblog.com/2008/09/11/can-you-trust-check-table/&amp;title=Can you Trust CHECK TABLE ?" title="Bookmark this post on del.icio.us"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/delicious.png" alt="delicious" /></a> | <a href="http://digg.com/submit?phase=2&amp;url=http://www.mysqlperformanceblog.com/2008/09/11/can-you-trust-check-table/&amp;title=Can you Trust CHECK TABLE ?" title="Digg this post on Digg.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/digg.png" alt="digg" /></a> | <a href="http://reddit.com/submit?url=http://www.mysqlperformanceblog.com/2008/09/11/can-you-trust-check-table/&amp;title=Can you Trust CHECK TABLE ?" title="Submit this post on reddit.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/reddit.png" alt="reddit" /></a> | <a href="http://www.netscape.com/submit/?U=http://www.mysqlperformanceblog.com/2008/09/11/can-you-trust-check-table/&amp;T=Can you Trust CHECK TABLE ?" title="Vote for this article on Netscape"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/netscape.gif" alt="netscape" /></a> | <a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.mysqlperformanceblog.com/2008/09/11/can-you-trust-check-table/&amp;title=Can you Trust CHECK TABLE ?" title="Add to Google Bookmarks"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/google.png" alt="Google Bookmarks" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlperformanceblog.com/2008/09/11/can-you-trust-check-table/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>ANALYZE:  MyISAM vs Innodb</title>
		<link>http://www.mysqlperformanceblog.com/2008/09/03/analyze-myisam-vs-innodb/</link>
		<comments>http://www.mysqlperformanceblog.com/2008/09/03/analyze-myisam-vs-innodb/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 21:09:22 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[Innodb]]></category>
		<category><![CDATA[myisam]]></category>

		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=485</guid>
		<description><![CDATA[Following up on my Previous Post I decided to do little test to see how accurate stats we can get for for Index Stats created by ANALYZE TABLE for MyISAM and Innodb.
But before we go into that I wanted to highlight about using ANALYZE TABLE in production as some people seems to be thinking I [...]]]></description>
			<content:encoded><![CDATA[<p>Following up on my <a href="http://www.mysqlperformanceblog.com/2008/09/02/beware-of-running-analyze-in-production/">Previous Post</a> I decided to do little test to see how accurate stats we can get for for Index Stats created by <strong>ANALYZE TABLE</strong> for MyISAM and Innodb.</p>
<p>But before we go into that I wanted to highlight about using <strong>ANALYZE TABLE</strong> in production as some people seems to be thinking I advice to use it.... a lot.    In fact I should say I see more systems which have ANALYZE abused - run too frequently without much need than systems which do not run ANALYZE  frequently enough.</p>
<p>First it is worth to note MySQL only saves very basic cardinality information for index prefixes for index stats and these rarely change. There is no histograms or any other skew metrics etc.  MySQL optimizer also uses number of rows in the table for many decisions but this is computed  live (maintained for MyISAM and estimated during query execution for Innodb).  This  basic information means it does not change whole that quickly at extent to affect optimizer plans. </p>
<p>If you look at the stats accuracy along running <strong>ANALYZE TABLE</strong> after initial table population and when there are significant changes makes sense.   For Innodb as index stats are computed first time table is accessed after restart this often means "never" because MySQL servers are restarted frequently enough.  Even once per 3 months is often enough for many workloads.  Add to this Innodb stats are less accurate by nature which means you can allow more data change while your<br />
index stats remain as good as new. </p>
<p>Looking at stats accuracy is however a wrong way to look at the problem. Your index stats are a bit off, so what ?   What really matters is not how accurate stats are but how good plans you're getting for your queries.  If you're getting as good plans as with perfect stats why bother updating them ?<br />
Also note many simple "queries"  (using constants for index accesses) will not use index cardinality data at all but will estimate number of rows during query execution.</p>
<p>I typically look at <strong>ANALYZE TABLE </strong> and adding it to the table if I see having it run helps to get good plans.  If query plans are good or bad independently of it being run there is need to bother - for bad plans use FORCE INDEX or change the query and report MySQL Optimizer Bug <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>But now lets see in the difference of behavior of <strong>ANALYZE TABLE</strong> for MyISAM vs Innodb.</p>
<p>I used the following simple table for tests: </p>
<div class="igBar"><span id="lsql-46"><a href="#" onclick="javascript:showPlainTxt('sql-46'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-46">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`antest`</span> <span style="color:#006600; font-weight:bold;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`i`</span> int<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`c`</span> char<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">80</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #ff0000;">`i`</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">`i`</span><span style="color:#006600; font-weight:bold;">&#41;</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #ff0000;">`c`</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">`c`</span>,<span style="color: #ff0000;">`i`</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#41;</span> ENGINE=MyISAM <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET=latin1 </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>I have populated it with data with following true cardinality:</p>
<div class="igBar"><span id="lsql-47"><a href="#" onclick="javascript:showPlainTxt('sql-47'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-47">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SELECT</span> count<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #993333; font-weight: bold;">DISTINCT</span> c<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> antest;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-------------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| count<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #993333; font-weight: bold;">DISTINCT</span> c<span style="color:#006600; font-weight:bold;">&#41;</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-------------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">101</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-------------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">1</span> row <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">36</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SELECT</span> count<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #993333; font-weight: bold;">DISTINCT</span> i<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> antest;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-------------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| count<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #993333; font-weight: bold;">DISTINCT</span> i<span style="color:#006600; font-weight:bold;">&#41;</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-------------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">101</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-------------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">1</span> row <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">20</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SELECT</span> count<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #993333; font-weight: bold;">DISTINCT</span> i,c<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> antest;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| count<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #993333; font-weight: bold;">DISTINCT</span> i,c<span style="color:#006600; font-weight:bold;">&#41;</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">10201</span> |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">1</span> row <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">43</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Lets see how stats look for <strong>MYISAM</strong>:</p>
<div class="igBar"><span id="lsql-48"><a href="#" onclick="javascript:showPlainTxt('sql-48'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-48">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">INDEX</span> <span style="color: #993333; font-weight: bold;">FROM</span> antest;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #993333; font-weight: bold;">TABLE</span>&nbsp; | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | <span style="color: #993333; font-weight: bold;">NULL</span> | Index_type | Comment |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | i&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">NULL</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">NULL</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;| YES&nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">2</span> | i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">NULL</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">3</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Aha as you can see there is no cardinality stored with table as ANALYZE did not run yet.</p>
<div class="igBar"><span id="lsql-49"><a href="#" onclick="javascript:showPlainTxt('sql-49'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-49">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">INDEX</span> <span style="color: #993333; font-weight: bold;">FROM</span> antest;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #993333; font-weight: bold;">TABLE</span>&nbsp; | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | <span style="color: #993333; font-weight: bold;">NULL</span> | Index_type | Comment |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | i&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">101</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">101</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;| YES&nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">2</span> | i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">10240</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">3</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">01</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>As you can see after running ANALYZE we have exact cardinality for i and c columns, with cardinality for the pair (c,i) looks a bit off but is within 0.5% of the correct value so we can count on MyISAM values as almost exact.</p>
<p>As you see ANALYZE table tool a little bit of time to run (even for this very small table) this is because ANALYZE does index scans to find number of exact values in the table.</p>
<p>Now let us populate antest_innodb  table which is same but uses Innodb format:</p>
<div class="igBar"><span id="lsql-50"><a href="#" onclick="javascript:showPlainTxt('sql-50'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-50">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> antest_innodb <span style="color: #993333; font-weight: bold;">SELECT</span>&nbsp; * <span style="color: #993333; font-weight: bold;">FROM</span> antest;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">245760</span> rows affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">54</span>.<span style="color: #cc66cc;color:#800000;">29</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Records: <span style="color: #cc66cc;color:#800000;">245760</span>&nbsp; Duplicates: <span style="color: #cc66cc;color:#800000;">0</span>&nbsp; Warnings: <span style="color: #cc66cc;color:#800000;">0</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">INDEX</span> <span style="color: #993333; font-weight: bold;">FROM</span> antest_innodb;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #993333; font-weight: bold;">TABLE</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | <span style="color: #993333; font-weight: bold;">NULL</span> | Index_type | Comment |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest_innodb |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | i&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">245900</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest_innodb |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">245900</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;| YES&nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest_innodb |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">2</span> | i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">245900</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">3</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Very interesting result - after loading the data with INSERT in Innodb table we do not get NULL cardinality as with MyISAM but instead we get very wrong cardinality which shows us index prefix is unique  (245900 is estimate for the row count in the table)</p>
<p>It is worth to note if you do ALTER TABLE Innodb, same as MyISAM will internally run analyze as soon as table is rebuilt and values will be more sensible:</p>
<div class="igBar"><span id="lsql-51"><a href="#" onclick="javascript:showPlainTxt('sql-51'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-51">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> antest_innodb type=innodb;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">245760</span> rows affected, <span style="color: #cc66cc;color:#800000;">1</span> warning <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">51</span>.<span style="color: #cc66cc;color:#800000;">87</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Records: <span style="color: #cc66cc;color:#800000;">245760</span>&nbsp; Duplicates: <span style="color: #cc66cc;color:#800000;">0</span>&nbsp; Warnings: <span style="color: #cc66cc;color:#800000;">0</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">INDEX</span> <span style="color: #993333; font-weight: bold;">FROM</span> antest_innodb;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #993333; font-weight: bold;">TABLE</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | <span style="color: #993333; font-weight: bold;">NULL</span> | Index_type | Comment |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest_innodb |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | i&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">332</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest_innodb |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">18</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;| YES&nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest_innodb |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">2</span> | i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">20491</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">3</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Note however how much are these values off from reality.  The "i" key cardinality is overestimated 3 times,  "c" key prefix cardinality is underestimated 5 times and the combined (c,i) key cardinality is overestimated 2 times.  So Innodb stats are are very  inexact.  Fortunately for most queries which use these stats accuracy at the order of magnitude is enough. Sometimes it is not and you're thinking why a hell it could be picking this strange plan.</p>
<p>Let us run ANALYZE TABLE for Innodb couple of more times to see how values change:</p>
<div class="igBar"><span id="lsql-52"><a href="#" onclick="javascript:showPlainTxt('sql-52'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-52">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; analyze <span style="color: #993333; font-weight: bold;">TABLE</span> antest_innodb;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------------------+---------+----------+----------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #993333; font-weight: bold;">TABLE</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Op&nbsp; &nbsp; &nbsp; | Msg_type | Msg_text |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------------------+---------+----------+----------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| test.antest_innodb | analyze | <span style="color: #993333; font-weight: bold;">STATUS</span>&nbsp; &nbsp;| OK&nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------------------+---------+----------+----------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">1</span> row <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">INDEX</span> <span style="color: #993333; font-weight: bold;">FROM</span> antest_innodb;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #993333; font-weight: bold;">TABLE</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | <span style="color: #993333; font-weight: bold;">NULL</span> | Index_type | Comment |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest_innodb |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | i&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">338</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest_innodb |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">18</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;| YES&nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest_innodb |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">2</span> | i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">20491</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">3</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; analyze <span style="color: #993333; font-weight: bold;">TABLE</span> antest_innodb;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------------------+---------+----------+----------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #993333; font-weight: bold;">TABLE</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Op&nbsp; &nbsp; &nbsp; | Msg_type | Msg_text |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------------------+---------+----------+----------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| test.antest_innodb | analyze | <span style="color: #993333; font-weight: bold;">STATUS</span>&nbsp; &nbsp;| OK&nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------------------+---------+----------+----------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">1</span> row <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">INDEX</span> <span style="color: #993333; font-weight: bold;">FROM</span> antest_innodb;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #993333; font-weight: bold;">TABLE</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | <span style="color: #993333; font-weight: bold;">NULL</span> | Index_type | Comment |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest_innodb |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | i&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">92</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest_innodb |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">384</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;| YES&nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest_innodb |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">2</span> | i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">20491</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">3</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>As we see subsequent runs change stats dramatically. For c prefix we got value changed to become 15 times larger.   So Innodb stats are both inexact and unstable.  So restarting server with Innodb may change stats dramatically and affect some query plans. You also may be getting different plans on different slaves with same data.</p>
<p>Another difference when it comes from handling the statistics comes from NULL handling.<br />
MyISAM has a special variable which controls if NULLs should be considered equal when computing stats:</p>
<div class="igBar"><span id="lsql-53"><a href="#" onclick="javascript:showPlainTxt('sql-53'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-53">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">VARIABLES</span> <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">"myisam_stats_method"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------------+---------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| Variable_name&nbsp; &nbsp; &nbsp; &nbsp;| Value&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------------+---------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| myisam_stats_method | nulls_unequal |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------------+---------------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">1</span> row <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Too see the difference let me set column "c" to NULL in both tables and see how values change:</p>
<div class="igBar"><span id="lsql-54"><a href="#" onclick="javascript:showPlainTxt('sql-54'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-54">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">UPDATE</span> antest <span style="color: #993333; font-weight: bold;">SET</span> c=<span style="color: #993333; font-weight: bold;">NULL</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">245760</span> rows affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">11</span>.<span style="color: #cc66cc;color:#800000;">48</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Rows matched: <span style="color: #cc66cc;color:#800000;">245760</span>&nbsp; Changed: <span style="color: #cc66cc;color:#800000;">245760</span>&nbsp; Warnings: <span style="color: #cc66cc;color:#800000;">0</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">UPDATE</span> antest_innodb <span style="color: #993333; font-weight: bold;">SET</span> c=<span style="color: #993333; font-weight: bold;">NULL</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">245760</span> rows affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">1</span> min <span style="color: #cc66cc;color:#800000;">20</span>.<span style="color: #cc66cc;color:#800000;">19</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Rows matched: <span style="color: #cc66cc;color:#800000;">245760</span>&nbsp; Changed: <span style="color: #cc66cc;color:#800000;">245760</span>&nbsp; Warnings: <span style="color: #cc66cc;color:#800000;">0</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">INDEX</span> <span style="color: #993333; font-weight: bold;">FROM</span> antest;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #993333; font-weight: bold;">TABLE</span>&nbsp; | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | <span style="color: #993333; font-weight: bold;">NULL</span> | Index_type | Comment |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | i&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">101</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">245760</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;| YES&nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">2</span> | i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">245760</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">3</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; analyze <span style="color: #993333; font-weight: bold;">TABLE</span> antest_innodb;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------------------+---------+----------+----------+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #993333; font-weight: bold;">TABLE</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Op&nbsp; &nbsp; &nbsp; | Msg_type | Msg_text |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------------------+---------+----------+----------+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| test.antest_innodb | analyze | <span style="color: #993333; font-weight: bold;">STATUS</span>&nbsp; &nbsp;| OK&nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------------------+---------+----------+----------+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">1</span> row <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">01</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">INDEX</span> <span style="color: #993333; font-weight: bold;">FROM</span> antest_innodb;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #993333; font-weight: bold;">TABLE</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | <span style="color: #993333; font-weight: bold;">NULL</span> | Index_type | Comment |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest_innodb |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | i&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">418</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest_innodb |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">8</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;| YES&nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest_innodb |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">2</span> | i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">196</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">---------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">3</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>As you can see MyISAM set cardinality for prefix (c) and key(c,i) approximately to number of rows in the table treating all nulls different values.  Innodb on the contrary  treats all NULL values the same so<br />
cardinality for (c) and (c,i) dropped significantly. </p>
<p>This means <strong>Innodb and MyISAM have different stats computation method by default</strong>.</p>
<p>Lets check how stats change for MyISAM if we change the stats computation method:</p>
<div class="igBar"><span id="lsql-55"><a href="#" onclick="javascript:showPlainTxt('sql-55'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-55">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SET</span> myisam_stats_method=<span style="color: #ff0000;">'nulls_equal'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Query OK, <span style="color: #cc66cc;color:#800000;">0</span> rows affected <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; analyze <span style="color: #993333; font-weight: bold;">TABLE</span> antest;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-------------+---------+----------+-----------------------------+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #993333; font-weight: bold;">TABLE</span>&nbsp; &nbsp; &nbsp; &nbsp;| Op&nbsp; &nbsp; &nbsp; | Msg_type | Msg_text&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-------------+---------+----------+-----------------------------+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| test.antest | analyze | <span style="color: #993333; font-weight: bold;">STATUS</span>&nbsp; &nbsp;| <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IS</span> already up <span style="color: #993333; font-weight: bold;">TO</span> date |</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">-------------+---------+----------+-----------------------------+</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">1</span> row <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>oops.  Little gotcha.  MySQL considers table up to date even though stats stored were computed with different method.  If your table is written to actively you should not have this problem; I just did couple of updates to refresh update time.</p>
<div class="igBar"><span id="lsql-56"><a href="#" onclick="javascript:showPlainTxt('sql-56'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-56">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mysql&gt; <span style="color: #993333; font-weight: bold;">SHOW</span> <span style="color: #993333; font-weight: bold;">INDEX</span> <span style="color: #993333; font-weight: bold;">FROM</span> antest;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| <span style="color: #993333; font-weight: bold;">TABLE</span>&nbsp; | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | <span style="color: #993333; font-weight: bold;">NULL</span> | Index_type | Comment |</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | i&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">101</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">1</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;| YES&nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">| antest |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">1</span> | c&nbsp; &nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;color:#800000;">2</span> | i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| A&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;color:#800000;">101</span> |&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">NULL</span> | <span style="color: #993333; font-weight: bold;">NULL</span>&nbsp; &nbsp;|&nbsp; &nbsp; &nbsp; | BTREE&nbsp; &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+<span style="color: #808080; font-style: italic;">--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc66cc;color:#800000;">3</span> rows <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>.<span style="color: #cc66cc;color:#800000;">00</span> sec<span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>So with nulls_equal method we see very different picture.  It is considered we only have one distinct value for "c" and there are 101 distict values for (c,i) which is the same as value of distinct values in i column.   These stats look much closer to what we get for Innodb table with same data though we can see Innodb stats are a bit off from reality too.</p>
<p>MySQL version note:  This is from MySQL 5.0.62 if there are other versions which show different behavior.</p>
    <hr noshade style="margin:0;height:1px" />
    <p>Entry posted by peter |
      <a href="http://www.mysqlperformanceblog.com/2008/09/03/analyze-myisam-vs-innodb/#comments">5 comments</a></p>
    <p>Add to: <a href="http://del.icio.us/post?url=http://www.mysqlperformanceblog.com/2008/09/03/analyze-myisam-vs-innodb/&amp;title=ANALYZE:  MyISAM vs Innodb" title="Bookmark this post on del.icio.us"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/delicious.png" alt="delicious" /></a> | <a href="http://digg.com/submit?phase=2&amp;url=http://www.mysqlperformanceblog.com/2008/09/03/analyze-myisam-vs-innodb/&amp;title=ANALYZE:  MyISAM vs Innodb" title="Digg this post on Digg.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/digg.png" alt="digg" /></a> | <a href="http://reddit.com/submit?url=http://www.mysqlperformanceblog.com/2008/09/03/analyze-myisam-vs-innodb/&amp;title=ANALYZE:  MyISAM vs Innodb" title="Submit this post on reddit.com"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/reddit.png" alt="reddit" /></a> | <a href="http://www.netscape.com/submit/?U=http://www.mysqlperformanceblog.com/2008/09/03/analyze-myisam-vs-innodb/&amp;T=ANALYZE:  MyISAM vs Innodb" title="Vote for this article on Netscape"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/netscape.gif" alt="netscape" /></a> | <a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.mysqlperformanceblog.com/2008/09/03/analyze-myisam-vs-innodb/&amp;title=ANALYZE:  MyISAM vs Innodb" title="Add to Google Bookmarks"><img src="http://www.mysqlperformanceblog.com/wp-content/themes/boxy-but-gold/images/google.png" alt="Google Bookmarks" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mysqlperformanceblog.com/2008/09/03/analyze-myisam-vs-innodb/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
