@@ -724,25 +724,6 @@ ri_restrict(TriggerData *trigdata, bool is_no_action)
724724 */
725725 case FKCONSTR_MATCH_SIMPLE :
726726 case FKCONSTR_MATCH_FULL :
727- switch (ri_NullCheck (RelationGetDescr (pk_rel ), old_row , riinfo , true))
728- {
729- case RI_KEYS_ALL_NULL :
730- case RI_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- return PointerGetDatum (NULL );
738-
739- case RI_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 case FKCONSTR_MATCH_SIMPLE :
902883 case FKCONSTR_MATCH_FULL :
903- switch (ri_NullCheck (RelationGetDescr (pk_rel ), old_row , riinfo , true))
904- {
905- case RI_KEYS_ALL_NULL :
906- case RI_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- return PointerGetDatum (NULL );
914-
915- case RI_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 case FKCONSTR_MATCH_SIMPLE :
10661027 case FKCONSTR_MATCH_FULL :
1067- switch (ri_NullCheck (RelationGetDescr (pk_rel ), old_row , riinfo , true))
1068- {
1069- case RI_KEYS_ALL_NULL :
1070- case RI_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- return PointerGetDatum (NULL );
1078-
1079- case RI_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 case FKCONSTR_MATCH_SIMPLE :
12751216 case FKCONSTR_MATCH_FULL :
1276- switch (ri_NullCheck (RelationGetDescr (pk_rel ), old_row , riinfo , true))
1277- {
1278- case RI_KEYS_ALL_NULL :
1279- case RI_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- return PointerGetDatum (NULL );
1287-
1288- case RI_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 case FKCONSTR_MATCH_SIMPLE :
14811402 case FKCONSTR_MATCH_FULL :
1482- switch (ri_NullCheck (RelationGetDescr (pk_rel ), old_row , riinfo , true))
1483- {
1484- case RI_KEYS_ALL_NULL :
1485- case RI_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- return PointerGetDatum (NULL );
1493-
1494- case RI_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 update or delete to 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 */
16271530bool
@@ -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