<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5852997211129961388</id><updated>2011-11-18T08:59:26.182Z</updated><category term='MyISAM'/><category term='Introduction'/><category term='maatkit'/><category term='i18n'/><category term='OLAP'/><category term='Performance'/><category term='pager'/><category term='Hack'/><category term='tool'/><category term='Optimizer'/><category term='changing gears'/><category term='Table Status'/><category term='monitoring'/><category term='Day Out'/><category term='Security'/><category term='Drizzle'/><category term='Best Practices'/><category term='InnoDB plugin'/><category term='Open Source'/><category term='mKhoj'/><category term='InnoDB'/><category term='auto_increment'/><category term='MyEye'/><category term='MySQL meetup'/><category term='Bangalore'/><category term='Community'/><category term='Tablespace'/><category term='Index'/><category term='Linux'/><category term='administration'/><category term='temporary tables'/><category term='book review'/><category term='memcached'/><category term='Locks'/><category term='maintenance'/><category term='fun'/><category term='Yahoo'/><category term='Transaction'/><category term='replication'/><title type='text'>Optim MySQL</title><subtitle type='html'>Keep watching this blog for interesting stuff on MySQL - Database Tuning, Traps and much more.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://optimmysql.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>38</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-5155243874930948977</id><published>2008-09-07T09:12:00.000+01:00</published><updated>2008-09-07T10:13:32.638+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='changing gears'/><category scheme='http://www.blogger.com/atom/ns#' term='mKhoj'/><category scheme='http://www.blogger.com/atom/ns#' term='Yahoo'/><category scheme='http://www.blogger.com/atom/ns#' term='Bangalore'/><title type='text'>Changing Gears</title><content type='html'>This week I'm changing gears of my life. On Friday (5th September), I&amp;nbsp; yodeled and bled purple for one last time. It has been 2 years and 8 months when I first joined Yahoo! directly from college during which the size of Yahoo!, here at Bangalore, has almost tripled. Definitely the most rewarding and learning time for me as I worked and interacted with some really cool, supportive and intelligent people.&lt;br /&gt;
&lt;br /&gt;
It was really a difficult decision to consider as I had no reasons to leave. It took me some time to convince myself. The only reason probably is that I got an opportunity to do something that always wanted to, that is working for a startup :). &lt;br /&gt;
&lt;br /&gt;
Starting Monday I'm joining &lt;a href="http://mkhoj.com/"&gt;mKhoj&lt;/a&gt;, an Indian startup in the "Mobile Advertising marketplace" here at Bangalore. Looks like exciting times ahead.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_d3Cdsg3970Q/SMOPj7F-1wI/AAAAAAAAAQw/caW2HK1VvLo/s1600-h/canon.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/_d3Cdsg3970Q/SMOPj7F-1wI/AAAAAAAAAQw/vZy0M_Us5Cg/s400-R/canon.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Here are few things that I remembered to collect. Hooded sweatshirt and a nice clock (my parting gifts), my star, a YEFI calendar, yo yo badge holder and a gluestick. Definitely I will miss Yahoo! while enjoying at mKhoj.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-5155243874930948977?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=5155243874930948977' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/5155243874930948977'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/5155243874930948977'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/09/changing-gears.html' title='Changing Gears'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_d3Cdsg3970Q/SMOPj7F-1wI/AAAAAAAAAQw/vZy0M_Us5Cg/s72-Rc/canon.jpg' height='72' width='72'/><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-5547304859517996002</id><published>2008-08-28T09:24:00.000+01:00</published><updated>2008-08-28T10:23:19.392+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Day Out'/><category scheme='http://www.blogger.com/atom/ns#' term='maintenance'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><category scheme='http://www.blogger.com/atom/ns#' term='InnoDB'/><title type='text'>Variable's Day Out #16: innodb_log_file_size</title><content type='html'>&lt;b&gt;Properties:&amp;nbsp;&lt;/b&gt; &lt;br /&gt;
&lt;table border="1" cellpadding="2" cellspacing="0" style="width: 500px;"&gt;&lt;tbody&gt;
&lt;tr&gt;     &lt;td valign="top" width="187"&gt;Applicable To&lt;/td&gt;     &lt;td valign="top" width="311"&gt;InnoDB&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="top" width="187"&gt;Server Startup Option&lt;/td&gt; &lt;td valign="top" width="311"&gt;&lt;code&gt;--innodb_log_file_size=&lt;i&gt;&amp;lt;value&amp;gt;&lt;/i&gt;&lt;/code&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="top" width="187"&gt;Scope&lt;/td&gt;     &lt;td valign="top" width="311"&gt;Global&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="top" width="187"&gt;Dynamic&lt;/td&gt;     &lt;td valign="top" width="311"&gt;Yes&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="top" width="187"&gt;Possible Values&lt;/td&gt; &lt;td valign="top" width="311"&gt;Integer: Range: 1M - 4G&lt;br /&gt;
&amp;lt;1M will be adjusted to 1M &lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="top" width="187"&gt;Default Value&lt;/td&gt;     &lt;td valign="top" width="311"&gt;5M&lt;/td&gt; &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign="top" width="187"&gt;Category&lt;/td&gt;     &lt;td valign="top" width="311"&gt;Performance, Maintenance&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;b&gt;Description:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This variable defines the size of each log file in a log group. While setting this variable it should be noted that combined size of all log files should be less than 4GB.&lt;br /&gt;
&lt;br /&gt;
InnoDB requires these logs for recovery in case of a crash. So how come the size of these logs effect server performance? As stated in MySQL manual "The larger the value, the less checkpoint           flush activity is needed in the buffer pool, saving disk I/O.", these logs help InnoDB in running more confidently as it knows that even if data is not written to the persistent storage often it can still have it.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Best Value:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
A larger value helps you in performance but only up to some point. After a certain value, the performance gain will be minimal or it can be negative.&lt;b&gt; &lt;/b&gt;Another issue to be considered is that a value too large will slow down recovery as there will be more and more logs to be scanned. But definitely the default is too small.&lt;br /&gt;
&lt;br /&gt;
My usual recommendation is to set it to 256M or if you feel its big (because maybe you have too many crashes and of course crash recoveries) then 128M. Anything beyond this range should be tested properly and justified.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;How to set?&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
If you just change the size of this variable, MySQL will crib about the changed log file size and start without the InnoDB engine. The safe way of re-setting this value is:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Stop the MySQL server&lt;/li&gt;
&lt;li&gt;Backup your data and log files&lt;/li&gt;
&lt;li&gt;Delete log files&lt;/li&gt;
&lt;li&gt;Set the new value for innodb_log_file_size in my.cnf&lt;/li&gt;
&lt;li&gt;Start mysql server&lt;/li&gt;
&lt;/ol&gt;&lt;b&gt;Read More:&lt;/b&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;b&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.1/en/innodb-parameters.html#option_mysqld_innodb_log_file_size"&gt;MySQL manual entry on innodb_log_file_size&lt;/a&gt;&amp;nbsp;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://www.mysqlperformanceblog.com/2006/07/03/choosing-proper-innodb_log_file_size/"&gt;Choosing proper innodb_log_file_size @mysqlperformanceblog.com&lt;/a&gt;&amp;nbsp;&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;a href="http://ebergen.net/wordpress/2008/01/13/innodb_log_file_size/"&gt;Eric Bergen on innodb_log_file_size&lt;/a&gt;&amp;nbsp;&lt;/b&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://mysqldatabaseadministration.blogspot.com/2007/01/increase-innodblogfilesize-proper-way.html"&gt;Increase innodb_log_file_size: the proper way&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-5547304859517996002?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=5547304859517996002' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/5547304859517996002'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/5547304859517996002'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/08/variables-day-out-16-innodblogfilesize.html' title='Variable&apos;s Day Out #16: innodb_log_file_size'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-7987694432210136425</id><published>2008-08-12T10:03:00.000+01:00</published><updated>2008-08-12T10:22:58.942+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='fun'/><category scheme='http://www.blogger.com/atom/ns#' term='Drizzle'/><category scheme='http://www.blogger.com/atom/ns#' term='i18n'/><category scheme='http://www.blogger.com/atom/ns#' term='Community'/><title type='text'>Translation is Fun!!</title><content type='html'>&lt;div style="text-align: left;"&gt;Morning, I saw &lt;a href="http://mysql-ha.com/2008/08/11/drizzle-i18n/"&gt;Monty's post&lt;/a&gt; asking for contribution to drizzle's i18n efforts. I did checked out Hindi language and well I must say translation is a fun activity.&amp;nbsp;&lt;/div&gt;&lt;br /&gt;
&lt;div style="text-align: left;"&gt;If you think that will be as easy as using some online translation tool (I tried &lt;a href="http://www.google.com/translate_t?sl=en&amp;amp;tl=hi"&gt;Google Translate&lt;/a&gt;), you may be wrong. Many sentences that make direct sense in English get completely screwed when translated word by word. Sometimes they are translated into a perfect meaningful sentence and that is when you can laugh out loudly. &lt;/div&gt;&lt;br /&gt;
As of now I'm doing Hindi (already 80 translations down) and next I'm gonna pick Punjabi. Wow! I know languages.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-7987694432210136425?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=7987694432210136425' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/7987694432210136425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/7987694432210136425'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/08/translation-is-fun.html' title='Translation is Fun!!'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-4758429296282607316</id><published>2008-07-30T10:38:00.002+01:00</published><updated>2008-07-30T11:12:19.196+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Best Practices'/><category scheme='http://www.blogger.com/atom/ns#' term='Open Source'/><category scheme='http://www.blogger.com/atom/ns#' term='MySQL meetup'/><category scheme='http://www.blogger.com/atom/ns#' term='Community'/><category scheme='http://www.blogger.com/atom/ns#' term='Bangalore'/><title type='text'>MySQL camp with Kaj (29th july)</title><content type='html'>I was there in the meetup and my feeling was a mix about the same. It was nice to have &lt;a href="http://blogs.mysql.com/kaj/"&gt;Kaj&lt;/a&gt; here (for the first time) and listen to him about Sun's acquisition. On the other hand it was disheartening to see so few people from corporates turning up. It was almost negligible. I'm still positive on this and do expect many more people to turn up. There were a total of three talks in the meet and then we had some chit chat with people.

In his first talk, Kaj first greeted everybody in Hindi, Tamil and Kannada and many were delighted. Kaj touched various aspects of Sun's acquisition and also their on-boarding struggle. He also mentioned about MySQL considering Sun's liberal SCA in place of their stricter CLA. (I haven't gone through SCA to actually comment on it's benefits)

Second talk by &lt;a href="http://blogs.sun.com/thava/"&gt;Thava&lt;/a&gt; was on how to contribute code to MySQL. It was a nice talk and showed various resource points and steps of doing so in a right manner.

Third talk, again by Kaj, was on the different ways of contributing to MySQL and MySQL community other than code. He showed screenshots of &lt;a href="http://forums.mysql.com/"&gt;forums&lt;/a&gt;, &lt;a href="http://forge.mysql.com/"&gt;forge&lt;/a&gt;, &lt;a href="http://www.planetmysql.org/"&gt;planetmysql&lt;/a&gt;, few blogs (he forgot mine ;) ), &lt;a href="http://bugs.mysql.com/"&gt;bugs.mysql&lt;/a&gt; and how to use them. Interestingly, my name appeared on the planetmysql page :) .

Overall it was nice that it started and we need to find out ways for more participation.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-4758429296282607316?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=4758429296282607316' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/4758429296282607316'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/4758429296282607316'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/07/mysql-camp-with-kaj-29th-july_30.html' title='MySQL camp with Kaj (29th july)'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-4512011174658933857</id><published>2008-07-15T11:45:00.005+01:00</published><updated>2008-07-15T11:57:51.038+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MyISAM'/><category scheme='http://www.blogger.com/atom/ns#' term='Day Out'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><title type='text'>Variable's Day Out #15: bulk_insert_buffer_size</title><content type='html'>&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;&lt;table border="1" cellpadding="2" cellspacing="0" width="500"&gt; &lt;tbody&gt;&lt;tr&gt;     &lt;td valign="top" width="187"&gt;Applicable To&lt;/td&gt;     &lt;td valign="top" width="311"&gt;MyISAM&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;     &lt;td valign="top" width="187"&gt;Server Startup Option&lt;/td&gt; &lt;td valign="top" width="311"&gt;&lt;code&gt;--bulk_insert_buffer_size=&lt;em&gt;&amp;lt;value&amp;gt;&lt;/em&gt;&lt;/code&gt;&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt;     &lt;td valign="top" width="187"&gt;Scope&lt;/td&gt;     &lt;td valign="top" width="311"&gt;Both&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;     &lt;td valign="top" width="187"&gt;Dynamic&lt;/td&gt;     &lt;td valign="top" width="311"&gt;Yes&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;     &lt;td valign="top" width="187"&gt;Possible Values&lt;/td&gt; &lt;td valign="top" width="311"&gt;Integer:&lt;p&gt;Range: 0 - 4294967295 (4G)&lt;/p&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;     &lt;td valign="top" width="187"&gt;Default Value&lt;/td&gt;     &lt;td valign="top" width="311"&gt;8388608 (8M)&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;     &lt;td valign="top" width="187"&gt;Category&lt;/td&gt;     &lt;td valign="top" width="311"&gt;Performance&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;This cache is used by MyISAM to optimize bulk inserts. This cache is a special tree-like structure. Bulk inserts include statements like &lt;code&gt;LOAD DATA INFILE...&lt;/code&gt;, &lt;code&gt;INSERT ... SELECT&lt;/code&gt;, &lt;code&gt;INSERT ... VALUES (...), (...), ..., (...)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Bulk inserts are often used to minimize disk writes etc and are very common in applications inserting lots of data. I often use bulk inserting using the following technique: (pseudocode)&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;code&gt;CREATE TEMPORARY TABLE tmp_table LIKE main_table&lt;/code&gt;&lt;/li&gt;  &lt;li&gt;&lt;code&gt;LOOP:&lt;/code&gt;
  &lt;ul&gt;&lt;li&gt;&lt;code&gt;INSERT ROWS INTO TEMPORARY TABLE&lt;/code&gt;&lt;/li&gt;     &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;code&gt;INSERT INTO main_table SELECT * FROM tmp_table&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If you are using any technique for bulk insertion, you should be carefully setting this parameter.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Optimal Value:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;This depends on the way your bulk inserts are structured. If you are doing bulk inserts with data being close to or more than 10k, this comes really handy.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Read more:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#option_mysqld_bulk_insert_buffer_size"&gt;MySQL manual entry on bulk_insert_buffer_size&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://venublog.com/2007/11/07/load-data-infile-performance/"&gt;LOAD DATA INFILE - performance case study (Venu Anuganti)&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Hope you enjoyed reading this.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-4512011174658933857?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=4512011174658933857' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/4512011174658933857'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/4512011174658933857'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/07/properties-applicable-to-myisam-server.html' title='Variable&apos;s Day Out #15: bulk_insert_buffer_size'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-3725181957677226059</id><published>2008-07-08T16:18:00.004+01:00</published><updated>2008-07-08T17:57:05.274+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='pager'/><category scheme='http://www.blogger.com/atom/ns#' term='Hack'/><category scheme='http://www.blogger.com/atom/ns#' term='maatkit'/><category scheme='http://www.blogger.com/atom/ns#' term='tool'/><title type='text'>MySQL command line pager &amp; mysmartpager</title><content type='html'>Few days back, Baron &lt;a href="http://www.mysqlperformanceblog.com/2008/06/23/neat-tricks-for-the-mysql-command-line-pager/"&gt;re-introduced MySQL's command line pager command&lt;/a&gt; and described some cool tricks with maatkit's &lt;span style="font-weight: bold;font-family:courier new;" &gt;mk-visual-explain&lt;/span&gt; (one of my favorite tools). Soon after reading it, I wished if it was possible to describe regex based (on query) paging.

I have written a small hack, christened &lt;span style="font-weight: bold;font-family:courier new;" &gt;mysmartpager&lt;/span&gt;, that can actually do regex based paging for you.

The idea is simple, write a relay that will redirect the output based on to the desired pager. The problem was complex, there was no direct way of getting to know the original query. There are a couple of indirect ways of doing so, but of course with hurdles:
&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Run mysql client with --xml option:&lt;/span&gt; This will print the output of each command in xml and the command itself is included in the xml. The downside was not many pagers (including &lt;span style="font-weight: bold;font-family:courier new;" &gt;mk-visual-explain&lt;/span&gt;) understand the xml format and parsing the xml to create a output like string was going to be costly. This will also include writing a lot of code that I don't do for a hack. :)&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;Use the tee command: &lt;/span&gt;MySQL allows you to tee output to a file that contains everything from standard output including &lt;span style="font-weight: bold;font-family:courier new;" &gt;mysql&gt; command...&lt;/span&gt; We could have used and easily take the last command using a simple grep. The problem is output is tee'd after pager exits.&lt;/li&gt;&lt;/ul&gt;Well, that was easy. Now since we know that MySQL will tee after the pager exits we will make the pager exit while still working. And introduce &lt;span style="font-weight: bold;font-family:courier new;" &gt;exit if fork;&lt;/span&gt; in our code. :)

It's working fine for me with small display problems like the time spent is now displayed above the query result. That's fine for me.

&lt;span style="font-weight: bold;"&gt;Files:

&lt;/span&gt;I don't have an exact way of uploading files into blogger so got it on scribd.
&lt;ul&gt;&lt;li style="font-family: courier new; font-weight: bold;"&gt;&lt;a href="http://www.scribd.com/doc/3863288/mysmartpager"&gt;mysmartpager&lt;/a&gt;&lt;/li&gt;&lt;li style="font-family: courier new; font-weight: bold;"&gt;&lt;a href="http://www.scribd.com/doc/3863313/mysmartpagercnf"&gt;mysmartpager.cnf&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a style="font-family: courier new; font-weight: bold;" href="http://www.scribd.com/doc/3863314/mysmartpager"&gt;.mysmartpager&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;
&lt;span style="font-weight: bold;"&gt;Install:&lt;/span&gt;
&lt;ul&gt;&lt;li&gt;Copy &lt;span style="font-weight: bold;font-family:courier new;" &gt;mysmartpager&lt;/span&gt; file to your &lt;span style="font-weight: bold;font-family:courier new;" &gt;/path/to/bin&lt;/span&gt; directory&lt;/li&gt;&lt;li&gt;Copy &lt;span style="font-weight: bold;font-family:courier new;" &gt;.mysmartpager&lt;/span&gt; file to your &lt;span style="font-weight: bold;font-family:courier new;" &gt;$HOME&lt;/span&gt; directory&lt;/li&gt;&lt;li&gt;Copy &lt;span style="font-weight: bold;font-family:courier new;" &gt;mysmartpager.cnf&lt;/span&gt; file to your MySQL's config directory and make sure it is included.&lt;/li&gt;&lt;li&gt;Make appropriate changes in &lt;span style="font-weight: bold;font-family:courier new;" &gt;mysmartpager.cnf&lt;/span&gt; file
&lt;/li&gt;&lt;li&gt;More regexs (perl regex's can be written in &lt;span style="font-weight: bold;font-family:courier new;" &gt;.mysmartpager&lt;/span&gt;)&lt;/li&gt;&lt;/ul&gt;
I have listed three regex's in &lt;span style="font-family: courier new; font-weight: bold;"&gt;.mysmartpager&lt;/span&gt; file. Would like to hear more ideas flowing.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-3725181957677226059?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=3725181957677226059' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/3725181957677226059'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/3725181957677226059'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/07/mysql-command-line-pager-mysmartpager.html' title='MySQL command line pager &amp; mysmartpager'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-2600129907103066961</id><published>2008-07-04T11:43:00.001+01:00</published><updated>2008-07-04T11:43:48.094+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='book review'/><category scheme='http://www.blogger.com/atom/ns#' term='Community'/><title type='text'>Reading "High Performance MySQL, 2nd Edition"</title><content type='html'>&lt;p&gt;I haven't received my copy of the book yet, but being unable to control my temptation I have started reading it over Safari while waiting for my own very personal copy. :)&lt;/p&gt;  &lt;p&gt;Already a fan of the first edition, you can feel the same charisma being carried over in this book also. The best part of the book is the simplicity by which you are set sailing over MySQL.&lt;/p&gt;  &lt;p&gt;Without doubt, it is one of the best books MySQL can ask for. Certainly, I would recommend this book to anyone who is associated with the word MySQL. Or otherwise if you answer &lt;strong&gt;yes&lt;/strong&gt; to any of these questions below, then go and grab a copy.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;em&gt;Are you a developer working/struggling with MySQL?&lt;/em&gt;&lt;/li&gt;    &lt;li&gt;&lt;em&gt;Are you a DBA working/struggling with MySQL?&lt;/em&gt;&lt;/li&gt;    &lt;li&gt;&lt;em&gt;Do you intend to learn MySQL?&lt;/em&gt;&lt;/li&gt;    &lt;li&gt;&lt;em&gt;Are you fascinated by databases and open-source?&lt;/em&gt;&lt;/li&gt;    &lt;li&gt;&lt;em&gt;Do you work with some other RDBMS and have an open mind?&lt;/em&gt;&lt;/li&gt;    &lt;li&gt;&lt;em&gt;Are you an Internet entrepreneur worried about your &lt;strong&gt;one fine day?&lt;/strong&gt;&lt;/em&gt;&lt;/li&gt;    &lt;li&gt;&lt;em&gt;...&lt;/em&gt;&lt;/li&gt;    &lt;li&gt;&lt;em&gt;...&lt;/em&gt;&lt;/li&gt;    &lt;li&gt;&lt;em&gt;...&lt;/em&gt;&lt;/li&gt;    &lt;li&gt;&lt;em&gt;Do you love dolphins?&lt;/em&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Well, there are some blanks left for you to fill in your own reasons. :)&lt;/p&gt;  &lt;p&gt;As for me, I would take this opportunity to thanks &lt;a href="http://www.percona.com/team/baron-schwartz.html"&gt;Baron&lt;/a&gt;, &lt;a href="http://www.percona.com/team/peter-zaitsev.html"&gt;Peter&lt;/a&gt;, &lt;a href="http://www.percona.com/team/vadim-tkachenko.html"&gt;Vadim&lt;/a&gt;, and &lt;a href="http://openquery.com.au/company/people"&gt;Arjen&lt;/a&gt; for a wonderful book and resort back to reading.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-2600129907103066961?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=2600129907103066961' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/2600129907103066961'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/2600129907103066961'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/07/reading-performance-mysql-2nd-edition.html' title='Reading &amp;quot;High Performance MySQL, 2nd Edition&amp;quot;'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-5367994458782564151</id><published>2008-06-19T08:53:00.002+01:00</published><updated>2008-06-19T09:00:40.600+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='temporary tables'/><category scheme='http://www.blogger.com/atom/ns#' term='replication'/><title type='text'>Temporary tables as seen by replication slave</title><content type='html'>&lt;p&gt;Few days back, one of my colleagues posted a good question. It sounds something like this; &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;"Temporary tables are session based that means under different sessions we can create temporary tables with similar names. Now since slave thread is singleton, how does it manage to keep them separate?"&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;He was very much right in asking this and the answer is not all that intuitive. Lets go through the binlog events to see why it is not that intuitive.&lt;/p&gt;  &lt;div   style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;   &lt;div   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;     &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; mysql&amp;gt; SHOW BINLOG EVENTS &lt;span style="color: rgb(0, 0, 255);"&gt;IN&lt;/span&gt; &lt;span style="color: rgb(0, 96, 128);"&gt;'log-bin.000016'&lt;/span&gt;;&lt;/pre&gt;    &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; . . .     &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt; | log-bin.000016 |  389 | Query       | 2515922453 |         488 | &lt;span style="color: rgb(0, 0, 255);"&gt;use&lt;/span&gt; `test`; &lt;span style="color: rgb(0, 0, 255);"&gt;CREATE&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;TEMPORARY&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;TABLE&lt;/span&gt; test.t(a &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;)         |    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt; | log-bin.000016 |  488 | Query       | 2515922453 |         582 | &lt;span style="color: rgb(0, 0, 255);"&gt;use&lt;/span&gt; `test`; INSERT &lt;span style="color: rgb(0, 0, 255);"&gt;INTO&lt;/span&gt; test.t(a) &lt;span style="color: rgb(0, 0, 255);"&gt;VALUES&lt;/span&gt;(1)         |    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt; | log-bin.000016 |  582 | Query       | 2515922453 |         676 | &lt;span style="color: rgb(0, 0, 255);"&gt;use&lt;/span&gt; `test`; INSERT &lt;span style="color: rgb(0, 0, 255);"&gt;INTO&lt;/span&gt; test.t(a) &lt;span style="color: rgb(0, 0, 255);"&gt;VALUES&lt;/span&gt;(3)         |    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt; | log-bin.000016 |  676 | Query       | 2515922453 |         775 | &lt;span style="color: rgb(0, 0, 255);"&gt;use&lt;/span&gt; `test`; &lt;span style="color: rgb(0, 0, 255);"&gt;CREATE&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;TEMPORARY&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;TABLE&lt;/span&gt; test.t(a &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;)         |    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt; | log-bin.000016 |  775 | Query       | 2515922453 |         869 | &lt;span style="color: rgb(0, 0, 255);"&gt;use&lt;/span&gt; `test`; INSERT &lt;span style="color: rgb(0, 0, 255);"&gt;INTO&lt;/span&gt; test.t(a) &lt;span style="color: rgb(0, 0, 255);"&gt;VALUES&lt;/span&gt;(7)         |    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt; | log-bin.000016 |  869 | Query       | 2515922453 |         944 | &lt;span style="color: rgb(0, 0, 255);"&gt;use&lt;/span&gt; `test`; &lt;span style="color: rgb(0, 0, 255);"&gt;drop&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;table&lt;/span&gt; t         |    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt; ...&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
Under general conditions if you run these statements in sequence, you will end up with a &lt;code&gt;Table `t` already exists&lt;/code&gt; when you put second &lt;code&gt;create temporary table&lt;/code&gt;. But with replication this seems to just work, how? Well, the truth is &lt;code&gt;SHOW BINLOG EVENTS&lt;/code&gt; doesn't show the full truth.

&lt;p&gt;&lt;strong&gt;The Magic Behind:&lt;/strong&gt;&lt;/p&gt;For such situations, MySQL uses a special flag &lt;code&gt;LOG_EVENT_THREAD_SPECIFIC_F&lt;/code&gt; that is set if the event is dependent on the connection it was executed on. This translates into setting a session level variable &lt;code&gt;pseudo_thread_id&lt;/code&gt; instructing the slave thread to treat a bundle of statements in a special way and do not create any confusion. Now this is actually a very safe method of doing things and being very extra paranoid I wondered why this was not there for every session? Simple answer is; &lt;strong&gt;performance reasons.&lt;/strong&gt; :)

&lt;p&gt;Check the outcome of &lt;code&gt;mysqlbinlog&lt;/code&gt;:&lt;/p&gt;&lt;div&gt;&lt;div   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; $ mysqlbinlog log-bin.000016    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; ...    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;# at 389&lt;/span&gt;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;#080617  2:06:11 server id -1779044843  end_log_pos 488     Query    thread_id=138    exec_time=0    error_code=0&lt;/span&gt;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt; SET TIMESTAMP=1213693571/*!*/;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt; SET @@session.pseudo_thread_id=138/*!*/;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt; CREATE TEMPORARY TABLE test.t(a int)/*!*/;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;# at 488&lt;/span&gt;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;#080617  2:06:15 server id -1779044843  end_log_pos 582     Query    thread_id=138    exec_time=0    error_code=0&lt;/span&gt;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt; SET TIMESTAMP=1213693575/*!*/;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt; SET @@session.pseudo_thread_id=138/*!*/;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt; INSERT INTO test.t(a) VALUES(1)/*!*/;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;# at 582&lt;/span&gt;   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;#080617  2:06:36 server id -1779044843  end_log_pos 676     Query    thread_id=138    exec_time=0    error_code=0&lt;/span&gt;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt; SET TIMESTAMP=1213693596/*!*/;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt; SET @@session.pseudo_thread_id=138/*!*/;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt; INSERT INTO test.t(a) VALUES(3)/*!*/;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;# at 676&lt;/span&gt;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;#080617  2:06:55 server id -1779044843  end_log_pos 775     Query    thread_id=141    exec_time=0    error_code=0&lt;/span&gt;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt; SET TIMESTAMP=1213693615/*!*/;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  21:&lt;/span&gt; SET @@session.pseudo_thread_id=141/*!*/;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  22:&lt;/span&gt; CREATE TEMPORARY TABLE test.t(a int)/*!*/;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  23:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;# at 775&lt;/span&gt;   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  24:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;#080617  2:11:07 server id -1779044843  end_log_pos 869     Query    thread_id=141    exec_time=0    error_code=0&lt;/span&gt;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  25:&lt;/span&gt; SET TIMESTAMP=1213693867/*!*/;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  26:&lt;/span&gt; SET @@session.pseudo_thread_id=141/*!*/;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  27:&lt;/span&gt; INSERT INTO test.t(a) VALUES(7)/*!*/;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  28:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;# at 869&lt;/span&gt;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  29:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;#080617  2:15:50 server id -1779044843  end_log_pos 944     Query    thread_id=141    exec_time=0    error_code=0&lt;/span&gt;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  30:&lt;/span&gt; SET TIMESTAMP=1213694150/*!*/;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  31:&lt;/span&gt; SET @@session.pseudo_thread_id=141/*!*/;    &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  32:&lt;/span&gt; drop table t/*!*/;   &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  33:&lt;/span&gt; ...&lt;/pre&gt;
 &lt;/div&gt;
   I delved into the code to know what all situations need this flag to be set. So far, it is set only when using temporary tables and with a possibility/extensibility of using with other situations in future. Other situations like transactions take care of themselves by the way they are logged.
&lt;/div&gt;
I'm running few tests to see if it handles all the conditions related to temporary tables created inside transactions. Will publish soon if something pops up.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-5367994458782564151?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=5367994458782564151' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/5367994458782564151'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/5367994458782564151'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/06/temporary-tables-as-seen-by-replication.html' title='Temporary tables as seen by replication slave'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-6145215625173365716</id><published>2008-06-03T11:29:00.001+01:00</published><updated>2008-06-03T11:29:49.359+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Open Source'/><category scheme='http://www.blogger.com/atom/ns#' term='Community'/><title type='text'>Go! Take the survey</title><content type='html'>&lt;p&gt;&lt;a href="http://www.paragon-cs.com/wordpress/"&gt;Keith Murphy&lt;/a&gt; and &lt;a href="http://marksitblog.blogspot.com/"&gt;Mark Schoonover&lt;/a&gt; have put together an excellent &lt;a href="http://www.kwiksurveys.com/online-survey.php?surveyID=KOKK_e414c40b"&gt;survey&lt;/a&gt; which is already doing good (seeing the numbers they have been clocking). Survey results will be out in the summer issue of &lt;a href="http://www.paragon-cs.com/mag/"&gt;MySQL magazine&lt;/a&gt;. I feel this is a &amp;quot;must take&amp;quot; survey for everyone in the MySQL community. And do not forget to mention my blog in the &amp;quot;top 5 favorite MySQL blogs&amp;quot; ;-). Just kidding! &lt;/p&gt;  &lt;p&gt;Overall, this is the best survey regarding MySQL that I have ever taken, don't miss it. It will hardly take 10 minutes of your busy schedule. &lt;em&gt;A busy man has the time do anything, right?&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Quick Links:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.kwiksurveys.com/online-survey.php?surveyID=KOKK_e414c40b"&gt;Survey&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.paragon-cs.com/mag/"&gt;MySQL Magazine&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-6145215625173365716?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=6145215625173365716' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/6145215625173365716'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/6145215625173365716'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/06/go-take-survey.html' title='Go! Take the survey'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-4135633677156046375</id><published>2008-05-30T10:59:00.001+01:00</published><updated>2008-05-30T10:59:10.739+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Day Out'/><category scheme='http://www.blogger.com/atom/ns#' term='Best Practices'/><category scheme='http://www.blogger.com/atom/ns#' term='monitoring'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><category scheme='http://www.blogger.com/atom/ns#' term='Index'/><title type='text'>Variable's Day Out #14: log_queries_not_using_indexes</title><content type='html'>&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="500" border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="187"&gt;Applicable To&lt;/td&gt;        &lt;td valign="top" width="311"&gt;MySQL Server&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="187"&gt;Server Startup Option&lt;/td&gt;        &lt;td valign="top" width="311"&gt;&lt;code&gt;--log-queries-not-using-indexes&lt;/code&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="187"&gt;Scope&lt;/td&gt;        &lt;td valign="top" width="311"&gt;Global&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="187"&gt;Dynamic&lt;/td&gt;        &lt;td valign="top" width="311"&gt;Yes&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="187"&gt;Possible Values&lt;/td&gt;        &lt;td valign="top" width="311"&gt;Boolean&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="187"&gt;Default&lt;/td&gt;        &lt;td valign="top" width="311"&gt;False&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="187"&gt;Category&lt;/td&gt;        &lt;td valign="top" width="311"&gt;Performance, Monitoring, Best Practices&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;If you have slow query logs enabled (with &lt;code&gt;--log-slow-queries&lt;/code&gt;), this variable will help interpret all those queries that are not using indexes as slow queries.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Usage:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;While designing a MySQL oriented application, I generally design my schema first without introducing any index (only exception being the PRIMARY ones). Get the application ready. Next enable &lt;code&gt;log_queries_not_using_indexes&lt;/code&gt; and &lt;strong&gt;start index usage testing&lt;/strong&gt;. Analyze all queries, introduce indexes one by one and you are all set to go. This helps a lot in rewriting queries, figuring out the best possible index etc. Many times I have seen the need for swapping WHERE clause CONDITIONS for making it possible for the query to use an existing index.&lt;/p&gt;  &lt;p&gt;For already deployed systems' performance glitches and production outages, this flag do serve as a starting point.&lt;/p&gt;  &lt;p&gt;Though as always, usage of a variable is subject to circumstances. For my conditions and usage pattern, this variable comes very handy.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Read more:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.1/en/server-options.html#option_mysqld_log-queries-not-using-indexes"&gt;MySQL manual entry on log-queries-not-using-indexes&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.1/en/slow-query-log.html"&gt;Slow Query Logs&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Hope you enjoyed reading this.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-4135633677156046375?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=4135633677156046375' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/4135633677156046375'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/4135633677156046375'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/05/variable-day-out-14-logqueriesnotusingi.html' title='Variable&amp;#39;s Day Out #14: log_queries_not_using_indexes'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-8614611300476874987</id><published>2008-05-20T20:25:00.001+01:00</published><updated>2008-05-20T20:25:56.906+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Day Out'/><category scheme='http://www.blogger.com/atom/ns#' term='replication'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><title type='text'>Variable's Day Out #13: binlog_format</title><content type='html'>&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="500" border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="196"&gt;Applicable To&lt;/td&gt;        &lt;td valign="top" width="302"&gt;MySQL Server&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="196"&gt;Introduced In&lt;/td&gt;        &lt;td valign="top" width="302"&gt;5.1.5&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="196"&gt;Server Startup Option&lt;/td&gt;        &lt;td valign="top" width="302"&gt;--binlog-format=&lt;em&gt;&amp;lt;value&amp;gt;&lt;/em&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="196"&gt;Scope&lt;/td&gt;        &lt;td valign="top" width="302"&gt;Both&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="196"&gt;Dynamic&lt;/td&gt;        &lt;td valign="top" width="302"&gt;Yes&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="196"&gt;Possible Values&lt;/td&gt;        &lt;td valign="top" width="302"&gt;enum(ROW, STATEMENT, MIXED)&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="196"&gt;Default&lt;/td&gt;        &lt;td valign="top" width="302"&gt;&amp;lt; 5.1.12: STATEMENT          &lt;br /&gt;&amp;gt;= 5.1.12: MIXED&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="196"&gt;Categories&lt;/td&gt;        &lt;td valign="top" width="302"&gt;Replication, Performance&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Starting with 5.1.5, MySQL has implemented ROW based replication format which logs the physical changes to individual row changes. This looks like the most optimal way to many users. But it is not always, rather not optimal most of the times. E.g. consider a statement that does bulk insert of thousands of rows. In ROW based logging, there will be those many entries in binlog and otherwise it would have been just one single statement.&lt;/p&gt;  &lt;p&gt;STATEMENT based replication, the old good historical way, propagates SQL statements from master to slave and has been working good all those years except for few cases like statements using non deterministic UDFs. &lt;/p&gt;  &lt;p&gt;In MIXED format, MySQL uses STATEMENT based replication by default other than a few cases like &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;when USER(), CURRENT_USER() are used &lt;/li&gt;    &lt;li&gt;when a call to UDF is involved &lt;/li&gt;    &lt;li&gt;when 2 or more tables with AUTO_INCREMENT columns are updated. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;... For full list of all such cases, refer the &lt;a href="http://dev.mysql.com/doc/refman/5.1/en/binary-log-mixed.html"&gt;official documentation&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;What about UDF's?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;A user defined function or stored procedure is very hard to predict. In such cases, statement based replication can create inconsistencies. Few days back, I saw a case where a table&amp;#160; included in &lt;code&gt;Replicate_Ignore_Table&lt;/code&gt; list was propagating statements from a procedure. If one has procedures and such cases, consider using ROW or MIXED mode replication.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;What to use?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Though ROW based replication is the safest in case of creating inconsistencies, it may lead to sheer performance degradation thanks to binlog size. On the other hand STATEMENT based replication has drawbacks like with UDFs etc. IMHO, MIXED mode is the best way out unless you have some very special case. The only problem is that there might be more cases that need to be handled by mixed mode than currently being served. We need time's stamp on it. :)&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Read more:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.1/en/server-options.html#option_mysqld_binlog-format"&gt;MySQL manual entry on binlog_format&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.1/en/replication-formats.html"&gt;MySQL manual on Replication Formats&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.1/en/binary-log-mixed.html"&gt;MySQL manual: Mixed Binary Logging Format&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.1/en/replication-sbr-rbr.html"&gt;Statement based vs Row based replication&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hope you enjoyed reading this.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-8614611300476874987?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=8614611300476874987' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/8614611300476874987'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/8614611300476874987'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/05/variable-day-out-13-binlogformat.html' title='Variable&amp;#39;s Day Out #13: binlog_format'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-1875485526100667644</id><published>2008-05-19T13:07:00.001+01:00</published><updated>2008-05-19T15:00:10.336+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Day Out'/><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><category scheme='http://www.blogger.com/atom/ns#' term='InnoDB'/><title type='text'>Variable's Day Out #12: innodb_flush_method</title><content type='html'>&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="500" border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="174"&gt;Applicable To&lt;/td&gt;        &lt;td valign="top" width="324"&gt;InnoDB on Unix like OS&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="174"&gt;Server Startup Option&lt;/td&gt;        &lt;td valign="top" width="324"&gt;--innodb_flush_method=&lt;em&gt;&amp;lt;value&amp;gt;&lt;/em&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="174"&gt;Scope&lt;/td&gt;        &lt;td valign="top" width="324"&gt;Global&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="174"&gt;Dynamic&lt;/td&gt;        &lt;td valign="top" width="324"&gt;No&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="174"&gt;Possible Values&lt;/td&gt;        &lt;td valign="top" width="324"&gt;enum(O_DSYNC, O_DIRECT, &lt;em&gt;&amp;lt;&amp;lt;none&amp;gt;&amp;gt;&lt;/em&gt; )&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="174"&gt;Default Value&lt;/td&gt;        &lt;td valign="top" width="324"&gt;&lt;em&gt;&amp;lt;&amp;lt;none&amp;gt;&amp;gt;&lt;/em&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="174"&gt;Category&lt;/td&gt;        &lt;td valign="top" width="324"&gt;Performance&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;This variable changes the way InnoDB open files and flush data to disk and is should be considered as very important for InnoDB performance. By default, InnoDB uses &lt;code&gt;fsync()&lt;/code&gt; (without &lt;code&gt;O_DSYNC&lt;/code&gt;) to flush both log and data files.&lt;/p&gt;  &lt;p&gt;Setting this variable to &lt;code&gt;O_DIRECT&lt;/code&gt; will result in InnoDB using &lt;code&gt;O_DIRECT&lt;/code&gt; while opening files and &lt;code&gt;fsync()&lt;/code&gt; to flush both data and log files. &lt;code&gt;O_DIRECT&lt;/code&gt; is useful when an application maintains it's own caching mechanism which is very well true for MySQL/InnoDB. &lt;code&gt;O_DIRECT&lt;/code&gt; is the option that should be used in most of the cases as it takes the overhead of double buffering and reduces swap pressure. You should be careful if you are not using a battery backed up RAID cache as it may lead to data loss in case of a crash. Also, the MySQL documentation warns against using &lt;code&gt;O_DIRECT&lt;/code&gt; when files are located on a SAN, I don't have any idea on that.&lt;/p&gt;  &lt;p&gt;&lt;code&gt;O_DSYNC&lt;/code&gt; makes InnoDB to use &lt;code&gt;O_SYNC&lt;/code&gt; to open and flush the log files, and uses &lt;code&gt;fsync()&lt;/code&gt; to flush data files.&lt;/p&gt;  &lt;p&gt;For Windows, the flush method is always &lt;code&gt;async_unbuffered&lt;/code&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Recommendation:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;If you are not doing anything unusual like SAN storage etc (which otherwise also you should reconsider before doing), always use &lt;code&gt;O_DIRECT&lt;/code&gt; for this. This leads to a significant improvement in InnoDB performance by removing double buffering. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Read More:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.1/en/innodb-parameters.html#option_mysqld_innodb_flush_method"&gt;MySQL manual entry on innodb_flush_method&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.mysqlperformanceblog.com/2007/11/04/heikki-tuuri-answers-to-innodb-questions-part-ii/"&gt;Heikki Tuuri recommends &lt;code&gt;O_DIRECT&lt;/code&gt;: Check Q35&lt;/a&gt; @ mysqlperformanceblog.com &lt;/li&gt;    &lt;li&gt;&lt;a href="http://linux.die.net/man/2/fsync"&gt;&lt;code&gt;man 2 fsync&lt;/code&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://linux.die.net/man/2/open"&gt;&lt;code&gt;man 2 open&lt;/code&gt;&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hope you enjoyed reading this.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-1875485526100667644?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=1875485526100667644' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/1875485526100667644'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/1875485526100667644'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/05/variable-day-out-12-innodbflushmethod.html' title='Variable&amp;#39;s Day Out #12: innodb_flush_method'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-455379691933171343</id><published>2008-05-18T16:50:00.001+01:00</published><updated>2008-05-19T14:59:29.349+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Day Out'/><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><category scheme='http://www.blogger.com/atom/ns#' term='maintenance'/><category scheme='http://www.blogger.com/atom/ns#' term='administration'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><title type='text'>Variable's Day Out #11: large_pages</title><content type='html'>&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="500" border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="194"&gt;Applicable To&lt;/td&gt;        &lt;td valign="top" width="304"&gt;MySQL/Linux&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="194"&gt;Server Startup Option&lt;/td&gt;        &lt;td valign="top" width="304"&gt;--large-pages&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="194"&gt;Scope&lt;/td&gt;        &lt;td valign="top" width="304"&gt;Global&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="194"&gt;Dynamic&lt;/td&gt;        &lt;td valign="top" width="304"&gt;No way&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="194"&gt;Possible Values&lt;/td&gt;        &lt;td valign="top" width="304"&gt;True|False flag&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="194"&gt;Default Value&lt;/td&gt;        &lt;td valign="top" width="304"&gt;False&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="194"&gt;Category&lt;/td&gt;        &lt;td valign="top" width="304"&gt;Performance, Administration&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;This option, currently available only for Linux, if set enables the usage of large pages by MySQL. Many operating systems/system architectures support optional memory pages bigger than the default size (4 KB). Usually the large page size is 2 MB, this can be checked in the &lt;code&gt;large_page_size&lt;/code&gt; variable in MySQL.&lt;/p&gt;  &lt;p&gt;For applications that do a lot of memory accesses, as MySQL can, reduced TLB (Translation Lookaside Buffer) misses lead to better performance. Also having large pages, makes MySQL buffers less susceptible of being swapped out.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;When to Use?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Try to keep it enabled, I have never heard of any side effects (In other words if you find any do let me know, I will update the blog post :) ). Other things that can be considered are:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;How much of swapping is happening on the system? &lt;/li&gt;    &lt;li&gt;What are the other applications running on that system? Though it is a bad idea to run other heavy applications on the same box as MySQL (at least in production), but if you can't get rid of them, using large-pages will make MySQL avoid swapping. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;strong&gt;How to configure?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Before large pages can be used on Linux, it is necessary to configure the HugeTLB memory pool.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Check your total memory &lt;code&gt;(MemTotal)&lt;/code&gt;, huge page size &lt;code&gt;(Hugepagesize)&lt;/code&gt; etc and decide how many huge pages you want to run with. This information is available in &lt;code&gt;/proc/meminfo file.&lt;/code&gt; &lt;/li&gt;    &lt;li&gt;Set the number of huge pages to be used by the system. use &lt;code&gt;sysctl -w vm.nr_hugepages = &lt;em&gt;&amp;lt;value&amp;gt;&lt;/em&gt;&lt;/code&gt; &lt;/li&gt;    &lt;li&gt;Ensure to set memlock for mysql user in &lt;code&gt;/etc/security/limits.conf&lt;/code&gt; to allow this user using large memory. &lt;/li&gt;    &lt;li&gt;Stop MySQL. &lt;/li&gt;    &lt;li&gt;Restart your system. &lt;/li&gt;    &lt;li&gt;Start MySQL server with &lt;code&gt;large-pages&lt;/code&gt; option. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;If nothing goes wrong, you should be all set and going.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Read more:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.1/en/server-options.html#option_mysqld_large-pages"&gt;MySQL manual entry on large-pages&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.mysqlperformanceblog.com/2008/04/06/should-you-have-your-swap-file-enabled-while-running-mysql/"&gt;Swap file discussion @ mysqlperformanceblog.com&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://lwn.net/Articles/6969/"&gt;Large page support in the Linux kernel&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.puschitz.com/TuningLinuxForOracle.shtml#UsingVeryLargeMemory"&gt;Using Very Large Memory&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#option_mysqld_large_page_size"&gt;MySQL manual entry on large_page_size&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hope you enjoyed reading this.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-455379691933171343?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=455379691933171343' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/455379691933171343'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/455379691933171343'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/05/variable-day-out-11-largepages.html' title='Variable&amp;#39;s Day Out #11: large_pages'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-1812792816511964889</id><published>2008-05-15T13:12:00.001+01:00</published><updated>2008-05-15T13:12:54.739+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='memcached'/><category scheme='http://www.blogger.com/atom/ns#' term='maintenance'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><title type='text'>Memcached, but do you need it?</title><content type='html'>&lt;p&gt;With all due respect to the technology and it's advocates (myself included), after a surge in articles describing the merits of using memcached I'm just pushing a thought breakpoint for developers to think whether they actually need it or not?&lt;/p&gt;  &lt;p&gt;Recently, I ran into cases where the developers have decided to use memcached over MySQL style architecture after reading some/many good/nice articles about it without giving a damn to their requirements. I would like to list few things as a checklist for developers to decide on their architecture. There is still no precise answer but sometimes few cases can be just ruled out :).&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;What is the total size of your data? &lt;em&gt;It might be a possibility that you can keep the data in memory in each node, or MySQL can just keep the whole thing (data+indexes) in a buffer.&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;How frequently your data is updated? &lt;em&gt;Very frequent updates may lead to low cache hit ratio for memcached data. And refreshing memcached too many times may lead to unnecessary overhead. Remember doing [get,get,set] vs [get].&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;What is the peak load on your system? &lt;em&gt;Consider if MySQL itself can handle the peak load or otherwise if even memcached cannot handle the peak load with given infrastructure.&lt;/em&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;I generally ask people a simple question, Why they think they should be using memcached (or something else even)? To shock them, I even ask them &amp;quot;Why they think they should be using MySQL?&amp;quot;. And believe me, this is what I believe developers should be asking themselves.&lt;/p&gt;  &lt;p&gt;There is only one good argument against this, what if tomorrow you need to suddenly scale or what if your projections need memcached? In such cases, I suggest people to design their data layers in a flexible way, flexible enough to allow things in and out.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-1812792816511964889?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=1812792816511964889' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/1812792816511964889'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/1812792816511964889'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/05/memcached-but-do-you-need-it.html' title='Memcached, but do you need it?'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-3860612724249288574</id><published>2008-05-14T10:08:00.001+01:00</published><updated>2008-05-14T10:08:46.257+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Open Source'/><category scheme='http://www.blogger.com/atom/ns#' term='Community'/><title type='text'>Long Live Open Source</title><content type='html'>&lt;p&gt;&lt;em&gt;&lt;strong&gt;&amp;#8220;Don&amp;#8217;t worry about people stealing an idea. If it&amp;#8217;s original, you will have to ram it down their throats.&amp;#8221;        &lt;br /&gt;&amp;#8212; Howard Aiken&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;MySQL is &lt;a href="http://blogs.mysql.com/kaj/2008/05/06/mysql-server-is-open-source-even-backup-extensions/"&gt;back on Open Source track&lt;/a&gt; and that is definitely the best news for all (including community, MySQL and Sun as well). I think that now Sun/MySQL have agreed to the importance of community, it becomes community's responsibility to give them more reasons to believe so. Let's participate like never before.&lt;/p&gt;  &lt;p&gt;Kaj, in his &lt;a href="http://blogs.mysql.com/kaj/2008/05/06/mysql-server-is-open-source-even-backup-extensions/"&gt;post&lt;/a&gt; says &lt;em&gt;&amp;quot;...model to be useful for both those who spend money to save time, and those who spend time to save money&amp;quot;. &lt;/em&gt;This is what Open Source is, isn't it?&lt;/p&gt;  &lt;p&gt;All in all, a decision most awaited and most welcome is taken. Thanks a ton to everybody who made this happen.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-3860612724249288574?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=3860612724249288574' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/3860612724249288574'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/3860612724249288574'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/05/long-live-open-source.html' title='Long Live Open Source'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-5025629368717377801</id><published>2008-05-13T07:09:00.001+01:00</published><updated>2008-05-13T07:09:18.425+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Day Out'/><title type='text'>Last 10 Variable Day Outs</title><content type='html'>&lt;p&gt;Well, the first summary of last 10 variable day outs.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Day Outs:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Day Out #1: &lt;a href="http://optimmysql.blogspot.com/2008/03/variable-day-out-1-delaykeywrite.html"&gt;delay_key_write&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Day Out #2: &lt;a href="http://optimmysql.blogspot.com/2008/03/variable-day-out-2-keybuffersize.html"&gt;key_buffer_size&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Day Out #3: &lt;a href="http://optimmysql.blogspot.com/2008/03/variable-day-out-3-maxconnecterrors.html"&gt;max_connect_errors&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Day Out #4: &lt;a href="http://optimmysql.blogspot.com/2008/04/variable-day-out-4-innodbbufferpoolsize.html"&gt;innodb_buffer_pool_size&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Day Out #5: &lt;a href="http://optimmysql.blogspot.com/2008/04/variable-day-out-5-innodbthreadconcurre.html"&gt;innodb_thread_concurrency&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Day Out #6: &lt;a href="http://optimmysql.blogspot.com/2008/04/variable-day-out-6-innodbbufferpoolread.html"&gt;Innodb_buffer_pool_reads&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Day Out #7: &lt;a href="http://optimmysql.blogspot.com/2008/04/variable-day-out-7-innodbautoinclockmod.html"&gt;innodb_autoinc_lock_mode&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Day Out #8: &lt;a href="http://optimmysql.blogspot.com/2008/04/variable-day-out-8-innodbadditionalmemp.html"&gt;innodb_additional_mem_pool_size&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Day Out #9: &lt;a href="http://optimmysql.blogspot.com/2008/04/variable-day-out-9-longquerytime.html"&gt;long_query_time&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Day Out #10: &lt;a href="http://optimmysql.blogspot.com/2008/05/variable-day-out-10-innodbfilepertable.html"&gt;innodb_file_per_table&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;em&gt;(If you want some specific variable to be discussed here, do let me know. Contact me by posting a comment on the blog or send me a mail.)&lt;/em&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-5025629368717377801?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=5025629368717377801' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/5025629368717377801'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/5025629368717377801'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/05/last-10-variable-day-outs.html' title='Last 10 Variable Day Outs'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-2129952226776316098</id><published>2008-05-12T18:48:00.001+01:00</published><updated>2008-05-13T06:28:28.906+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Day Out'/><category scheme='http://www.blogger.com/atom/ns#' term='maintenance'/><category scheme='http://www.blogger.com/atom/ns#' term='Tablespace'/><category scheme='http://www.blogger.com/atom/ns#' term='InnoDB plugin'/><category scheme='http://www.blogger.com/atom/ns#' term='InnoDB'/><title type='text'>Variable's Day Out #10: innodb_file_per_table</title><content type='html'>&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="500" border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="178"&gt;Applicable To&lt;/td&gt;        &lt;td valign="top" width="320"&gt;InnoDB&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="178"&gt;Server Startup Option&lt;/td&gt;        &lt;td valign="top" width="320"&gt;--innodb-file-per-table&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="178"&gt;Scope&lt;/td&gt;        &lt;td valign="top" width="320"&gt;Global&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="178"&gt;Dynamic&lt;/td&gt;        &lt;td valign="top" width="320"&gt;General InnoDB Engine: No         &lt;br /&gt;InnoDB plug-in: Yes&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="178"&gt;Possible Values &lt;/td&gt;        &lt;td valign="top" width="320"&gt;Enable|Disable Flag&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="178"&gt;Default Value&lt;/td&gt;        &lt;td valign="top" width="320"&gt;Disabled&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="178"&gt;Category&lt;/td&gt;        &lt;td valign="top" width="320"&gt;Maintenance&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;strong&gt;Descr&lt;/strong&gt;&lt;strong&gt;iption:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;This variable if enabled, makes InnoDB to create a separate &lt;code&gt;.ibd&lt;/code&gt; file for storing indexes and data. Setting this variable makes it easy to manage disks with huge tables. Having this option enabled, makes it a lot easier to move bigger (or smaller) &lt;code&gt;.ibd&lt;/code&gt; files to separate physical disks and/or have backups of certain tables without affecting others.&lt;/p&gt;  &lt;p&gt;As I have mentioned in my &lt;a href="http://optimmysql.blogspot.com/2007/07/innodb-tablespace-size.html"&gt;earlier post&lt;/a&gt;, that InnoDB does not return back the space once claimed for a tablespace, this variable comes handy in managing such situations. Though I have not seen any performance gain while using this option, people do cite such metrics. Again, I would say as always that it may be case dependent.&lt;/p&gt;  &lt;p&gt;It should be noted that this option only effects tables that are created after this option is enabled (and server is restarted). Tables that are created with this option disabled are created in the shared tablespace and remain there even if this option is enabled in between. Also, even if all the tables are created with this option enabled, InnoDB still needs the shared tablespace to store its internal data dictionary and undo logs.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Speical case: InnoDB plug-in&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;With the introduction of InnoDB plug-in, this variable becomes dynamic in nature and holds much more importance than just disk maintenance. You should have this variable enabled to be able to use the new file format. But even in InnoDB plug-in the restriction on tablespaces not returning disk space is intact.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Read More:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.1/en/innodb-parameters.html#option_mysqld_innodb_file_per_table"&gt;MySQL manual entry on &lt;code&gt;innodb_file_per_table&lt;/code&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.1/en/multiple-tablespaces.html"&gt;Using per-table tablespaces&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://optimmysql.blogspot.com/2007/07/innodb-tablespace-size.html"&gt;InnoDB tablespace size @ Optim MySQL&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.innodb.com/doc/innodb_plugin-1.0/innodb-other-changes.html#innodb-other-changes-innodb_file_per_table"&gt;Dynamic &lt;code&gt;innodb_file_per_table&lt;/code&gt; with InnoDB plug-in&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-2129952226776316098?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=2129952226776316098' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/2129952226776316098'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/2129952226776316098'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/05/variable-day-out-10-innodbfilepertable.html' title='Variable&amp;#39;s Day Out #10: innodb_file_per_table'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-1391687449677148582</id><published>2008-04-28T13:01:00.001+01:00</published><updated>2008-04-28T13:01:36.202+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Day Out'/><category scheme='http://www.blogger.com/atom/ns#' term='monitoring'/><title type='text'>Variable's Day Out #9: long_query_time</title><content type='html'>&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="500" border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="171"&gt;Applicable To&lt;/td&gt;        &lt;td valign="top" width="327"&gt;MySQL Server&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="171"&gt;Server Startup Option&lt;/td&gt;        &lt;td valign="top" width="327"&gt;--long-query-time=&lt;em&gt;&amp;lt;value&amp;gt;&lt;/em&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="171"&gt;Scope&lt;/td&gt;        &lt;td valign="top" width="327"&gt;Both&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="171"&gt;Dynamic&lt;/td&gt;        &lt;td valign="top" width="327"&gt;Yes&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="171"&gt;Possible Values&lt;/td&gt;        &lt;td valign="top" width="327"&gt;(&amp;lt; 5.1.21): Integer          &lt;br /&gt;(&amp;gt;=5.1.21): Numeric&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="171"&gt;Minimum Value&lt;/td&gt;        &lt;td valign="top" width="327"&gt;(&amp;lt; 5.1.21): 1          &lt;br /&gt;(&amp;gt;=5.1.21): 0&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="171"&gt;Default Value&lt;/td&gt;        &lt;td valign="top" width="327"&gt;10&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="171"&gt;Category&lt;/td&gt;        &lt;td valign="top" width="327"&gt;Monitoring&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;In case (as generally the case is) one wants to know about the bottlenecks in their system, MySQL's has a small answer to this in &lt;a href="http://dev.mysql.com/doc/refman/5.1/en/slow-query-log.html"&gt;&amp;quot;Slow Query Logs&amp;quot;&lt;/a&gt;. Any query that takes more time than specified by &lt;code&gt;long_query_time&lt;/code&gt;, is labeled as a slow query and logged. Time measurement for a query is done in real time and not CPU time. So, whether a query is slow or not depends on the system that you are running on and the load the system is running under.&lt;/p&gt;  &lt;p&gt;For many people's delight, as of MySQL 5.1.21, the long_query_time can be specified in microseconds and minimum value has been changed to 0. Earlier, the minimum value was 1.&amp;#160; If set to &amp;quot;0&amp;quot;, it will log all the queries under slow query log. However, the new microsecond resolution in 5.1.21 is only supported when logging to a file and microsecond part is ignored when logging to table. The table logging was introduced in MySQL 5.1.6.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;How to Use:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;This is completely dependent on your use-case, SLA's etc. I have two systems, one of them is running with &lt;code&gt;long_query_time&lt;/code&gt; being 5 seconds. Whereas for the second one, we are planning to upgrade so to become capable of using microsecond resolution (actually we need up-to millisecond resolution ;) ).&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Related Variables:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;code&gt;log_slow_queries&lt;/code&gt; &lt;/li&gt;    &lt;li&gt;&lt;code&gt;log_queries_not_using_indexes&lt;/code&gt; &lt;/li&gt;    &lt;li&gt;&lt;code&gt;min_examined_row_limits&lt;/code&gt; &lt;/li&gt;    &lt;li&gt;&lt;code&gt;log_output&lt;/code&gt; &lt;/li&gt;    &lt;li&gt;&lt;code&gt;slow_query_log_file&lt;/code&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;Read More:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#option_mysqld_long_query_time"&gt;MySQL manual entry on long_query_time&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.1/en/slow-query-log.html"&gt;&amp;quot;The Slow Query Log&amp;quot; documentation&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.1/en/log-tables.html"&gt;... &amp;amp; Slow Query Log Output Destinations&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hope you enjoyed reading this.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-1391687449677148582?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=1391687449677148582' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/1391687449677148582'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/1391687449677148582'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/04/variable-day-out-9-longquerytime.html' title='Variable&amp;#39;s Day Out #9: long_query_time'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-467015424111373117</id><published>2008-04-16T13:30:00.002+01:00</published><updated>2008-04-16T13:32:52.608+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Day Out'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><category scheme='http://www.blogger.com/atom/ns#' term='InnoDB'/><title type='text'>Variable's Day Out #8: innodb_additional_mem_pool_size</title><content type='html'>&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;  &lt;table border="1" cellpadding="2" cellspacing="0" width="500"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="172"&gt;Applicable To&lt;/td&gt;        &lt;td valign="top" width="326"&gt;InnoDB&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="172"&gt;Server Startup Option&lt;/td&gt;        &lt;td valign="top" width="326"&gt;--innodb-additional-mem-pool-size=&lt;em&gt;&amp;lt;value&amp;gt;&lt;/em&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="172"&gt;Scope&lt;/td&gt;        &lt;td valign="top" width="326"&gt;Global&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="172"&gt;Dynamic&lt;/td&gt;        &lt;td valign="top" width="326"&gt;No&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="172"&gt;Possible Values&lt;/td&gt;        &lt;td valign="top" width="326"&gt;Integer:         
Range: 524288 (512K) - 4294967295 (4G)&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="172"&gt;Default Value&lt;/td&gt;        &lt;td valign="top" width="326"&gt;1048576 (1M)&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="172"&gt;Category&lt;/td&gt;        &lt;td valign="top" width="326"&gt;Performance&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;As per MySQL &lt;a href="http://dev.mysql.com/doc/refman/5.0/en/innodb-parameters.html#option_mysqld_innodb_additional_mem_pool_size"&gt;documentation&lt;/a&gt;, this pool is used to store data dictionary information and other internal data structures. If InnoDB runs out of memory on this pool, it starts allocating from OS. &lt;/p&gt;  &lt;p&gt;Most of the additional memory pool usage goes to &lt;strong&gt;tables in the data dictionary and connections&lt;/strong&gt;. Normally, with increasing number of tables you may need to allocate more memory to this pool. But as modern OS'es have good and fast memory allocating functions, this variable does not hit performance.&lt;/p&gt;  &lt;p&gt;Anyhow, if you need to see how much of additional memory pool is being used, it's available via &lt;code&gt;SHOW ENGINE INNODB STATUS&lt;/code&gt;. &lt;/p&gt;  &lt;div&gt;   &lt;div   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;     &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; SHOW ENGINE INNODB STATUS \G&lt;/pre&gt;    &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; .&lt;/pre&gt;    &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt; .&lt;/pre&gt;    &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt; --------------------&lt;span style="color: rgb(0, 128, 0);"&gt;--&lt;/span&gt;&lt;/pre&gt;    &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;BUFFER POOL AND MEMORY&lt;/span&gt;&lt;/pre&gt;    &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt; --------------------&lt;span style="color: rgb(0, 128, 0);"&gt;--&lt;/span&gt;&lt;/pre&gt;    &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;Total memory allocated XXXXXXXXXXXXX; in additional pool allocated XXXXXXX&lt;/span&gt;&lt;/pre&gt;    &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;Dictionary memory allocated XXXXX&lt;/span&gt;&lt;/pre&gt;    &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt; .&lt;/pre&gt;    &lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt; .&lt;/pre&gt;
 &lt;/div&gt;&lt;code&gt;
