diff options
Diffstat (limited to 'src/backend/utils/adt/selfuncs.c')
-rw-r--r-- | src/backend/utils/adt/selfuncs.c | 37 |
1 files changed, 5 insertions, 32 deletions
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index 5d56748f0a7..1fbb0b28c3b 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -3919,17 +3919,6 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel, 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; @@ -4015,7 +4004,8 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel, Assert(nmatches_vars + nmatches_exprs > 1); - stats = statext_ndistinct_load(statOid); + rte = planner_rt_fetch(rel->relid, root); + stats = statext_ndistinct_load(statOid, rte->inh); /* * If we have a match, search it for the specific item that matches (there @@ -5245,17 +5235,6 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid, if (vardata->statsTuple) break; - /* - * 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 && rte->relkind != RELKIND_PARTITIONED_TABLE) - break; - /* skip stats without per-expression stats */ if (info->kind != STATS_EXT_EXPRESSIONS) continue; @@ -5274,22 +5253,16 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid, /* found a match, see if we can extract pg_statistic row */ if (equal(node, expr)) { - HeapTuple t = statext_expressions_load(info->statOid, pos); - - /* Get statistics object's table for permission check */ - RangeTblEntry *rte; Oid userid; - vardata->statsTuple = t; - /* * XXX Not sure if we should cache the tuple somewhere. * Now we just create a new copy every time. */ - vardata->freefunc = ReleaseDummy; + vardata->statsTuple = + statext_expressions_load(info->statOid, rte->inh, pos); - rte = planner_rt_fetch(onerel->relid, root); - Assert(rte->rtekind == RTE_RELATION); + vardata->freefunc = ReleaseDummy; /* * Use checkAsUser if it's set, in case we're accessing |