MyISAM for data reads

Solution 1:

Before you decide upon MyISAM or InnoDB you will have to look over both Storage Engines in terms of how what each caches

MyISAM

When read, a MyISAM table's indexes can be read once from the .MYI file and loaded in the MyISAM Key Cache (as sized by key_buffer_size). How can you make a MyISAM table's .MYD faster to read? With this:

ALTER TABLE mytable ROW_FORMAT=Fixed;

I wrote about this in my past posts

  • Sep 20, 2011 : https://dba.stackexchange.com/questions/5974/best-of-myisam-and-innodb/6008#6008 (Please Read This One First)
  • May 10, 2011 : https://dba.stackexchange.com/questions/2640/what-is-the-performance-impact-of-using-char-vs-varchar-on-a-fixed-size-field/2643#2643 (TRADEOFF #2)
  • Aug 12, 2011 : https://dba.stackexchange.com/questions/4576/which-dbms-is-good-for-super-fast-reads-and-a-simple-data-structure/4589#4589 (Paragraph 3)
  • Jan 03, 2012 : https://dba.stackexchange.com/questions/10069/optimized-my-cnf-for-high-end-and-busy-server/10080#10080 (Under the heading Replication)

InnoDB

OK, what about InnoDB? Does InnoDB do any disk I/O for queries? Surprisingly, yes it does !! You are probably thinking I am crazy for saying that, but it is absolutely true, even for SELECT queries. At this point, you are probably wondering "How in the world is InnoDB doing disk I/O for queries?"

It all goes back to InnoDB being an ACID-complaint Transactional Storage Engine. In order for InnoDB to be Transactional, it has to support the I in ACID, which is Isolation. The technique for maintaining isolation for transactions is done via MVCC, Multiversion Concurrency Control. In simple terms, InnoDB records what data looks like before transactions attempt to change them. Where does that get recorded? In the system tablespace file, better known as ibdata1. That requires disk I/O.

COMPARISON

Since both InnoDB and MyISAM do disk I/O, what random factors dictate who is faster?

  • Size of Columns
  • Column Format
  • Character Sets
  • Range of Numeric Values (requiring large enough INTs)
  • Rows Being Split Across Blocks (Row Chaining)
  • Data Fragmentation caused by DELETEs and UPDATEs
  • Size of Primary Key (InnoDB has a Clustered Index, requiring two key lookups)
  • Size of Index Entries
  • the list goes on...

EPILOGUE

Thus, in a heavy-read environment, it is possible for a MyISAM table with a Fixed Row Format to outperform InnoDB reads out of the InnoDB Buffer Pool if there is enough data being written into the undo logs contained within ibdata1 to support the transactional behavior imposed on the InnoDB data. Plan your data types, queries, and storage engine real carefully. Once the data grows, it might become very difficult to move data around.

By the way, I wrote something like this 5 days ago : How do I assign a memory limit for mySQL?

Solution 2:

MyISAM will always run a lot faster than innodb when there is no contention for the data. Start adding multiple sessions trying to update the same tablse, and innodb very quickly gets the performance advantage.

How you tune the system for the 2 engines is very different.

The reason that different engines exist is because different workloads / access patterns exist.