additional pool allocated&lt;/code&gt; will show amount of memory allocated in additional memory pool, the usage. And out of usage, &lt;code&gt;Dictionary memory allocated&lt;/code&gt; will show amount of memory being used for data dictionary.&lt;/div&gt;&lt;strong&gt;
Best value:&lt;/strong&gt;

There is hardly any impact of a smaller value for this variable. Still it is better to have a value which around 20% more than what &lt;code&gt;SHOW ENGINE INNODB STATUS&lt;/code&gt; shows for &lt;code&gt;additional pool allocated&lt;/code&gt;. It's proportional to (number of tables + number of concurrent connections).
&lt;strong&gt;
Read more:&lt;/strong&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.0/en/innodb-parameters.html#option_mysqld_innodb_additional_mem_pool_size"&gt;MySQL manual entry on innodb_additional_mem_pool_size&lt;/a&gt;&lt;/li&gt;  &lt;li&gt;&lt;a href="http://www.mysqlperformanceblog.com/2006/09/29/what-to-tune-in-mysql-server-after-installation/"&gt;What to tune in MySQL ... @mysqlperformanceblog.com&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;a href="http://www.mail-archive.com/mysql@lists.mysql.com/msg63247.html"&gt;Heikki Tuuri on "Calculating innodb_additional_mem_pool_size?"&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;Hope you enjoyed reading this post.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-467015424111373117?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=467015424111373117' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/467015424111373117'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/467015424111373117'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/04/variable-day-out-8-innodbadditionalmemp.html' title='Variable&amp;#39;s Day Out #8: innodb_additional_mem_pool_size'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-3582190616024265802</id><published>2008-04-15T15:48:00.000+01:00</published><updated>2008-04-15T15:49:05.386+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='auto_increment'/><category scheme='http://www.blogger.com/atom/ns#' term='Locks'/><category scheme='http://www.blogger.com/atom/ns#' term='Day Out'/><category scheme='http://www.blogger.com/atom/ns#' term='replication'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><category scheme='http://www.blogger.com/atom/ns#' term='InnoDB'/><title type='text'>Variable's Day Out #7: innodb_autoinc_lock_mode</title><content type='html'>&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="500" border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="145"&gt;Applicable To&lt;/td&gt;        &lt;td valign="top" width="352"&gt;InnoDB&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="145"&gt;Introduced In&lt;/td&gt;        &lt;td valign="top" width="352"&gt;5.1.22&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="145"&gt;Server Startup Option&lt;/td&gt;        &lt;td valign="top" width="352"&gt;--innodb-autoinc-lock-mode=&lt;em&gt;&amp;lt;value&amp;gt;&lt;/em&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="145"&gt;Scope&lt;/td&gt;        &lt;td valign="top" width="352"&gt;Global&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="145"&gt;Dynamic&lt;/td&gt;        &lt;td valign="top" width="352"&gt;No&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="145"&gt;Possible Values&lt;/td&gt;        &lt;td valign="top" width="352"&gt;enum(0,1,2)          &lt;br /&gt;Interpretation:           &lt;br /&gt;          &lt;table cellspacing="0" cellpadding="2" width="350" border="1"&gt;&lt;tbody&gt;             &lt;tr&gt;               &lt;td valign="top" width="123"&gt;&lt;strong&gt;Value&lt;/strong&gt;&lt;/td&gt;                &lt;td valign="top" width="225"&gt;&lt;strong&gt;Meaning&lt;/strong&gt;&lt;/td&gt;             &lt;/tr&gt;              &lt;tr&gt;               &lt;td valign="top" width="123"&gt;0&lt;/td&gt;                &lt;td valign="top" width="225"&gt;Traditional&lt;/td&gt;             &lt;/tr&gt;              &lt;tr&gt;               &lt;td valign="top" width="123"&gt;1&lt;/td&gt;                &lt;td valign="top" width="225"&gt;Consecutive&lt;/td&gt;             &lt;/tr&gt;              &lt;tr&gt;               &lt;td valign="top" width="123"&gt;2&lt;/td&gt;                &lt;td valign="top" width="225"&gt;Interleaved&lt;/td&gt;             &lt;/tr&gt;           &lt;/tbody&gt;&lt;/table&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="145"&gt;Default Value&lt;/td&gt;        &lt;td valign="top" width="352"&gt;1 (consecutive)&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="145"&gt;Categories&lt;/td&gt;        &lt;td valign="top" width="352"&gt;Scalability, Performance&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;This variable was introduced in 5.1.22 as a result of the &lt;a title="http://bugs.mysql.com/bug.php?id=16979" href="http://bugs.mysql.com/bug.php?id=16979"&gt;[Bug 16979]&lt;/a&gt; and comes very handy when stuck with auto_increment scalability issue, also mentioned in my &lt;a href="http://optimmysql.blogspot.com/2007/07/autoincrement-in-innodb.html"&gt;previous post&lt;/a&gt;. So what do traditional, consecutive and interleaved mean?&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Traditional&lt;/em&gt; is &amp;quot;traditional&amp;quot;, this takes back InnoDB to pre-innodb_autoinc_lock_mode and a table level AUTO-INC lock is obtained and held until the statement is done. This ensures consecutive auto-increment values by a single statement. Remember, this lock is scoped for a statement and not transaction and hence is not equivalent to serializing transactions as someone raised a question to me recently.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Consecutive&lt;/em&gt;, the default lock mode, works in context switching method. For inserts where the number of rows is not known (bulk inserts), ie &lt;code&gt;INSERT ... SELECT, REPLACE ... SELECT, LOAD DATA&lt;/code&gt;, it takes a table level AUTO-INC lock. Otherwise for inserts where the number of rows is known in advance (simple inserts), it uses a light weight mutex during the allocation of auto-increment values. The mutex is of course checked for only if no other transaction holds the AUTO-INC lock. However for inserts where user provides auto-increment values for some rows (mixed mode inserts), InnoDB tends to allocate more values and lose them.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Interleaved&lt;strong&gt; &lt;/strong&gt;&lt;/em&gt;mode just ensures uniqueness for each generated auto-incremented value. This mode never takes an AUTO-INC lock and multiple statements can keep generating values simultaneously.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;How to use?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;My overall recommendation is not to change this variable and keep it to default. And if you are having mixed mode insert statements that contradict the usage, better look into them. Otherwise, following are the constraints on usage.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Use &lt;em&gt;interleaved &lt;/em&gt;only when your tables don't have auto-increment columns. Also if you don't know/don't care if they have, then you have more issues to resolve. :)&lt;/li&gt;    &lt;li&gt;&amp;quot;mixed mode inserts&amp;quot; can lead to losing values with &lt;em&gt;consecutive&lt;/em&gt; mode.&lt;/li&gt;    &lt;li&gt;It's not safe to use statement based or mixed replication with &lt;em&gt;interleaved &lt;/em&gt;mode.&lt;/li&gt;    &lt;li&gt;&lt;em&gt;Traditional &lt;/em&gt;mode has scalability issues, but is safe when used with mixed mode inserts.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;Read more:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.1/en/innodb-parameters.html#option_mysqld_innodb_autoinc_lock_mode"&gt;MySQL manual entry on innodb_autoinc_lock_mode&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.1/en/innodb-auto-increment-handling.html#innodb-auto-increment-configurable"&gt;&lt;strong&gt;Configurable InnoDB Auto-Increment Locking&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://bugs.mysql.com/bug.php?id=16979"&gt;[Bug 16979]&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Hope you enjoyed reading this.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-3582190616024265802?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=3582190616024265802' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/3582190616024265802'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/3582190616024265802'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/04/variable-day-out-7-innodbautoinclockmod.html' title='Variable&amp;#39;s Day Out #7: innodb_autoinc_lock_mode'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-8502545158934592279</id><published>2008-04-11T12:55:00.001+01:00</published><updated>2008-04-11T12:55:20.157+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Day Out'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><category scheme='http://www.blogger.com/atom/ns#' term='InnoDB'/><title type='text'>Variable's Day Out #6: Innodb_buffer_pool_reads</title><content type='html'>&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="500" border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="170"&gt;Applicable To&lt;/td&gt;        &lt;td valign="top" width="328"&gt;InnoDB&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="170"&gt;Type&lt;/td&gt;        &lt;td valign="top" width="328"&gt;Status Variable&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="170"&gt;Scope&lt;/td&gt;        &lt;td valign="top" width="328"&gt;GLOBAL | SESSION&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="170"&gt;Dynamic&lt;/td&gt;        &lt;td valign="top" width="328"&gt;NA&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="170"&gt;Possible Values&lt;/td&gt;        &lt;td valign="top" width="328"&gt;Integer&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="170"&gt;Default Value&lt;/td&gt;        &lt;td valign="top" width="328"&gt;NA&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="170"&gt;Category&lt;/td&gt;        &lt;td valign="top" width="328"&gt;Performance&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;According to the &lt;a href="http://dev.mysql.com/doc/refman/5.0/en/server-status-variables.html#option_mysqld_Innodb_buffer_pool_reads" target="_blank"&gt;official documentation&lt;/a&gt;, this variable defines &amp;quot;The number of logical reads that &lt;code&gt;InnoDB&lt;/code&gt; could not satisfy from the buffer pool and had to do a single-page read.&amp;quot;. &lt;/p&gt;  &lt;p&gt;But we can go a little further to see the what happens in and around this variable. As per the &lt;em&gt;&lt;/em&gt;&lt;a href="http://forge.mysql.com/wiki/MySQL_Internals_Files_In_InnoDB_Sources" target="_blank"&gt;MySQL Internals documentation&lt;/a&gt;, a buffer is defined as a memory area that contains copies of pages that ordinarily are in the main data file (read innodb tablespace). And &amp;quot;buffer pool&amp;quot; is simply a set of all the buffers. Now, when InnoDB needs to access a new page it looks first in the buffer pool, in case page isn't there InnoDB reads it from the disk to a new buffer. InnoDB chucks old buffers (basing its decision on LRU algorithm) when it has to make space for a new buffer. This is the time when this variable gets incremented.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Best value:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Without doubt, 0 (zero). But that is only possible if you are not using InnoDB. :)&lt;/p&gt;  &lt;p&gt;So, while using InnoDB, you have to see that this variable remains as small as possible when compared to &lt;font face="Courier New"&gt;Innodb_buffer_pool_read_requests&lt;/font&gt;. In case you are seeing a high value for this, you might like to increase your &lt;font face="Courier New"&gt;&lt;a href="http://optimmysql.blogspot.com/2008/04/variable-day-out-4-innodbbufferpoolsize.html" target="_blank"&gt;innodb_buffer_pool_size&lt;/a&gt;&lt;/font&gt; and/or look at the size of your data/indexes at large.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;What else:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;I always used to wonder the difference between &lt;code&gt;Innodb_buffer_pool_reads&lt;/code&gt; and &lt;code&gt;Innodb_pages_read&lt;/code&gt;, but never too seriously until I read &lt;a href="http://mysqlguy.net/2008/02/25/status-variables-difference-between-innodbpagesread-and-innodbbufferpoolreads" target="_blank"&gt;Jay Janssen's query&lt;/a&gt; about it. And then thought of figuring out myself. As I stated there also &amp;quot;&lt;font face="Courier New"&gt;Innodb_pages_read&lt;/font&gt; are the pages read from buffer pool and &lt;font face="courier new"&gt;Innodb_buffer_pool_reads&lt;/font&gt; are the pages read for the buffer pool&amp;quot;, so no confusion.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Read more:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.0/en/server-status-variables.html#option_mysqld_Innodb_buffer_pool_reads" target="_blank"&gt;MySQL manual entry on Innodb_buffer_pool_reads&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://forge.mysql.com/wiki/MySQL_Internals_Files_In_InnoDB_Sources" target="_blank"&gt;MySQL Internals documentation of InnoDB source files&lt;/a&gt; - read [\buf (BUFFERING)] section.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://mysqlguy.net/2008/02/25/status-variables-difference-between-innodbpagesread-and-innodbbufferpoolreads" target="_blank"&gt;Jay Janssen's post asking differnence and many answers&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://mysqlguy.net/2008/02/28/the-scoop-innodb-reads" target="_blank"&gt;Jay Janssen's own answer on the same.&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hope you enjoyed reading this.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-8502545158934592279?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=8502545158934592279' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/8502545158934592279'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/8502545158934592279'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/04/variable-day-out-6-innodbbufferpoolread.html' title='Variable&amp;#39;s Day Out #6: Innodb_buffer_pool_reads'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-722309643170117177</id><published>2008-04-08T14:24:00.000+01:00</published><updated>2008-04-08T14:25:35.376+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Day Out'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><category scheme='http://www.blogger.com/atom/ns#' term='InnoDB'/><title type='text'>Variable's Day Out #5: innodb_thread_concurrency</title><content type='html'>&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="500" border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="146"&gt;Applicable To&lt;/td&gt;        &lt;td valign="top" width="352"&gt;InnoDB&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="146"&gt;Server Startup Option&lt;/td&gt;        &lt;td valign="top" width="352"&gt;--innodb_thread_concurrency=&lt;em&gt;&amp;lt;value&amp;gt;&lt;/em&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="146"&gt;Scope&lt;/td&gt;        &lt;td valign="top" width="352"&gt;Global&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="146"&gt;Dynamic&lt;/td&gt;        &lt;td valign="top" width="352"&gt;Yes&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="146"&gt;Possible Values&lt;/td&gt;        &lt;td valign="top" width="352"&gt;Integer:          &lt;br /&gt;Range: 0 - 1000           &lt;br /&gt;Interpretation:           &lt;br /&gt;          &lt;table cellspacing="0" cellpadding="2" width="347" border="1"&gt;&lt;tbody&gt;             &lt;tr&gt;               &lt;td valign="top" width="131"&gt;&lt;strong&gt;MySQL Version&lt;/strong&gt;&lt;/td&gt;                &lt;td valign="top" width="214"&gt;&lt;strong&gt;Value&lt;/strong&gt;&lt;/td&gt;             &lt;/tr&gt;              &lt;tr&gt;               &lt;td valign="top" width="131"&gt;4.x&lt;/td&gt;                &lt;td valign="top" width="214"&gt;0 - sets it to 1                  &lt;br /&gt;&amp;gt;500 - Infinite Concurrency&lt;/td&gt;             &lt;/tr&gt;              &lt;tr&gt;               &lt;td valign="top" width="131"&gt;&amp;lt; 5.0.19&lt;/td&gt;                &lt;td valign="top" width="214"&gt;0 - sets it to 1                  &lt;br /&gt;&amp;gt;= 20 - Infinite Concurrency&lt;/td&gt;             &lt;/tr&gt;              &lt;tr&gt;               &lt;td valign="top" width="131"&gt;&amp;gt;= 5.0.19&lt;/td&gt;                &lt;td valign="top" width="214"&gt;0 - Infinite Concurrency&lt;/td&gt;             &lt;/tr&gt;           &lt;/tbody&gt;&lt;/table&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="146"&gt;Default Value&lt;/td&gt;        &lt;td valign="top" width="352"&gt;         &lt;table cellspacing="0" cellpadding="2" width="347" border="1"&gt;&lt;tbody&gt;             &lt;tr&gt;               &lt;td valign="top" width="126"&gt;&lt;strong&gt;MySQL Version&lt;/strong&gt;&lt;/td&gt;                &lt;td valign="top" width="219"&gt;&lt;strong&gt;Default Value&lt;/strong&gt;&lt;/td&gt;             &lt;/tr&gt;              &lt;tr&gt;               &lt;td valign="top" width="126"&gt;&amp;lt; 5.0.8&lt;/td&gt;                &lt;td valign="top" width="219"&gt;8 (Finite)&lt;/td&gt;             &lt;/tr&gt;              &lt;tr&gt;               &lt;td valign="top" width="126"&gt;5.0.8 - 5.0.18&lt;/td&gt;                &lt;td valign="top" width="219"&gt;20 (Infinite)&lt;/td&gt;             &lt;/tr&gt;              &lt;tr&gt;               &lt;td valign="top" width="126"&gt;5.0.19 - 5.0.20&lt;/td&gt;                &lt;td valign="top" width="219"&gt;0 (Infinite)&lt;/td&gt;             &lt;/tr&gt;              &lt;tr&gt;               &lt;td valign="top" width="126"&gt;&amp;gt;= 5.0.21&lt;/td&gt;                &lt;td valign="top" width="219"&gt;8 (Finite)&lt;/td&gt;             &lt;/tr&gt;           &lt;/tbody&gt;&lt;/table&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="146"&gt;Category&lt;/td&gt;        &lt;td valign="top" width="352"&gt;Performance&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;innodb_thread_concurrency&lt;/font&gt; is the variable that limits the number of operating system threads that can run concurrently inside the InnoDB engine. Rest of the threads have to wait in a FIFO queue for execution. Also, threads waiting for locks are not counted in the number of concurrently executing threads.&lt;/p&gt;  &lt;p&gt;In the beginning of a thread execution, InnoDB checks the count of already running threads. If it is greater than or equal to the limit set by this variable, then the thread waits for some time and gives a new try. In case the second try also fails, the thread enters a FIFO queue. The sleep time was 50 ms and later on changed to 10 ms, and is managed by &lt;font face="Courier New"&gt;innodb_thread_sleep_delay&lt;/font&gt; from 5.0.3 onwards. On entering the InnoDB, the thread is given number of &amp;quot;free tickets&amp;quot;, number as defined by &lt;font face="Courier New"&gt;innodb_concurrency_tickets&lt;/font&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Optimal Setting:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Depends on your environment. The value largely depends on the version of MySQL, number of CPUs, number of Disks, and the kind of load that you are running. As a general principle, you may like to set it to twice the number of CPUs and Disks. And may consider only Disks for Disk IO intensive load and only CPUs for CPU intensive load. Also, if you have greater than or equal to 4 CPUs, you may consider lowering this variable, courtesy &lt;a href="http://bugs.mysql.com/bug.php?id=15815" target="_blank"&gt;[Bug 15815]&lt;/a&gt;, for un-patched MySQL versions (read the bug for the discussion). For machines with 1 or 2 CPUs, go for the kill, set it to infinite.&lt;/p&gt;  &lt;p&gt;Hyperthreading is worse than anything else, it is in many ways different than multi-CPU problems. Because hyperthreading tries to make a single processor work like two while making the instances share a lot of pipelines and cache. You might consider turning hyperthreading off when running MySQL.&lt;/p&gt;  &lt;p&gt;In my experience, I have seen a big enough &lt;font face="Courier New"&gt;&lt;a href="http://optimmysql.blogspot.com/2008/04/variable-day-out-4-innodbbufferpoolsize.html" target="_blank"&gt;innodb_buffer_pool_size&lt;/a&gt;&lt;/font&gt; to complement this variable on a multi-CPU machine, of course with the bug resolved. I will be publishing some numbers on it soon.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Read more:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.0/en/innodb-parameters.html#option_mysqld_innodb_thread_concurrency" target="_blank"&gt;MySQL manual entry on innodb_thread_concurrency&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.mysqlperformanceblog.com/2006/06/05/innodb-thread-concurrency/" target="_blank"&gt;InnoDB thread concurrency at mysqlperformanceblog.com&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://developers.sun.com/solaris/articles/mysql_perf_tune.html" target="_blank"&gt;MySQL InnoDB performance tuning on Solaris 10 OS&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://bugs.mysql.com/bug.php?id=15815" target="_blank"&gt;[Bug 15815]&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hope this post was helpful to you.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-722309643170117177?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=722309643170117177' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/722309643170117177'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/722309643170117177'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/04/variable-day-out-5-innodbthreadconcurre.html' title='Variable&amp;#39;s Day Out #5: innodb_thread_concurrency'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-7088954812776091796</id><published>2008-04-03T12:55:00.001+01:00</published><updated>2008-04-03T12:55:26.420+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Day Out'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><category scheme='http://www.blogger.com/atom/ns#' term='InnoDB'/><title type='text'>Variable's Day Out #4: innodb_buffer_pool_size</title><content type='html'>&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="500" border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="159"&gt;Applicable To&lt;/td&gt;        &lt;td valign="top" width="339"&gt;InnoDB&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="159"&gt;Server Startup Option&lt;/td&gt;        &lt;td valign="top" width="339"&gt;--innodb_buffer_pool_size=&amp;lt;value&amp;gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="159"&gt;Scope&lt;/td&gt;        &lt;td valign="top" width="339"&gt;Global&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="159"&gt;Dynamic&lt;/td&gt;        &lt;td valign="top" width="339"&gt;No&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="159"&gt;Possible Values&lt;/td&gt;        &lt;td valign="top" width="339"&gt;Integer         &lt;br /&gt;Range: 1048576 (1MB) - 4294967295 (4GB)          &lt;br /&gt;&lt;em&gt;(more for 64 bit machines)&lt;/em&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="159"&gt;Default Value&lt;/td&gt;        &lt;td valign="top" width="339"&gt;8388608 (8MB)&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="159"&gt;Category&lt;/td&gt;        &lt;td valign="top" width="339"&gt;Performance&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;One of the Peter's &lt;a href="http://www.mysqlperformanceblog.com/2006/09/29/what-to-tune-in-mysql-server-after-installation/" target="_blank"&gt;&amp;quot;what to tune?&amp;quot;&lt;/a&gt; parameters, this innodb buffer pool is a cache for both indexes and data and should be considered as the most important option for InnoDB performance. In case your server is hosting InnoDB heavy database, you can allocate up to 70-80% of the physical memory to this buffer. Anything more than this might cause paging in the operating system. Obviously if your server is not InnoDB heavy and you are using a mix of certain engines, dividing memory can be lot more complicated. This may also be taken as an argument against mixing engine types. :)&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Optimal Setting:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;As always, there is no magic number and the optimal value for you depends on your requirements. In case your data size is too much, you can always chose to provide as much as possible to this buffer pool. While doing so always remember that InnoDB will eat up some space for data structures related to your buffer pool also. On the other hand, if your projected database size (data+indexes) is small enough to fit in the memory, allocate around 10-15% more than your data-size.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Read more:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.0/en/innodb-parameters.html#option_mysqld_innodb_buffer_pool_size" target="_blank"&gt;MySQL manual entry on innodb_buffer_pool_size&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.mysqlperformanceblog.com/2006/09/29/what-to-tune-in-mysql-server-after-installation/" target="_blank"&gt;Tuning mysql at mysqlperformanceblog.com&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.mysqlperformanceblog.com/2007/11/03/choosing-innodb_buffer_pool_size/" target="_blank"&gt;Choosing the right size for innodb_buffer_pool_size&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.mysqlperformanceblog.com/2006/05/30/innodb-memory-usage/" target="_blank"&gt;InnoDB memory usage&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://feedblog.org/2007/09/29/using-o_direct-on-linux-and-innodb-to-fix-swap-insanity/" target="_blank"&gt;Using O_DIRECT on Linux and InnoDB to fix swapping&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Hope this post was helpful to you. Keep posting your comments.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-7088954812776091796?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=7088954812776091796' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/7088954812776091796'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/7088954812776091796'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/04/variable-day-out-4-innodbbufferpoolsize.html' title='Variable&amp;#39;s Day Out #4: innodb_buffer_pool_size'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-6330202336839538753</id><published>2008-03-29T14:49:00.000Z</published><updated>2008-03-29T14:51:01.830Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Security'/><category scheme='http://www.blogger.com/atom/ns#' term='Day Out'/><category scheme='http://www.blogger.com/atom/ns#' term='monitoring'/><title type='text'>Variable's Day Out #3: max_connect_errors</title><content type='html'>&lt;p&gt;&amp;#160;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="500" border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="177"&gt;Applicable To&lt;/td&gt;        &lt;td valign="top" width="321"&gt;MySQL Server&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="177"&gt;Server Startup Option&lt;/td&gt;        &lt;td valign="top" width="321"&gt;--max_connect_errors=&lt;em&gt;&amp;lt;value&amp;gt;&lt;/em&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="177"&gt;Scope&lt;/td&gt;        &lt;td valign="top" width="321"&gt;Global&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="177"&gt;Dynamic&lt;/td&gt;        &lt;td valign="top" width="321"&gt;Yes&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="177"&gt;Possible Values&lt;/td&gt;        &lt;td valign="top" width="321"&gt;Integer          &lt;br /&gt;Range: 1 - 4294967295&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="177"&gt;Default Value&lt;/td&gt;        &lt;td valign="top" width="321"&gt;10&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="177"&gt;Category&lt;/td&gt;        &lt;td valign="top" width="321"&gt;Security&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;This variable determines how many interrupted connections can occur from a host. If the number of interrupted connections from this host surpasses this number, that host is blocked from further connections. All of the following, as listed &lt;a href="http://dev.mysql.com/doc/refman/5.0/en/communication-errors.html" target="_blank"&gt;here&lt;/a&gt;, will cause the counter to be incremented.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Client program did not call &lt;font face="courier new"&gt;mysql_close()&lt;/font&gt; before exiting.&lt;/li&gt;    &lt;li&gt;Client had been sleeping more than &lt;font face="Courier New"&gt;wait_timeout&lt;/font&gt; or &lt;font face="Courier New"&gt;interactive_timeout&lt;/font&gt; without issuing any requests to the server.&lt;/li&gt;    &lt;li&gt;Client program ended abruptly in the middle of a data transfer.&lt;/li&gt;    &lt;li&gt;Client doesn't have privileges to connect to a database.&lt;/li&gt;    &lt;li&gt;Client uses incorrect password.&lt;/li&gt;    &lt;li&gt;It takes more than &lt;font face="Courier New"&gt;connect_timeout&lt;/font&gt; seconds to get a connect packet.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;You can always unblock the hosts with a &lt;font face="Courier New"&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.0/en/flush.html" target="_blank"&gt;FLUSH HOSTS&lt;/a&gt;&lt;/font&gt; statement.&lt;/p&gt;  &lt;p&gt;Prior to 5.1, any error would just increment the counter for a host. In 5.1, if a host is not yet blocked, any successful handshake resets the counter to 0.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Usage:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;It depends on the system admin, how they want to use this variable. For example, If the MySQL server is at a physically distant location from it's clients, one might not want unnecessary network issues to get a host blocked. Otherwise, if the expected client machines are somewhat known, one might not want to invite hackers. &lt;/p&gt;  &lt;p&gt;I generally consider a higher value for this variable to be a security threat, as some unfriendly people may use it for a DOS attack. It's better to keep the value low and system admin aware of the hosts being blocked.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Read More:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#option_mysqld_max_connect_errors" target="_blank"&gt;MySQL manual entry on max_connect_errors&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.0/en/communication-errors.html" target="_blank"&gt;Communication Errors and Aborted Connections&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://lists.mysql.com/internals/33469" target="_blank"&gt;Nice discussion on resetting counter&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://bugs.mysql.com/bug.php?id=32222" target="_blank"&gt;Possible feature in future&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.0/en/blocked-host.html" target="_blank"&gt;Host 'host_name' is blocked error explained&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hope this post was helpful to you. Keep posting your comments.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-6330202336839538753?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=6330202336839538753' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/6330202336839538753'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/6330202336839538753'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/03/variable-day-out-3-maxconnecterrors.html' title='Variable&amp;#39;s Day Out #3: max_connect_errors'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-6556580107543494033</id><published>2008-03-28T12:57:00.001Z</published><updated>2008-03-28T12:57:38.453Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='MyISAM'/><category scheme='http://www.blogger.com/atom/ns#' term='Day Out'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><category scheme='http://www.blogger.com/atom/ns#' term='Index'/><title type='text'>Variable's Day Out #2: key_buffer_size</title><content type='html'>&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="500" border="1"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="177"&gt;Engine(s)&lt;/td&gt;        &lt;td valign="top" width="321"&gt;MyISAM&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="177"&gt;Server Startup Option&lt;/td&gt;        &lt;td valign="top" width="321"&gt;--key_buffer_size=&lt;em&gt;&amp;lt;value&amp;gt;&lt;/em&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="177"&gt;Scope&lt;/td&gt;        &lt;td valign="top" width="321"&gt;Global&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="177"&gt;Dynamic&lt;/td&gt;        &lt;td valign="top" width="321"&gt;Yes&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="177"&gt;Possible Values&lt;/td&gt;        &lt;td valign="top" width="321"&gt;Integer          &lt;br /&gt;Range: 8 - 4294967295 (4 GB)&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="177"&gt;Default Value&lt;/td&gt;        &lt;td valign="top" width="321"&gt;131072 (128 KB)&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="177"&gt;Category&lt;/td&gt;        &lt;td valign="top" width="321"&gt;Performance&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;This is a global buffer where MySQL caches frequently used blocks of index data for MyISAM data. Maximum allowed size is 4GB on a 32 bit platform. Greater values are permitted for 64-bit platforms beyond MySQL 5.0.52.&lt;/p&gt;  &lt;p&gt;Keeping this buffer to an optimal value (neither too low nor too high) contributes heavily to the performance of your MySQL server. As given in the &lt;a href="http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#option_mysqld_key_buffer_size" target="_blank"&gt;MySQL Documentation&lt;/a&gt;, &amp;quot;using a value that is 25% of total memory on a machine that mainly runs MySQL is quite common&amp;quot;. As &lt;a href="http://www.mysqlperformanceblog.com/2006/09/29/what-to-tune-in-mysql-server-after-installation/" target="_blank"&gt;suggested by Peter&lt;/a&gt;, &amp;quot;Set up to 30-40% of available memory if you use MyISAM tables exclusively. Right size depends on amount of indexes, data size and workload&amp;quot;. &lt;/p&gt;  &lt;p&gt;Starting with 25%, one can keep monitoring &lt;strong&gt;key cache hit ratio&lt;/strong&gt; and increase it over time. A key cache hit ratio of more than 95% should be good enough. Also, for preventing oneself from allocating too much memory to this buffer, monitoring &lt;strong&gt;key buffer usage &lt;/strong&gt;should be helpful. I feel one should target towards more than 80% of buffer usage.&lt;/p&gt;  &lt;p&gt;If you are not using very few MyISAM tables, still key_buffer can be useful for MySQL's tables and temporary tables as well.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Calculations:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;font face="Courier"&gt;key_cache_hit_ratio = (1 - Key_reads/Key_read_requests) * 100&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font face="Courier"&gt;key_buffer_usage&amp;#160;&amp;#160;&amp;#160; = (1 - (Key_blocks_unused * key_cache_block_size)/key_buffer_size) * 100&lt;/font&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;Read More:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#option_mysqld_key_buffer_size" target="_blank"&gt;MySQL manual entry on key_buffer_size&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.mysqlperformanceblog.com/2006/09/29/what-to-tune-in-mysql-server-after-installation/" target="_blank"&gt;What to tune in MySQL server after installation&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.0/en/myisam-key-cache.html" target="_blank"&gt;MyISAM Key Cache - MySQL Manual&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hope this post was helpful to you.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-6556580107543494033?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=6556580107543494033' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/6556580107543494033'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/6556580107543494033'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/03/variable-day-out-2-keybuffersize.html' title='Variable&amp;#39;s Day Out #2: key_buffer_size'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-7615237938455362874</id><published>2008-03-27T11:02:00.000Z</published><updated>2008-03-27T13:03:50.055Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='MyISAM'/><category scheme='http://www.blogger.com/atom/ns#' term='Day Out'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><title type='text'>Variable's Day Out #1: delay_key_write</title><content type='html'>&lt;p&gt;After seeing some very good "of-the-day" series, I thought why should MySQL variables be left behind. So, my contribution in the race - "variable's day out". I won't brand it "of-the-day" series as it calls for too much of dedication and given my track record I shouldn't promise that. Henceforth, instead of calling a variable lucky enough for a day, lets call a day lucky enough for a variable. Though I will try my best to keep the lucky days rolling.&lt;/p&gt;  &lt;p&gt;  
Today's variable is &lt;span style="font-weight: bold;font-family:courier new;" &gt;delay_key_write.     
    
