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

Commit71ed7eb

Browse files
committed
Revise handling of index-type-specific indexscan cost estimation, per
pghackers discussion of 5-Jan-2000. The amopselect and amopnpagesestimators are gone, and in their place is a per-AM amcostestimateprocedure (linked to from pg_am, not pg_amop).
1 parent7884517 commit71ed7eb

File tree

30 files changed

+500
-1111
lines changed

30 files changed

+500
-1111
lines changed

‎doc/src/sgml/catalogs.sgml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" This is -*-nroff-*-
22
.\" XXX standard disclaimer belongs here....
3-
.\" $Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.2 2000/01/11 01:40:04 tgl Exp $
3+
.\" $Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.3 2000/01/22 23:50:08 tgl Exp $
44
.TH "SYSTEM CATALOGS" INTRO 03/13/94 PostgreSQL PostgreSQL
55
.SH "Section 7 - System Catalogs"
66
.deLS
@@ -138,6 +138,8 @@ pg_am
138138
regproc ambuild/* "build new index" function */
139139
regproc amcreate /* - deprecated */
140140
regproc amdestroy/* - deprecated */
141+
regproc amcostestimate/* estimate cost of an indexscan */
142+
141143
.fi
142144
.nfM
143145
pg_amop
@@ -148,10 +150,6 @@ pg_amop
148150
oid amopopr/* the operator */
149151
int2 amopstrategy/* traversal/search strategy number
150152
to which this operator applies */
151-
regproc amopselect/* function to calculate the operator
152-
selectivity */
153-
regproc amopnpages/* function to calculate the number of
154-
pages that will be examined */
155153
.fi
156154
.nfM
157155
pg_amproc

‎doc/src/sgml/xindex.sgml

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/xindex.sgml,v 1.5 1999/07/2215:11:05 thomas Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/xindex.sgml,v 1.6 2000/01/2223:50:08 tgl Exp $
33
Postgres documentation
44
-->
55

