Skip to content

Commit d7c310c

Browse files
committed
Minor code rearrangement to save a few cycles in RI_FKey_check when
the subject tuple is already deleted: we need not open the pk_rel until after we check that.
1 parent 548237f commit d7c310c

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/backend/utils/adt/ri_triggers.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
1919
*
20-
* $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.86 2006/07/14 14:52:24 momjian Exp $
20+
* $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.87 2006/08/21 19:15:29 tgl Exp $
2121
*
2222
* ----------
2323
*/
@@ -193,17 +193,11 @@ RI_FKey_check(PG_FUNCTION_ARGS)
193193
*/
194194
ri_CheckTrigger(fcinfo, "RI_FKey_check", RI_TRIGTYPE_INUP);
195195

196-
tgnargs = trigdata->tg_trigger->tgnargs;
197-
tgargs = trigdata->tg_trigger->tgargs;
198-
199196
/*
200-
* Get the relation descriptors of the FK and PK tables and the new tuple.
201-
*
202-
* pk_rel is opened in RowShareLock mode since that's what our eventual
203-
* SELECT FOR SHARE will get on it.
197+
* Get arguments.
204198
*/
205-
pk_rel = heap_open(trigdata->tg_trigger->tgconstrrelid, RowShareLock);
206-
fk_rel = trigdata->tg_relation;
199+
tgnargs = trigdata->tg_trigger->tgnargs;
200+
tgargs = trigdata->tg_trigger->tgargs;
207201
if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
208202
{
209203
old_row = trigdata->tg_trigtuple;
@@ -224,10 +218,16 @@ RI_FKey_check(PG_FUNCTION_ARGS)
224218
*/
225219
Assert(new_row_buf != InvalidBuffer);
226220
if (!HeapTupleSatisfiesItself(new_row->t_data, new_row_buf))
227-
{
228-
heap_close(pk_rel, RowShareLock);
229221
return PointerGetDatum(NULL);
230-
}
222+
223+
/*
224+
* Get the relation descriptors of the FK and PK tables.
225+
*
226+
* pk_rel is opened in RowShareLock mode since that's what our eventual
227+
* SELECT FOR SHARE will get on it.
228+
*/
229+
fk_rel = trigdata->tg_relation;
230+
pk_rel = heap_open(trigdata->tg_trigger->tgconstrrelid, RowShareLock);
231231

232232
/* ----------
233233
* SQL3 11.9 <referential constraint definition>

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