mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Rethink representation of index clauses' mapping to index columns.
In commit e2c2c2e8b1
I made use of nested
list structures to show which clauses went with which index columns, but
on reflection that's a data structure that only an old-line Lisp hacker
could love. Worse, it adds unnecessary complication to the many places
that don't much care which clauses go with which index columns. Revert
to the previous arrangement of flat lists of clauses, and instead add a
parallel integer list of column numbers. The places that care about the
pairing can chase both lists with forboth(), while the places that don't
care just examine one list the same as before.
The only real downside to this is that there are now two more lists that
need to be passed to amcostestimate functions in case they care about
column matching (which btcostestimate does, so not passing the info is not
an option). Rather than deal with 11-argument amcostestimate functions,
pass just the IndexPath and expect the functions to extract fields from it.
That gets us down to 7 arguments which is better than 11, and it seems
more future-proof against likely additions to the information we keep
about an index path.
This commit is contained in:
@ -410,10 +410,14 @@ create_seqscan_path(PlannerInfo *root, RelOptInfo *rel)
|
||||
* Creates a path node for an index scan.
|
||||
*
|
||||
* 'index' is a usable index.
|
||||
* 'clause_groups' is a list of lists of RestrictInfo nodes
|
||||
* 'indexclauses' is a list of RestrictInfo nodes representing clauses
|
||||
* to be used as index qual conditions in the scan.
|
||||
* 'indexorderbys' is a list of lists of lists of bare expressions (not
|
||||
* RestrictInfos) to be used as index ordering operators.
|
||||
* 'indexclausecols' is an integer list of index column numbers (zero based)
|
||||
* the indexclauses can be used with.
|
||||
* 'indexorderbys' is a list of bare expressions (no RestrictInfos)
|
||||
* to be used as index ordering operators in the scan.
|
||||
* 'indexorderbycols' is an integer list of index column numbers (zero based)
|
||||
* the ordering operators can be used with.
|
||||
* 'pathkeys' describes the ordering of the path.
|
||||
* 'indexscandir' is ForwardScanDirection or BackwardScanDirection
|
||||
* for an ordered index, or NoMovementScanDirection for
|
||||
@ -427,8 +431,10 @@ create_seqscan_path(PlannerInfo *root, RelOptInfo *rel)
|
||||
IndexPath *
|
||||
create_index_path(PlannerInfo *root,
|
||||
IndexOptInfo *index,
|
||||
List *clause_groups,
|
||||
List *indexclauses,
|
||||
List *indexclausecols,
|
||||
List *indexorderbys,
|
||||
List *indexorderbycols,
|
||||
List *pathkeys,
|
||||
ScanDirection indexscandir,
|
||||
bool indexonly,
|
||||
@ -437,7 +443,7 @@ create_index_path(PlannerInfo *root,
|
||||
IndexPath *pathnode = makeNode(IndexPath);
|
||||
RelOptInfo *rel = index->rel;
|
||||
List *indexquals,
|
||||
*allclauses;
|
||||
*indexqualcols;
|
||||
|
||||
/*
|
||||
* For a join inner scan, there's no point in marking the path with any
|
||||
@ -457,16 +463,16 @@ create_index_path(PlannerInfo *root,
|
||||
pathnode->path.pathkeys = pathkeys;
|
||||
|
||||
/* Convert clauses to indexquals the executor can handle */
|
||||
indexquals = expand_indexqual_conditions(index, clause_groups);
|
||||
|
||||
/* Flatten the clause-groups list to produce indexclauses list */
|
||||
allclauses = flatten_clausegroups_list(clause_groups);
|
||||
expand_indexqual_conditions(index, indexclauses, indexclausecols,
|
||||
&indexquals, &indexqualcols);
|
||||
|
||||
/* Fill in the pathnode */
|
||||
pathnode->indexinfo = index;
|
||||
pathnode->indexclauses = allclauses;
|
||||
pathnode->indexclauses = indexclauses;
|
||||
pathnode->indexquals = indexquals;
|
||||
pathnode->indexqualcols = indexqualcols;
|
||||
pathnode->indexorderbys = indexorderbys;
|
||||
pathnode->indexorderbycols = indexorderbycols;
|
||||
|
||||
pathnode->isjoininner = (outer_rel != NULL);
|
||||
pathnode->indexscandir = indexscandir;
|
||||
@ -476,7 +482,7 @@ create_index_path(PlannerInfo *root,
|
||||
/*
|
||||
* We must compute the estimated number of output rows for the
|
||||
* indexscan. This is less than rel->rows because of the additional
|
||||
* selectivity of the join clauses. Since clause_groups may contain
|
||||
* selectivity of the join clauses. Since indexclauses may contain
|
||||
* both restriction and join clauses, we have to do a set union to get
|
||||
* the full set of clauses that must be considered to compute the
|
||||
* correct selectivity. (Without the union operation, we might have
|
||||
@ -489,7 +495,9 @@ create_index_path(PlannerInfo *root,
|
||||
* Note that we force the clauses to be treated as non-join clauses
|
||||
* during selectivity estimation.
|
||||
*/
|
||||
allclauses = list_union_ptr(rel->baserestrictinfo, allclauses);
|
||||
List *allclauses;
|
||||
|
||||
allclauses = list_union_ptr(rel->baserestrictinfo, indexclauses);
|
||||
pathnode->rows = rel->tuples *
|
||||
clauselist_selectivity(root,
|
||||
allclauses,
|
||||
@ -508,8 +516,7 @@ create_index_path(PlannerInfo *root,
|
||||
pathnode->rows = rel->rows;
|
||||
}
|
||||
|
||||
cost_index(pathnode, root, index, indexquals, indexorderbys,
|
||||
indexonly, outer_rel);
|
||||
cost_index(pathnode, root, outer_rel);
|
||||
|
||||
return pathnode;
|
||||
}
|
||||
|
Reference in New Issue
Block a user