@@ -403,20 +403,9 @@ CREATE OPERATOR = (
403403
<entry>the <filename>oid</filename>s of the operators for the opclass
404404
(which we'll get in just a minute)</entry>
405405
</row>
406-
<row>
407-
<entry>amopselect, amopnpages</entry>
408-
<entry>cost functions</entry>
409-
</row>
410406
</tbody>
411407
</tgroup>
412408
</table>
413-
414-
The cost functions are used by the query optimizer to decide whether or
415-
not to use a given index in a scan. Fortunately, these already exist.
416-
The two functions we'll use are <filename>btreesel</filename>, which
417-
estimates the selectivity of the <acronym>B-tree</acronym>, and
418-
<filename>btreenpage</filename>, which estimates the number of pages a
419-
search will touch in the tree.
420409
</para>
421410

422411
<para>
@@ -460,10 +449,8 @@ CREATE OPERATOR = (
460449
equal, in <filename>pg_amop</filename>. We add the instances we need:
461450

462451
<programlisting>
463-
INSERT INTO pg_amop (amopid, amopclaid, amopopr, amopstrategy,
464-
amopselect, amopnpages)
465-
SELECT am.oid, opcl.oid, c.opoid, 1,
466-
'btreesel'::regproc, 'btreenpage'::regproc
452+
INSERT INTO pg_amop (amopid, amopclaid, amopopr, amopstrategy)
453+
SELECT am.oid, opcl.oid, c.opoid, 1
467454
FROM pg_am am, pg_opclass opcl, complex_abs_ops_tmp c
468455
WHERE amname = 'btree' AND
469456
opcname = 'complex_abs_ops' AND
@@ -519,13 +506,11 @@ CREATE OPERATOR = (
519506

520507
<para>
521508
Now we need to add a hashing strategy to allow the type to be indexed.
522-
We do this by using another type in pg_am but we reuse thesames ops.
509+
We do this by using another type in pg_am but we reuse thesame ops.
523510

524511
<programlisting>
525-
INSERT INTO pg_amop (amopid, amopclaid, amopopr, amopstrategy,
526-
amopselect, amopnpages)
527-
SELECT am.oid, opcl.oid, c.opoid, 1,
528-
'hashsel'::regproc, 'hashnpage'::regproc
512+
INSERT INTO pg_amop (amopid, amopclaid, amopopr, amopstrategy)
513+
SELECT am.oid, opcl.oid, c.opoid, 1
529514
FROM pg_am am, pg_opclass opcl, complex_abs_ops_tmp c
530515
WHERE amname = 'hash' AND
531516
opcname = 'complex_abs_ops' AND

‎src/backend/access/index/indexam.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.38 1999/12/30 05:04:50 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.39 2000/01/22 23:50:09 tgl Exp $
1111
*
1212
* INTERFACE ROUTINES
1313
*index_open- open an index relation by relationId
@@ -69,21 +69,6 @@
6969
#include"access/heapam.h"
7070
#include"utils/relcache.h"
7171

72-
/* ----------------
73-
* undefine macros we aren't going to use that would otherwise
74-
* get in our way.. delete is defined in c.h and the am's are
75-
* defined in heapam.h
76-
* ----------------
77-
*/
78-
#undef delete
79-
#undef aminsert
80-
#undef amdelete
81-
#undef ambeginscan
82-
#undef amrescan
83-
#undef amendscan
84-
#undef ammarkpos
85-
#undef amrestrpos
86-
#undef amgettuple
8772

8873
/* ----------------------------------------------------------------
8974
*macros used in index_ routines
@@ -358,6 +343,27 @@ index_getnext(IndexScanDesc scan,
358343
returnresult;
359344
}
360345

346+
/* ----------------
347+
*index_cost_estimator
348+
*
349+
*Fetch the amcostestimate procedure OID for an index.
350+
*
351+
*We could combine fetching and calling the procedure,
352+
*as index_insert does for example; but that would require
353+
*importing a bunch of planner/optimizer stuff into this file.
354+
* ----------------
355+
*/
356+
RegProcedure
357+
index_cost_estimator(Relationrelation)
358+
{
359+
RegProcedureprocedure;
360+
361+
RELATION_CHECKS;
362+
GET_REL_PROCEDURE(cost_estimator,amcostestimate);
363+
364+
returnprocedure;
365+
}
366+
361367
/* ----------------
362368
*index_getprocid
363369
*

‎src/backend/commands/variable.c

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Routines for handling of 'SET var TO',
33
*'SHOW var' and 'RESET var' statements.
44
*
5-
* $Id: variable.c,v 1.27 2000/01/15 02:59:29 petere Exp $
5+
* $Id: variable.c,v 1.28 2000/01/22 23:50:10 tgl Exp $
66
*
77
*/
88

@@ -14,7 +14,8 @@
1414
#include"catalog/pg_shadow.h"
1515
#include"commands/variable.h"
1616
#include"miscadmin.h"
17-
#include"optimizer/internal.h"
17+
#include"optimizer/cost.h"
18+
#include"optimizer/paths.h"
1819
#include"utils/builtins.h"
1920
#include"utils/tqual.h"
2021
#include"utils/trace.h"
@@ -45,10 +46,6 @@ static bool show_XactIsoLevel(void);
4546
staticboolreset_XactIsoLevel(void);
4647
staticboolparse_XactIsoLevel(constchar*);
4748

48-
externCost_cpu_page_weight_;
49-
externCost_cpu_index_page_weight_;
50-
externbool_use_geqo_;
51-
externint32_use_geqo_rels_;
5249
externbool_use_keyset_query_optimizer;
5350

5451
/*
@@ -183,23 +180,23 @@ parse_geqo(const char *value)
183180

184181
if (strcasecmp(tok,"on")==0)
185182
{
186-
int32geqo_rels=GEQO_RELS;
183+
intnew_geqo_rels=GEQO_RELS;
187184

188185
if (val!=NULL)
189186
{
190-
geqo_rels=pg_atoi(val,sizeof(int32),'\0');
191-
if (geqo_rels <=1)
187+
new_geqo_rels=pg_atoi(val,sizeof(int),'\0');
188+
if (new_geqo_rels <=1)
192189
elog(ERROR,"Bad value for # of relations (%s)",val);
193190
pfree(val);
194191
}
195-
_use_geqo_= true;
196-
_use_geqo_rels_=geqo_rels;
192+
enable_geqo= true;
193+
geqo_rels=new_geqo_rels;
197194
}
198195
elseif (strcasecmp(tok,"off")==0)
199196
{
200197
if ((val!=NULL)&& (*val!='\0'))
201198
elog(ERROR,"%s does not allow a parameter",tok);
202-
_use_geqo_= false;
199+
enable_geqo= false;
203200
}
204201
else
205202
elog(ERROR,"Bad value for GEQO (%s)",value);
@@ -212,8 +209,8 @@ static bool
212209
show_geqo()
213210
{
214211

215-
if (_use_geqo_)
216-
elog(NOTICE,"GEQO is ON beginning with %d relations",_use_geqo_rels_);
212+
if (enable_geqo)
213+
elog(NOTICE,"GEQO is ON beginning with %d relations",geqo_rels);
217214
else
218215
elog(NOTICE,"GEQO is OFF");
219216
return TRUE;
@@ -224,11 +221,11 @@ reset_geqo(void)
224221
{
225222

226223
#ifdefGEQO
227-
_use_geqo_= true;
224+
enable_geqo= true;
228225
#else
229-
_use_geqo_= false;
226+
enable_geqo= false;
230227
#endif
231-
_use_geqo_rels_=GEQO_RELS;
228+
geqo_rels=GEQO_RELS;
232229
return TRUE;
233230
}
234231

@@ -240,16 +237,16 @@ reset_geqo(void)
240237
staticbool
241238
parse_cost_heap(constchar*value)
242239
{
243-
float32res;
240+
float64res;
244241

245242
if (value==NULL)
246243
{
247244
reset_cost_heap();
248245
return TRUE;
249246
}
250247

251-
res=float4in((char*)value);
252-
_cpu_page_weight_=*res;
248+
res=float8in((char*)value);
249+
cpu_page_weight=*res;
253250

254251
return TRUE;
255252
}
@@ -258,14 +255,14 @@ static bool
258255
show_cost_heap()
259256
{
260257

261-
elog(NOTICE,"COST_HEAP is %f",_cpu_page_weight_);
258+
elog(NOTICE,"COST_HEAP is %f",cpu_page_weight);
262259
return TRUE;
263260
}
264261

265262
staticbool
266263
reset_cost_heap()
267264
{
268-
_cpu_page_weight_=_CPU_PAGE_WEIGHT_;
265+
cpu_page_weight=CPU_PAGE_WEIGHT;
269266
return TRUE;
270267
}
271268

@@ -277,16 +274,16 @@ reset_cost_heap()
277274
staticbool
278275
parse_cost_index(constchar*value)
279276
{
280-
float32res;
277+
float64res;
281278

282279
if (value==NULL)
283280
{
284281
reset_cost_index();
285282
return TRUE;
286283
}
287284

288-
res=float4in((char*)value);
289-
_cpu_index_page_weight_=*res;
285+
res=float8in((char*)value);
286+
cpu_index_page_weight=*res;
290287

291288
return TRUE;
292289
}
@@ -295,14 +292,14 @@ static bool
295292
show_cost_index()
296293
{
297294

298-
elog(NOTICE,"COST_INDEX is %f",_cpu_index_page_weight_);
295+
elog(NOTICE,"COST_INDEX is %f",cpu_index_page_weight);
299296
return TRUE;
300297
}
301298

302299
staticbool
303300
reset_cost_index()
304301
{
305-
_cpu_index_page_weight_=_CPU_INDEX_PAGE_WEIGHT_;
302+
cpu_index_page_weight=CPU_INDEX_PAGE_WEIGHT;
306303
return TRUE;
307304
}
308305

‎src/backend/nodes/copyfuncs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.100 2000/01/17 00:14:46 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.101 2000/01/22 23:50:11 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1031,6 +1031,7 @@ _copyIndexOptInfo(IndexOptInfo *from)
10311031
}
10321032

10331033
newnode->relam=from->relam;
1034+
newnode->amcostestimate=from->amcostestimate;
10341035
newnode->indproc=from->indproc;
10351036
Node_Copy(from,newnode,indpred);
10361037

‎src/backend/nodes/readfuncs.c

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.78 2000/01/14 00:53:21 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.79 2000/01/22 23:50:12 tgl Exp $
1111
*
1212
* NOTES
1313
* Most of the read functions for plan nodes are tested. (In fact, they
@@ -1330,34 +1330,6 @@ _readRelOptInfo()
13301330
returnlocal_node;
13311331
}
13321332

1333-
/* ----------------
1334-
*_readIndexOptInfo
1335-
* ----------------
1336-
*/
1337-
staticIndexOptInfo*
1338-
_readIndexOptInfo()
1339-
{
1340-
IndexOptInfo*local_node;
1341-
char*token;
1342-
intlength;
1343-
1344-
local_node=makeNode(IndexOptInfo);
1345-
1346-
token=lsptok(NULL,&length);/* get :indexoid */
1347-
token=lsptok(NULL,&length);/* now read it */
1348-
local_node->indexoid= (Oid)atoi(token);
1349-
1350-
token=lsptok(NULL,&length);/* get :pages */
1351-
token=lsptok(NULL,&length);/* now read it */
1352-
local_node->pages=atol(token);
1353-
1354-
token=lsptok(NULL,&length);/* get :tuples */
1355-
token=lsptok(NULL,&length);/* now read it */
1356-
local_node->tuples=atof(token);
1357-
1358-
returnlocal_node;
1359-
}
1360-
13611333
/* ----------------
13621334
*_readTargetEntry
13631335
* ----------------
@@ -1900,8 +1872,6 @@ parsePlanString(void)
19001872
return_value=_readEState();
19011873
elseif (length==10&&strncmp(token,"RELOPTINFO",length)==0)
19021874
return_value=_readRelOptInfo();
1903-
elseif (length==12&&strncmp(token,"INDEXOPTINFO",length)==0)
1904-
return_value=_readIndexOptInfo();
19051875
elseif (length==11&&strncmp(token,"TARGETENTRY",length)==0)
19061876
return_value=_readTargetEntry();
19071877
elseif (length==3&&strncmp(token,"RTE",length)==0)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp