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/plannodes.h | |
| parent | fa351d5a0db0672b6f586315720302e493116f27 (diff) | |
| download | postgresql-a0185461dd94c8d31d8d55a7f2839b0d2f172ab9.tar.gz | |
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/plannodes.h')
| -rw-r--r-- | src/include/nodes/plannodes.h | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h index 60467f5276..ababded845 100644 --- a/src/include/nodes/plannodes.h +++ b/src/include/nodes/plannodes.h @@ -285,11 +285,8 @@ typedef Scan SeqScan; * * indexqual has the same form, but the expressions have been commuted if * necessary to put the indexkeys on the left, and the indexkeys are replaced - * by Var nodes identifying the index columns (varattno is the index column - * position, not the base table's column, even though varno is for the base - * table). This is a bit hokey ... would be cleaner to use a special-purpose - * node type that could not be mistaken for a regular Var. But it will do - * for now. + * by Var nodes identifying the index columns (their varno is INDEX_VAR and + * their varattno is the index column number). * * indexorderbyorig is similarly the original form of any ORDER BY expressions * that are being implemented by the index, while indexorderby is modified to @@ -302,8 +299,7 @@ typedef Scan SeqScan; * (Note these fields are used for amcanorderbyop cases, not amcanorder cases.) * * indexorderdir specifies the scan ordering, for indexscans on amcanorder - * indexes (for other indexes it should be "don't care"). indexonly specifies - * an index-only scan, for indexscans on amcanreturn indexes. + * indexes (for other indexes it should be "don't care"). * ---------------- */ typedef struct IndexScan @@ -315,10 +311,36 @@ typedef struct IndexScan List *indexorderby; /* list of index ORDER BY exprs */ List *indexorderbyorig; /* the same in original form */ ScanDirection indexorderdir; /* forward or backward or don't care */ - bool indexonly; /* attempt to skip heap fetches? */ } IndexScan; /* ---------------- + * index-only scan node + * + * IndexOnlyScan is very similar to IndexScan, but it specifies an + * index-only scan, in which the data comes from the index not the heap. + * Because of this, *all* Vars in the plan node's targetlist, qual, and + * index expressions reference index columns and have varno = INDEX_VAR. + * Hence we do not need separate indexqualorig and indexorderbyorig lists, + * since their contents would be equivalent to indexqual and indexorderby. + * + * To help EXPLAIN interpret the index Vars for display, we provide + * indextlist, which represents the contents of the index as a targetlist + * with one TLE per index column. Vars appearing in this list reference + * the base table, and this is the only field in the plan node that may + * contain such Vars. + * ---------------- + */ +typedef struct IndexOnlyScan +{ + Scan scan; + Oid indexid; /* OID of index to scan */ + List *indexqual; /* list of index quals (usually OpExprs) */ + List *indexorderby; /* list of index ORDER BY exprs */ + List *indextlist; /* TargetEntry list describing index's cols */ + ScanDirection indexorderdir; /* forward or backward or don't care */ +} IndexOnlyScan; + +/* ---------------- * bitmap index scan node * * BitmapIndexScan delivers a bitmap of potential tuple locations; |
