]> granicus.if.org Git - postgresql/commitdiff
Remove dead foreign key optimization code
authorPeter Eisentraut <peter_e@gmx.net>
Thu, 19 Jul 2018 06:20:59 +0000 (08:20 +0200)
committerPeter Eisentraut <peter_e@gmx.net>
Sat, 10 Nov 2018 15:14:51 +0000 (16:14 +0100)
The ri_KeysEqual() calls in the foreign-key trigger functions to
optimize away some updates are useless because since
adfeef55cbcc5dc72a772777f88c1be05a70dfee those triggers are not enqueued
at all.  (It's also not useful to keep these checks as some kind of
backstop, since it's also semantically correct to just run the full
check even with equal keys.)

Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
src/backend/utils/adt/ri_triggers.c

index 049b20449a141eb6d5e368e9be0ad909522d46f6..dfa9ab98c31423e8fb701fd5bdbf16a9ddf31273 100644 (file)
@@ -744,20 +744,6 @@ ri_restrict(TriggerData *trigdata, bool is_no_action)
                                        break;
                        }
 
-                       /*
-                        * In UPDATE, no need to do anything if old and new keys are equal
-                        */
-                       if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
-                       {
-                               HeapTuple       new_row = trigdata->tg_newtuple;
-
-                               if (ri_KeysEqual(pk_rel, old_row, new_row, riinfo, true))
-                               {
-                                       heap_close(fk_rel, RowShareLock);
-                                       return PointerGetDatum(NULL);
-                               }
-                       }
-
                        /*
                         * If another PK row now exists providing the old key values, we
                         * should not do anything.  However, this check should only be
@@ -1098,15 +1084,6 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
                                        break;
                        }
 
-                       /*
-                        * No need to do anything if old and new keys are equal
-                        */
-                       if (ri_KeysEqual(pk_rel, old_row, new_row, riinfo, true))
-                       {
-                               heap_close(fk_rel, RowExclusiveLock);
-                               return PointerGetDatum(NULL);
-                       }
-
                        if (SPI_connect() != SPI_OK_CONNECT)
                                elog(ERROR, "SPI_connect failed");
 
@@ -1316,20 +1293,6 @@ ri_setnull(TriggerData *trigdata)
                                        break;
                        }
 
-                       /*
-                        * In UPDATE, no need to do anything if old and new keys are equal
-                        */
-                       if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
-                       {
-                               HeapTuple       new_row = trigdata->tg_newtuple;
-
-                               if (ri_KeysEqual(pk_rel, old_row, new_row, riinfo, true))
-                               {
-                                       heap_close(fk_rel, RowExclusiveLock);
-                                       return PointerGetDatum(NULL);
-                               }
-                       }
-
                        if (SPI_connect() != SPI_OK_CONNECT)
                                elog(ERROR, "SPI_connect failed");
 
@@ -1536,20 +1499,6 @@ ri_setdefault(TriggerData *trigdata)
                                        break;
                        }
 
-                       /*
-                        * In UPDATE, no need to do anything if old and new keys are equal
-                        */
-                       if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
-                       {
-                               HeapTuple       new_row = trigdata->tg_newtuple;
-
-                               if (ri_KeysEqual(pk_rel, old_row, new_row, riinfo, true))
-                               {
-                                       heap_close(fk_rel, RowExclusiveLock);
-                                       return PointerGetDatum(NULL);
-                               }
-                       }
-
                        if (SPI_connect() != SPI_OK_CONNECT)
                                elog(ERROR, "SPI_connect failed");