Table of Contents

Oracle Database - Locks and Foreign Keys - Concurrency control of parent keys

About

Oracle Database maximizes the concurrency control of parent keys in relation to dependent foreign keys.

Locking behaviour depends on whether foreign key columns are indexed. If foreign keys are not indexed, then the child table will probably be locked more frequently, deadlocks will occur, and concurrency will be decreased. For this reason foreign keys should almost always be indexed. The only exception is when the matching unique or primary key is never updated or deleted.

Type of Foreign Keys

Unindexed

When both of the following conditions are true, the database acquires a full table lock on the child table:

DML on a child table does not acquire a table lock on the parent table.

Example:

Oracle Database Lock Foreign Key Unindexed

Indexed

When both of the following conditions are true, the database does not acquire a full table lock on the child table:

A lock on the parent table prevents transactions from acquiring exclusive table locks, but does not prevent DML on the parent or child table during the primary key modification. This situation is preferable if primary key modifications occur on the parent table while updates occur on the child table.

The figure below shows child table employees with an indexed department_id column. A transaction deletes department 280 from departments. This deletion does not cause the database to acquire a full table lock on the employees table as in the unindexed above scenario.

Oracle Database Lock Foreign Key Indexed

If the child table specifies ON DELETE CASCADE, then deletions from the parent table can result in deletions from the child table. For example, the deletion of department 280 can cause the deletion of records from employees for employees in the deleted department. In this case, waiting and locking rules are the same as:

Documentation / Reference