Search code examples
mysqllockingtable-locking

Why is table-level locking better than row-level locking for large tables?


According to the MySQL manual:

For large tables, table locking is often better than row locking,

Why is this? I would presume that row-level locking is better because when you lock on a larger table, you're locking more data.


Solution

  • from the (pre-edit) link

    Slower than page-level or table-level locks when used on a large part of the table because you must acquire many more locks

    use a row level lock if you are only hitting a row or two. If your code hits many or unknown rows, stick with table lock.