pgsql: Fix problems when a plain-inheritance parent table is excluded.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix problems when a plain-inheritance parent table is excluded.
Дата
Msg-id E1qvMSP-0029RO-7P@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/387f9ed0a0832760a709d27abd630002903e3459

Modified Files
--------------
src/backend/executor/nodeModifyTable.c |  9 +++++----
src/backend/optimizer/plan/planner.c   | 14 ++++----------
src/backend/optimizer/util/pathnode.c  |  2 +-
src/include/nodes/pathnodes.h          |  2 +-
src/include/nodes/plannodes.h          | 13 +++++++------
src/test/regress/expected/inherit.out  | 27 +++++++++++++++++++++++++++
src/test/regress/sql/inherit.sql       | 19 +++++++++++++++++++
7 files changed, 64 insertions(+), 22 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Peter Geoghegan
Дата:
Сообщение: pgsql: Doc: indexUnchanged is strictly a hint.
Следующее
От: Daniel Gustafsson
Дата:
Сообщение: pgsql: Speed up pg_regress server readiness testing.