aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-02-18 23:00:38 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-02-18 23:00:38 +0000
commit5f4170c6f734758d009c39e83cf1cc74f86918e4 (patch)
tree5bf1b90eb66f7de034de2df4ca44b0e742788fb0
parent7d7b60bf8668e02bcbc443e238c8afb187abc249 (diff)
downloadpostgresql-5f4170c6f734758d009c39e83cf1cc74f86918e4.tar.gz
postgresql-5f4170c6f734758d009c39e83cf1cc74f86918e4.zip
Remove unnecessary opening of other relation in RI_FKey_keyequal_upd_pk
and RI_FKey_keyequal_upd_fk, as well as no-longer-needed calls of ri_BuildQueryKeyFull. Aside from saving a few cycles, this avoids needless deadlock risks when an update is not changing the columns that participate in an RI constraint. Per a gripe from Alexey Nalbat. Back-patch to 8.3. Earlier releases did have a need to open the other relation due to the way in which they retrieved information about the RI constraint, so this problem unfortunately can't easily be improved pre-8.3. Tom Lane and Stephan Szabo
-rw-r--r--src/backend/utils/adt/ri_triggers.c26
1 files changed, 4 insertions, 22 deletions
diff --git a/src/backend/utils/adt/ri_triggers.c b/src/backend/utils/adt/ri_triggers.c
index 66df8e1b839..ce560054cea 100644
--- a/src/backend/utils/adt/ri_triggers.c
+++ b/src/backend/utils/adt/ri_triggers.c
@@ -15,7 +15,7 @@
*
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.103 2008/02/07 22:58:35 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.103.2.1 2008/02/18 23:00:38 tgl Exp $
*
* ----------
*/
@@ -67,13 +67,12 @@
#define RI_PLAN_RESTRICT_UPD_CHECKREF 8
#define RI_PLAN_SETNULL_DEL_DOUPDATE 9
#define RI_PLAN_SETNULL_UPD_DOUPDATE 10
-#define RI_PLAN_KEYEQUAL_UPD 11
#define MAX_QUOTED_NAME_LEN (NAMEDATALEN*2+3)
#define MAX_QUOTED_REL_NAME_LEN (MAX_QUOTED_NAME_LEN*2)
#define RIAttName(rel, attnum) NameStr(*attnumAttName(rel, attnum))
-#define RIAttType(rel, attnum) SPI_gettypeid(RelationGetDescr(rel), attnum)
+#define RIAttType(rel, attnum) attnumTypeId(rel, attnum)
#define RI_TRIGTYPE_INSERT 1
#define RI_TRIGTYPE_UPDATE 2
@@ -2516,8 +2515,6 @@ RI_FKey_keyequal_upd_pk(Trigger *trigger, Relation pk_rel,
HeapTuple old_row, HeapTuple new_row)
{
RI_ConstraintInfo riinfo;
- Relation fk_rel;
- RI_QueryKey qkey;
/*
* Get arguments.
@@ -2530,18 +2527,11 @@ RI_FKey_keyequal_upd_pk(Trigger *trigger, Relation pk_rel,
if (riinfo.nkeys == 0)
return true;
- fk_rel = heap_open(riinfo.fk_relid, AccessShareLock);
-
switch (riinfo.confmatchtype)
{
case FKCONSTR_MATCH_UNSPECIFIED:
case FKCONSTR_MATCH_FULL:
- ri_BuildQueryKeyFull(&qkey, &riinfo,
- RI_PLAN_KEYEQUAL_UPD);
-
- heap_close(fk_rel, AccessShareLock);
-
- /* Return if key's are equal */
+ /* Return true if keys are equal */
return ri_KeysEqual(pk_rel, old_row, new_row, &riinfo, true);
/* Handle MATCH PARTIAL set null delete. */
@@ -2570,8 +2560,6 @@ RI_FKey_keyequal_upd_fk(Trigger *trigger, Relation fk_rel,
HeapTuple old_row, HeapTuple new_row)
{
RI_ConstraintInfo riinfo;
- Relation pk_rel;
- RI_QueryKey qkey;
/*
* Get arguments.
@@ -2584,17 +2572,11 @@ RI_FKey_keyequal_upd_fk(Trigger *trigger, Relation fk_rel,
if (riinfo.nkeys == 0)
return true;
- pk_rel = heap_open(riinfo.pk_relid, AccessShareLock);
-
switch (riinfo.confmatchtype)
{
case FKCONSTR_MATCH_UNSPECIFIED:
case FKCONSTR_MATCH_FULL:
- ri_BuildQueryKeyFull(&qkey, &riinfo,
- RI_PLAN_KEYEQUAL_UPD);
- heap_close(pk_rel, AccessShareLock);
-
- /* Return if key's are equal */
+ /* Return true if keys are equal */
return ri_KeysEqual(fk_rel, old_row, new_row, &riinfo, false);
/* Handle MATCH PARTIAL set null delete. */