diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-10-11 14:20:06 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-10-11 14:21:30 -0400 |
commit | a0185461dd94c8d31d8d55a7f2839b0d2f172ab9 (patch) | |
tree | 3bd68d4e123336bbdefa8fd92372f0af7fb6d64f /src/include/nodes/relation.h | |
parent | fa351d5a0db0672b6f586315720302e493116f27 (diff) | |
download | postgresql-a0185461dd94c8d31d8d55a7f2839b0d2f172ab9.tar.gz postgresql-a0185461dd94c8d31d8d55a7f2839b0d2f172ab9.zip |
Rearrange the implementation of index-only scans.
This commit changes index-only scans so that data is read directly from the
index tuple without first generating a faux heap tuple. The only immediate
benefit is that indexes on system columns (such as OID) can be used in
index-only scans, but this is necessary infrastructure if we are ever to
support index-only scans on expression indexes. The executor is now ready
for that, though the planner still needs substantial work to recognize
the possibility.
To do this, Vars in index-only plan nodes have to refer to index columns
not heap columns. I introduced a new special varno, INDEX_VAR, to mark
such Vars to avoid confusion. (In passing, this commit renames the two
existing special varnos to OUTER_VAR and INNER_VAR.) This allows
ruleutils.c to handle them with logic similar to what we use for subplan
reference Vars.
Since index-only scans are now fundamentally different from regular
indexscans so far as their expression subtrees are concerned, I also chose
to change them to have their own plan node type (and hence, their own
executor source file).
Diffstat (limited to 'src/include/nodes/relation.h')
-rw-r--r-- | src/include/nodes/relation.h | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h index cf48ba433c8..45ca52e516e 100644 --- a/src/include/nodes/relation.h +++ b/src/include/nodes/relation.h @@ -449,6 +449,10 @@ typedef struct RelOptInfo * The indexprs and indpred expressions have been run through * prepqual.c and eval_const_expressions() for ease of matching to * WHERE clauses. indpred is in implicit-AND form. + * + * indextlist is a TargetEntry list representing the index columns. + * It provides an equivalent base-relation Var for each simple column, + * and links to the matching indexprs element for each expression column. */ typedef struct IndexOptInfo { @@ -478,6 +482,8 @@ typedef struct IndexOptInfo List *indexprs; /* expressions for non-simple index columns */ List *indpred; /* predicate if a partial index, else NIL */ + List *indextlist; /* targetlist representing index columns */ + bool predOK; /* true if predicate matches query */ bool unique; /* true if a unique index */ bool hypothetical; /* true if index doesn't really exist */ @@ -640,6 +646,9 @@ typedef struct Path /*---------- * IndexPath represents an index scan over a single index. * + * This struct is used for both regular indexscans and index-only scans; + * path.pathtype is T_IndexScan or T_IndexOnlyScan to show which is meant. + * * 'indexinfo' is the index to be scanned. * * 'indexclauses' is a list of index qualification clauses, with implicit @@ -673,14 +682,10 @@ typedef struct Path * NoMovementScanDirection for an indexscan, but the planner wants to * distinguish ordered from unordered indexes for building pathkeys.) * - * 'indexonly' is TRUE for an index-only scan, that is, the index's access - * method has amcanreturn = TRUE and we only need columns available from the - * index. - * * 'indextotalcost' and 'indexselectivity' are saved in the IndexPath so that * we need not recompute them when considering using the same index in a * bitmap index/heap scan (see BitmapHeapPath). The costs of the IndexPath - * itself represent the costs of an IndexScan plan type. + * itself represent the costs of an IndexScan or IndexOnlyScan plan type. * * 'rows' is the estimated result tuple count for the indexscan. This * is the same as path.parent->rows for a simple indexscan, but it is @@ -698,7 +703,6 @@ typedef struct IndexPath List *indexorderbys; bool isjoininner; ScanDirection indexscandir; - bool indexonly; Cost indextotalcost; Selectivity indexselectivity; double rows; /* estimated number of result tuples */ @@ -714,11 +718,12 @@ typedef struct IndexPath * The individual indexscans are represented by IndexPath nodes, and any * logic on top of them is represented by a tree of BitmapAndPath and * BitmapOrPath nodes. Notice that we can use the same IndexPath node both - * to represent a regular IndexScan plan, and as the child of a BitmapHeapPath - * that represents scanning the same index using a BitmapIndexScan. The - * startup_cost and total_cost figures of an IndexPath always represent the - * costs to use it as a regular IndexScan. The costs of a BitmapIndexScan - * can be computed using the IndexPath's indextotalcost and indexselectivity. + * to represent a regular (or index-only) index scan plan, and as the child + * of a BitmapHeapPath that represents scanning the same index using a + * BitmapIndexScan. The startup_cost and total_cost figures of an IndexPath + * always represent the costs to use it as a regular (or index-only) + * IndexScan. The costs of a BitmapIndexScan can be computed using the + * IndexPath's indextotalcost and indexselectivity. * * BitmapHeapPaths can be nestloop inner indexscans. The isjoininner and * rows fields serve the same purpose as for plain IndexPaths. |