Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit49ed4dd

Browse files
committed
Further work on planning of indexscans. Cleaned up interfaces
to index_selectivity so that it can be handed an indexqual clause listrather than a bunch of assorted derivative data.
1 parent8ae29a1 commit49ed4dd

File tree

11 files changed

+319
-497
lines changed

11 files changed

+319
-497
lines changed

‎src/backend/optimizer/path/clausesel.c

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.24 1999/07/24 23:21:09 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.25 1999/07/25 23:07:24 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -142,8 +142,8 @@ compute_clause_selec(Query *root, Node *clause)
142142
BooleanEqualOperator,
143143
relid,
144144
((Var*)clause)->varoattno,
145-
"t",
146-
_SELEC_CONSTANT_RIGHT_);
145+
Int8GetDatum(true),
146+
SEL_CONSTANT |SEL_RIGHT);
147147
}
148148
elseif (IsA(clause,Param))
149149
{
@@ -215,37 +215,40 @@ compute_clause_selec(Query *root, Node *clause)
215215
*/
216216
Oidopno= ((Oper*) ((Expr*)clause)->oper)->opno;
217217
RegProcedureoprrest=get_oprrest(opno);
218-
Oidrelid;
219-
intrelidx;
220-
AttrNumberattno;
221-
Datumconstval;
222-
intflag;
223-
224-
get_relattval(clause,&relidx,&attno,&constval,&flag);
225-
relid=getrelid(relidx,root->rtable);
226218

227219
/*
228220
* if the oprrest procedure is missing for whatever reason, use a
229221
* selectivity of 0.5
230222
*/
231223
if (!oprrest)
232224
s1= (Cost)0.5;
233-
elseif (attno==InvalidAttrNumber)
225+
else
234226
{
235-
/*
236-
* attno can be Invalid if the clause had a function in it,
237-
* i.e. WHERE myFunc(f) = 10
238-
*/
239-
/* this should be FIXED somehow to use function selectivity */
240-
s1= (Cost) (0.5);
227+
intrelidx;
228+
AttrNumberattno;
229+
Datumconstval;
230+
intflag;
231+
232+
get_relattval(clause,0,&relidx,&attno,&constval,&flag);
233+
if (relidx <=0||attno <=0)
234+
{
235+
/*
236+
* attno can be Invalid if the clause had a function in it,
237+
* i.e. WHERE myFunc(f) = 10
238+
*
239+
* XXX should be FIXED to use function selectivity
240+
*/
241+
s1= (Cost) (0.5);
242+
}
243+
else
244+
s1= (Cost)restriction_selectivity(oprrest,
245+
opno,
246+
getrelid(relidx,
247+
root->rtable),
248+
attno,
249+
constval,
250+
flag);
241251
}
242-
else
243-
s1= (Cost)restriction_selectivity(oprrest,
244-
opno,
245-
relid,
246-
attno,
247-
(char*)constval,
248-
flag);
249252
}
250253
else
251254
{
@@ -256,14 +259,6 @@ compute_clause_selec(Query *root, Node *clause)
256259
*/
257260
Oidopno= ((Oper*) ((Expr*)clause)->oper)->opno;
258261
RegProcedureoprjoin=get_oprjoin(opno);
259-
intrelid1,
260-
relid2;
261-
AttrNumberattno1,
262-
attno2;
263-
264-
get_rels_atts(clause,&relid1,&attno1,&relid2,&attno2);
265-
relid1=getrelid(relid1,root->rtable);
266-
relid2=getrelid(relid2,root->rtable);
267262

268263
/*
269264
* if the oprjoin procedure is missing for whatever reason, use a
@@ -272,12 +267,25 @@ compute_clause_selec(Query *root, Node *clause)
272267
if (!oprjoin)
273268
s1= (Cost) (0.5);
274269
else
275-
s1= (Cost)join_selectivity(oprjoin,
276-
opno,
277-
relid1,
278-
attno1,
279-
relid2,
280-
attno2);
270+
{
271+
intrelid1,
272+
relid2;
273+
AttrNumberattno1,
274+
attno2;
275+
276+
get_rels_atts(clause,&relid1,&attno1,&relid2,&attno2);
277+
if (relid1>0&&relid2>0&&attno1>0&&attno2>0)
278+
s1= (Cost)join_selectivity(oprjoin,
279+
opno,
280+
getrelid(relid1,
281+
root->rtable),
282+
attno1,
283+
getrelid(relid2,
284+
root->rtable),
285+
attno2);
286+
else/* XXX more code for function selectivity? */
287+
s1= (Cost) (0.5);
288+
}
281289
}
282290
}
283291

