Disable support for partitionwise joins in problematic cases

Enterprise / PostgreSQL - Etsuro Fujita [postgresql.org] - 31 August 2018 11:34 EDT

Commit f49842d, which added support for partitionwise joins, built the child's tlist by applying adjust_appendrel_attrs() to the parent's. So in the case where the parent's included a whole-row Var for the parent, the child's contained a ConvertRowtypeExpr. To cope with that, that commit added code to the planner, such as setrefs.c, but some code paths still assumed that the tlist for a scan (or join) rel would only include Vars and PlaceHolderVars, which was true before that commit, causing errors:

- When creating an explicit sort node for an input path for a mergejoin path for a child join, prepare_sort_from_pathkeys() threw the 'could not find pathkey item to sort' error.
- When deparsing a relation participating in a pushed down child join as a subquery in contrib/postgres_fdw, get_relation_column_alias_ids() threw the 'unexpected expression in subquery output' error.
- When performing set_plan_references() on a local join plan generated by contrib/postgres_fdw for EvalPlanQual support for a pushed down child join, fix_join_expr() threw the 'variable not found in subplan target lists' error.

To fix these, two approaches have been proposed: one by Ashutosh Bapat and one by me. While the former keeps building the child's tlist with a ConvertRowtypeExpr, the latter builds it with a whole-row Var for the child not to violate the planner assumption, and tries to fix it up later, But both approaches need more work, so refuse to generate partitionwise join paths when whole-row Vars are involved, instead. We don't need to handle ConvertRowtypeExprs in the child's tlists for now, so this commit also removes the changes to the planner.

Previously, partitionwise join computed attr_needed data for each child separately, and built the child join's tlist using that data, which also required an extra step for adding PlaceHolderVars to that tlist, but it would be more efficient to build it from the parent join's tlist through the adjust_appendrel_attrs() transformation. So this commit builds that list that way, and simplifies build_joinrel_tlist() and placeholder.c as well as part of set_append_rel_size() to basically what they were before partitionwise join went in.

Back-patch to PG11 where partitionwise join was introduced.

Report by Rajkumar Raghuwanshi. Analysis by Ashutosh Bapat, who also provided some of regression tests. Patch by me, reviewed by Robert Haas.

Discussion: https://postgr.es/m/CAKcux6ktu-8tefLWtQuuZBYFaZA83vUzuRd7c1YHC-yEWyYFpg@mail.gmail.com

7cfdc77023 Disable support for partitionwise joins in problematic cases.
contrib/postgres_fdw/expected/postgres_fdw.out | 71 +++++++++---
contrib/postgres_fdw/sql/postgres_fdw.sql | 14 ++-
src/backend/nodes/outfuncs.c | 1 +
src/backend/optimizer/path/allpaths.c | 78 ++++++--------
src/backend/optimizer/path/joinrels.c | 7 ++
src/backend/optimizer/plan/setrefs.c | 58 +---------
src/backend/optimizer/util/placeholder.c | 58 ----------
src/backend/optimizer/util/relnode.c | 125 +++++++++++-----------
src/include/nodes/relation.h | 8 +-
src/test/regress/expected/partition_aggregate.out | 32 ++++++
src/test/regress/expected/partition_join.out | 57 +++++++---
src/test/regress/sql/partition_aggregate.sql | 5 +
src/test/regress/sql/partition_join.sql | 8 +-
13 files changed, 266 insertions(+), 256 deletions(-)

Upstream: git.postgresql.org


  • Share