pgsql: Postpone reparameterization of paths until create_plan().

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Postpone reparameterization of paths until create_plan().
Дата
Msg-id E1rmeck-004dC4-0j@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Postpone reparameterization of paths until create_plan().

When considering nestloop paths for individual partitions within
a partitionwise join, if the inner path is parameterized, it is
parameterized by the topmost parent of the outer rel, not the
corresponding outer rel itself.  Therefore, we need to translate the
parameterization so that the inner path is parameterized by the
corresponding outer rel.

Up to now, we did this while generating join paths.  However, that's
problematic because we must also translate some expressions that are
shared across all paths for a relation, such as restriction clauses
(kept in the RelOptInfo and/or IndexOptInfo) and TableSampleClauses
(kept in the RangeTblEntry).  The existing code fails to translate
these at all, leading to wrong answers, odd failures such as
"variable not found in subplan target list", or executor crashes.
But we can't modify them during path generation, because that would
break things if we end up choosing some non-partitioned-join path.

So this patch postpones reparameterization of the inner path until
createplan.c, where it is safe to modify the referenced RangeTblEntry,
RelOptInfo or IndexOptInfo, because we have made a final choice of which
Path to use.  We do still have to check during path generation that
the reparameterization will be possible.  So we introduce a new
function path_is_reparameterizable_by_child() to detect that.

The duplication between path_is_reparameterizable_by_child() and
reparameterize_path_by_child() is a bit annoying, but there seems
no other good answer.  A small benefit is that we can avoid building
useless reparameterized trees in cases where a non-partitioned join
is ultimately chosen.  Also, reparameterize_path_by_child() can now
be allowed to scribble on the input paths, saving a few cycles.

This fix repairs the same problems previously addressed in the
back branches by commits 62f120203 et al.

Richard Guo, reviewed at various times by Ashutosh Bapat, Andrei
Lepikhov, Alena Rybakina, Robert Haas, and myself

Discussion: https://postgr.es/m/CAMbWs496+N=UAjOc=rcD3P7B6oJe4rZw08e_TZRUsWbPxZW3Tw@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/b7e2121ab7d6166b835a46ceaab1b6a6dc589703

Modified Files
--------------
src/backend/optimizer/path/joinpath.c        |  67 +++---
src/backend/optimizer/plan/createplan.c      |  17 ++
src/backend/optimizer/util/pathnode.c        | 292 +++++++++++++++++++++------
src/include/optimizer/pathnode.h             |   2 +
src/test/regress/expected/partition_join.out | 168 +++++++++++++++
src/test/regress/sql/partition_join.sql      |  40 ++++
6 files changed, 485 insertions(+), 101 deletions(-)


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

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: pgsql: gen_node_support.pl: Mark location fields as type alias ParseLoc
Следующее
От: Nathan Bossart
Дата:
Сообщение: pgsql: Inline pg_popcount{32,64} into pg_popcount().