Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcf59277

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 ofri_BuildQueryKeyFull. Aside from saving a few cycles, this avoids needlessdeadlock risks when an update is not changing the columns that participatein an RI constraint. Per a gripe from Alexey Nalbat.Back-patch to 8.3. Earlier releases did have a need to open the otherrelation due to the way in which they retrieved information about the RIconstraint, so this problem unfortunately can't easily be improved pre-8.3.Tom Lane and Stephan Szabo
1 parentfc54be8 commitcf59277

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
#defineRI_PLAN_RESTRICT_UPD_CHECKREF8
6868
#defineRI_PLAN_SETNULL_DEL_DOUPDATE9
6969
#defineRI_PLAN_SETNULL_UPD_DOUPDATE10
70-
#defineRI_PLAN_KEYEQUAL_UPD11
7170

7271
#defineMAX_QUOTED_NAME_LEN (NAMEDATALEN*2+3)
7372
#defineMAX_QUOTED_REL_NAME_LEN (MAX_QUOTED_NAME_LEN*2)
7473

7574
#defineRIAttName(rel,attnum)NameStr(*attnumAttName(rel, attnum))
76-
#defineRIAttType(rel,attnum)SPI_gettypeid(RelationGetDescr(rel), attnum)
75+
#defineRIAttType(rel,attnum)attnumTypeId(rel, attnum)
7776

7877
#defineRI_TRIGTYPE_INSERT 1
7978
#defineRI_TRIGTYPE_UPDATE 2
@@ -2516,8 +2515,6 @@ RI_FKey_keyequal_upd_pk(Trigger *trigger, Relation pk_rel,
25162515
HeapTupleold_row,HeapTuplenew_row)
25172516
{
25182517
RI_ConstraintInforiinfo;
2519-
Relationfk_rel;
2520-
RI_QueryKeyqkey;
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
caseFKCONSTR_MATCH_UNSPECIFIED:
25382533
caseFKCONSTR_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
returnri_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
HeapTupleold_row,HeapTuplenew_row)
25712561
{
25722562
RI_ConstraintInforiinfo;
2573-
Relationpk_rel;
2574-
RI_QueryKeyqkey;
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
caseFKCONSTR_MATCH_UNSPECIFIED:
25922578
caseFKCONSTR_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
returnri_KeysEqual(fk_rel,old_row,new_row,&riinfo, false);
25992581

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp