Mysql – InnoDB vs MyISAM with many indexes

indexinnodbmyisamMySQL

I am not sure if there is a right or wrong answer to this question, as I suppose it severely depends on the situation, but for the sake of a mental exercise, I'll go ahead and ask it anyway:

I have a MyISAM table in my database that stands central to my site. There are many reference tables created around it and many other tables that link directly to row ids from this table. The table is about 260k rows in size, with 28 fields which for the most part is varchars and ints. I have about 15 indexes on it (the data is about 70 MiB, indexes are about 80 MiB). There are maybe several hundred writes a day, versus the tens of thousands of reads. My databases are located on an SSD drive.

Now my question is; would be be beneficial to alter this table to a InnoDB table? I am working on extending my systems to include API traffic as well, meaning that the table will even the queried even more and I want to make sure that everything runs as smooth as possible. Because of this, I'm slightly leaning towards converting it to InnoDB. However, since the table requires many indexes, I'm thinking MyISAM might work more effectively. Can anyone help me make up my mind? Thanks in advance1

Edit: (added by jcolebrand from a comment)

I have added the indexes a long time ago and I changed some things to the PHP code base, so maybe some indexes are out-dated, but overall; yes, they are all used. I run many different types of queries on the table. Different query, different index. But my main question here does not concern the table read performance, but how it performs with many indexes. InnoDB indexes are 'leaved'/ stored with the data, instead of MyISAM's key-file principle. I am just worried that this might cause enough of a performance drop not to outweigh the table lock issue.

Best Answer

There are maybe several hundred writes a day, versus the tens of thousands of reads. My databases are located on an SSD drive.

Based on this statement, let's play with some numbers. Lets's say there are 500 writes a day and 20,000 reads a day. That computes out to the following

  • 97.56% reads per day
  • 2.44% writes per day
  • 40 reads / write

As much as I love InnoDB, I would have to choose MyISAM in this case for several reasons

REASON #1

You only have 150MiB of MyISAM tables (70MiB Data, 80 MiB Indexes)

REASON #2

InnoDB indexes tend to get very bloaty because Secondary Indexes have keys into the Clustered Index. This always results in a double index lookup. This can be overlooked with large, write-heavy datasets.

REASON #3

InnoDB tablespaces tend to get very bloaty because of MVCC being created and discarded without an automatic reclaiming of disk space:

All this can be avoid with MyISAM

REASON #4

InnoDB protects individual rows by performing MVCC for transaction control. The overhead generated for reads in a day would probably be greater than 150 MiB.

I can probably name 2 or 3 more reasons, but let's cut to the chase: Is there anything that can improve performance for MyISAM in your case? Why, yes there is.

Your said the following

The table is about 260k rows in size, with 28 fields which for the most part is varchars and ints

If you have many varchars, there is something you can do to increase read/write performance. For any MyISAM table mydb.mytable: run this command:

ALTER TABLE mydb.mytable ROW_FORMAT=Fixed;

What will this do, this will treat all VARCHARs as CHARs. Every row will be the exact same length. This will increase disk space 80%-100%. In your case, let's assume it doubles your 150 MiB MyISAM table to 300 MiB. Where is the benefit? Your MyISAM table can now be read/written anywhere from 20% - 30% faster without changing anything else I learned that from pages 72,73 from MySQL Database Design and Tuning.

I have written about this in the past: