Search code examples
mysqlconcurrencynonblockingmyisam

Is it possible to do a non-blocking read of MyISAM table?


I have a log table with heavy write operations: that was the reason of choosing MyISAM for it.

Now I need to execute a complicated SELECT query which takes a lot time and blocks the table: no one can write to it then.

  • The table has a high 'write' load
  • I don't care if I don't get the most recent records
  • The data is never deleted

What are the options to read the data without blocking the table?

  • LIMIT is applied after the query is completed, so is not an option
  • Modifying all INSERT statements to make them DELAYED is not an option
  • InnoDB is also is not an option
  • HANDLER query is not an option: I need complex WHERE conditions

Solution

  • Some suggestions, maybe one or the other is suitable for you

    1. option: Slave

      Configure a slave that you use for your SELECT query. That won't block the inserts. However, this requires a second server, some configuration and storage space, so this is not a good solution, just to get your data.

    2. option: use low-priority-updates: http://dev.mysql.com/doc/refman/5.0/en/table-locking.html

      This can be done on a server level or connection level, so you don't have to modify every insert statement.

    3. worker process

      • Make your inserts as usual.
      • create a worker process that "moves" your log entries (for each row in table A, make a insert in table B, delete row in Table A) to another table.
      • Now you can query Table B