mysqlmyisamtable-lock

myisam place table-lock on table even when dealing with 'select' query?


i am reading the book High Performance MySQL, it mentions:

performing one query per table uses table locks more efficiently: the queries 
will lock the tables invididually and relatively briefly, instead of locking 
them all for a longer time.

MyISAM places table-lock even when selecting something? can someone explain a little bit?


Solution

  • MyISAM has different kinds of locks. A SELECT operation places a READ LOCK on the table. There can be multiple active read locks at any given time, as long as there are no active WRITE LOCKS. Operations that modify the table, eg. INSERT, UPDATE, DELETE or ALTER TABLE place a WRITE LOCK on the table. Write lock can only be placed on a table when there are no active read locks; If there are active read locks, MyISAM queues the write lock to be activated as soon as all active read locks are expired.

    Likewise when there's an active write lock, attempting to place a read lock on a table will queue the lock (and the associated query) until write locks have expired on the table.

    Ultimately this all means that:

    For more information see: http://dev.mysql.com/doc/refman/5.5/en/internal-locking.html