Avoid assuming that statistics for a parent relation reflect the properties of

the union of its child relations as well.  This might have been a good idea
when it was originally coded, but it's a fatally bad idea when inheritance is
being used for partitioning.  It's better to have no stats at all than
completely misleading stats.  Per report from Mark Liberman.

The bug arguably exists all the way back, but I've only patched HEAD and 8.1
because we weren't particularly trying to support partitioning before 8.1.

Eventually we ought to look at deriving union statistics instead of just
punting, but for now the drop kick looks good.
This commit is contained in:
Tom Lane 2006-05-02 04:34:24 +00:00
parent 0619268b4b
commit a3fe5ed594
2 changed files with 21 additions and 6 deletions

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.137.2.2 2006/02/13 16:22:29 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.137.2.3 2006/05/02 04:34:24 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -263,6 +263,13 @@ set_inherited_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("SELECT FOR UPDATE/SHARE is not supported for inheritance queries"))); errmsg("SELECT FOR UPDATE/SHARE is not supported for inheritance queries")));
/*
* We might have looked up indexes for the parent rel, but they're
* really not relevant to the appendrel. Reset the pointer to avoid
* any confusion.
*/
rel->indexlist = NIL;
/* /*
* Initialize to compute size estimates for whole inheritance tree * Initialize to compute size estimates for whole inheritance tree
*/ */

View File

@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.191.2.1 2005/11/22 18:23:22 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.191.2.2 2006/05/02 04:34:24 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -2970,19 +2970,27 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
(varRelid == 0 || varRelid == ((Var *) basenode)->varno)) (varRelid == 0 || varRelid == ((Var *) basenode)->varno))
{ {
Var *var = (Var *) basenode; Var *var = (Var *) basenode;
Oid relid; RangeTblEntry *rte;
vardata->var = basenode; /* return Var without relabeling */ vardata->var = basenode; /* return Var without relabeling */
vardata->rel = find_base_rel(root, var->varno); vardata->rel = find_base_rel(root, var->varno);
vardata->atttype = var->vartype; vardata->atttype = var->vartype;
vardata->atttypmod = var->vartypmod; vardata->atttypmod = var->vartypmod;
relid = getrelid(var->varno, root->parse->rtable); rte = rt_fetch(var->varno, root->parse->rtable);
if (OidIsValid(relid)) if (rte->inh)
{
/*
* XXX This means the Var represents a column of an append relation.
* Later add code to look at the member relations and try to derive
* some kind of combined statistics?
*/
}
else if (rte->rtekind == RTE_RELATION)
{ {
vardata->statsTuple = SearchSysCache(STATRELATT, vardata->statsTuple = SearchSysCache(STATRELATT,
ObjectIdGetDatum(relid), ObjectIdGetDatum(rte->relid),
Int16GetDatum(var->varattno), Int16GetDatum(var->varattno),
0, 0); 0, 0);
} }