0

I am trying to find out which MySQL table engine is best for each of our table and requirements.

The tables with many reads(SELECT queries) are MyISAM. The tables with many writes(INSERT/UPDATE queries) are InnoDB. These are the only two types that we used, but now we have different scenarios and we do not know which DB engine is best.

1)We have a table users that we UPDATE/SELECT very often, like 1 row every second for SELECT and 1 row every 1 second for UPDATE, but the INSERTS are rare, like 1 every 300 seconds. For this we chose MyISAM.

2)We have a table users_data where we INSERT data as often as we do it in table users, like every 300 seconds, but we do not UPDATE this table too often, but we read from it once every 1 second. For this we chose MyISAM

3)We have a table transactions where we INSERT data very often, like 1 row every 4-5 seconds, and we SELECT large packs from this every 20-30 seconds (we make many SUM's often from this table based on userid). For this we chose MyISAM.

4)We have a table transactions_logs where we store id (which is the same as transactions table), merchant name, email and we INSERT data very often, like 1 row every 4-5 seconds, but we read this very rarely. For this we chose InnoDB. Rarely we join table transactions and transactions_logs for statistics.

5)We have a table pages where we only SELECT data very often,like 1 row per second. For this we chose MyISAM and we turned on MySQL cache.

Questions:

a)We have another table with 1 INSERT every 100000 seconds, but many SELECT/UPDATE queries per second? What type should this be? We are using MyISAM for now for this type. We read data from it, we modify it, then we update it and we do this once per 1-2 seconds. Is MyISAM the best option for this?

b)Do you think that we should've used InnoDB for all tables? I've read that since MySQL 5.6, InnoDB is the default table type and probably it was optimised a lot.

2 Answers 2

1

Fundamentally, I use the following two differences between MyISAM and InnoDB to choose which one to use in a specific scenario:

  • InnoDB supports transactions, MyISAM does not.
  • InnoDB has row-level locking, MyISAM has table-level locking.

(Source: MySQL 5.7 Reference Manual)

My rule of thumb is to use MyISAM when there are a high number of select queries and low number of update/insert queries. Whenever write performance, or data integrity are of importance I'll use InnoDB.

While the above is useful as a starting point, every database, and every application, are different. The specific details of your hardware and software setup will ultimately dictate which engine choice is best. When in doubt, test!

However, I will say that, based on the numbers provided, and assuming 'modern' server hardware, you're not anywhere near the performance limits of MySQL so either engine would suffice.

6
  • So if you have a table where you store the balance of an account, and that field is read and updated every 1 second ... what would you choose? I chose MyISAM.
    – NVG
    Mar 17, 2015 at 11:33
  • I would use InnoDB; to ensure transactional integrity and cause less read issues if using row-locking instead of table-locking to update. But if you want to be sure you are making the best choice in your situation you must test and compare both engines under relevant conditions.
    – timclutton
    Mar 17, 2015 at 11:57
  • I have tested and I am not really satisfied with the results. I will try InnoDB. Does InnoDB use row-locking by default?
    – NVG
    Mar 17, 2015 at 13:45
  • 1
    Yes; from the manual: "InnoDB does locking on the row level and runs queries as nonlocking consistent reads by default, in the style of Oracle."
    – timclutton
    Mar 17, 2015 at 14:34
  • So from my understanding it seems that MyISAM locks the whole table, then executes all queries for session A, then unlocks the table, then does the same for each session, thus slowing the database read/write processes. On the other hand, InnoDB locks just the row that is modified (which most of the time is a row with an unique id that corresponds only to the currently logged in user), therefore no other users/sessions are affected by the row locking. Is this correct?
    – NVG
    Mar 17, 2015 at 14:37
0

MyISAM Works great for read only loads and Write and Read forever loads. It handles co-currency with locking the entire table on writes. This can make it very slow on write heavy loads.

INNODB Is a little more complicated, adds some configuration options that must be configured somewhat properly. This adds support for row level locking, which is great for rows that are added, updated less than 1 per second ideally (giving plenty of time to read/write).

1
  • So if you have a table where you store the balance of an account, and that field is read and updated every 1 second ... what would you choose? I chose MyISAM.
    – NVG
    Mar 17, 2015 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.