Skip to content

Commit 427c6b5

Browse files
committed
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.
1 parent a65a494 commit 427c6b5

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/backend/optimizer/path/allpaths.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.145 2006/04/30 18:30:39 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.146 2006/05/02 04:34:18 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -273,6 +273,13 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
273273
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
274274
errmsg("SELECT FOR UPDATE/SHARE is not supported for inheritance queries")));
275275

276+
/*
277+
* We might have looked up indexes for the parent rel, but they're
278+
* really not relevant to the appendrel. Reset the pointer to avoid
279+
* any confusion.
280+
*/
281+
rel->indexlist = NIL;
282+
276283
/*
277284
* Initialize to compute size estimates for whole append relation
278285
*/

src/backend/utils/adt/selfuncs.c

+13-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.203 2006/04/27 17:52:40 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.204 2006/05/02 04:34:18 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -3265,19 +3265,27 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
32653265
(varRelid == 0 || varRelid == ((Var *) basenode)->varno))
32663266
{
32673267
Var *var = (Var *) basenode;
3268-
Oid relid;
3268+
RangeTblEntry *rte;
32693269

32703270
vardata->var = basenode; /* return Var without relabeling */
32713271
vardata->rel = find_base_rel(root, var->varno);
32723272
vardata->atttype = var->vartype;
32733273
vardata->atttypmod = var->vartypmod;
32743274

3275-
relid = getrelid(var->varno, root->parse->rtable);
3275+
rte = rt_fetch(var->varno, root->parse->rtable);
32763276

3277-
if (OidIsValid(relid))
3277+
if (rte->inh)
3278+
{
3279+
/*
3280+
* XXX This means the Var represents a column of an append relation.
3281+
* Later add code to look at the member relations and try to derive
3282+
* some kind of combined statistics?
3283+
*/
3284+
}
3285+
else if (rte->rtekind == RTE_RELATION)
32783286
{
32793287
vardata->statsTuple = SearchSysCache(STATRELATT,
3280-
ObjectIdGetDatum(relid),
3288+
ObjectIdGetDatum(rte->relid),
32813289
Int16GetDatum(var->varattno),
32823290
0, 0);
32833291
}

0 commit comments

Comments
 (0)