Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do index type (unique and non-unique) affect table locking as result of DML?

If there is an FK in child table that is not indexed then any updates to PK of the parent table locks entire child table, unless FK in child table is indexed.

My question is that if we want to prevent whole table lock then is the FK index has to be unique? Or It doesn't matter if the index is unique or non-unique?

like image 403
VishalDevgire Avatar asked Nov 16 '25 20:11

VishalDevgire


1 Answers

The index doesn't have to be unique. It can be a regular or compound one.

The purpose of the index on a foreign key is to avoid full table locking while doing:

  1. Delete in parent table
  2. update of primary key column

and is useful while doing joins by avoiding Full Table scans.

See http://www.dba-oracle.com/t_foreign_key_indexing.htm

like image 59
Gurwinder Singh Avatar answered Nov 19 '25 15:11

Gurwinder Singh