‎src/backend/optimizer/path/indxpath.c

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.64 1999/07/2517:53:27 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.65 1999/07/2523:07:24 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1216,25 +1216,20 @@ index_innerjoin(Query *root, RelOptInfo *rel, RelOptInfo *index,
12161216
{
12171217
List*clausegroup=lfirst(i);
12181218
IndexPath*pathnode=makeNode(IndexPath);
1219-
Costtemp_selec;
1220-
floattemp_pages;
1221-
List*attnos,
1222-
*values,
1223-
*flags;
1224-
1225-
get_joinvars(lfirsti(rel->relids),clausegroup,
1226-
&attnos,&values,&flags);
1227-
index_selectivity(lfirsti(index->relids),
1228-
index->classlist,
1229-
get_opnos(clausegroup),
1230-
getrelid(lfirsti(rel->relids),
1231-
root->rtable),
1232-
attnos,
1233-
values,
1234-
flags,
1235-
length(clausegroup),
1236-
&temp_pages,
1237-
&temp_selec);
1219+
List*indexquals;
1220+
floatnpages;
1221+
floatselec;
1222+
1223+
indexquals=get_actual_clauses(clausegroup);
1224+
1225+
index_selectivity(root,
1226+
lfirsti(rel->relids),
1227+
lfirsti(index->relids),
1228+
indexquals,
1229+
&npages,
1230+
&selec);
1231+
1232+
/* XXX this code ought to be merged with create_index_path */
12381233

12391234
pathnode->path.pathtype=T_IndexScan;
12401235
pathnode->path.parent=rel;
@@ -1249,14 +1244,14 @@ index_innerjoin(Query *root, RelOptInfo *rel, RelOptInfo *index,
12491244
*/
12501245
pathnode->indexid=index->relids;
12511246
pathnode->indexkeys=index->indexkeys;
1252-
pathnode->indexqual=lcons(get_actual_clauses(clausegroup),NIL);
1247+
pathnode->indexqual=lcons(indexquals,NIL);
12531248

12541249
/* joinid saves the rels needed on the outer side of the join */
12551250
pathnode->path.joinid=lfirst(outerrelids_list);
12561251

12571252
pathnode->path.path_cost=cost_index((Oid)lfirsti(index->relids),
1258-
(int)temp_pages,
1259-
temp_selec,
1253+
(int)npages,
1254+
selec,
12601255
rel->pages,
12611256
rel->tuples,
12621257
index->pages,

‎src/backend/optimizer/path/orindxpath.c

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/orindxpath.c,v 1.29 1999/07/24 23:21:10 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/orindxpath.c,v 1.30 1999/07/25 23:07:24 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -121,11 +121,14 @@ create_or_index_paths(Query *root,
121121
pathnode->indexqual=NIL;
122122
foreach(orclause,clausenode->clause->args)
123123
{
124-
List*sublist;
125-
if (and_clause(lfirst(orclause)))
126-
sublist= ((Expr*)lfirst(orclause))->args;
124+
Expr*subclause= (Expr*)lfirst(orclause);
125+
List*sublist;
126+
127+
if (and_clause((Node*)subclause))
128+
sublist=subclause->args;
127129
else
128-
sublist=lcons(lfirst(orclause),NIL);
130+
sublist=lcons(subclause,NIL);
131+
/* expansion call... */
129132
pathnode->indexqual=lappend(pathnode->indexqual,
130133
sublist);
131134
}
@@ -224,56 +227,34 @@ best_or_subclause_index(Query *root,
224227
Cost*retCost,/* return value */
225228
Cost*retSelec)/* return value */
226229
{
227-
Oidrelid=getrelid(lfirsti(rel->relids),
228-
root->rtable);
229-
Oidopno= ((Oper*)subclause->oper)->opno;
230-
AttrNumberattno= (get_leftop(subclause))->varattno;
231-
boolconstant_on_right=non_null((Expr*)get_rightop(subclause));
232-
Datumvalue;
233-
intflag;
234-
List*opnos,
235-
*attnos,
236-
*values,
237-
*flags;
238230
boolfirst_run= true;
231+
List*indexquals;
239232
List*ilist;
240233

241234
/* if we don't match anything, return zeros */
242235
*retIndexid=0;
243236
*retCost= (Cost)0.0;
244237
*retSelec= (Cost)0.0;
245238

246-
if (constant_on_right)/* XXX looks pretty bogus ... tgl */
247-
value= ((Const*)get_rightop(subclause))->constvalue;
248-
else
249-
value=NameGetDatum("");
250-
if (constant_on_right)
251-
flag= (_SELEC_IS_CONSTANT_||_SELEC_CONSTANT_RIGHT_);
239+
/* convert 'or' subclause to an indexqual list */
240+
if (and_clause((Node*)subclause))
241+
indexquals=subclause->args;
252242
else
253-
flag=_SELEC_CONSTANT_RIGHT_;
254-
255-
/* prebuild lists since we will pass same list to each index */
256-
opnos=lconsi(opno,NIL);
257-
attnos=lconsi(attno,NIL);
258-
values=lconsi(value,NIL);
259-
flags=lconsi(flag,NIL);
243+
indexquals=lcons(subclause,NIL);
244+
/* expansion call... */
260245

261246
foreach(ilist,indices)
262247
{
263248
RelOptInfo*index= (RelOptInfo*)lfirst(ilist);
264249
Oidindexid= (Oid)lfirsti(index->relids);
265250
Costsubcost;
266-
floatnpages,
267-
selec;
268-
269-
index_selectivity(indexid,
270-
index->classlist,
271-
opnos,
272-
relid,
273-
attnos,
274-
values,
275-
flags,
276-
1,
251+
floatnpages;
252+
floatselec;
253+
254+
index_selectivity(root,
255+
lfirsti(rel->relids),
256+
indexid,
257+
indexquals,
277258
&npages,
278259
&selec);
279260

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp