Commit e6dd664d authored by Tom Lane's avatar Tom Lane

Docs: create some user-facing documentation about index-only scans.

We didn't have any real user documentation about how index-only scans
work or how to design indexes to exploit them.  Remedy that.
Per gripe from David Johnston.
parent 6f69b963
......@@ -3406,9 +3406,6 @@ include_dir 'conf.d'
<varlistentry id="guc-enable-indexonlyscan" xreflabel="enable_indexonlyscan">
<term><varname>enable_indexonlyscan</varname> (<type>boolean</type>)
<indexterm>
<primary>index-only scan</primary>
</indexterm>
<indexterm>
<primary><varname>enable_indexonlyscan</> configuration parameter</primary>
</indexterm>
......@@ -3416,7 +3413,8 @@ include_dir 'conf.d'
<listitem>
<para>
Enables or disables the query planner's use of index-only-scan plan
types. The default is <literal>on</>.
types (see <xref linkend="indexes-index-only-scans">).
The default is <literal>on</>.
</para>
</listitem>
</varlistentry>
......
......@@ -354,10 +354,11 @@ amvacuumcleanup (IndexVacuumInfo *info,
bool
amcanreturn (Relation indexRelation, int attno);
</programlisting>
Check whether the index can support <firstterm>index-only scans</> on the
given column, by returning the indexed column values for an index entry in
the form of an <structname>IndexTuple</structname>. The attribute number
is 1-based, i.e. the first columns attno is 1. Returns TRUE if supported,
Check whether the index can support <link
linkend="indexes-index-only-scans"><firstterm>index-only scans</></link> on
the given column, by returning the indexed column values for an index entry
in the form of an <structname>IndexTuple</structname>. The attribute number
is 1-based, i.e. the first column's attno is 1. Returns TRUE if supported,
else FALSE. If the access method does not support index-only scans at all,
the <structfield>amcanreturn</> field in its <structname>IndexAmRoutine</>
struct can be set to NULL.
......@@ -489,8 +490,8 @@ amgettuple (IndexScanDesc scan,
</para>
<para>
If the index supports index-only scans (i.e.,
<function>amcanreturn</function> returns TRUE for it),
If the index supports <link linkend="indexes-index-only-scans">index-only
scans</link> (i.e., <function>amcanreturn</function> returns TRUE for it),
then on success the AM must also check
<literal>scan-&gt;xs_want_itup</>, and if that is true it must return
the original indexed data for the index entry, in the form of an
......@@ -700,9 +701,10 @@ amrestrpos (IndexScanDesc scan);
<para>
If the index stores the original indexed data values (and not some lossy
representation of them), it is useful to support index-only scans, in
representation of them), it is useful to
support <link linkend="indexes-index-only-scans">index-only scans</link>, in
which the index returns the actual data not just the TID of the heap tuple.
This will only work if the visibility map shows that the TID is on an
This will only avoid I/O if the visibility map shows that the TID is on an
all-visible page; else the heap tuple must be visited anyway to check
MVCC visibility. But that is no concern of the access method's.
</para>
......
This diff is collapsed.
......@@ -102,8 +102,9 @@
</listitem>
<listitem>
<simpara>To update the visibility map, which speeds up index-only
scans.</simpara>
<simpara>To update the visibility map, which speeds
up <link linkend="indexes-index-only-scans">index-only
scans</link>.</simpara>
</listitem>
<listitem>
......@@ -363,9 +364,11 @@
Since <productname>PostgreSQL</productname> indexes don't contain tuple
visibility information, a normal index scan fetches the heap tuple for each
matching index entry, to check whether it should be seen by the current
transaction. An <firstterm>index-only scan</>, on the other hand, checks
the visibility map first. If it's known that all tuples on the page are
visible, the heap fetch can be skipped. This is most noticeable on
transaction.
An <link linkend="indexes-index-only-scans"><firstterm>index-only
scan</></link>, on the other hand, checks the visibility map first.
If it's known that all tuples on the page are
visible, the heap fetch can be skipped. This is most useful on
large data sets where the visibility map can prevent disk accesses.
The visibility map is vastly smaller than the heap, so it can easily be
cached even when the heap is very large.
......
......@@ -636,9 +636,11 @@ Note that indexes do not have VMs.
The visibility map stores two bits per heap page. The first bit, if set,
indicates that the page is all-visible, or in other words that the page does
not contain any tuples that need to be vacuumed.
This information can also be used by <firstterm>index-only scans</> to answer
queries using only the index tuple.
This information can also be used
by <link linkend="indexes-index-only-scans"><firstterm>index-only
scans</></link> to answer queries using only the index tuple.
The second bit, if set, means that all tuples on the page have been frozen.
That means that even an anti-wraparound vacuum need not revisit the page.
</para>
<para>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment