postgresql/src
Tom Lane b1444a09dc Fix problems when a plain-inheritance parent table is excluded.
When an UPDATE/DELETE/MERGE's target table is an old-style
inheritance tree, it's possible for the parent to get excluded
from the plan while some children are not.  (I believe this is
only possible if we can prove that a CHECK ... NO INHERIT
constraint on the parent contradicts the query WHERE clause,
so it's a very unusual case.)  In such a case, ExecInitModifyTable
mistakenly concluded that the first surviving child is the target
table, leading to at least two bugs:

1. The wrong table's statement-level triggers would get fired.

2. In v16 and up, it was possible to fail with "invalid perminfoindex
0 in RTE with relid nnnn" due to the child RTE not having permissions
data included in the query plan.  This was hard to reproduce reliably
because it did not occur unless the update triggered some non-HOT
index updates.

In v14 and up, this is easy to fix by defining ModifyTable.rootRelation
to be the parent RTE in plain inheritance as well as partitioned cases.

While the wrong-triggers bug also appears in older branches, the
relevant code in both the planner and executor is quite a bit
different, so it would take a good deal of effort to develop and
test a suitable patch.  Given the lack of field complaints about the
trigger issue, I'll desist for now.  (Patching v11 for this seems
unwise anyway, given that it will have no more releases after next
month.)

Per bug #18147 from Hans Buschmann.

Amit Langote and Tom Lane

Discussion: https://postgr.es/m/18147-6fc796538913ee88@postgresql.org
2023-10-24 14:48:34 -04:00
..
backend Fix problems when a plain-inheritance parent table is excluded. 2023-10-24 14:48:34 -04:00
bin pg_upgrade: Fix test name in 002_pg_upgrade.pl 2023-10-18 18:23:43 +09:00
common Improve pglz_decompress's defenses against corrupt compressed data. 2023-10-18 20:43:17 -04:00
fe_utils Don't spuriously report FD_SETSIZE exhaustion on Windows. 2023-10-14 15:54:49 -07:00
include Fix problems when a plain-inheritance parent table is excluded. 2023-10-24 14:48:34 -04:00
interfaces Translation updates 2023-09-11 14:23:11 +02:00
makefiles Use --strip-unneeded when stripping static libraries with GNU strip. 2023-04-20 18:12:32 -04:00
pl Remove environment sensitivity in pl/tcl regression test. 2023-09-29 20:21:11 -04:00
port Meson: check for pg_config_paths.h left over from make 2023-08-24 10:33:48 +12:00
template
test Fix problems when a plain-inheritance parent table is excluded. 2023-10-24 14:48:34 -04:00
timezone Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
tools Fix exception safety bug in typcache.c. 2023-09-13 15:06:07 +12:00
tutorial Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
.gitignore
DEVELOPERS
Makefile Integrate pg_bsd_indent into our build/test infrastructure. 2023-02-12 12:22:21 -05:00
Makefile.global.in Suppress macOS warnings about duplicate libraries in link commands. 2023-09-29 14:07:30 -04:00
Makefile.shlib Stop using "-multiply_defined suppress" on macOS. 2023-09-26 21:06:21 -04:00
meson.build Integrate pg_bsd_indent into our build/test infrastructure. 2023-02-12 12:22:21 -05:00
nls-global.mk