0

This is a two part question. When I perform a SELECT on a table, am I locking that table from any usage while the SELECT is running?

If so, what is a way to not lock the table while performing a SELECT statement? I'm using MySQL 4.1.20 MyISAM.

update there is a similar question here Any way to select without causing locking in MySQL? but the answer doesn't work with MyISAM

Community
  • 1
  • 1
dev.e.loper
  • 35,446
  • 76
  • 161
  • 247

3 Answers3

2

Yes, with MyISAM tables, the select locks the table for inserts/updates. However several selects can run concurrently (i.e. it applies a read lock). If there's no free space in the middle of the table, inserts will add data to the end of the (internal) storage, and those inserts can still be run concurrently with the selects though.

More info here. Note that MyISAM and InnoDB works very differently in this regard.

nos
  • 223,662
  • 58
  • 417
  • 506
0

There's table locking and row locking. I recommend you read up on database engines MyISAM with Table Locking and InnoDB Row Locking

Mikhail
  • 8,692
  • 8
  • 56
  • 82
-1

Think about it: are you changing any table cells when you do your SELECT? If not, there's no need to lock the table and MySQL doesn't. Table locking has to happen at UPDATE time, not at SELECT time.

Pete Wilson
  • 8,610
  • 6
  • 39
  • 51
  • MyISAM puts a table level read lock on tables when doing selects, InnoDB applies more granular locking. But the point is, even selects applies locking, though for some storage engines it depends on the isolation level. (And other DBs goes a different route and uses MVCC to further avoid locking) – nos Oct 21 '11 at 18:04