Fix OR index selectivity problem.
This commit is contained in:
parent
c831d08fac
commit
f7430af934
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/orindxpath.c,v 1.22 1999/03/08 13:35:50 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/orindxpath.c,v 1.23 1999/03/08 14:01:55 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -33,8 +33,7 @@
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
best_or_subclause_indices(Query *root, RelOptInfo *rel, List *subclauses,
|
best_or_subclause_indices(Query *root, RelOptInfo *rel, List *subclauses,
|
||||||
List *indices, List *examined_indexids, Cost subcost, List *selectivities,
|
List *indices, List **indexids, Cost *cost, Cost *selec);
|
||||||
List **indexids, Cost *cost, List **selecs);
|
|
||||||
static void best_or_subclause_index(Query *root, RelOptInfo *rel, Expr *subclause,
|
static void best_or_subclause_index(Query *root, RelOptInfo *rel, Expr *subclause,
|
||||||
List *indices, int *indexid, Cost *cost, Cost *selec);
|
List *indices, int *indexid, Cost *cost, Cost *selec);
|
||||||
|
|
||||||
@ -87,20 +86,17 @@ create_or_index_paths(Query *root,
|
|||||||
if (index_flag)
|
if (index_flag)
|
||||||
{ /* used to be a lisp every function */
|
{ /* used to be a lisp every function */
|
||||||
IndexPath *pathnode = makeNode(IndexPath);
|
IndexPath *pathnode = makeNode(IndexPath);
|
||||||
List *indexids;
|
List *indexids = NIL;
|
||||||
Cost cost;
|
Cost cost;
|
||||||
List *selecs;
|
Cost selec;
|
||||||
|
|
||||||
best_or_subclause_indices(root,
|
best_or_subclause_indices(root,
|
||||||
rel,
|
rel,
|
||||||
clausenode->clause->args,
|
clausenode->clause->args,
|
||||||
clausenode->indexids,
|
clausenode->indexids,
|
||||||
NIL,
|
|
||||||
(Cost) 0,
|
|
||||||
NIL,
|
|
||||||
&indexids,
|
&indexids,
|
||||||
&cost,
|
&cost,
|
||||||
&selecs);
|
&selec);
|
||||||
|
|
||||||
pathnode->path.pathtype = T_IndexScan;
|
pathnode->path.pathtype = T_IndexScan;
|
||||||
pathnode->path.parent = rel;
|
pathnode->path.parent = rel;
|
||||||
@ -132,7 +128,7 @@ create_or_index_paths(Query *root,
|
|||||||
((Path *) pathnode)->path_cost += xfunc_get_path_cost((Path) pathnode);
|
((Path *) pathnode)->path_cost += xfunc_get_path_cost((Path) pathnode);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
clausenode->selectivity = (Cost) floatVal(lfirst(selecs));
|
clausenode->selectivity = (Cost) selec;
|
||||||
t_list = lappend(t_list, pathnode);
|
t_list = lappend(t_list, pathnode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,8 +150,7 @@ create_or_index_paths(Query *root,
|
|||||||
* 'examined_indexids' is a list of those index ids to be used with
|
* 'examined_indexids' is a list of those index ids to be used with
|
||||||
* subclauses that have already been examined
|
* subclauses that have already been examined
|
||||||
* 'subcost' is the cost of using the indices in 'examined_indexids'
|
* 'subcost' is the cost of using the indices in 'examined_indexids'
|
||||||
* 'selectivities' is a list of the selectivities of subclauses that
|
* 'selec' is a list of all subclauses that have already been examined
|
||||||
* have already been examined
|
|
||||||
*
|
*
|
||||||
* Returns a list of the indexids, cost, and selectivities of each
|
* Returns a list of the indexids, cost, and selectivities of each
|
||||||
* subclause, e.g., ((i1 i2 i3) cost (s1 s2 s3)), where 'i' is an OID,
|
* subclause, e.g., ((i1 i2 i3) cost (s1 s2 s3)), where 'i' is an OID,
|
||||||
@ -166,15 +161,15 @@ best_or_subclause_indices(Query *root,
|
|||||||
RelOptInfo *rel,
|
RelOptInfo *rel,
|
||||||
List *subclauses,
|
List *subclauses,
|
||||||
List *indices,
|
List *indices,
|
||||||
List *examined_indexids,
|
|
||||||
Cost subcost,
|
|
||||||
List *selectivities,
|
|
||||||
List **indexids, /* return value */
|
List **indexids, /* return value */
|
||||||
Cost *cost, /* return value */
|
Cost *cost, /* return value */
|
||||||
List **selecs) /* return value */
|
Cost *selec) /* return value */
|
||||||
{
|
{
|
||||||
List *slist;
|
List *slist;
|
||||||
|
|
||||||
|
*selec = (Cost) 0.0;
|
||||||
|
*cost = (Cost) 0.0;
|
||||||
|
|
||||||
foreach(slist, subclauses)
|
foreach(slist, subclauses)
|
||||||
{
|
{
|
||||||
int best_indexid;
|
int best_indexid;
|
||||||
@ -184,17 +179,15 @@ best_or_subclause_indices(Query *root,
|
|||||||
best_or_subclause_index(root, rel, lfirst(slist), lfirst(indices),
|
best_or_subclause_index(root, rel, lfirst(slist), lfirst(indices),
|
||||||
&best_indexid, &best_cost, &best_selec);
|
&best_indexid, &best_cost, &best_selec);
|
||||||
|
|
||||||
examined_indexids = lappendi(examined_indexids, best_indexid);
|
*indexids = lappendi(*indexids, best_indexid);
|
||||||
subcost += best_cost;
|
*cost += best_cost;
|
||||||
selectivities = lappend(selectivities, makeFloat(best_selec));
|
*selec += best_selec;
|
||||||
|
if (*selec > (Cost) 1.0)
|
||||||
|
*selec = (Cost) 1.0;
|
||||||
|
|
||||||
indices = lnext(indices);
|
indices = lnext(indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
*indexids = examined_indexids;
|
|
||||||
*cost = subcost;
|
|
||||||
*selecs = selectivities;
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.26 1999/02/21 03:48:54 scrappy Exp $
|
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.27 1999/03/08 14:01:57 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -545,7 +545,6 @@ IndexSelectivity(Oid indexrelid,
|
|||||||
select = 1.0;
|
select = 1.0;
|
||||||
for (n = 0; n < nIndexKeys; ++n)
|
for (n = 0; n < nIndexKeys; ++n)
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find the AM class for this key.
|
* Find the AM class for this key.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user