mirror of
https://github.com/postgres/postgres.git
synced 2025-11-15 03:41:20 +03:00
Further work on planning of indexscans. Cleaned up interfaces
to index_selectivity so that it can be handed an indexqual clause list rather than a bunch of assorted derivative data.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.24 1999/07/24 23:21:09 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.25 1999/07/25 23:07:24 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -142,8 +142,8 @@ compute_clause_selec(Query *root, Node *clause)
|
||||
BooleanEqualOperator,
|
||||
relid,
|
||||
((Var *) clause)->varoattno,
|
||||
"t",
|
||||
_SELEC_CONSTANT_RIGHT_);
|
||||
Int8GetDatum(true),
|
||||
SEL_CONSTANT | SEL_RIGHT);
|
||||
}
|
||||
else if (IsA(clause, Param))
|
||||
{
|
||||
@@ -215,14 +215,6 @@ compute_clause_selec(Query *root, Node *clause)
|
||||
*/
|
||||
Oid opno = ((Oper *) ((Expr *) clause)->oper)->opno;
|
||||
RegProcedure oprrest = get_oprrest(opno);
|
||||
Oid relid;
|
||||
int relidx;
|
||||
AttrNumber attno;
|
||||
Datum constval;
|
||||
int flag;
|
||||
|
||||
get_relattval(clause, &relidx, &attno, &constval, &flag);
|
||||
relid = getrelid(relidx, root->rtable);
|
||||
|
||||
/*
|
||||
* if the oprrest procedure is missing for whatever reason, use a
|
||||
@@ -230,22 +222,33 @@ compute_clause_selec(Query *root, Node *clause)
|
||||
*/
|
||||
if (!oprrest)
|
||||
s1 = (Cost) 0.5;
|
||||
else if (attno == InvalidAttrNumber)
|
||||
{
|
||||
/*
|
||||
* attno can be Invalid if the clause had a function in it,
|
||||
* i.e. WHERE myFunc(f) = 10
|
||||
*/
|
||||
/* this should be FIXED somehow to use function selectivity */
|
||||
s1 = (Cost) (0.5);
|
||||
}
|
||||
else
|
||||
s1 = (Cost) restriction_selectivity(oprrest,
|
||||
opno,
|
||||
relid,
|
||||
attno,
|
||||
(char *) constval,
|
||||
flag);
|
||||
{
|
||||
int relidx;
|
||||
AttrNumber attno;
|
||||
Datum constval;
|
||||
int flag;
|
||||
|
||||
get_relattval(clause, 0, &relidx, &attno, &constval, &flag);
|
||||
if (relidx <= 0 || attno <= 0)
|
||||
{
|
||||
/*
|
||||
* attno can be Invalid if the clause had a function in it,
|
||||
* i.e. WHERE myFunc(f) = 10
|
||||
*
|
||||
* XXX should be FIXED to use function selectivity
|
||||
*/
|
||||
s1 = (Cost) (0.5);
|
||||
}
|
||||
else
|
||||
s1 = (Cost) restriction_selectivity(oprrest,
|
||||
opno,
|
||||
getrelid(relidx,
|
||||
root->rtable),
|
||||
attno,
|
||||
constval,
|
||||
flag);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -256,14 +259,6 @@ compute_clause_selec(Query *root, Node *clause)
|
||||
*/
|
||||
Oid opno = ((Oper *) ((Expr *) clause)->oper)->opno;
|
||||
RegProcedure oprjoin = get_oprjoin(opno);
|
||||
int relid1,
|
||||
relid2;
|
||||
AttrNumber attno1,
|
||||
attno2;
|
||||
|
||||
get_rels_atts(clause, &relid1, &attno1, &relid2, &attno2);
|
||||
relid1 = getrelid(relid1, root->rtable);
|
||||
relid2 = getrelid(relid2, root->rtable);
|
||||
|
||||
/*
|
||||
* if the oprjoin procedure is missing for whatever reason, use a
|
||||
@@ -272,12 +267,25 @@ compute_clause_selec(Query *root, Node *clause)
|
||||
if (!oprjoin)
|
||||
s1 = (Cost) (0.5);
|
||||
else
|
||||
s1 = (Cost) join_selectivity(oprjoin,
|
||||
opno,
|
||||
relid1,
|
||||
attno1,
|
||||
relid2,
|
||||
attno2);
|
||||
{
|
||||
int relid1,
|
||||
relid2;
|
||||
AttrNumber attno1,
|
||||
attno2;
|
||||
|
||||
get_rels_atts(clause, &relid1, &attno1, &relid2, &attno2);
|
||||
if (relid1 > 0 && relid2 > 0 && attno1 > 0 && attno2 > 0)
|
||||
s1 = (Cost) join_selectivity(oprjoin,
|
||||
opno,
|
||||
getrelid(relid1,
|
||||
root->rtable),
|
||||
attno1,
|
||||
getrelid(relid2,
|
||||
root->rtable),
|
||||
attno2);
|
||||
else /* XXX more code for function selectivity? */
|
||||
s1 = (Cost) (0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.64 1999/07/25 17:53:27 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.65 1999/07/25 23:07:24 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1216,25 +1216,20 @@ index_innerjoin(Query *root, RelOptInfo *rel, RelOptInfo *index,
|
||||
{
|
||||
List *clausegroup = lfirst(i);
|
||||
IndexPath *pathnode = makeNode(IndexPath);
|
||||
Cost temp_selec;
|
||||
float temp_pages;
|
||||
List *attnos,
|
||||
*values,
|
||||
*flags;
|
||||
List *indexquals;
|
||||
float npages;
|
||||
float selec;
|
||||
|
||||
get_joinvars(lfirsti(rel->relids), clausegroup,
|
||||
&attnos, &values, &flags);
|
||||
index_selectivity(lfirsti(index->relids),
|
||||
index->classlist,
|
||||
get_opnos(clausegroup),
|
||||
getrelid(lfirsti(rel->relids),
|
||||
root->rtable),
|
||||
attnos,
|
||||
values,
|
||||
flags,
|
||||
length(clausegroup),
|
||||
&temp_pages,
|
||||
&temp_selec);
|
||||
indexquals = get_actual_clauses(clausegroup);
|
||||
|
||||
index_selectivity(root,
|
||||
lfirsti(rel->relids),
|
||||
lfirsti(index->relids),
|
||||
indexquals,
|
||||
&npages,
|
||||
&selec);
|
||||
|
||||
/* XXX this code ought to be merged with create_index_path */
|
||||
|
||||
pathnode->path.pathtype = T_IndexScan;
|
||||
pathnode->path.parent = rel;
|
||||
@@ -1249,14 +1244,14 @@ index_innerjoin(Query *root, RelOptInfo *rel, RelOptInfo *index,
|
||||
*/
|
||||
pathnode->indexid = index->relids;
|
||||
pathnode->indexkeys = index->indexkeys;
|
||||
pathnode->indexqual = lcons(get_actual_clauses(clausegroup), NIL);
|
||||
pathnode->indexqual = lcons(indexquals, NIL);
|
||||
|
||||
/* joinid saves the rels needed on the outer side of the join */
|
||||
pathnode->path.joinid = lfirst(outerrelids_list);
|
||||
|
||||
pathnode->path.path_cost = cost_index((Oid) lfirsti(index->relids),
|
||||
(int) temp_pages,
|
||||
temp_selec,
|
||||
(int) npages,
|
||||
selec,
|
||||
rel->pages,
|
||||
rel->tuples,
|
||||
index->pages,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/orindxpath.c,v 1.29 1999/07/24 23:21:10 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/orindxpath.c,v 1.30 1999/07/25 23:07:24 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -121,11 +121,14 @@ create_or_index_paths(Query *root,
|
||||
pathnode->indexqual = NIL;
|
||||
foreach(orclause, clausenode->clause->args)
|
||||
{
|
||||
List *sublist;
|
||||
if (and_clause(lfirst(orclause)))
|
||||
sublist = ((Expr *) lfirst(orclause))->args;
|
||||
Expr *subclause = (Expr *) lfirst(orclause);
|
||||
List *sublist;
|
||||
|
||||
if (and_clause((Node *) subclause))
|
||||
sublist = subclause->args;
|
||||
else
|
||||
sublist = lcons(lfirst(orclause), NIL);
|
||||
sublist = lcons(subclause, NIL);
|
||||
/* expansion call... */
|
||||
pathnode->indexqual = lappend(pathnode->indexqual,
|
||||
sublist);
|
||||
}
|
||||
@@ -224,18 +227,8 @@ best_or_subclause_index(Query *root,
|
||||
Cost *retCost, /* return value */
|
||||
Cost *retSelec) /* return value */
|
||||
{
|
||||
Oid relid = getrelid(lfirsti(rel->relids),
|
||||
root->rtable);
|
||||
Oid opno = ((Oper *) subclause->oper)->opno;
|
||||
AttrNumber attno = (get_leftop(subclause))->varattno;
|
||||
bool constant_on_right = non_null((Expr *) get_rightop(subclause));
|
||||
Datum value;
|
||||
int flag;
|
||||
List *opnos,
|
||||
*attnos,
|
||||
*values,
|
||||
*flags;
|
||||
bool first_run = true;
|
||||
List *indexquals;
|
||||
List *ilist;
|
||||
|
||||
/* if we don't match anything, return zeros */
|
||||
@@ -243,37 +236,25 @@ best_or_subclause_index(Query *root,
|
||||
*retCost = (Cost) 0.0;
|
||||
*retSelec = (Cost) 0.0;
|
||||
|
||||
if (constant_on_right) /* XXX looks pretty bogus ... tgl */
|
||||
value = ((Const *) get_rightop(subclause))->constvalue;
|
||||
/* convert 'or' subclause to an indexqual list */
|
||||
if (and_clause((Node *) subclause))
|
||||
indexquals = subclause->args;
|
||||
else
|
||||
value = NameGetDatum("");
|
||||
if (constant_on_right)
|
||||
flag = (_SELEC_IS_CONSTANT_ || _SELEC_CONSTANT_RIGHT_);
|
||||
else
|
||||
flag = _SELEC_CONSTANT_RIGHT_;
|
||||
|
||||
/* prebuild lists since we will pass same list to each index */
|
||||
opnos = lconsi(opno, NIL);
|
||||
attnos = lconsi(attno, NIL);
|
||||
values = lconsi(value, NIL);
|
||||
flags = lconsi(flag, NIL);
|
||||
indexquals = lcons(subclause, NIL);
|
||||
/* expansion call... */
|
||||
|
||||
foreach(ilist, indices)
|
||||
{
|
||||
RelOptInfo *index = (RelOptInfo *) lfirst(ilist);
|
||||
Oid indexid = (Oid) lfirsti(index->relids);
|
||||
Cost subcost;
|
||||
float npages,
|
||||
selec;
|
||||
float npages;
|
||||
float selec;
|
||||
|
||||
index_selectivity(indexid,
|
||||
index->classlist,
|
||||
opnos,
|
||||
relid,
|
||||
attnos,
|
||||
values,
|
||||
flags,
|
||||
1,
|
||||
index_selectivity(root,
|
||||
lfirsti(rel->relids),
|
||||
indexid,
|
||||
indexquals,
|
||||
&npages,
|
||||
&selec);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user