Fix ENABLE/DISABLE TRIGGER to handle recursion correctly
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Thu, 4 Aug 2022 18:02:02 +0000 (20:02 +0200)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 5 Aug 2022 07:47:26 +0000 (09:47 +0200)
commitec0925c22a3da7199650c9903a03a0017705ed5c
tree50cf501b9d2ccdf1153ffb8879f6d18ab79287ce
parentd2e150831af85fd30742f551a497db6639d91d0b
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
src/backend/commands/tablecmds.c
src/backend/commands/trigger.c
src/include/commands/trigger.h
src/include/nodes/parsenodes.h
src/test/regress/expected/triggers.out
src/test/regress/sql/triggers.sql