postgresql/src/backend/optimizer/util
Tom Lane 8f4a6b9e4f 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
..
Makefile Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
appendinfo.c Rework planning and execution of UPDATE and DELETE. 2021-03-31 11:52:37 -04:00
clauses.c Handle RLS dependencies in inlined set-returning functions properly. 2023-05-08 10:12:44 -04:00
inherit.c Fix calculation of which GENERATED columns need to be updated. 2023-01-05 14:12:17 -05:00
joininfo.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
orclauses.c Fix pull_varnos' miscomputation of relids set for a PlaceHolderVar. 2021-01-21 15:37:23 -05:00
paramassign.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
pathnode.c Fix problems when a plain-inheritance parent table is excluded. 2023-10-24 14:48:34 -04:00
placeholder.c Fix pull_varnos' miscomputation of relids set for a PlaceHolderVar. 2021-01-21 15:37:23 -05:00
plancat.c Fix calculation of which GENERATED columns need to be updated. 2023-01-05 14:12:17 -05:00
predtest.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
relnode.c Rework planning and execution of UPDATE and DELETE. 2021-03-31 11:52:37 -04:00
restrictinfo.c Disallow replacing joins with scans in problematic cases. 2023-07-28 15:45:04 +09:00
tlist.c Fix typos in comments, code and documentation 2023-01-03 16:26:30 +09:00
var.c Suppress more variable-set-but-not-used warnings from clang 15. 2022-09-21 13:52:38 -04:00