&lt;/span&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;  &lt;table border="1" cellpadding="2" cellspacing="0" width="500"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="212"&gt;Engines&lt;/td&gt;        &lt;td valign="top" width="286"&gt;MyISAM&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="212"&gt;Server Startup Option&lt;/td&gt;        &lt;td valign="top" width="286"&gt;--delay-key-writes[=&amp;lt;OFF|ON|ALL&amp;gt;]&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="212"&gt;Scope&lt;/td&gt;        &lt;td valign="top" width="286"&gt;Global&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="212"&gt;Dynamic&lt;/td&gt;        &lt;td valign="top" width="286"&gt;Yes&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="212"&gt;Possible Values&lt;/td&gt;        &lt;td valign="top" width="286"&gt;enum('ON', 'OFF', 'ALL')&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="212"&gt;Default Value&lt;/td&gt;        &lt;td valign="top" width="286"&gt;ON&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="212"&gt;Category&lt;/td&gt;        &lt;td valign="top" width="286"&gt;Performance&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;For MyISAM tables, delayed key writes doesn't allow key buffers to be flushed between writes.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Values:&lt;/strong&gt;&lt;/p&gt;  &lt;table border="1" cellpadding="2" cellspacing="0" width="498"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="104"&gt;OFF&lt;/td&gt;        &lt;td valign="top" width="391"&gt;Disables delayed key writing.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="104"&gt;ON&lt;/td&gt;        &lt;td valign="top" width="391"&gt;Enables for the tables created with DELAYED_KEY_WRITE option.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="104"&gt;ALL&lt;/td&gt;        &lt;td valign="top" width="391"&gt;Enables delayed key writing for all MyISAM tables.&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Enabling delayed key writing is good for heavy load tables (read or write heavy) as it decreases disk access.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;If the server goes down, the indexes have to be rebuilt.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Read more:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.0/en/server-options.html#option_mysqld_delay-key-write" target="_blank"&gt;MySQL manual entry on delay_key_write&lt;/a&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;Hope this post was helpful to you. Keep posting your comments.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-7615237938455362874?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=7615237938455362874' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/7615237938455362874'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/7615237938455362874'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/03/variable-day-out-1-delaykeywrite.html' title='Variable&amp;#39;s Day Out #1: delay_key_write'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-4838206157515546840</id><published>2008-03-27T10:48:00.000Z</published><updated>2008-03-27T11:01:59.387Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Optimizer'/><category scheme='http://www.blogger.com/atom/ns#' term='tool'/><category scheme='http://www.blogger.com/atom/ns#' term='MyEye'/><category scheme='http://www.blogger.com/atom/ns#' term='monitoring'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><title type='text'>MyEye update</title><content type='html'>Since ages, I was busy with many projects including my marriage. Nice to be back on the blog with an update on MyEye - the project I announced in my very first post.

MyEye is an (or is going to be an) open source monitoring tool for MySQL installations with handy knowledge-base and advisories for MySQL DBAs.

So, I'm done with the first round of analysis and design for MyEye. As far as it is planned, it's going to be a framework that would provide interface for people to write their own monitoring rules. Meanwhile MyEye web site is also under construction and I will be publishing the documentation soon there.

