当前位置:网站首页>Classification of gbase 8s locks

Classification of gbase 8s locks

2022-06-25 04:32:00 Eight delicacies tofu

         The object of the lock is the data object in the database , Such as tables in relational databases 、 Record 、 attribute 、 Index, etc. , The time to lock a data object is before the transaction operates on it , Send a lock request to the system . After locking, the transaction obtains control over the data object , Before a transaction releases its lock , Other transactions cannot enter this data object Do anything . Blocking is a queuing mechanism , Queue parallel tasks in lock order , Turn parallel tasks into strings Line task . GBase8s  Adopt the blocking mechanism of global management , Allocation of a memory set in shared memory to mark lock usage , Keep the owner of the lock in each lock structure 、 Locked objects ( It's a watch 、 Record 、 Or OK )、 The type of lock, etc . stay GBase8s Each lock in the occupies 128 Byte.

1. Database level lock (Database-Ievel Locks)

         Before we pass CONNECT DATABASE perhaps CREATE DATABASE Statement accessing the database , The system will automatically add a share to the database (S) lock , This prevents other users from deleting the database or The user adds and excludes it on the database (X) lock .

2. Table lock (Table-Ievel Locks) Table level lock means that the locked object is a table , You can explicitly lock and release the table with the following statement :

BEGIN WORK;

LOCK TABLE tab1 IN EXCLUSIVE MODE;

LOCK TABLE tab2 IN SHARE MODE;

UNLOCK TABLE tab1;

         Perform the following DDL When the sentence is ,GBase8t It will automatically lock the table , Such as ALTER FRAGMENT、 ALTER INDEX、ALTER TABLE、CREATE INDEX ( If not used ONLINE Pattern )、DROP INDEX( If not used ONLINE Pattern )、RENAME COLUMN、RENAME TABLE.

         When the entire table or most of the data in the table needs to be updated , The efficiency of using table lock is high .

3. Page level lock (Page Locks)

        GBase8t Physically store multiple lines of records on the data page (Page) On , Page level lock means that the object of the lock is a piece of data page , When using page level locks to access records ,GBase8t The accessed data page will be locked automatically . When in physical order When accessing and updating multiple records , Using page level locks is more efficient .

   You can specify the page lock mode as follows :

ALTER TABLE tab1 LOCK MODE (PAGE);

CREATE TABLE tab1 (…) LOCK MODE PAGE ;

       CREATE TABLE If the lock mode is not specified , ... will be used ONCONFIG Parameters DEF_TABLE_ LOCKMODE To specify the locking mode of the table .

4. Row-level locks (Row Locks)

         The data of relational database is managed by rows , So row level locks are easy to understand . stay OLTP Bank level in the system Locks are widely used , Only a small number of records accessed need to be locked , Using row level locks is more efficient .

   The row level lock mode can be specified as follows :

ALTER TABLE tab1 LOCK MODE (ROW);

CREATE TABLE tab1 (…) LOCK MODE ROW ;

       CREATE TABLE If the lock mode is not specified , ... will be used ONCONFIG Parameters DEF_TABLE_ LOCKMODE To specify the locking mode of the table .

5. Index lock (Index key)

         The index uses B+ The storage structure of the tree , Therefore, the lock management of the index is to manage the index Key value . Database mining be widely used 、 Lock management of index in the way of closed area , Examples are as follows :

Create table tab1 (c1 int,c2 int) lock mode row;

Create unique index idx_tab1 on tab1(c1);

Insert into tab1 values(1,2);

Insert into tab1 values(2,2);

Insert into tab1 values(3,2);

         Assume that only the above 3 rows , When executed update tab1 set c1=0 where c1>=3; When the sentence is ,GBase8t The index will be key The value is 3 Lock the closed section of records , This means that you cannot add key Greater than 3 The record of . If you execute at this time insert into tab1 values(4,2), Will prompt Index Lock conflict error .

原网站

版权声明
本文为[Eight delicacies tofu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206250244319307.html