diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index 1999cd4436..24900ce593 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -1305,15 +1305,13 @@ set_append_rel_size(PlannerInfo *root, RelOptInfo *rel, } /* - * If this is a partitioned baserel, set the consider_partitionwise_join - * flag; currently, we only consider partitionwise joins with the baserel - * if its targetlist doesn't contain a whole-row Var. + * Currently, we only consider partitionwise joins with the baserel + * if its targetlist doesn't contain a whole-row Var; turn it off + * otherwise. */ - if (enable_partitionwise_join && - rel->reloptkind == RELOPT_BASEREL && - rte->relkind == RELKIND_PARTITIONED_TABLE && - rel->attr_needed[InvalidAttrNumber - rel->min_attr] == NULL) - rel->consider_partitionwise_join = true; + if (rel->consider_partitionwise_join && + rel->attr_needed[InvalidAttrNumber - rel->min_attr] != NULL) + rel->consider_partitionwise_join = false; /* * Initialize to compute size estimates for whole append relation. diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c index fe83ec4519..80c26af4a1 100644 --- a/src/backend/optimizer/util/relnode.c +++ b/src/backend/optimizer/util/relnode.c @@ -253,6 +253,9 @@ build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent) break; } + /* Set if this relation can participate in partitionwise join. */ + rel->consider_partitionwise_join = (rel->part_scheme != NULL); + /* Save the finished struct in the query's simple_rel_array */ root->simple_rel_array[relid] = rel;