While reading this link, I did not understand the point on avoiding table locks by adding indexes on the foreign key column. Can anyone please help me understand the point?
Additionally, I never knew of the importance of adding indexes to foreign key before reading the same link(thanks to Thomas Kyte and the forum!). Can anyone please point me to more such important implementations that I need to consider when implementing foreign keys.
Assume two tables,
PARENTandCHILD. Assume that there is a foreign key constraint onCHILD.PARENT_IDreferencingPARENT.PARENT_IDand thatCHILD.PARENT_IDis a required (not null) column, and that no index exists onCHILD.PARENT_ID.When updating
PARENT_IDor deleting records fromPARENT, Oracle needs to prevent new transactions from concurrently adding new records inCHILDwith the values ofPARENT_IDbeing removed. Oracle could use an index againstCHILD.PARENT_IDto check to see what records, if any, may be affected – and to block new rows using thePARENT_IDbeing affected from being committed until the activity againstPARENTfrom committing or rolling back.However, no such index exists for this concurrency issue. So Oracle uses the only tool it has – locking the
CHILDtable completely until the operation againstPARENTcommits or rolls back.