Skip to Content
MySQL Reference Manual
book

MySQL Reference Manual

by Michael Widenius, David Axmark, Kaj Arno
June 2002
Intermediate to advanced
816 pages
20h 46m
English
O'Reilly Media, Inc.
Content preview from MySQL Reference Manual

Locking Methods

Currently MySQL only supports table locking for ISAM/MyISAM and HEAP tables, page-level locking for BDB tables and row-level locking for InnoDB tables. See Section 5.3.1. With MyISAM tables one can freely mix INSERT and SELECT without locks (Versioning).

Starting in Version 3.23.33, you can analyse the table lock contention on your system by checking Table_locks_waited and Table_locks_immediate environment variables.

To decide if you want to use a table type with row level locking, you will want to look at what the application does and what the select/update pattern of the data is.

Pros for row locking:

  • Fewer lock conflicts when accessing different rows in many threads

  • Fewer changes for rollbacks

  • Makes it possible to lock a single row for a long time

Cons:

  • Takes more memory than page level or table locks.

  • Is slower than page level or table locks when used on a big part of the table because one has to do many more locks.

  • Is definitely much worse than other locks if you often do GROUP BY on a large part of the data, or if one has to often scan the whole table.

  • With higher level locks one can also more easily support locks of different types to tune the application, as the lock overhead is less notable than it is for row level locks.

Table locks are superior to page level/row level locks in the following cases:

  • Mostly reads.

  • Read and updates on strict keys; this is where one updates or deletes a row that can be fetched with one key read:

    UPDATE table_name SET column=value WHERE ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

MySQL Cookbook

MySQL Cookbook

Paul DuBois
MySQL 8 Cookbook

MySQL 8 Cookbook

Karthik Appigatla
MySQL Stored Procedure Programming

MySQL Stored Procedure Programming

Guy Harrison, Steven Feuerstein

Publisher Resources

ISBN: 0596002653Purchase bookErrata Page