Will be looking forward to your contributions for creating an open knowledge base for MyEye.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-4838206157515546840?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=4838206157515546840' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/4838206157515546840'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/4838206157515546840'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2008/03/myeye-update.html' title='MyEye update'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-4396535050765818488</id><published>2007-11-22T20:40:00.001Z</published><updated>2008-02-28T09:56:06.044Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Hack'/><category scheme='http://www.blogger.com/atom/ns#' term='Locks'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><title type='text'>GET_LOCK &amp; FAMILY</title><content type='html'>&lt;p&gt;Again I have a well neglected and documented feature of MySQL. As we all often need and use locks in MySQL, we tend to forget (or not bother about) MySQL internals and how they cause trouble. For example, try something like LOCK TABLE ... WRITE on an InnoDB table in a transaction and see the same transaction getting timed out while waiting for a lock on one of the rows, Ref: &lt;a href="http://bugs.mysql.com/bug.php?id=5998"&gt;[Bug 5998]&lt;/a&gt;. All these problems occur when we have difference in semantics of statement at MySQL and Engine levels. But recently, we figured out this good technique of keeping the logic with ourselves and not relying on MySQL too much. Though even this technique is not fool proof in all the cases.&lt;/p&gt; &lt;p&gt;The secret is: use GET_LOCK function of MySQL. GET_LOCK(&lt;em&gt;str, timeout&lt;/em&gt;) function tries to get an exclusive lock with a name &lt;em&gt;(str) &lt;/em&gt;using &lt;em&gt;timeout &lt;/em&gt;seconds. The return values are tri-state, &lt;em&gt;1 &lt;/em&gt;if the lock was obtained successfully, &lt;em&gt;0&lt;/em&gt; if there was a timeout and &lt;em&gt;NULL&lt;/em&gt; in case of an error. For applications just bothered about getting the lock, following can be used.&lt;/p&gt; &lt;div&gt; &lt;div   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;SELECT&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;COALESCE&lt;/span&gt;(GET_LOCK(&lt;span style="color: rgb(0, 96, 128);"&gt;'lock_string_name'&lt;/span&gt;, 2), 0)&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
This is guaranteed to return either 1 or 0 meaning lock taken or otherwise respectively. Locks taken using GET_LOCK function are released in following conditions
&lt;ul&gt;&lt;li&gt;Lock is released explicitly using RELEASE LOCK function.&lt;/li&gt;&lt;li&gt;Issue a new GET_LOCK request.
&lt;/li&gt;&lt;li&gt;Connection terminates.&lt;/li&gt;&lt;/ul&gt;Other functions of this family are IS_FREE_LOCK and IS_USED_LOCK which are used to check the lock string status. IS_FREE_LOCK checks if the string is free i.e., returns 1 if the string is free, 0 if it is in use and NULL in case of an error. IS_USED_LOCK checks if the lock is used and returns the connection identifier of the clients that holds the lock otherwise 0. Again NULL is used for error cases.
&lt;p&gt;&lt;strong&gt;USEFULLNESS:&lt;/strong&gt;
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;This is one way of maintaining the mutual exclusivity of a process in a distributed environment while ensuring BCP also. Just have a named lock which will can be obtained only by one process at a time and rest of the processes just timing out and retrying for the lock after a sound sleep.&lt;/li&gt;
&lt;li&gt;The lock is very light weight and doesn't eat up too many resources at the MySQL server end.&lt;/li&gt;
&lt;li&gt;Lock is at MySQL level and engines are not involved at all, thus saving you to read bundles of documentation before using something.&lt;/li&gt;&lt;/ul&gt;&lt;strong&gt;CONS:&lt;/strong&gt;
&lt;ul&gt;&lt;li&gt;It requires due diligence in the application to ensure that all the conflicting transactions are taken care of. Even one single left out transaction may spoil the whole game. So, I would suggest such techniques are not good for heavily loaded (read lines of code) applications or otherwise you have a good QA team.&lt;/li&gt;
&lt;li&gt;It actually cannot equate other locks as you can have obtain only one lock for a connection.&lt;/li&gt;&lt;/ul&gt;&lt;strong&gt;MISC:&lt;/strong&gt;
&lt;ul&gt;&lt;li&gt;These locks are at connection level and do not respect transactions. Meaning, committing transactions do not have any effect on these locks. I think the fairness of this feature depends on the use case, hence this was put under MISC category :)&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Hope this blog was helpful to you. Keep posting your comments.&lt;/p&gt;&lt;p&gt;
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-4396535050765818488?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=4396535050765818488' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/4396535050765818488'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/4396535050765818488'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2007/11/getlock-family.html' title='GET_LOCK &amp;amp; FAMILY'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-414930427531082425</id><published>2007-09-12T18:56:00.001+01:00</published><updated>2007-09-12T18:57:40.247+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Optimizer'/><category scheme='http://www.blogger.com/atom/ns#' term='Hack'/><title type='text'>Customized Order By Sequence - A Small Hack</title><content type='html'>&lt;p&gt;What if you have to customize the sequence of order by clause on a column. Say, you have a integer column &lt;em&gt;'weight' &lt;/em&gt;that can have values ranging from 1 to 5 and you want to get the rows in the sequence 4,2,5,1,3. So what do you do? Here is a simple trick using the &lt;em&gt;field &lt;/em&gt;function.&lt;/p&gt; &lt;div&gt; &lt;div   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; mysql&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;SELECT&lt;/span&gt; * &lt;span style="color: rgb(0, 0, 255);"&gt;FROM&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;table&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;ORDER&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;BY&lt;/span&gt; FIELD(weight, 4, 2, 5, 1, 3);&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;Now what does it do. Field function returns the index of the first argument in the rest of the list. So, effectively the order by logic will be the same, just that the values that are being ordered are generated on the fly.
&lt;p&gt;Other approach can be to use CASE.. WHEN .. END statement as mentioned in the &lt;a href="http://dev.mysql.com/doc/refman/5.0/en/case-statement.html"&gt;MySQL Documentation&lt;/a&gt;. The above code can be rewritten as:
&lt;/p&gt;&lt;div&gt;&lt;div   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; mysql&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;SELECT&lt;/span&gt; *, &lt;span style="color: rgb(0, 0, 255);"&gt;CASE&lt;/span&gt; &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;     -&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;WHEN&lt;/span&gt; weight = 1 &lt;span style="color: rgb(0, 0, 255);"&gt;THEN&lt;/span&gt; 4&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     -&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;WHEN&lt;/span&gt; weight = 2 &lt;span style="color: rgb(0, 0, 255);"&gt;THEN&lt;/span&gt; 2&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     -&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;WHEN&lt;/span&gt; weight = 3 &lt;span style="color: rgb(0, 0, 255);"&gt;THEN&lt;/span&gt; 5&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;     -&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;WHEN&lt;/span&gt; weight = 4 &lt;span style="color: rgb(0, 0, 255);"&gt;THEN&lt;/span&gt; 1&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;     -&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;WHEN&lt;/span&gt; weight = 5 &lt;span style="color: rgb(0, 0, 255);"&gt;THEN&lt;/span&gt; 3&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;     -&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;END&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;AS&lt;/span&gt; weight_custom&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;     -&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;FROM&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;table&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;     -&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;ORDER&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;BY&lt;/span&gt; weight_custom;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
But I'm a little biased towards the first approach due to its simplicity. Though it's a matter of personal choice.
&lt;p&gt;Such requirements are rare, just a food for thought. &lt;/p&gt;Hope this blog was helpful to you. Keep posting your comments.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-414930427531082425?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=414930427531082425' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/414930427531082425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/414930427531082425'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2007/09/customized-order-by-sequence-small-hack.html' title='Customized Order By Sequence - A Small Hack'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-2913461048837330022</id><published>2007-09-12T14:25:00.001+01:00</published><updated>2008-02-28T09:55:31.201Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Locks'/><category scheme='http://www.blogger.com/atom/ns#' term='Transaction'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><category scheme='http://www.blogger.com/atom/ns#' term='InnoDB'/><category scheme='http://www.blogger.com/atom/ns#' term='Index'/><title type='text'>InnoDB Deadlock - Next Key Locking</title><content type='html'>&lt;p&gt;So you use InnoDB, have indexes on your table, think of row level locking and concurrent queries, feel good and go to sleep. All this while forgetting that even UPDATE and SELECT .... FOR UPDATE statements will (or may) also use the same index for scanning or updating. Then what? You may ask. &lt;/p&gt; &lt;p&gt;Well, InnoDB row level locking works in a somewhat different manner when using indexes. In this case, InnoDB locks index records in shared or exclusive mode when searching or scanning an index. Therefore, as mentioned in &lt;a href="http://dev.mysql.com/doc/refman/5.0/en/innodb-next-key-locking.html"&gt;MySQL Documentation&lt;/a&gt;, the row level locks are actually index record locks.&lt;/p&gt; &lt;p&gt;To complicate matters (or resolve issues) further, the lock is a gap lock. A gap lock refers to a lock that only locks a gap before some index record.&lt;/p&gt; &lt;p&gt;As per the example in &lt;a href="http://dev.mysql.com/doc/refman/5.0/en/innodb-next-key-locking.html"&gt;MySQL Documentation&lt;/a&gt;, lets say we have a query like this.&lt;/p&gt; &lt;div&gt; &lt;div   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;SELECT&lt;/span&gt; * &lt;span style="color: rgb(0, 0, 255);"&gt;FROM&lt;/span&gt; child &lt;span style="color: rgb(0, 0, 255);"&gt;WHERE&lt;/span&gt; id &amp;gt; 100 &lt;span style="color: rgb(0, 0, 255);"&gt;FOR&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;UPDATE&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
And there is an index on &lt;em&gt;id&lt;/em&gt; column. The query will lock all the index records where id is greater than 100, like 103, 107, etc. Meanwhile, the query also locks out inserts made in the gaps, say for 101,102, 104, 105, 106, 108 and above. If this is not done, there may be inserts while the transaction is under way.
&lt;p&gt;Now let us consider a little tricky problem. Suppose we have a table &lt;em&gt;table_name &lt;/em&gt;with index on &lt;em&gt;colx.&lt;/em&gt; We will have two queries running in parallel. For sure, both the queries are working on only one row each and as per the application, they are always different queries.&lt;/p&gt;The queries we have are:
&lt;div&gt;
&lt;div   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; mysql&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;SELECT&lt;/span&gt; * &lt;span style="color: rgb(0, 0, 255);"&gt;FROM&lt;/span&gt; table_name &lt;span style="color: rgb(0, 0, 255);"&gt;WHERE&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;     -&amp;gt; colx &lt;span style="color: rgb(0, 0, 255);"&gt;IS&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;NULL&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     -&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;LIMIT&lt;/span&gt; 1&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     -&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;FOR&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;UPDATE&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
and
&lt;div&gt;
&lt;div   style="border-style: none; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; mysql&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;UPDATE&lt;/span&gt; table_name &lt;span style="color: rgb(0, 0, 255);"&gt;SET&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;     -&amp;gt; colx = &lt;span style="color: rgb(0, 0, 255);"&gt;NULL&lt;/span&gt;, coly = &lt;span style="color: rgb(0, 0, 255);"&gt;NULL&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     -&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;WHERE&lt;/span&gt; colz = &lt;span style="color: rgb(0, 96, 128);"&gt;'something'&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
The first query starts locking the index records. But locking is not done in a single shot, it is done record by record. Meanwhile, the second query also gets lock on the record that signifies the current value of &lt;em&gt;colx&lt;/em&gt; and proceeds towards the NULL value record. Now by the time second query gets to the NULL value record, that gets locked by the first query and first query somehow waits for the lock already grabbed by second one. Huh!
&lt;p&gt;You need to be very (un)lucky to achieve this.&lt;/p&gt;&lt;strong&gt;Workarounds&lt;/strong&gt;
&lt;ol&gt;&lt;li&gt;Figure out all such indexes and queries where a deadlock can happen. In most cases, theoretical investigation may lead to unnecessary paranoia, so its better to have a regression test on your system and monitor for deadlocks. If you can, part away from those indexes.
&lt;/li&gt;&lt;li&gt;If you think you cannot live without your indexes, and the queries involved in deadlocks are mutually exclusive, you can go ahead with enabling &lt;code&gt;innodb_locks_unsafe_for_binlog&lt;/code&gt; without citing this blog as a reference. It's all your choice.
&lt;/li&gt;&lt;li&gt;The tests I have conducted have been done on MySQL 4.1.x. There is a &lt;a href="http://dev.mysql.com/doc/refman/5.0/en/innodb-parameters.html"&gt;claim&lt;/a&gt; that from MySQL 5.0.2, UPDATE and DELETE only locks rows that are going to be affected. So this should reduce the probability of deadlocks. I haven't tested it though.&lt;/li&gt;&lt;/ol&gt;Hope this blog was helpful to you. Keep posting your comments.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-2913461048837330022?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=2913461048837330022' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/2913461048837330022'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/2913461048837330022'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2007/09/innodb-deadlock-next-key-locking.html' title='InnoDB Deadlock - Next Key Locking'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-4952175346464471672</id><published>2007-08-08T17:13:00.001+01:00</published><updated>2007-08-08T17:15:41.642+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='auto_increment'/><category scheme='http://www.blogger.com/atom/ns#' term='InnoDB'/><title type='text'>InnoDB Repeating AUTO_INCREMENT Values</title><content type='html'>&lt;p&gt;This is a continuation of my earlier post with the same title. Recently while solving a problem where values of an auto_increment fields were getting repeated, a well documented and often neglected feature of InnoDB came forward. Lets first have a glimpse of the system and the problem.&lt;/p&gt; &lt;p&gt;We are maintaining a job queue in an InnoDB table for a distributed resource environment. This job queue is populated by distributed schedulers from the system, the job is assigned to a resource and once the job is done, it is removed from the job queue. The system runs on an assumption that the job id, which is an auto_increment field, always remain unique throughout the life of the system. I acknowledge that the usage is debatable, but lets keep it separate from this.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;The problem:&lt;/strong&gt; The operations team restarted the MySQL server in between. After that restart, some job id's got repeated. This broke the basic assumption of unique job id's and affected the whole business at large.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;What caused this:&lt;/strong&gt; After some hours of debugging and hypothesizing we figured out that the way InnoDB handles auto_increment values at server start is completely different from how MyISAM does and somewhat against the basic assumption of auto_increment values. InnoDB doesn't persists the auto_increment value between two MySQL instances. Rather when the server starts, for the first insert into the table, InnoDB executes the equivalent of this statement.&lt;/p&gt; &lt;div&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;SELECT&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;MAX&lt;/span&gt;(ai_col) &lt;span style="color: rgb(0, 0, 255);"&gt;FROM&lt;/span&gt; T &lt;span style="color: rgb(0, 0, 255);"&gt;FOR&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;UPDATE&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;
As I said, this is a well &lt;a href="http://dev.mysql.com/doc/refman/5.1/en/innodb-auto-increment-column.html"&gt;documented&lt;/a&gt; feature, but often neglected. In our case, it happened that before the server shutdown, few of the values from the upper bracket were deleted, as normally they would have been.
&lt;p&gt;&lt;strong&gt;Workarounds:&lt;/strong&gt;&lt;/p&gt;If you have such a system, where you rely too much on the auto_increment values from InnoDB, delete values frequently and assume them to be unique throughout the system, beware!
&lt;ol&gt;&lt;li&gt;Try and give up the auto_increment column, if you can afford to, and maintain the logic of incrementing values in your code. There might be other concerns, but then its all your own choice.&lt;/li&gt;
&lt;li&gt;Have another table which has only one auto_increment column, reference this from your original table and make sure you don't delete values from the upper bracket. You can safely expire the older entries in order to keep this table small enough.&lt;/li&gt;&lt;/ol&gt;Hope this blog was helpful to you. Keep posting your comments.
&lt;p&gt;
&lt;/p&gt;&lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:ce3c7de6-acbf-4827-a4da-2f43eda1b1a8" contenteditable="false" style="margin: 0px; padding: 0px; display: inline;"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/MySQL" rel="tag"&gt;MySQL&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/InnoDB" rel="tag"&gt;InnoDB&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/AUTO_INCREMENT" rel="tag"&gt;AUTO_INCREMENT&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-4952175346464471672?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=4952175346464471672' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/4952175346464471672'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/4952175346464471672'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2007/08/innodb-repeating-autoincrement-values.html' title='InnoDB Repeating AUTO_INCREMENT Values'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-8870170192743615025</id><published>2007-07-22T16:09:00.001+01:00</published><updated>2008-02-28T09:55:31.200Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><category scheme='http://www.blogger.com/atom/ns#' term='OLAP'/><title type='text'>OLAP Paradise - WITH ROLLUP</title><content type='html'>&lt;p&gt;Though this is an age old concept, but after seeing the ignorance factor of many regarding this, I thought of writing a bit about it. ROLLUP is a GROUP BY modifier that adds extra rows to the output which contain summary data. At each level of aggregation the aggregated column is filled with a NULL value.&lt;/p&gt; &lt;p&gt;Let's see a small example. I know the values are too small for the data presented, but just to keep it readable.&lt;/p&gt; &lt;div&gt; &lt;div   style="border-style: none; padding: 0px; overflow: visible; width: 80.48%; color: black; line-height: 12pt; height: 494px; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; mysql&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;CREATE&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;TABLE&lt;/span&gt; `rollup_1` (&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;   `url` &lt;span style="color: rgb(0, 0, 255);"&gt;varchar&lt;/span&gt;(255) &lt;span style="color: rgb(0, 0, 255);"&gt;DEFAULT&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;NULL&lt;/span&gt;,&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;   `&lt;span style="color: rgb(0, 0, 255);"&gt;year&lt;/span&gt;` &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;(11) &lt;span style="color: rgb(0, 0, 255);"&gt;DEFAULT&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;NULL&lt;/span&gt;,&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;   `country` &lt;span style="color: rgb(0, 0, 255);"&gt;char&lt;/span&gt;(2) &lt;span style="color: rgb(0, 0, 255);"&gt;DEFAULT&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;NULL&lt;/span&gt;,&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;   `visit` &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;(11) &lt;span style="color: rgb(0, 0, 255);"&gt;DEFAULT&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;NULL&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt; ) ENGINE=MyISAM &lt;span style="color: rgb(0, 0, 255);"&gt;DEFAULT&lt;/span&gt; CHARSET=latin1;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt; Query OK, 0 &lt;span style="color: rgb(0, 0, 255);"&gt;rows&lt;/span&gt; affected (0.01 sec)&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt; mysql&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;SELECT&lt;/span&gt; * &lt;span style="color: rgb(0, 0, 255);"&gt;FROM&lt;/span&gt; rollup_1;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt; +----------------------+------+---------+-------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt; | url                  | &lt;span style="color: rgb(0, 0, 255);"&gt;year&lt;/span&gt; | country | visit |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt; +----------------------+------+---------+-------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt; | http://www.yahoo.com | 2005 | US      | 12000 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 74.89%; color: black; line-height: 12pt; height: 16px; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt; | http://www.yahoo.com | 2005 | &lt;span style="color: rgb(0, 0, 255);"&gt;IN&lt;/span&gt;      | 10000 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt; | http://www.yahoo.com | 2006 | US      | 16000 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt; | http://www.yahoo.com | 2006 | &lt;span style="color: rgb(0, 0, 255);"&gt;IN&lt;/span&gt;      | 10700 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt; | http://www.yahoo.com | 2007 | US      | 21000 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt; | http://www.yahoo.com | 2007 | &lt;span style="color: rgb(0, 0, 255);"&gt;IN&lt;/span&gt;      | 13200 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt; +----------------------+------+---------+-------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt; 6 &lt;span style="color: rgb(0, 0, 255);"&gt;rows&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;set&lt;/span&gt; (0.00 sec)&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  21:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  22:&lt;/span&gt; mysql&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;SELECT&lt;/span&gt; IFNULL(url, &lt;span style="color: rgb(0, 96, 128);"&gt;'TOTAL'&lt;/span&gt;) &lt;span style="color: rgb(0, 0, 255);"&gt;AS&lt;/span&gt; url, &lt;span style="color: rgb(0, 0, 255);"&gt;SUM&lt;/span&gt;(visit) &lt;span style="color: rgb(0, 0, 255);"&gt;AS&lt;/span&gt; visit &lt;span style="color: rgb(0, 0, 255);"&gt;FROM&lt;/span&gt; rollup_1 &lt;span style="color: rgb(0, 0, 255);"&gt;GROUP&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;BY&lt;/span&gt; url &lt;span style="color: rgb(0, 0, 255);"&gt;WITH&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;ROLLUP&lt;/span&gt;;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  23:&lt;/span&gt; +----------------------+-------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  24:&lt;/span&gt; | url                  | visit |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  25:&lt;/span&gt; +----------------------+-------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  26:&lt;/span&gt; | http://www.yahoo.com | 82900 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  27:&lt;/span&gt; | TOTAL                | 82900 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  28:&lt;/span&gt; +----------------------+-------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  29:&lt;/span&gt; 2 &lt;span style="color: rgb(0, 0, 255);"&gt;rows&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;set&lt;/span&gt;, 1 warning (0.00 sec)&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  30:&lt;/span&gt;  &lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;Complete analysis:
&lt;div&gt;&lt;div   style="border-style: none; padding: 0px; overflow: visible; width: 80.61%; color: black; line-height: 12pt; height: 350px; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; mysql&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;SELECT&lt;/span&gt; IFNULL(url, &lt;span style="color: rgb(0, 96, 128);"&gt;'ALL_URLS'&lt;/span&gt;) &lt;span style="color: rgb(0, 0, 255);"&gt;AS&lt;/span&gt; url,&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;     -&amp;gt; IFNULL(&lt;span style="color: rgb(0, 0, 255);"&gt;year&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;'ALL_YEARS'&lt;/span&gt;) &lt;span style="color: rgb(0, 0, 255);"&gt;AS&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;year&lt;/span&gt;,&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     -&amp;gt; IFNULL(country, &lt;span style="color: rgb(0, 96, 128);"&gt;'ALL_COUNTRIES'&lt;/span&gt;) &lt;span style="color: rgb(0, 0, 255);"&gt;AS&lt;/span&gt; country,&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     -&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;SUM&lt;/span&gt;(visit) &lt;span style="color: rgb(0, 0, 255);"&gt;FROM&lt;/span&gt; rollup_1&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;     -&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;GROUP&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;BY&lt;/span&gt; url, &lt;span style="color: rgb(0, 0, 255);"&gt;year&lt;/span&gt;, country &lt;span style="color: rgb(0, 0, 255);"&gt;WITH&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;ROLLUP&lt;/span&gt;;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt; +----------------------+-----------+---------------+------------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt; | url                  | &lt;span style="color: rgb(0, 0, 255);"&gt;year&lt;/span&gt;      | country       | &lt;span style="color: rgb(0, 0, 255);"&gt;SUM&lt;/span&gt;(visit) |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt; +----------------------+-----------+---------------+------------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt; | http://www.yahoo.com | 2005      | &lt;span style="color: rgb(0, 0, 255);"&gt;IN&lt;/span&gt;            |      10000 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt; | http://www.yahoo.com | 2005      | US            |      12000 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt; | http://www.yahoo.com | 2005      | ALL_COUNTRIES |      22000 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt; | http://www.yahoo.com | 2006      | &lt;span style="color: rgb(0, 0, 255);"&gt;IN&lt;/span&gt;            |      10700 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt; | http://www.yahoo.com | 2006      | US            |      16000 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt; | http://www.yahoo.com | 2006      | ALL_COUNTRIES |      26700 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt; | http://www.yahoo.com | 2007      | &lt;span style="color: rgb(0, 0, 255);"&gt;IN&lt;/span&gt;            |      13200 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt; | http://www.yahoo.com | 2007      | US            |      21000 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt; | http://www.yahoo.com | 2007      | ALL_COUNTRIES |      34200 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt; | http://www.yahoo.com | ALL_YEARS | ALL_COUNTRIES |      82900 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt; | ALL_URLS             | ALL_YEARS | ALL_COUNTRIES |      82900 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt; +----------------------+-----------+---------------+------------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  21:&lt;/span&gt; 11 &lt;span style="color: rgb(0, 0, 255);"&gt;rows&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;set&lt;/span&gt;, 3 warnings (0.00 sec)&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
There is a small Gotcha while using ROLLUP. As you can see, my table definition does not put a NOT NULL constraint on any of the fields. Though you might have guessed what I'm pointing to, let's see this example.
&lt;div&gt;
&lt;div   style="border-style: none; padding: 0px; overflow: visible; width: 80.77%; color: black; line-height: 12pt; height: 414px; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; mysql&amp;gt; INSERT &lt;span style="color: rgb(0, 0, 255);"&gt;INTO&lt;/span&gt; rollup_1 &lt;span style="color: rgb(0, 0, 255);"&gt;values&lt;/span&gt; (&lt;span style="color: rgb(0, 96, 128);"&gt;'http://www.yahoo.com'&lt;/span&gt;, 2007, &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;, 12000);&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt; Query OK, 1 &lt;span style="color: rgb(0, 0, 255);"&gt;row&lt;/span&gt; affected (0.00 sec)&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt; mysql&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;SELECT&lt;/span&gt; IFNULL(url, &lt;span style="color: rgb(0, 96, 128);"&gt;'ALL_URLS'&lt;/span&gt;) &lt;span style="color: rgb(0, 0, 255);"&gt;AS&lt;/span&gt; url, &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;     -&amp;gt; IFNULL(&lt;span style="color: rgb(0, 0, 255);"&gt;year&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;'ALL_YEARS'&lt;/span&gt;) &lt;span style="color: rgb(0, 0, 255);"&gt;AS&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;year&lt;/span&gt;, &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;     -&amp;gt; IFNULL(country, &lt;span style="color: rgb(0, 96, 128);"&gt;'ALL_COUNTRIES'&lt;/span&gt;) &lt;span style="color: rgb(0, 0, 255);"&gt;AS&lt;/span&gt; country, &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;     -&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;SUM&lt;/span&gt;(visit) &lt;span style="color: rgb(0, 0, 255);"&gt;FROM&lt;/span&gt; rollup_1 &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt;     -&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;GROUP&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;BY&lt;/span&gt; url, &lt;span style="color: rgb(0, 0, 255);"&gt;year&lt;/span&gt;, country &lt;span style="color: rgb(0, 0, 255);"&gt;WITH&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;ROLLUP&lt;/span&gt;;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt; +----------------------+-----------+---------------+------------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt; | url                  | &lt;span style="color: rgb(0, 0, 255);"&gt;year&lt;/span&gt;      | country       | &lt;span style="color: rgb(0, 0, 255);"&gt;SUM&lt;/span&gt;(visit) |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt; +----------------------+-----------+---------------+------------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt; | http://www.yahoo.com | 2005      | &lt;span style="color: rgb(0, 0, 255);"&gt;IN&lt;/span&gt;            |      10000 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt; | http://www.yahoo.com | 2005      | US            |      12000 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt; | http://www.yahoo.com | 2005      | ALL_COUNTRIES |      22000 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt; | http://www.yahoo.com | 2006      | &lt;span style="color: rgb(0, 0, 255);"&gt;IN&lt;/span&gt;            |      10700 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt; | http://www.yahoo.com | 2006      | US            |      16000 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt; | http://www.yahoo.com | 2006      | ALL_COUNTRIES |      26700 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt; | http://www.yahoo.com | 2007      | ALL_COUNTRIES |      12000 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt; | http://www.yahoo.com | 2007      | &lt;span style="color: rgb(0, 0, 255);"&gt;IN&lt;/span&gt;            |      13200 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt; | http://www.yahoo.com | 2007      | US            |      21000 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  21:&lt;/span&gt; | http://www.yahoo.com | 2007      | ALL_COUNTRIES |      46200 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  22:&lt;/span&gt; | http://www.yahoo.com | ALL_YEARS | ALL_COUNTRIES |      94900 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  23:&lt;/span&gt; | ALL_URLS             | ALL_YEARS | ALL_COUNTRIES |      94900 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  24:&lt;/span&gt; +----------------------+-----------+---------------+------------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  25:&lt;/span&gt; 12 &lt;span style="color: rgb(0, 0, 255);"&gt;rows&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;set&lt;/span&gt;, 3 warnings (0.00 sec)&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;As you can see in the output, there are two rows claiming to provide data for url='http://www.yahoo.com' and year=2007, question is which one is which one? Few good answers are:
&lt;ol&gt;&lt;li&gt;One that appears late in the result set.

