From 722bf7017bbe796decc79c1fde03e7a83dae9ada Mon Sep 17 00:00:00 2001 From: Simon Riggs Date: Tue, 8 Feb 2011 12:23:20 +0000 Subject: Extend ALTER TABLE to allow Foreign Keys to be added without initial validation. FK constraints that are marked NOT VALID may later be VALIDATED, which uses an ShareUpdateExclusiveLock on constraint table and RowShareLock on referenced table. Significantly reduces lock strength and duration when adding FKs. New state visible from psql. Simon Riggs, with reviews from Marko Tiikkaja and Robert Haas --- src/backend/utils/adt/ri_triggers.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/backend/utils/adt/ri_triggers.c') diff --git a/src/backend/utils/adt/ri_triggers.c b/src/backend/utils/adt/ri_triggers.c index 7bc1ab1e812..5ef1563d1c9 100644 --- a/src/backend/utils/adt/ri_triggers.c +++ b/src/backend/utils/adt/ri_triggers.c @@ -2608,8 +2608,11 @@ RI_FKey_keyequal_upd_fk(Trigger *trigger, Relation fk_rel, * This is not a trigger procedure, but is called during ALTER TABLE * ADD FOREIGN KEY to validate the initial table contents. * - * We expect that a ShareRowExclusiveLock or higher has been taken on rel and pkrel; - * hence, we do not need to lock individual rows for the check. + * We expect that the caller has made provision to prevent any problems + * caused by concurrent actions. This could be either by locking rel and + * pkrel at ShareRowExclusiveLock or higher, or by otherwise ensuring + * that triggers implementing the checks are already active. + * Hence, we do not need to lock individual rows for the check. * * If the check fails because the current user doesn't have permissions * to read both tables, return false to let our caller know that they will -- cgit v1.2.3