Fix plan created for inherited UPDATE/DELETE with all tables excluded.
In the case where inheritance_planner() finds that every table has
been excluded by constraints, it thought it could get away with
making a plan consisting of just a dummy Result node. While certainly
there's no updating or deleting to be done, this had two user-visible
problems: the plan did not report the correct set of output columns
when a RETURNING clause was present, and if there were any
statement-level triggers that should be fired, it didn't fire them.
Hence, rather than only generating the dummy Result, we need to
stick a valid ModifyTable node on top, which requires a tad more
effort here.
It's been broken this way for as long as inheritance_planner() has
known about deleting excluded subplans at all (cf commit 635d42e9c),
so back-patch to all supported branches.
Amit Langote and Tom Lane, per a report from Petr Fedorov.
Discussion: https://postgr.es/m/[email protected]
Branch
------
REL9_4_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/99a1554a2680d25f0b54d4209ccfc76c443df6e3
Modified Files
--------------
src/backend/optimizer/plan/planner.c | 52 +++++++++++++++++++++++-----------
src/test/regress/expected/inherit.out | 39 +++++++++++++++++++++++++
src/test/regress/expected/triggers.out | 34 ++++++++++++++++++++++
src/test/regress/sql/inherit.sql | 15 ++++++++++
src/test/regress/sql/triggers.sql | 27 ++++++++++++++++++
5 files changed, 150 insertions(+), 17 deletions(-)