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

Restructure SPGiST opclass interface API to support whole-index scans.

The original API definition was incapable of supporting whole-index scans
because there was no way to invoke leaf-value reconstruction without
checking any qual conditions.  Also, it was inefficient for
multiple-qual-condition scans because value reconstruction got done over
again for each qual condition, and because other internal work in the
consistent functions likewise had to be done for each qual.  To fix these
issues, pass the whole scankey array to the opclass consistent functions,
instead of only letting them see one item at a time.  (Essentially, the
loop over scankey entries is now inside the consistent functions not
outside them.  This makes the consistent functions a bit more complicated,
but not unreasonably so.)

In itself this commit does nothing except save a few cycles in
multiple-qual-condition index scans, since we can't support whole-index
scans on SPGiST indexes until nulls are included in the index.  However,
I consider this a must-fix for 9.2 because once we release it will get
very much harder to change the opclass API definition.
This commit is contained in:
Tom Lane
2012-03-10 18:36:49 -05:00
parent 39d74e346c
commit 03e56f798e
7 changed files with 523 additions and 532 deletions

View File

@ -439,8 +439,8 @@ CREATE FUNCTION my_inner_consistent(internal, internal) RETURNS void ...
<programlisting>
typedef struct spgInnerConsistentIn
{
StrategyNumber strategy; /* operator strategy number */
Datum query; /* operator's RHS value */
ScanKey scankeys; /* array of operators and comparison values */
int nkeys; /* length of array */
Datum reconstructedValue; /* value reconstructed at parent */
int level; /* current level (counting from zero) */
@ -463,8 +463,17 @@ typedef struct spgInnerConsistentOut
} spgInnerConsistentOut;
</programlisting>
<structfield>strategy</> and
<structfield>query</> describe the index search condition.
The array <structfield>scankeys</>, of length <structfield>nkeys</>,
describes the index search condition(s). These conditions are
combined with AND &mdash; only index entries that satisfy all of
them are interesting. (Note that <structfield>nkeys</> = 0 implies
that all index entries satisfy the query.) Usually the consistent
function only cares about the <structfield>sk_strategy</> and
<structfield>sk_argument</> fields of each array entry, which
respectively give the indexable operator and comparison value.
In particular it is not necessary to check <structfield>sk_flags</> to
see if the comparison value is NULL, because the SP-GiST core code
will filter out such conditions.
<structfield>reconstructedValue</> is the value reconstructed for the
parent tuple; it is <literal>(Datum) 0</> at the root level or if the
<function>inner_consistent</> function did not provide a value at the
@ -527,8 +536,8 @@ CREATE FUNCTION my_leaf_consistent(internal, internal) RETURNS bool ...
<programlisting>
typedef struct spgLeafConsistentIn
{
StrategyNumber strategy; /* operator strategy number */
Datum query; /* operator's RHS value */
ScanKey scankeys; /* array of operators and comparison values */
int nkeys; /* length of array */
Datum reconstructedValue; /* value reconstructed at parent */
int level; /* current level (counting from zero) */
@ -544,8 +553,17 @@ typedef struct spgLeafConsistentOut
} spgLeafConsistentOut;
</programlisting>
<structfield>strategy</> and
<structfield>query</> define the index search condition.
The array <structfield>scankeys</>, of length <structfield>nkeys</>,
describes the index search condition(s). These conditions are
combined with AND &mdash; only index entries that satisfy all of
them satisfy the query. (Note that <structfield>nkeys</> = 0 implies
that all index entries satisfy the query.) Usually the consistent
function only cares about the <structfield>sk_strategy</> and
<structfield>sk_argument</> fields of each array entry, which
respectively give the indexable operator and comparison value.
In particular it is not necessary to check <structfield>sk_flags</> to
see if the comparison value is NULL, because the SP-GiST core code
will filter out such conditions.
<structfield>reconstructedValue</> is the value reconstructed for the
parent tuple; it is <literal>(Datum) 0</> at the root level or if the
<function>inner_consistent</> function did not provide a value at the
@ -566,8 +584,8 @@ typedef struct spgLeafConsistentOut
<structfield>leafValue</> must be set to the value originally supplied
to be indexed for this leaf tuple. Also,
<structfield>recheck</> may be set to <literal>true</> if the match
is uncertain and so the operator must be re-applied to the actual heap
tuple to verify the match.
is uncertain and so the operator(s) must be re-applied to the actual
heap tuple to verify the match.
</para>
</listitem>
</varlistentry>