Lock (1) -- lock granularity and hierarchy

Source: Internet
Author: User

The Microsoft SQL Server database engine has multi-granularity locking, allowing a transaction to lock different types of resources. To minimize the lock overhead, the database engine automatically locks resources at the appropriate task level. Locking at a smaller granularity (such as rows) can increase the concurrency, but the overhead is high, because if many rows are locked, more locks need to be held. Locking in a large granularity (such as a table) reduces the concurrency, because locking the entire table limits access to any part of other transactions in the table. However, the overhead is low because there are fewer locks to be maintained.

Generally, database engines must obtain multi-granularity locks to fully protect resources. These multi-granularity locks are called lock hierarchies. For example, in order to completely protect the reading of indexes, Database Engine instances may have to obtain the row-based shared locks and the intention-shared locks on pages and tables.

The following table lists the resources that can be locked by the database engine.

Resources Description
RID The row identifier used to lock a single row in the heap.
Key The index is used to protect the row locks for key ranges in serializable transactions.
Page 8 KB pages in the database, such as data pages or index pages.
Extent A group of eight consecutive pages, such as data pages or index pages.
HOBT Heap or B-tree.
Table The entire table that includes all data and indexes.
File Database files.
Application Resources dedicated to applications.
Metadata Metadata lock.
Allocation_unit Allocation unit.
Database The entire database.

 

 

 

 

 

 

 

 

Relationship between lock granularity and concurrency

 

 

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.