1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-21 16:02:15 +03:00

Fix planner failure with extended statistics on partitioned tables.

Some cases would result in "cache lookup failed for statistics object",
due to trying to fetch inherited statistics when only non-inherited
ones are available or vice versa.

Richard Guo and Justin Pryzby

Discussion: https://postgr.es/m/20221030170520.GM16921@telsasoft.com
This commit is contained in:
Tom Lane
2022-11-01 14:34:44 -04:00
parent 495e73c207
commit f4857082bc
3 changed files with 18 additions and 4 deletions

View File

@ -3913,7 +3913,7 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel,
Oid statOid = InvalidOid;
MVNDistinct *stats;
StatisticExtInfo *matched_info = NULL;
RangeTblEntry *rte;
RangeTblEntry *rte = planner_rt_fetch(rel->relid, root);
/* bail out immediately if the table has no extended statistics */
if (!rel->statlist)
@ -3933,6 +3933,10 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel,
if (info->kind != STATS_EXT_NDISTINCT)
continue;
/* skip statistics with mismatching stxdinherit value */
if (info->inherit != rte->inh)
continue;
/*
* Determine how many expressions (and variables in non-matched
* expressions) match. We'll then use these numbers to pick the
@ -4004,7 +4008,6 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel,
Assert(nmatches_vars + nmatches_exprs > 1);
rte = planner_rt_fetch(rel->relid, root);
stats = statext_ndistinct_load(statOid, rte->inh);
/*
@ -5241,6 +5244,10 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
if (info->kind != STATS_EXT_EXPRESSIONS)
continue;
/* skip stats with mismatching stxdinherit value */
if (info->inherit != rte->inh)
continue;
pos = 0;
foreach(expr_item, info->exprs)
{