• Etsuro Fujita's avatar
    Disable support for partitionwise joins in problematic cases. · 7cfdc770
    Etsuro Fujita authored
    Commit f49842d1, 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
    7cfdc770
partition_aggregate.out 62.9 KB