MySQL-----Lock (Row lock, table lock, page lock, optimistic lock, pessimistic lock)

Source: Internet
Author: User
Tags rollback

Review:

ACID: In the process of writing or updating data, the DBMS has four features for ensuring that transactions are correct and reliable: atomicity (indivisibility), consistency, isolation (independence), persistence

a transaction : A complete logical process consisting of a series of database operations

atomicity : All operations in a transaction, either complete or not complete, rollback (RollBack) If an error occurs

consistency : The integrity of the database does not break before the transaction starts and after the transaction ends

Isolation : The ability of a database to read and write and modify its data at the same time for multiple concurrent transactions, which prevents inconsistencies in data resulting from cross-execution when multiple transactions are executing concurrently. Transaction isolation is divided into distinct levels : READ UNCOMMITTED, read commit, repeatable read, serialization

Persistence : After the transaction is finished, changes to the data are permanent and the system fails to change

lock : a mechanism that coordinates the concurrent access of multiple processes or threads to a resource. Lock conflict is an important factor that affects the performance of concurrent access to a database.

The storage engine supports different locking mechanisms

Row lock Table lock Page lock
MyISAM Support
BDB Support Support
InnoDB Support Support

Overhead, lock speed, deadlock, granularity, concurrency performance

    • row lock : overhead, locking slow, deadlock, lock granularity is small, lock collision probability is low, concurrency is high
    • table lock : Low overhead, lock fast, no deadlock, locking granularity, high lock collision probability, the lowest degree of concurrency
    • page lock : The cost and lock speed between the row and table locks, a deadlock occurs, the lock granularity between the table and row locks, the degree of concurrency is generally

# # #根据具体应用决定适合那种锁, only from the angle of the lock: table locks are suitable for query-based, table locks are suitable for concurrent updating of small amounts of different data by a large number of index conditions, and the application of concurrent queries

MyISAM table lock

MyISAM only supports table locks, and as applications improve transactional integrity and concurrency, MySQL begins to develop a transaction-based storage engine that comes out of InnoDB row locks and bdb page locks, InnoDB by Oracle Acquisition

This is recorded first, and subsequent updates

MySQL-----Lock (Row lock, table lock, page lock, optimistic lock, pessimistic lock)

Related Article

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.