Jul 17, 2015

When to use MyISAM or InnoDB

When designing a database in MySQL one of the most common questions one can ask themselves is, is it better to use MyISAM or InnoDB engines for tables. There are other types of engines, but these are most common. There are also many articles on this topic, but I found that it boils down to a few simple things:

If you need FULLTEXT search, you need to use MyISAM.

If you need Foregin key support (for cascading and such), or you need to support transactions, you need to use InnoDB.




In general, if you do not need any of the special features, it's better to use MyISAM as it performs better (faster and more disk-friendly) for web applications.


There are other features that are not present in other engines as well.

 MyISAM Storage Engine Features
Storage limits256TBTransactionsNoLocking granularityTable
MVCCNoGeospatial data type supportYesGeospatial indexing supportYes
B-tree indexesYesT-tree indexesNoHash indexesNo
Full-text search indexesYesClustered indexesNoData cachesNo
Index cachesYesCompressed dataYes[a]Encrypted data[b]Yes
Cluster database supportNoReplication support[c]YesForeign key supportNo
Backup / point-in-time recovery[d]YesQuery cache supportYesUpdate statistics for data dictionaryYes
[a] Compressed MyISAM tables are supported only when using the compressed row format. Tables using the compressed row format with MyISAM are read only.
[b] Implemented in the server (via encryption functions), rather than in the storage engine.
[c] Implemented in the server, rather than in the storage engine.
[d] Implemented in the server, rather than in the storage engine.

Key Advantages of InnoDB

InnoDB is a high-reliability and high-performance storage engine for MySQL. Key advantages of InnoDB include:
  • Its design follows the ACID model, with transactions featuring commitrollback, and crash-recovery capabilities to protect user data.
  • Row-level locking (without escalation to coarser granularity locks) and Oracle-style consistent reads increase multi-user concurrency and performance.
  • InnoDB tables arrange your data on disk to optimize common queries based on primary keys. Each InnoDB table has a primary key index called the clustered index that organizes the data to minimize I/O for primary key lookups.
  • To maintain data integrity, InnoDB also supports FOREIGN KEY referential-integrity constraints.
  • You can freely mix InnoDB tables with tables from other MySQL storage engines, even within the same statement. For example, you can use a join operation to combine data from InnoDB and MEMORY tables in a single query.
  • InnoDB has been designed for CPU efficiency and maximum performance when processing large data volumes.

No comments: