-
+
+ This must eventually become part of a much larger chapter about
+ writing new index access methods.
+
+
Every index access method must provide a cost estimation function for
RelOptInfo *rel,
IndexOptInfo *index,
List *indexQuals,
- Cost *indexAccessCost,
+ Cost *indexStartupCost,
+ Cost *indexTotalCost,
Selectivity *indexSelectivity);
- The last two parameters are pass-by-reference outputs:
+ The last three parameters are pass-by-reference outputs:
- *indexAccessCost
+ *indexStartupCost
- Set to cost of index processing.
+ Set to cost of index startup processing
+
+
+
+
+
+ *indexTotalCost
+
+ Set to total cost of index processing
- The indexAccessCost should be computed in the units used by
- src/backend/optimizer/path/costsize.c: a disk block fetch has cost 1.0,
- and the cost of processing one index tuple should usually be taken as
- cpu_index_page_weight (which is a user-adjustable optimizer parameter).
- The access cost should include all disk and CPU costs associated with
- scanning the index itself, but NOT the cost of retrieving or processing
+ The index access costs should be computed in the units used by
+ src/backend/optimizer/path/costsize.c: a sequential disk block fetch
+ has cost 1.0, a nonsequential fetch has cost random_page_cost, and
+ the cost of processing one index tuple should usually be taken as
+ cpu_index_tuple_cost (which is a user-adjustable optimizer parameter).
+ In addition, an appropriate multiple of cpu_operator_cost should be charged
+ for any comparison operators invoked during index processing (especially
+ evaluation of the indexQuals themselves).
+
+
+ The access costs should include all disk and CPU costs associated with
+ scanning the index itself, but NOT the costs of retrieving or processing
the main-table tuples that are identified by the index.
+ The "startup cost" is the part of the total scan cost that must be expended
+ before we can begin to fetch the first tuple. For most indexes this can
+ be taken as zero, but an index type with a high startup cost might want
+ to set it nonzero.
+
+
The indexSelectivity should be set to the estimated fraction of the main
table tuples that will be retrieved during the index scan. In the case
Estimate and return the fraction of main-table tuples that will be visited
based on the given qual conditions. In the absence of any index-type-specific
- knowledge, use the standard optimizer function clauselist_selec():
+ knowledge, use the standard optimizer function clauselist_selectivity():
-*indexSelectivity = clauselist_selec(root, indexQuals);
+*indexSelectivity = clauselist_selectivity(root, indexQuals,
+ lfirsti(rel->relids));
- Compute the index access cost as
+ Compute the index access cost. A generic estimator might do this:
-*indexAccessCost = numIndexPages + cpu_index_page_weight * numIndexTuples;
+ /*
+ * Our generic assumption is that the index pages will be read
+ * sequentially, so they have cost 1.0 each, not random_page_cost.
+ * Also, we charge for evaluation of the indexquals at each index tuple.
+ * All the costs are assumed to be paid incrementally during the scan.
+ */
+ *indexStartupCost = 0;
+ *indexTotalCost = numIndexPages +
+ (cpu_index_tuple_cost + cost_qual_eval(indexQuals)) * numIndexTuples;
prorettype = 0
-pronargs = 6
-proargtypes = 0 0 0 0 0 0
+pronargs = 7
+proargtypes = 0 0 0 0 0 0 0
We use zero ("opaque") for all the arguments since none of them have types