Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5357566

Browse files
committed
During looking stuff up for a discussion on -general, I realized that
I'd placed the check for newly created matching pk rows for on update no action earlier than it needed to be so that it'd check even when the key values hadn't changed. This patch moves it to after checking for NULLs in the old row and comparing the values since the select's probably more expensive. Stephan Szabo
1 parent 9167a56 commit 5357566

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/backend/utils/adt/ri_triggers.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
1919
*
20-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.50 2003/04/26 22:21:47 tgl Exp $
20+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.51 2003/06/11 15:02:25 momjian Exp $
2121
*
2222
* ----------
2323
*/
@@ -883,17 +883,6 @@ RI_FKey_noaction_upd(PG_FUNCTION_ARGS)
883883
old_row = trigdata->tg_trigtuple;
884884

885885
match_type = ri_DetermineMatchType(tgargs[RI_MATCH_TYPE_ARGNO]);
886-
if (ri_Check_Pk_Match(pk_rel, fk_rel,
887-
old_row, trigdata->tg_trigger->tgoid,
888-
match_type, tgnargs, tgargs))
889-
{
890-
/*
891-
* There's either another row, or no row could match this one. In
892-
* either case, we don't need to do the check.
893-
*/
894-
heap_close(fk_rel, RowShareLock);
895-
return PointerGetDatum(NULL);
896-
}
897886

898887
switch (match_type)
899888
{
@@ -941,6 +930,18 @@ RI_FKey_noaction_upd(PG_FUNCTION_ARGS)
941930
return PointerGetDatum(NULL);
942931
}
943932

933+
if (ri_Check_Pk_Match(pk_rel, fk_rel,
934+
old_row, trigdata->tg_trigger->tgoid,
935+
match_type, tgnargs, tgargs))
936+
{
937+
/*
938+
* There's either another row, or no row could match this one. In
939+
* either case, we don't need to do the check.
940+
*/
941+
heap_close(fk_rel, RowShareLock);
942+
return PointerGetDatum(NULL);
943+
}
944+
944945
if (SPI_connect() != SPI_OK_CONNECT)
945946
elog(ERROR, "SPI_connect() failed in RI_FKey_noaction_upd()");
946947

0 commit comments

Comments
 (0)