&lt;/li&gt;&lt;li&gt;One that has a higher value for SUM(visit) field. This is arguable in general as there might be negative values, for our example we can say that's impossible.&lt;/li&gt;&lt;/ol&gt;The best answer is of course this. For using ROLLUP with data like this, please make sure that you have fields marked as NOT NULL and instead specify another DEFAULT like 'not set' or something else.
&lt;p&gt;While using ROLLUP, you may further like to consider few points.
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;ROLLUP and ORDER BY are mutually exclusive, they cannot be used in the same statement.

&lt;/li&gt;&lt;li&gt;If you are using LIMIT clause along with ROLLUP, remember LIMIT clause is applied after ROLLUP, so it may include the aggregated rows.

&lt;/li&gt;&lt;li&gt;In MySQL &lt;a href="http://dev.mysql.com/doc/refman/4.1/en/group-by-modifiers.html"&gt;documentation&lt;/a&gt;, it is mentioned that "Because the &lt;code&gt;NULL&lt;/code&gt; values in the super-aggregate rows are placed into the result set at such a late stage in query processing, you cannot test them as &lt;code&gt;NULL&lt;/code&gt; values within the query itself.". You can see in the above queries, we are actually testing this value to be replaced by TOTAL_* string. Also if your data itself does not have NULL values in it, it works wonders. Look at the output below, I have removed the row inserted above.
&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;div   style="border-style: none; padding: 0px; overflow: visible; width: 81.16%; color: black; line-height: 12pt; height: 254px; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; mysql&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;SELECT&lt;/span&gt; IFNULL(url, &lt;span style="color: rgb(0, 96, 128);"&gt;'ALL_URLS'&lt;/span&gt;) &lt;span style="color: rgb(0, 0, 255);"&gt;AS&lt;/span&gt; url, &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;     -&amp;gt; IFNULL(&lt;span style="color: rgb(0, 0, 255);"&gt;year&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;'ALL_YEARS'&lt;/span&gt;) &lt;span style="color: rgb(0, 0, 255);"&gt;AS&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;year&lt;/span&gt;, &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;     -&amp;gt; IFNULL(country, &lt;span style="color: rgb(0, 96, 128);"&gt;'ALL_COUNTRIES'&lt;/span&gt;) &lt;span style="color: rgb(0, 0, 255);"&gt;AS&lt;/span&gt; country, &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;     -&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;SUM&lt;/span&gt;(visit) &lt;span style="color: rgb(0, 0, 255);"&gt;FROM&lt;/span&gt; rollup_1 &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;     -&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;GROUP&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;BY&lt;/span&gt; url, &lt;span style="color: rgb(0, 0, 255);"&gt;year&lt;/span&gt;, country &lt;span style="color: rgb(0, 0, 255);"&gt;WITH&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;ROLLUP&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;HAVING&lt;/span&gt; country &lt;span style="color: rgb(0, 0, 255);"&gt;is&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt; +----------------------+-----------+---------------+------------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt; | url                  | &lt;span style="color: rgb(0, 0, 255);"&gt;year&lt;/span&gt;      | country       | &lt;span style="color: rgb(0, 0, 255);"&gt;SUM&lt;/span&gt;(visit) |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt; +----------------------+-----------+---------------+------------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt; | http://www.yahoo.com | 2005      | ALL_COUNTRIES |      22000 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt; | http://www.yahoo.com | 2006      | ALL_COUNTRIES |      26700 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt; | http://www.yahoo.com | 2007      | ALL_COUNTRIES |      34200 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt; | http://www.yahoo.com | ALL_YEARS | ALL_COUNTRIES |      82900 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt; | ALL_URLS             | ALL_YEARS | ALL_COUNTRIES |      82900 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt; +----------------------+-----------+---------------+------------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt; 5 &lt;span style="color: rgb(0, 0, 255);"&gt;rows&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;set&lt;/span&gt;, 4 warnings (0.00 sec)&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
Hope this blog was helpful to you. Keep posting your comments.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-8870170192743615025?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=8870170192743615025' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/8870170192743615025'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/8870170192743615025'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2007/07/olap-paradise-with-rollup.html' title='OLAP Paradise - WITH ROLLUP'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-4464691857393183623</id><published>2007-07-19T18:13:00.001+01:00</published><updated>2008-02-28T09:55:31.198Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Optimizer'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><category scheme='http://www.blogger.com/atom/ns#' term='InnoDB'/><category scheme='http://www.blogger.com/atom/ns#' term='Index'/><title type='text'>InnoDB Row Counting using Indexes</title><content type='html'>&lt;p&gt;This is always mentioned that InnoDB is slower in giving results for &lt;span style="font-family:courier;"&gt;COUNT(*)&lt;/span&gt; as compared to MyISAM. But as Peter points out in his &lt;a href="http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/"&gt;blog&lt;/a&gt; that this fact only applies to &lt;span style="font-family:courier;"&gt;COUNT(*)&lt;/span&gt; queries without &lt;span style="font-family:courier;"&gt;WHERE&lt;/span&gt; clause. This text is from Peter's blog only - "If you have query like SELECT COUNT(*) FROM IMAGE WHERE USER_ID=5 this query will be executed same way both for MyISAM and Innodb tables by performing index rage scan. This can be faster or slower both for MyISAM and Innodb depending on various conditions." Let's see what &lt;span style="font-family:courier;"&gt;EXPLAIN&lt;/span&gt; has in store for us.&lt;/p&gt; &lt;div&gt; &lt;div   style="border-style: none; padding: 0px; overflow: visible; width: 85.3%; color: black; line-height: 12pt; height: 492px; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; mysql&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;CREATE&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;TABLE&lt;/span&gt; `test_index` (&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;   `id` &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;(11) &lt;span style="color: rgb(0, 0, 255);"&gt;NOT&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;NULL&lt;/span&gt; AUTO_INCREMENT,&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;   `x` &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;(11) &lt;span style="color: rgb(0, 0, 255);"&gt;DEFAULT&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;NULL&lt;/span&gt;,&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;   `y` &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;(11) &lt;span style="color: rgb(0, 0, 255);"&gt;DEFAULT&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;NULL&lt;/span&gt;,&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;   `z` &lt;span style="color: rgb(0, 0, 255);"&gt;varchar&lt;/span&gt;(255) &lt;span style="color: rgb(0, 0, 255);"&gt;NOT&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;NULL&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;DEFAULT&lt;/span&gt; &lt;span style="color: rgb(0, 96, 128);"&gt;'testing'&lt;/span&gt;,&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;PRIMARY&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;KEY&lt;/span&gt; (`id`),&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;KEY&lt;/span&gt; `x` (`x`,`y`)&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt; ) ENGINE=InnoDB;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt; mysql&amp;gt; EXPLAIN &lt;span style="color: rgb(0, 0, 255);"&gt;SELECT&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;COUNT&lt;/span&gt;(*) &lt;span style="color: rgb(0, 0, 255);"&gt;FROM&lt;/span&gt; test_index \G&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt; *************************** 1. &lt;span style="color: rgb(0, 0, 255);"&gt;row&lt;/span&gt; ***************************&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt;            id: 1&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;   select_type: SIMPLE&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;table&lt;/span&gt;: test_index&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt;          type: &lt;span style="color: rgb(0, 0, 255);"&gt;index&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt; possible_keys: &lt;span style="color: rgb(0, 0, 255);"&gt;NULL&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt;           &lt;span style="color: rgb(0, 0, 255);"&gt;key&lt;/span&gt;: &lt;span style="color: rgb(0, 0, 255);"&gt;PRIMARY&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt;       key_len: 4&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt;           &lt;span style="color: rgb(0, 0, 255);"&gt;ref&lt;/span&gt;: &lt;span style="color: rgb(0, 0, 255);"&gt;NULL&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;rows&lt;/span&gt;: 4875772&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  21:&lt;/span&gt;         Extra: &lt;span style="color: rgb(0, 0, 255);"&gt;Using&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;index&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  22:&lt;/span&gt; 1 &lt;span style="color: rgb(0, 0, 255);"&gt;row&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;set&lt;/span&gt; (0.01 sec)&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  23:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  24:&lt;/span&gt; mysql&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;SELECT&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;COUNT&lt;/span&gt;(*) &lt;span style="color: rgb(0, 0, 255);"&gt;FROM&lt;/span&gt; test_index;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  25:&lt;/span&gt; +----------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  26:&lt;/span&gt; | &lt;span style="color: rgb(0, 0, 255);"&gt;COUNT&lt;/span&gt;(*) |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  27:&lt;/span&gt; +----------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  28:&lt;/span&gt; |  4915200 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  29:&lt;/span&gt; +----------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  30:&lt;/span&gt; 1 &lt;span style="color: rgb(0, 0, 255);"&gt;row&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;set&lt;/span&gt; (2.61 sec)&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The explain states that the counting is going to be done on PRIMARY index and Using Index. The best part is that since it is going to use PRIMARY index and since it is NOT NULL, MySQL will actually count the values from the index itself. So, contrary to the thought that something like &lt;span style="font-family:courier;"&gt;COUNT(1)&lt;/span&gt; will work faster is not true in this case. Here is an interesting case from a &lt;a href="http://bugs.mysql.com/bug.php?id=19271"&gt;bug&lt;/a&gt;.&lt;/p&gt;
&lt;div&gt;
&lt;div   style="border-style: none; padding: 0px; overflow: visible; width: 85.1%; color: black; line-height: 12pt; height: 734px; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   1:&lt;/span&gt; mysql&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;CREATE&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;TABLE&lt;/span&gt; `test` (&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   2:&lt;/span&gt;   `id` &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;(11) &lt;span style="color: rgb(0, 0, 255);"&gt;NOT&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;NULL&lt;/span&gt;,&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   3:&lt;/span&gt;   `int_k` &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;(11) &lt;span style="color: rgb(0, 0, 255);"&gt;NOT&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;NULL&lt;/span&gt;,&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   4:&lt;/span&gt;   `data1` &lt;span style="color: rgb(0, 0, 255);"&gt;varchar&lt;/span&gt;(255) &lt;span style="color: rgb(0, 0, 255);"&gt;NOT&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;NULL&lt;/span&gt;,&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   5:&lt;/span&gt;   `data2` &lt;span style="color: rgb(0, 0, 255);"&gt;varchar&lt;/span&gt;(255) &lt;span style="color: rgb(0, 0, 255);"&gt;NOT&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;NULL&lt;/span&gt;,&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   6:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;PRIMARY&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;KEY&lt;/span&gt; (`id`),&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   7:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;KEY&lt;/span&gt; `int_k` (`int_k`)&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   8:&lt;/span&gt; ) ENGINE=InnoDB &lt;span style="color: rgb(0, 0, 255);"&gt;DEFAULT&lt;/span&gt; CHARSET=latin1&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;   9:&lt;/span&gt; 1 &lt;span style="color: rgb(0, 0, 255);"&gt;row&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;set&lt;/span&gt; (0.00 sec)&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  10:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  11:&lt;/span&gt; mysql&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;CREATE&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;PROCEDURE&lt;/span&gt; populate()&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  12:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;begin&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  13:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;declare&lt;/span&gt; i &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  14:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;set&lt;/span&gt; i = 0;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  15:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;start&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;transaction&lt;/span&gt;;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  16:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;while&lt;/span&gt; i &amp;lt; 300000 do&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  17:&lt;/span&gt;     insert &lt;span style="color: rgb(0, 0, 255);"&gt;into&lt;/span&gt; test (id, int_k, data1, data2)&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  18:&lt;/span&gt;       &lt;span style="color: rgb(0, 0, 255);"&gt;values&lt;/span&gt; (i, i, repeat("-", 250), repeat("-", 250));&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  19:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;set&lt;/span&gt; i = i + 1;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  20:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; i % 1000 = 0 &lt;span style="color: rgb(0, 0, 255);"&gt;then&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  21:&lt;/span&gt;       &lt;span style="color: rgb(0, 0, 255);"&gt;start&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;transaction&lt;/span&gt;;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  22:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;end&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  23:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;end&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;while&lt;/span&gt;;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  24:&lt;/span&gt;   &lt;span style="color: rgb(0, 0, 255);"&gt;commit&lt;/span&gt;;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  25:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  26:&lt;/span&gt; 1 &lt;span style="color: rgb(0, 0, 255);"&gt;row&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;set&lt;/span&gt; (0.00 sec)&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  27:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  28:&lt;/span&gt; mysql&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;call&lt;/span&gt; populate;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  29:&lt;/span&gt; Query OK, 0 &lt;span style="color: rgb(0, 0, 255);"&gt;rows&lt;/span&gt; affected (1 &lt;span style="color: rgb(0, 0, 255);"&gt;min&lt;/span&gt; 0.65 sec)&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  30:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  31:&lt;/span&gt; mysql&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;SELECT&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;COUNT&lt;/span&gt;(*) &lt;span style="color: rgb(0, 0, 255);"&gt;FROM&lt;/span&gt; test;&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  32:&lt;/span&gt; +----------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  33:&lt;/span&gt; | &lt;span style="color: rgb(0, 0, 255);"&gt;COUNT&lt;/span&gt;(*) |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  34:&lt;/span&gt; +----------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  35:&lt;/span&gt; |   300000 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  36:&lt;/span&gt; +----------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  37:&lt;/span&gt; 1 &lt;span style="color: rgb(0, 0, 255);"&gt;row&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;set&lt;/span&gt; (1.08 sec)&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  38:&lt;/span&gt;  &lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  39:&lt;/span&gt; mysql&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;SELECT&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;COUNT&lt;/span&gt;(*) &lt;span style="color: rgb(0, 0, 255);"&gt;FROM&lt;/span&gt; test &lt;span style="color: rgb(0, 0, 255);"&gt;use&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;index&lt;/span&gt; (int_k);&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  40:&lt;/span&gt; +----------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  41:&lt;/span&gt; | &lt;span style="color: rgb(0, 0, 255);"&gt;COUNT&lt;/span&gt;(*) |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  42:&lt;/span&gt; +----------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  43:&lt;/span&gt; |   300000 |&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  44:&lt;/span&gt; +----------+&lt;/pre&gt;&lt;pre   style="border-style: none; margin: 0em; padding: 0px; overflow: visible; width: 100%; color: black; line-height: 12pt; background-color: rgb(244, 244, 244);font-family:consolas,'Courier New',courier,monospace;font-size:8pt;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt;  45:&lt;/span&gt; 1 &lt;span style="color: rgb(0, 0, 255);"&gt;row&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;set&lt;/span&gt; (0.12 sec)&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Using a secondary index is faster. But why? Generally speaking, the PRIMARY index should be faster because it is usually in order and can be read with sequential I/O at around 15 times more speed than generally fragmented secondary index. Actually this is a special case, since the secondary index is inserted into the table in perfect order, which is very rare. Also, as Heikki points out in the &lt;a href="http://bugs.mysql.com/bug.php?id=19271"&gt;bug&lt;/a&gt;&lt;/p&gt;"Since the minimum record size of InnoDB is about 20 bytes, and the fill-factor of a secondary index is typically 70 %, we can calculate that if the row length is &amp;gt; 15 * 1.5 * 20 = 450 bytes, then scanning the secondary index would probably be a better option."

