Skip to content

Commit cf59277

Browse files
committed
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
1 parent fc54be8 commit cf59277

File tree

1 file changed

+4
-22
lines changed

1 file changed

+4
-22
lines changed

src/backend/utils/adt/ri_triggers.c

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
1717
*
18-
* $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.103 2008/02/07 22:58:35 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.104 2008/02/18 23:00:32 tgl Exp $
1919
*
2020
* ----------
2121
*/
@@ -67,13 +67,12 @@
6767
#define RI_PLAN_RESTRICT_UPD_CHECKREF 8
6868
#define RI_PLAN_SETNULL_DEL_DOUPDATE 9
6969
#define RI_PLAN_SETNULL_UPD_DOUPDATE 10
70-
#define RI_PLAN_KEYEQUAL_UPD 11
7170

7271
#define MAX_QUOTED_NAME_LEN (NAMEDATALEN*2+3)
7372
#define MAX_QUOTED_REL_NAME_LEN (MAX_QUOTED_NAME_LEN*2)
7473

7574
#define RIAttName(rel, attnum) NameStr(*attnumAttName(rel, attnum))
76-
#define RIAttType(rel, attnum) SPI_gettypeid(RelationGetDescr(rel), attnum)
75+
#define RIAttType(rel, attnum) attnumTypeId(rel, attnum)
7776

7877
#define RI_TRIGTYPE_INSERT 1
7978
#define RI_TRIGTYPE_UPDATE 2
@@ -2516,8 +2515,6 @@ RI_FKey_keyequal_upd_pk(Trigger *trigger, Relation pk_rel,
25162515
HeapTuple old_row, HeapTuple new_row)
25172516
{
25182517
RI_ConstraintInfo riinfo;
2519-
Relation fk_rel;
2520-
RI_QueryKey qkey;
25212518

25222519
/*
25232520
* Get arguments.
@@ -2530,18 +2527,11 @@ RI_FKey_keyequal_upd_pk(Trigger *trigger, Relation pk_rel,
25302527
if (riinfo.nkeys == 0)
25312528
return true;
25322529

2533-
fk_rel = heap_open(riinfo.fk_relid, AccessShareLock);
2534-
25352530
switch (riinfo.confmatchtype)
25362531
{
25372532
case FKCONSTR_MATCH_UNSPECIFIED:
25382533
case FKCONSTR_MATCH_FULL:
2539-
ri_BuildQueryKeyFull(&qkey, &riinfo,
2540-
RI_PLAN_KEYEQUAL_UPD);
2541-
2542-
heap_close(fk_rel, AccessShareLock);
2543-
2544-
/* Return if key's are equal */
2534+
/* Return true if keys are equal */
25452535
return ri_KeysEqual(pk_rel, old_row, new_row, &riinfo, true);
25462536

25472537
/* Handle MATCH PARTIAL set null delete. */
@@ -2570,8 +2560,6 @@ RI_FKey_keyequal_upd_fk(Trigger *trigger, Relation fk_rel,
25702560
HeapTuple old_row, HeapTuple new_row)
25712561
{
25722562
RI_ConstraintInfo riinfo;
2573-
Relation pk_rel;
2574-
RI_QueryKey qkey;
25752563

25762564
/*
25772565
* Get arguments.
@@ -2584,17 +2572,11 @@ RI_FKey_keyequal_upd_fk(Trigger *trigger, Relation fk_rel,
25842572
if (riinfo.nkeys == 0)
25852573
return true;
25862574

2587-
pk_rel = heap_open(riinfo.pk_relid, AccessShareLock);
2588-
25892575
switch (riinfo.confmatchtype)
25902576
{
25912577
case FKCONSTR_MATCH_UNSPECIFIED:
25922578
case FKCONSTR_MATCH_FULL:
2593-
ri_BuildQueryKeyFull(&qkey, &riinfo,
2594-
RI_PLAN_KEYEQUAL_UPD);
2595-
heap_close(pk_rel, AccessShareLock);
2596-
2597-
/* Return if key's are equal */
2579+
/* Return true if keys are equal */
25982580
return ri_KeysEqual(fk_rel, old_row, new_row, &riinfo, false);
25992581

26002582
/* Handle MATCH PARTIAL set null delete. */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy