Thursday, December 27, 2007

MyISAM and InnoDB storage engines

Deciding which storage engine to use for you MySQL tables can be an important decision.  I have seen the question raised a few times here and there, most times by people who probably haven't bothered to look at the MySQL manual. Here, I will try to consolidate some of the important advantages and disadvantages to help you decide which storage engine you should use for your tables.  Some of the unique characteristics include:


MyISAMInnoDB
LockingTable LevelRow Level
TransactionsNoYes
Full Text IndexesYesNo
Foreign Key SupportNoYes

Go here for a full list

If you need transactions or foreign key support you can really only chose InnoDB, or if you need full text indexes you will have to choose MyISAM.  

If the above are not important to you, you may want to consider concurrency.  For this you should chose MyISAM if the number of reads vs writes is unbalanced one way or the other by more than 40%.  If your number of reads and writes is relatively equal you will get better concurrency with InnoDB.  

If your code uses a lot of "count (*) FROM table" you will need to rethink this if you need to use InnoDB because InnoDB tables do not store the number of rows in a table, every row needs to be counted each time this query is called and this can be extremely slow for large tables.

Sources: