What is the difference between a lock and a latch in the context of concurrent access to a database?

前端 未结 8 1644
别跟我提以往
别跟我提以往 2021-01-30 06:46

I am trying to understand a paper on concurrent B-tree, in which the author mentioned latch vs lock, and how latches do not need a \"Lock Manager\". I have been trying to figure

8条回答
  •  盖世英雄少女心
    2021-01-30 07:23

    Following is from SQL Server stand point.

    Latches are short-term light weight synchronization objects. Unlike locks, latches do not hold till the entire logical transaction. They hold only on the operation on the page.

    Latches are used by the engine for synchronization of multiple threads (for example trying to insert on a table). Latches are not for developer or application - it is for the engine to do it's task. Latches are internal control mechanism. Whereas locks are for the developer and application to control. Latches are for internal memory consistency. Locks are for logical transactional consistency.

    Waits caused by latches are very important for diagnosing performance issues. Take a look at Diagnosing and Resolving Latch Contention on SQL Server - Whitepaper. The PAGEIOLATCH_EX is an important wait type.

    References

    1. SQL Server Latches and their indication of performance issues
    2. Knee-Jerk Wait Statistics : PAGELATCH
    3. Inside SQL Server: Indexing and Locking

提交回复
热议问题