1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-20 15:22:23 +03:00

Allow index AMs to return either HeapTuple or IndexTuple format during IOS.

Previously, only IndexTuple format was supported for the output data of
an index-only scan.  This is fine for btree, which is just returning a
verbatim index tuple anyway.  It's not so fine for SP-GiST, which can
return reconstructed data that's much larger than a page.

To fix, extend the index AM API so that index-only scan data can be
returned in either HeapTuple or IndexTuple format.  There's other ways
we could have done it, but this way avoids an API break for index AMs
that aren't concerned with the issue, and it costs little except a couple
more fields in IndexScanDescs.

I changed both GiST and SP-GiST to use the HeapTuple method.  I'm not
very clear on whether GiST can reconstruct data that's too large for an
IndexTuple, but that seems possible, and it's not much of a code change to
fix.

Per a complaint from Vik Fearing.  Reviewed by Jason Li.

Discussion: https://postgr.es/m/49527f79-530d-0bfe-3dad-d183596afa92@2ndquadrant.fr
This commit is contained in:
Tom Lane
2017-02-27 17:20:34 -05:00
parent 30df93f698
commit 9b88f27cb4
11 changed files with 71 additions and 39 deletions

View File

@ -551,15 +551,19 @@ amgettuple (IndexScanDesc scan,
<para>
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
then on success the AM must also check <literal>scan-&gt;xs_want_itup</>,
and if that is true it must return the originally indexed data for the
index entry. The data can be returned in the form of an
<structname>IndexTuple</> pointer stored at <literal>scan-&gt;xs_itup</>,
with tuple descriptor <literal>scan-&gt;xs_itupdesc</>.
(Management of the data referenced by the pointer is the access method's
with tuple descriptor <literal>scan-&gt;xs_itupdesc</>; or in the form of
a <structname>HeapTuple</> pointer stored at <literal>scan-&gt;xs_hitup</>,
with tuple descriptor <literal>scan-&gt;xs_hitupdesc</>. (The latter
format should be used when reconstructing data that might possibly not fit
into an IndexTuple.) In either case,
management of the data referenced by the pointer is the access method's
responsibility. The data must remain good at least until the next
<function>amgettuple</>, <function>amrescan</>, or <function>amendscan</>
call for the scan.)
call for the scan.
</para>
<para>