Tuesday, February 05, 2008

MySQL storage engine comparsion: InnoDB vs MyISAM

While doing INSERT with MySQL, and where the table has key with AUTO_INCREMENT fields and the table uses InnoDB as storage engine. The problem is the record of insert is not showing as fast as you would expect. Sometimes have to wait for a while in order for the new record to show up.

This problem can be solved by tuning the InnoDB engine, presumably. But the best is to use MyISAM engine because

[url]http://dev.mysql.com/doc/refman/5.0/en/myisam-storage-engine.html[/url]
* Internal handling of one AUTO_INCREMENT column per table is supported. MyISAM automatically updates this column for INSERT and UPDATE operations. This makes AUTO_INCREMENT columns faster (at least 10%). Values at the top of the sequence are not reused after being deleted. (When an AUTO_INCREMENT column is defined as the last column of a multiple-column index, reuse of values deleted from the top of a sequence does occur.) The AUTO_INCREMENT value can be reset with ALTER TABLE or myisamchk.

[b]Reason[/b]
The reason is because InnoDB has internal buffer that will cache the data in memory first before doing a bulk write to the hdd, which, supposing to increase the performance of the database. However, in many development scenario, in order to show the change of db in real time manual commit is required:
mysql>commit;

No comments: