diff options
Diffstat (limited to 'src/backend/utils/adt/selfuncs.c')
-rw-r--r-- | src/backend/utils/adt/selfuncs.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index 9e39f9888e1..5d56748f0a7 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -3913,19 +3913,23 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel, Oid statOid = InvalidOid; MVNDistinct *stats; StatisticExtInfo *matched_info = NULL; - RangeTblEntry *rte = planner_rt_fetch(rel->relid, root); - - /* - * When dealing with inheritance trees, ignore extended stats (which were - * built without data from child rels, and thus do not represent them). - */ - if (rte->inh) - return false; + RangeTblEntry *rte; /* bail out immediately if the table has no extended statistics */ if (!rel->statlist) return false; + /* + * When dealing with regular inheritance trees, ignore extended stats + * (which were built without data from child rels, and thus do not + * represent them). For partitioned tables data there's no data in the + * non-leaf relations, so we build stats only for the inheritance tree. + * So for partitioned tables we do consider extended stats. + */ + rte = planner_rt_fetch(rel->relid, root); + if (rte->inh && rte->relkind != RELKIND_PARTITIONED_TABLE) + return false; + /* look for the ndistinct statistics object matching the most vars */ nmatches_vars = 0; /* we require at least two matches */ nmatches_exprs = 0; @@ -5242,11 +5246,14 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid, break; /* - * When dealing with inheritance trees, ignore extended stats (which - * were built without data from child rels, and so do not represent - * them). + * When dealing with regular inheritance trees, ignore extended + * stats (which were built without data from child rels, and thus + * do not represent them). For partitioned tables data there's no + * data in the non-leaf relations, so we build stats only for the + * inheritance tree. So for partitioned tables we do consider + * extended stats. */ - if (rte->inh) + if (rte->inh && rte->relkind != RELKIND_PARTITIONED_TABLE) break; /* skip stats without per-expression stats */ |