Till this feature is implemented and we have a much better optimized count(*) for InnoDB, please use secondary index explicitly for counting rows if you satisfy any of above conditions.

Hope this blog was helpful to you. Keep posting your comments.&lt;p&gt;
&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:e32d93eb-fa9f-49de-b891-b4d59a935bbe" contenteditable="false" style="margin: 0px; padding: 0px; display: inline;"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/InnoDB" rel="tag"&gt;InnoDB&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/MySQL" rel="tag"&gt;MySQL&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/Performance" rel="tag"&gt;Performance&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/Indexes" rel="tag"&gt;Indexes&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-4464691857393183623?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=4464691857393183623' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/4464691857393183623'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/4464691857393183623'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2007/07/innodb-row-counting-using-indexes.html' title='InnoDB Row Counting using Indexes'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-557938909765210910</id><published>2007-07-16T20:13:00.001+01:00</published><updated>2008-02-28T09:55:31.199Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Transaction'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><category scheme='http://www.blogger.com/atom/ns#' term='InnoDB'/><title type='text'>Implicit Commits and Transactions</title><content type='html'>&lt;p&gt;We think that whatever statements are there in a transaction can be rolled-back. Right? No! If by any chance you have statements that cause an implicit commit, then no. These statements commit the transaction mid-air. And if you think that these statements are only DDL, beware. There are many statements in MySQL that implicitly commit like &lt;span style="font-family:courier;"&gt;LOAD DATA INFILE&lt;/span&gt; was an implicit commit statement for all storage engines until 5.1.12. Even now, if you are using NDB, this is still a implicit commit statement.&lt;/p&gt; &lt;p&gt;Say, we have statements like this:&lt;/p&gt;&lt;pre&gt;1. START TRANSACTION
2. SOME INSERT STATEMENT
3. ONE MORE INSERT STATEMENT
4. ONE IMPLICIT COMMIT STATEMENT
5. ONE MORE INSERT STATEMENT
6. SOME MORE STATEMENTS
7. COMMIT
&lt;/pre&gt;The implicit commit statement (statement number 4) commits the statements above it and aborts the transaction, as already mentioned. So, what happens to the statements 5 and 6. They run as normal statements outside transaction, and beat the whole purpose of a transaction. As &lt;a href="http://dev.mysql.com/doc/refman/5.1/en/implicit-commit.html"&gt;MySQL documentation&lt;/a&gt; points out that this behavior occurs because we cannot have nested transactions. The same link also provides the list of all the implicit commit statements.
&lt;p&gt;There is an open bug (I saw lately) requesting a feature on this, as most of the users take transactions for granted.&lt;/p&gt;Hope this blog was helpful to you. Keep posting your comments.

&lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:c7f9fdd3-057c-4ac0-aca2-1c0b37ac9e0e" contenteditable="false" style="margin: 0px; padding: 0px; display: inline;"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/InnoDB" rel="tag"&gt;InnoDB&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/Performance" rel="tag"&gt;Performance&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/Transaction" rel="tag"&gt;Transaction&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-557938909765210910?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=557938909765210910' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/557938909765210910'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/557938909765210910'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2007/07/implicit-commits-and-transactions.html' title='Implicit Commits and Transactions'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-5888338902113867987</id><published>2007-07-14T19:09:00.001+01:00</published><updated>2008-02-28T09:55:31.197Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Locks'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><category scheme='http://www.blogger.com/atom/ns#' term='InnoDB'/><title type='text'>AUTO_INCREMENT in InnoDB</title><content type='html'>&lt;p&gt;It's very easy to have an auto_increment column in a table and maintain primary keys. Many people think so, and also they think that MySQL will do the best job for them. With InnoDB, the case is a little different as supposed to be. Basic assumption is that since InnoDB works with row-level locking, combining it with auto_increment should ward off worries. But it is just the beginning.&lt;/p&gt; &lt;p&gt;Let me clarify how auto_increment works. InnoDB maintains the auto_increment value in memory. Good approach. When an insert statement requests the auto_increment value, InnoDB takes the stored value, increment it by one and return. The value in memory is not incremented at this time. This is not bad, because who knows how many rows the insert statement has. &lt;/p&gt; &lt;p&gt;But, this means that InnoDB cannot provide auto_increment values to other threads until this finishes, hence we cannot have concurrent inserts even in InnoDB when using an auto_increment value. This is assured by a special AUTO-INC lock by InnoDB, which is an exclusive table level lock. We will see how this can affect your application and some workarounds.&lt;/p&gt; &lt;h4&gt;Application may suffer&lt;/h4&gt; &lt;p&gt;If you have concurrent inserts into an InnoDB table, start worrying. Single row inserts won't affect the performance noticeably. But, if you are doing bulk inserts and your inserts are taking enough time, one of your insert threads may exit because of lock wait timeout. Also, this will cause problems for other components of your application (even if they are read only) as these insert statements will keep connected and you may hit your max_connections.&lt;/p&gt; &lt;h4&gt;Workarounds&lt;/h4&gt; &lt;ol&gt; &lt;li&gt;As you might think, moving to MyISAM won't help. MyISAM by default takes a table lock while writing.&lt;/li&gt;&lt;li&gt;Do some magic and make sure your inserts do not execute concurrently. This is also not much possible in the case of web applications, where one doesn't have the control over the inserts, but neither web applications do bulk inserts. This can be managed where one is using a cron job to do bulk inserts, say from a log file.&lt;/li&gt; &lt;li&gt;Get rid of auto_increment. If your application actually needs to do bulk inserts from multiple sources at the same time and the above solution doesn't make sense, figure out your own primary key. Something like a combination of MD5 checksum over data combined with the length of the data may be a good option in most cases, but do not rely on it. Also, remember a multi-column primary key is not always a good option.
&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Hope this blog was helpful to you. Keep posting your comments.&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:2a79559b-ba33-402c-beca-8d2686aaa196" contenteditable="false" style="margin: 0px; padding: 0px; display: inline;"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/MySQL" rel="tag"&gt;MySQL&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/InnoDB" rel="tag"&gt;InnoDB&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/AUTO_INCREMENT" rel="tag"&gt;AUTO_INCREMENT&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-5888338902113867987?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=5888338902113867987' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/5888338902113867987'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/5888338902113867987'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2007/07/autoincrement-in-innodb.html' title='AUTO_INCREMENT in InnoDB'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-458424580032567306</id><published>2007-07-12T17:38:00.001+01:00</published><updated>2008-02-28T09:55:31.197Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='MyISAM'/><category scheme='http://www.blogger.com/atom/ns#' term='Tablespace'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><category scheme='http://www.blogger.com/atom/ns#' term='InnoDB'/><title type='text'>InnoDB Tablespace Size</title><content type='html'>&lt;p&gt;Unlike MyISAM where data for individual tables is stored in their respective files, InnoDB stores data in a tablespace. By default, there is one single tablespace and data of all the databases is stored in one file. This file has data dictionary, tables, as well as indexes in it. There is a global parameter &lt;font face="courier"&gt;innodb_data_file_path&lt;/font&gt; that defines this tablespace file. It has a syntax like &lt;font face="courier"&gt;ibdata1:256M:autoextend&lt;/font&gt;, this means at the beginning a file of size 256 MB will be created and then whenever the data size exceeds this, the file will be auto-extended. The &lt;font face="courier"&gt;innodb_autoextend_increment&lt;/font&gt; variable defines in MB's that by how much each increment should be. &lt;/p&gt; &lt;p&gt;Let's see how well can we play around:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;strong&gt;Inserts:&lt;/strong&gt;&amp;nbsp;Suppose&amp;nbsp;you have too many inserts and&amp;nbsp;InnoDB is extending the file too frequently.&amp;nbsp;It makes sense to increase the value of &lt;font face="courier"&gt;innodb_autoextend_increment.&lt;/font&gt;&amp;nbsp;Say we increase it to&amp;nbsp;16MB, then obviously the number of attempts to autoextend tablespace comes down by a factor of 2, hence performance. But beware before you take it too easy and increase the value too much. There&amp;nbsp;is a big&amp;nbsp;trap, we will come to&amp;nbsp;it shortly.  &lt;li&gt;&lt;strong&gt;Deletes: &lt;/strong&gt;Here is the trap. You have a 10 GB tablespace (after too many autoextends), delete some 5 GB data (data + indexes) and think now the tablespace is 5 GB. Wrong, InnoDB doesn't have the notion of giving back space to the file system. Though, it will make sure to use the freed up space for further inserts. So, this method directly cannot be used to free disk space. So, in case you have data which you can get rid of, get rid of quickly before the next autoextend is done. One&amp;nbsp;thing that can be done to reclaim space is to use &lt;font face="courier"&gt;OPTIMIZE TABLE&lt;/font&gt; frequently enough on tables that have high volume of inserts and deletes. But again remember,&amp;nbsp;MySQL locks a table during the time&amp;nbsp;&lt;font face="courier"&gt;OPTIMIZE TABLE&lt;/font&gt;&amp;nbsp;is running. Another Gotcha, right? &lt;font face="courier"&gt;OPTIMIZE TABLE&lt;/font&gt; does several other things for&amp;nbsp;which it makes sense to run it, though not that frequently. I will be posting&amp;nbsp;a blog soon on it.&amp;nbsp;  &lt;li&gt;&lt;strong&gt;Separate Files per Table: &lt;/strong&gt;InnoDB provides this option where data (data + indexes) for each table can be stored in a separate file through a global variable &lt;font face="courier"&gt;innodb_file_per_table&lt;/font&gt;. Though still a shared tablespace will be created for storing the likes of data dictionary et al. But still this approach makes sense as having data in small chunks (separate files) will improve the scope of managing&amp;nbsp;them well and may increase performance in general.  &lt;li&gt;&lt;strong&gt;Fixed Tablespace size: &lt;/strong&gt;One way to work around with the tablespace file size problems is to fix the tablespace size (remove autoextend) to an extrapolated value. So, when you hit the limit, you know it is time to cleanup. This is not that viable with all the applications, as extrapolation is not always possible. And also it increases the complexity of the application, which then needs to take care of all such error conditions and not lose any data.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;So, where does this end? You need to figure out what your data is, how critical it is, what all you want to do with it, what all you want your data to do. Then take some of the following steps.&lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;strong&gt;Move to MyISAM: &lt;/strong&gt;For all the tables (or even databases), for which you feel data is not that critical to have transactions et al, move them to MyISAM. So, for the problem we can't solve completely, we&amp;nbsp;destroy the problem.  &lt;li&gt;&lt;strong&gt;Separate Tablespace: &lt;/strong&gt;Its a lot easier to maintain 10 small problems than a single big one.  &lt;li&gt;&lt;strong&gt;Delete data/OPTIMIZE TABLE: &lt;/strong&gt;Figure out how soon you can get rid of data. You actually don't need to delete data as it is. Transfer it to a MyISAM table, compress the file and archive it somewhere else and then delete it from the main table. Likewise there are many ways to do it. Run &lt;font face="courier"&gt;OPTIMIZE TABLE&lt;/font&gt; frequently enough so that it doesn't&amp;nbsp;bother your reads and writes too much and also it doesn't take too much time to run. &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Hope this blog was helpful to you. Keep posting your comments.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-458424580032567306?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=458424580032567306' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/458424580032567306'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/458424580032567306'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2007/07/innodb-tablespace-size.html' title='InnoDB Tablespace Size'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-4930677394774931182</id><published>2007-07-09T18:21:00.001+01:00</published><updated>2008-02-28T09:55:31.200Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Table Status'/><category scheme='http://www.blogger.com/atom/ns#' term='MyISAM'/><category scheme='http://www.blogger.com/atom/ns#' term='Tablespace'/><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><category scheme='http://www.blogger.com/atom/ns#' term='InnoDB'/><title type='text'>Table Status</title><content type='html'>&lt;p&gt;Checking out the state of tables of your MySQL setup in production is important for fine tuning server parameters. MySQL's &lt;span style="font-family:Courier New;"&gt;SHOW TABLE STATUS&lt;/span&gt; command comes very handy in determining table states from a running environment. Here, I explain the output of the command.&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;"&gt;&lt;pre&gt;mysql&amp;gt; SHOW TABLE STATUS LIKE 'mytable' \G
****************** 1. row ******************
           Name: mytable
         Engine: InnoDB
        Version: 9
     Row_format: Dynamic
           Rows: 2465222
 Avg_row_length: 370
    Data_length: 913326080
Max_data_length: NULL
   Index_length: 146817024
      Data_free: 0
 Auto_increment: 18357110
    Create_time: 2007-05-11 22:27:56
    Update_time: NULL
     Check_time: NULL
      Collation: latin1_swedish_ci
       Checksum: NULL
 Create_options:
        Comment: InnoDB free: 869376 kB
1 row in set (0.34 sec)&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;Leaving behind the obvious parameters, we shall see only the more relevant ones and ones that look like more interesting.&lt;/p&gt; &lt;p&gt;&lt;em&gt;Row_format: &lt;/em&gt;This describes the length behavior of the rows in this table. Can have one value out of &lt;em&gt;Dynamic, Fixed or Compressed. &lt;/em&gt;Dynamic rows have variable length due to fields having type like BLOB, VARCHAR etc. Fixed rows are made up of fields that do not vary in length. Compressed rows exist for compressed tables as those in Compressed MyISAM.&lt;/p&gt; &lt;p&gt;&lt;em&gt;Rows: &lt;/em&gt;This describes the number of rows in a table. This number is always accurate for non-transactional engines like MyISAM, but an approximate value for transactional tables like InnoDB. Ever wondered why &lt;em&gt;select count(*) &lt;/em&gt;is faster on MyISAM than InnoDB.&lt;/p&gt; &lt;p&gt;&lt;em&gt;Avg_row_length: &lt;/em&gt;The name says it all. Anyhow, it's in bytes.&lt;/p&gt; &lt;p&gt;&lt;em&gt;Data_length: &lt;/em&gt;This is the total data (in bytes) in the table. For InnoDB tables, which tend to use a single tablespace, this can be a deterministic factor for splitting tables in their individual tablespaces.&lt;/p&gt; &lt;p&gt;&lt;em&gt;Max_data_lenth: &lt;/em&gt;This is generally not applicable for all the engines. This describes the maximum data that a table can hold. MyISAM tables generally have this restriction. &lt;/p&gt; &lt;p&gt;&lt;em&gt;Index_length: &lt;/em&gt;This parameter should be of utmost interest. This describes the total space (in bytes) taken up by the index of the table. The aggregate value of this field over all the tables under the same engine (or the engines that use same buffer for index data) can actually be a deterministic value for such buffers. For InnoDB tables, this can also play a role in splitting tables in their individual tablespaces.&lt;/p&gt; &lt;p&gt;As far as this moment is concerned, this much of explanation is enough. Users should take care of not going by the instinct of a single snap shot for this data. Rather this data should be collected periodically to actually see the change and decisions be made accordingly.&lt;/p&gt; &lt;p&gt;Hope this blog was helpful to you. Keep posting your comments.&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:9001747b-3562-48d6-9003-01e704d0a976" contenteditable="false" style="margin: 0px; padding: 0px; display: inline;"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/MyISAM" rel="tag"&gt;MyISAM&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/InnoDB" rel="tag"&gt;InnoDB&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/MySQL" rel="tag"&gt;MySQL&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/Table%20Status" rel="tag"&gt;Table Status&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/Tablespaces" rel="tag"&gt;Tablespaces&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/Tuning" rel="tag"&gt;Tuning&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-4930677394774931182?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=4930677394774931182' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/4930677394774931182'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/4930677394774931182'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2007/07/table-status.html' title='Table Status'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5852997211129961388.post-6963036493263195355</id><published>2007-07-08T16:36:00.000+01:00</published><updated>2008-02-28T09:53:31.776Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Introduction'/><title type='text'>Introduction</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:verdana;"&gt;&lt;span style="font-family:lucida grande;"&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-family:trebuchet ms;"&gt;Would appreciate your comments and love to work on MySQL related problems if you are facing any, that will also keep me motivated about posting stuff here.

My current project is &lt;a href="http://sourceforge.net/projects/myeye/"&gt;MyEye&lt;/a&gt;, which will be soon available. It is a tool that will keep a vigilant eye on your MySQL installation, provide valuable feedback and helps in monitoring too.

&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5852997211129961388-6963036493263195355?l=optimmysql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5852997211129961388&amp;postID=6963036493263195355' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/6963036493263195355'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5852997211129961388/posts/default/6963036493263195355'/><link rel='alternate' type='text/html' href='http://optimmysql.blogspot.com/2007/07/introduction.html' title='Introduction'/><author><name>Parvesh Garg</name><uri>http://www.blogger.com/profile/17439613571179900891</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://farm2.static.flickr.com/1289/864037347_700f1d42d1.jpg?v=0'/></author><thr:total>1</thr:total></entry></feed>
