1
1
<!--
2
- $Header: /cvsroot/pgsql/doc/src/sgml/Attic/indexcost.sgml,v 2.2 2000/03/31 03:27:40 thomas Exp $
2
+ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/indexcost.sgml,v 2.3 2000/03/31 17:18:26 tgl Exp $
3
3
-->
4
4
5
5
<chapter>
@@ -14,20 +14,12 @@ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/indexcost.sgml,v 2.2 2000/03/31 03:27
14
14
</para>
15
15
</note>
16
16
17
- <!--
18
- I have written the attached bit of doco about the new index cost
19
- estimator procedure definition, but I am not sure where to put it.
20
- There isn't (AFAICT) any existing documentation about how to make
21
- a new kind of index, which would be the proper place for it.
22
- May I impose on you to find/make a place for this and mark it up
23
- properly?
24
-
25
- Also, doc/src/graphics/catalogs.ag needs to be updated, but I have
26
- no idea how. (The amopselect and amopnpages fields of pg_amop
27
- are gone; pg_am has a new field amcostestimate.)
28
-
29
- regards, tom lane
30
- -->
17
+ <note>
18
+ <para>
19
+ This must eventually become part of a much larger chapter about
20
+ writing new index access methods.
21
+ </para>
22
+ </note>
31
23
32
24
<para>
33
25
Every index access method must provide a cost estimation function for
@@ -64,7 +56,8 @@ amcostestimate (Query *root,
64
56
RelOptInfo *rel,
65
57
IndexOptInfo *index,
66
58
List *indexQuals,
67
- Cost *indexAccessCost,
59
+ Cost *indexStartupCost,
60
+ Cost *indexTotalCost,
68
61
Selectivity *indexSelectivity);
69
62
</programlisting>
70
63
@@ -111,14 +104,23 @@ amcostestimate (Query *root,
111
104
</para>
112
105
113
106
<para>
114
- The last two parameters are pass-by-reference outputs:
107
+ The last three parameters are pass-by-reference outputs:
115
108
116
109
<variablelist>
117
110
<varlistentry>
118
- <term>*indexAccessCost </term>
111
+ <term>*indexStartupCost </term>
119
112
<listitem>
120
113
<para>
121
- Set to cost of index processing.
114
+ Set to cost of index startup processing
115
+ </para>
116
+ </listitem>
117
+ </varlistentry>
118
+
119
+ <varlistentry>
120
+ <term>*indexTotalCost</term>
121
+ <listitem>
122
+ <para>
123
+ Set to total cost of index processing
122
124
</para>
123
125
</listitem>
124
126
</varlistentry>
@@ -141,15 +143,29 @@ amcostestimate (Query *root,
141
143
</para>
142
144
143
145
<para>
144
- The indexAccessCost should be computed in the units used by
145
- src/backend/optimizer/path/costsize.c: a disk block fetch has cost 1.0,
146
- and the cost of processing one index tuple should usually be taken as
147
- cpu_index_page_weight (which is a user-adjustable optimizer parameter).
148
- The access cost should include all disk and CPU costs associated with
149
- scanning the index itself, but NOT the cost of retrieving or processing
146
+ The index access costs should be computed in the units used by
147
+ src/backend/optimizer/path/costsize.c: a sequential disk block fetch
148
+ has cost 1.0, a nonsequential fetch has cost random_page_cost, and
149
+ the cost of processing one index tuple should usually be taken as
150
+ cpu_index_tuple_cost (which is a user-adjustable optimizer parameter).
151
+ In addition, an appropriate multiple of cpu_operator_cost should be charged
152
+ for any comparison operators invoked during index processing (especially
153
+ evaluation of the indexQuals themselves).
154
+ </para>
155
+
156
+ <para>
157
+ The access costs should include all disk and CPU costs associated with
158
+ scanning the index itself, but NOT the costs of retrieving or processing
150
159
the main-table tuples that are identified by the index.
151
160
</para>
152
161
162
+ <para>
163
+ The "startup cost" is the part of the total scan cost that must be expended
164
+ before we can begin to fetch the first tuple. For most indexes this can
165
+ be taken as zero, but an index type with a high startup cost might want
166
+ to set it nonzero.
167
+ </para>
168
+
153
169
<para>
154
170
The indexSelectivity should be set to the estimated fraction of the main
155
171
table tuples that will be retrieved during the index scan. In the case
@@ -167,10 +183,11 @@ amcostestimate (Query *root,
167
183
<para>
168
184
Estimate and return the fraction of main-table tuples that will be visited
169
185
based on the given qual conditions. In the absence of any index-type-specific
170
- knowledge, use the standard optimizer function clauselist_selec ():
186
+ knowledge, use the standard optimizer function clauselist_selectivity ():
171
187
172
188
<programlisting>
173
- *indexSelectivity = clauselist_selec(root, indexQuals);
189
+ *indexSelectivity = clauselist_selectivity(root, indexQuals,
190
+ lfirsti(rel->relids));
174
191
</programlisting>
175
192
</para>
176
193
</step>
@@ -193,10 +210,18 @@ amcostestimate (Query *root,
193
210
194
211
<step>
195
212
<para>
196
- Compute the index access cost as
213
+ Compute the index access cost. A generic estimator might do this:
197
214
198
215
<programlisting>
199
- *indexAccessCost = numIndexPages + cpu_index_page_weight * numIndexTuples;
216
+ /*
217
+ * Our generic assumption is that the index pages will be read
218
+ * sequentially, so they have cost 1.0 each, not random_page_cost.
219
+ * Also, we charge for evaluation of the indexquals at each index tuple.
220
+ * All the costs are assumed to be paid incrementally during the scan.
221
+ */
222
+ *indexStartupCost = 0;
223
+ *indexTotalCost = numIndexPages +
224
+ (cpu_index_tuple_cost + cost_qual_eval(indexQuals)) * numIndexTuples;
200
225
</programlisting>
201
226
</para>
202
227
</step>
@@ -213,8 +238,8 @@ amcostestimate (Query *root,
213
238
214
239
<programlisting>
215
240
prorettype = 0
216
- pronargs = 6
217
- proargtypes = 0 0 0 0 0 0
241
+ pronargs = 7
242
+ proargtypes = 0 0 0 0 0 0 0
218
243
</programlisting>
219
244
220
245
We use zero ("opaque") for all the arguments since none of them have types
0 commit comments