pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix ENABLE/DISABLE TRIGGER to handle recursion correctly
Date: Fri, 05 Aug 2022 07:48:43 +0000
Message-ID: <E1oJs4Y-000OdC-Pj@gemulon.postgresql.org> (raw)

Fix ENABLE/DISABLE TRIGGER to handle recursion correctly

Using ATSimpleRecursion() in ATPrepCmd() to do so as bbb927b4db9b did is
not correct, because ATPrepCmd() can't distinguish between triggers that
may be cloned and those that may not, so would wrongly try to recurse
for the latter category of triggers.

So this commit restores the code in EnableDisableTrigger() that
86f575948c77 had added to do the recursion, which would do it only for
triggers that may be cloned, that is, row-level triggers.  This also
changes tablecmds.c such that ATExecCmd() is able to pass the value of
ONLY flag down to EnableDisableTrigger() using its new 'recurse'
parameter.

This also fixes what seems like an oversight of 86f575948c77 that the
recursion to partition triggers would only occur if EnableDisableTrigger()
had actually changed the trigger.  It is more apt to recurse to inspect
partition triggers even if the parent's trigger didn't need to be
changed: only then can we be certain that all descendants share the same
state afterwards.

Backpatch all the way back to 11, like bbb927b4db9b.  Care is taken not
to break ABI compatibility (and that no catversion bump is needed.)

Co-authored-by: Amit Langote <amitlangote09@gmail.com>
Reviewed-by: Dmitry Koval <d.koval@postgrespro.ru>
Discussion: https://postgr.es/m/CA+HiwqG-cZT3XzGAnEgZQLoQbyfJApVwOTQaCaas1mhpf+4V5A@mail.gmail.com

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/6e7b37264e96d3216240b207f763913164cf6487

Modified Files
--------------
src/backend/commands/tablecmds.c       | 64 +++++++++++++++++++++++-----------
src/backend/commands/trigger.c         | 47 +++++++++++++++++++++++--
src/backend/nodes/copyfuncs.c          |  1 +
src/backend/nodes/equalfuncs.c         |  1 +
src/include/commands/trigger.h         |  3 ++
src/include/nodes/parsenodes.h         |  1 +
src/test/regress/expected/triggers.out | 40 +++++++++++++++------
src/test/regress/sql/triggers.sql      | 11 +++++-
8 files changed, 134 insertions(+), 34 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1oJs4Y-000OdC-Pj@gemulon.postgresql.org>
Permalink:  ../E1oJs4Y-000OdC-Pj@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1oJs4Y-000OdC-Pj@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: alvherre@alvh.no-ip.org
  Subject: Re: pgsql: Fix ENABLE/DISABLE TRIGGER to handle recursion correctly
  In-Reply-To: <E1oJs4Y-000OdC-Pj@gemulon.postgresql.org>
  References: <E1oJs4Y-000OdC-Pj@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox