Re: unused/redundant foreign key code

2018-11-10 Thread Peter Eisentraut
On 09/11/2018 21:37, Daniel Gustafsson wrote:
>> On 8 Aug 2018, at 21:34, Peter Eisentraut  
>> wrote:
>>
>> I found some unused and some redundant code in ri_triggers.c that was
>> left around by some previous changes that aimed to optimize away certain
>> trigger invocations.  See attached patches.
> 
> Both of these patches apply cleanly with minimal offsets, build without
> warnings and make check passes.
> 
> From reading code and testing, I concur with your findings that this is indeed
> dead code.
> 
> +1 on this cleanup, I’m marking this as Ready for Committer.

Committed, thanks.

-- 
Peter Eisentraut  http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services



Re: unused/redundant foreign key code

2018-11-09 Thread Daniel Gustafsson
> On 8 Aug 2018, at 21:34, Peter Eisentraut  
> wrote:
> 
> I found some unused and some redundant code in ri_triggers.c that was
> left around by some previous changes that aimed to optimize away certain
> trigger invocations.  See attached patches.

Both of these patches apply cleanly with minimal offsets, build without
warnings and make check passes.

From reading code and testing, I concur with your findings that this is indeed
dead code.

+1 on this cleanup, I’m marking this as Ready for Committer.

cheers ./daniel


unused/redundant foreign key code

2018-08-08 Thread Peter Eisentraut
I found some unused and some redundant code in ri_triggers.c that was
left around by some previous changes that aimed to optimize away certain
trigger invocations.  See attached patches.

-- 
Peter Eisentraut  http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From 1fe8dac15a0013ef348dce1586db5af7bb02639a Mon Sep 17 00:00:00 2001
From: Peter Eisentraut 
Date: Thu, 19 Jul 2018 08:20:59 +0200
Subject: [PATCH 1/2] Remove dead foreign key optimization code

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.)
---
 src/backend/utils/adt/ri_triggers.c | 51 -
 1 file changed, 51 deletions(-)

diff --git a/src/backend/utils/adt/ri_triggers.c 
b/src/backend/utils/adt/ri_triggers.c
index fc034ce601..b674011aa7 100644
--- a/src/backend/utils/adt/ri_triggers.c
+++ b/src/backend/utils/adt/ri_triggers.c
@@ -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");
 
-- 
2.18.0

From d2bcff7d75bfbe07bcb27100fef8b3bedf279d2a Mon Sep 17 00:00:00 2001
From: Peter Eisentraut 
Date: Thu, 19 Jul 2018 08:37:32 +0200
Subject: [PATCH 2/2] Apply RI trigger skipping tests also for DELETE

The tests added in