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

Commit69ee2ff

Browse files
committed
Apply RI trigger skipping tests also for DELETE
The tests added incfa0f42 to skipfiring an RI trigger if any old key value is NULL can also be appliedfor DELETE. This should give a performance gain in those cases, and italso saves a lot of duplicate code in the actual RI triggers. (Thatcode was already dead code for the UPDATE cases.)Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
1 parent34479d9 commit69ee2ff

File tree

2 files changed

+6
-103
lines changed

2 files changed

+6
-103
lines changed

‎src/backend/commands/trigger.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5950,12 +5950,12 @@ AfterTriggerSaveEvent(EState *estate, ResultRelInfo *relinfo,
59505950
* certain cases where we can skip queueing the event because we can
59515951
* tell by inspection that the FK constraint will still pass.
59525952
*/
5953-
if (TRIGGER_FIRED_BY_UPDATE(event))
5953+
if (TRIGGER_FIRED_BY_UPDATE(event)||TRIGGER_FIRED_BY_DELETE(event))
59545954
{
59555955
switch (RI_FKey_trigger_type(trigger->tgfoid))
59565956
{
59575957
caseRI_TRIGGER_PK:
5958-
/* Update on trigger's PK table */
5958+
/* Updateor deleteon trigger's PK table */
59595959
if (!RI_FKey_pk_upd_check_required(trigger,rel,
59605960
oldtup,newtup))
59615961
{

‎src/backend/utils/adt/ri_triggers.c

Lines changed: 4 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -724,25 +724,6 @@ ri_restrict(TriggerData *trigdata, bool is_no_action)
724724
*/
725725
caseFKCONSTR_MATCH_SIMPLE:
726726
caseFKCONSTR_MATCH_FULL:
727-
switch (ri_NullCheck(RelationGetDescr(pk_rel),old_row,riinfo, true))
728-
{
729-
caseRI_KEYS_ALL_NULL:
730-
caseRI_KEYS_SOME_NULL:
731-
732-
/*
733-
* No check needed - there cannot be any reference to old
734-
* key if it contains a NULL
735-
*/
736-
heap_close(fk_rel,RowShareLock);
737-
returnPointerGetDatum(NULL);
738-
739-
caseRI_KEYS_NONE_NULL:
740-
741-
/*
742-
* Have a full qualified key - continue below
743-
*/
744-
break;
745-
}
746727

747728
/*
748729
* If another PK row now exists providing the old key values, we
@@ -900,26 +881,6 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS)
900881
*/
901882
caseFKCONSTR_MATCH_SIMPLE:
902883
caseFKCONSTR_MATCH_FULL:
903-
switch (ri_NullCheck(RelationGetDescr(pk_rel),old_row,riinfo, true))
904-
{
905-
caseRI_KEYS_ALL_NULL:
906-
caseRI_KEYS_SOME_NULL:
907-
908-
/*
909-
* No check needed - there cannot be any reference to old
910-
* key if it contains a NULL
911-
*/
912-
heap_close(fk_rel,RowExclusiveLock);
913-
returnPointerGetDatum(NULL);
914-
915-
caseRI_KEYS_NONE_NULL:
916-
917-
/*
918-
* Have a full qualified key - continue below
919-
*/
920-
break;
921-
}
922-
923884
if (SPI_connect()!=SPI_OK_CONNECT)
924885
elog(ERROR,"SPI_connect failed");
925886

@@ -1064,26 +1025,6 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
10641025
*/
10651026
caseFKCONSTR_MATCH_SIMPLE:
10661027
caseFKCONSTR_MATCH_FULL:
1067-
switch (ri_NullCheck(RelationGetDescr(pk_rel),old_row,riinfo, true))
1068-
{
1069-
caseRI_KEYS_ALL_NULL:
1070-
caseRI_KEYS_SOME_NULL:
1071-
1072-
/*
1073-
* No check needed - there cannot be any reference to old
1074-
* key if it contains a NULL
1075-
*/
1076-
heap_close(fk_rel,RowExclusiveLock);
1077-
returnPointerGetDatum(NULL);
1078-
1079-
caseRI_KEYS_NONE_NULL:
1080-
1081-
/*
1082-
* Have a full qualified key - continue below
1083-
*/
1084-
break;
1085-
}
1086-
10871028
if (SPI_connect()!=SPI_OK_CONNECT)
10881029
elog(ERROR,"SPI_connect failed");
10891030

@@ -1273,26 +1214,6 @@ ri_setnull(TriggerData *trigdata)
12731214
*/
12741215
caseFKCONSTR_MATCH_SIMPLE:
12751216
caseFKCONSTR_MATCH_FULL:
1276-
switch (ri_NullCheck(RelationGetDescr(pk_rel),old_row,riinfo, true))
1277-
{
1278-
caseRI_KEYS_ALL_NULL:
1279-
caseRI_KEYS_SOME_NULL:
1280-
1281-
/*
1282-
* No check needed - there cannot be any reference to old
1283-
* key if it contains a NULL
1284-
*/
1285-
heap_close(fk_rel,RowExclusiveLock);
1286-
returnPointerGetDatum(NULL);
1287-
1288-
caseRI_KEYS_NONE_NULL:
1289-
1290-
/*
1291-
* Have a full qualified key - continue below
1292-
*/
1293-
break;
1294-
}
1295-
12961217
if (SPI_connect()!=SPI_OK_CONNECT)
12971218
elog(ERROR,"SPI_connect failed");
12981219

@@ -1479,26 +1400,6 @@ ri_setdefault(TriggerData *trigdata)
14791400
*/
14801401
caseFKCONSTR_MATCH_SIMPLE:
14811402
caseFKCONSTR_MATCH_FULL:
1482-
switch (ri_NullCheck(RelationGetDescr(pk_rel),old_row,riinfo, true))
1483-
{
1484-
caseRI_KEYS_ALL_NULL:
1485-
caseRI_KEYS_SOME_NULL:
1486-
1487-
/*
1488-
* No check needed - there cannot be any reference to old
1489-
* key if it contains a NULL
1490-
*/
1491-
heap_close(fk_rel,RowExclusiveLock);
1492-
returnPointerGetDatum(NULL);
1493-
1494-
caseRI_KEYS_NONE_NULL:
1495-
1496-
/*
1497-
* Have a full qualified key - continue below
1498-
*/
1499-
break;
1500-
}
1501-
15021403
if (SPI_connect()!=SPI_OK_CONNECT)
15031404
elog(ERROR,"SPI_connect failed");
15041405

@@ -1617,11 +1518,13 @@ ri_setdefault(TriggerData *trigdata)
16171518
/* ----------
16181519
* RI_FKey_pk_upd_check_required -
16191520
*
1620-
*Check if we really need to fire the RI trigger for an update to a PK
1521+
*Check if we really need to fire the RI trigger for an updateor deleteto a PK
16211522
*relation. This is called by the AFTER trigger queue manager to see if
16221523
*it can skip queuing an instance of an RI trigger. Returns true if the
16231524
*trigger must be fired, false if we can prove the constraint will still
16241525
*be satisfied.
1526+
*
1527+
*new_row will be NULL if this is called for a delete.
16251528
* ----------
16261529
*/
16271530
bool
@@ -1648,7 +1551,7 @@ RI_FKey_pk_upd_check_required(Trigger *trigger, Relation pk_rel,
16481551
return false;
16491552

16501553
/* If all old and new key values are equal, no check is needed */
1651-
if (ri_KeysEqual(pk_rel,old_row,new_row,riinfo, true))
1554+
if (new_row&&ri_KeysEqual(pk_rel,old_row,new_row,riinfo, true))
16521555
return false;
16531556

16541557
/* Else we need to fire the trigger. */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp