Teradata Concurrency Control

Roland Wenzlofsky

July 28, 2015

minutes reading time


What is Teradata Concurrency Control?

Concurrency control prevents different sessions from updating, deleting, or inserting rows simultaneously. Two mechanisms are used for concurrency control: Locking and Transactions.

Teradata Transactions

Transactions define logical units which are encapsulating one or several statements. All statements of the same transaction have to succeed. Otherwise, the transaction (and, therefore, all transaction statements) will be rolled back.

Teradata Locks

Locks define usage rights on database objects like databases, tables, views, rows, etc.

Depending on the object type and the activity, different lock levels and granularities (i.e., which rows of an object are locked) are available.

Usually, The Teradata lock manager locks the objects automatically. Implicit locks are done by the lock manager on a database, tables, views, and rows (based on the row hash value).

There are four different levels of locking available: Exclusive, Write, Read, and Access.

The Teradata lock manager decides automatically which lock level will be used (this depends on the target object and the operation taking place).

Database objects are locked when a transaction is initiated and unlocked as soon as the transaction finishes, ensuring data consistency.

Depending on the object being locked and the activity (SQL statement), one of the following locking granularities will be automatically used:

Object Type LockedAutomatic Lock Handling
DatabaseLocks all tables located in the database
TableLocks all table rows and secondary indexes
ViewLocks all tables used in the view
RowLocks the row (identified by the row hash)

Besides defining the locking granularity, each lock must be based on one of the below lock levels. Each of them has some limitations if another session already holds other locks on the same object:

Lock LevelWhat is means
Exclusive LockOnly the requestor has access to the object. No other session can access the object until the lock is released.
Write LockAny other session can read the object, but data may be inconsistent as the lock owner may be changing data simultaneously.
Read LockUnlimited sessions can hold read locks, during which no modification of that object is permitted.
Access LockIt will be granted even if another session holds a Write Lock like the read lock. This may result in inconsistent data being read.

Here are some examples of combinations the Teradata Lock Manager will use automatically:

SQL StatementThe granularity with Indexed AccessThe granularity with FTS or NUSI AccessLock Level Mode
SELECTRow hashWhole TableRead
UPDATERow hashWhole TableWrite
DELETERow hashWhole TableWrite
INSERTRow hash Write
CREATE DATABASE
DROP DATABASE
MODIFY DATABASE
 Whole DatabaseExclusive
CREATE TABLE
DROP TABLE
ALTER TABLE
 Whole TableExclusive

Let me give you one warning: The Teradata lock manager has a limited amount of resources to lock on row hash granularity. The attempt to lock many rows on a row hash can cause the transaction’s abort.
Depending on the currently held lock level, additional lock requests for the same objects can be granted, or they will have to wait:

Requested Lock LevelActive Lock Level
NoneAccessReadWriteExclusive
Access LockGrantedGrantedGrantedGrantedWait
Read LockGrantedGrantedGrantedWaitWait
Write LockGrantedGrantedWaitWaitWait
Exclusive LockGrantedWaitWaitWaitWait

Locks are released as soon as the session’s transaction is finished.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

You might also like

>