Classification and algorithm of MySQL lock

Source: Internet
Author: User

The MySQL lock contains table-level locks and row-level locks in two large categories. Table-level locks are intent locks, have ix,is, are generally used before row-level locks, and row-level locks are traditional s and x locks. The compatibility features of these locks are as follows:

is
IX S X
Is Compatible Compatible Compatible Not compatible
Ix Compatible Compatible Not compatible Not compatible
S Compatible Not compatible Compatible Not compatible
X Not compatible Not compatible Not compatible Not compatible

There are 3 types of row lock algorithms in the InnoDB storage engine, namely:
* Record lock single Row Records locked

    • Gap Lock gap Lock, locks a range but does not contain the record itself
    • Next-key Lock Gaplock+recordlock

Record lock is easier to understand, gaplock need to be aware that it locks the range, including both the left and right gaps. The role of GAP lock is to prevent multiple transactions from inserting records into the same range, resulting in phantom reads.

Classification and algorithm of MySQL lock

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.