205
205
</para>
206
206
207
207
<para>
208
- Leaf tuples of an <acronym>SP-GiST</acronym> tree contain values of the
209
- same data type as the indexed column. Leaf tuples at the root level will
210
- always contain the original indexed data value, but leaf tuples at lower
211
- levels might contain only a compressed representation, such as a suffix.
208
+ Leaf tuples of an <acronym>SP-GiST</acronym> tree usually contain values
209
+ of the same data type as the indexed column, although it is also possible
210
+ for them to contain lossy representations of the indexed column.
211
+ Leaf tuples stored at the root level will directly represent
212
+ the original indexed data value, but leaf tuples at lower
213
+ levels might contain only a partial value, such as a suffix.
212
214
In that case the operator class support functions must be able to
213
215
reconstruct the original value using information accumulated from the
214
216
inner tuples that are passed through to reach the leaf level.
@@ -330,19 +332,29 @@ typedef struct spgConfigOut
330
332
</para>
331
333
332
334
<para>
333
- <structfield>leafType</structfield> is typically the same as
334
- <structfield>attType</structfield>. For the reasons of backward
335
- compatibility, method <function>config</function> can
336
- leave <structfield>leafType</structfield> uninitialized; that would
337
- give the same effect as setting <structfield>leafType</structfield> equal
338
- to <structfield>attType</structfield>. When <structfield>attType</structfield>
339
- and <structfield>leafType</structfield> are different, then optional
335
+ <structfield>leafType</structfield> should match the index storage type
336
+ defined by the operator class's <structfield>opckeytype</structfield>
337
+ catalog entry.
338
+ (Note that <structfield>opckeytype</structfield> can be zero,
339
+ implying the storage type is the same as the operator class's input
340
+ type, which is the most common situation.)
341
+ For reasons of backward compatibility, the <function>config</function>
342
+ method can set <structfield>leafType</structfield> to some other value,
343
+ and that value will be used; but this is deprecated since the index
344
+ contents are then incorrectly identified in the catalogs.
345
+ Also, it's permissible to
346
+ leave <structfield>leafType</structfield> uninitialized (zero);
347
+ that is interpreted as meaning the index storage type derived from
348
+ <structfield>opckeytype</structfield>.
349
+ </para>
350
+
351
+ <para>
352
+ When <structfield>attType</structfield>
353
+ and <structfield>leafType</structfield> are different, the optional
340
354
method <function>compress</function> must be provided.
341
355
Method <function>compress</function> is responsible
342
356
for transformation of datums to be indexed from <structfield>attType</structfield>
343
357
to <structfield>leafType</structfield>.
344
- Note: both consistent functions will get <structfield>scankeys</structfield>
345
- unchanged, without transformation using <function>compress</function>.
346
358
</para>
347
359
</listitem>
348
360
</varlistentry>
@@ -677,8 +689,7 @@ typedef struct spgInnerConsistentOut
677
689
<structfield>reconstructedValue</structfield> is the value reconstructed for the
678
690
parent tuple; it is <literal>(Datum) 0</literal> at the root level or if the
679
691
<function>inner_consistent</function> function did not provide a value at the
680
- parent level. <structfield>reconstructedValue</structfield> is always of
681
- <structname>spgConfigOut</structname>.<structfield>leafType</structfield> type.
692
+ parent level.
682
693
<structfield>traversalValue</structfield> is a pointer to any traverse data
683
694
passed down from the previous call of <function>inner_consistent</function>
684
695
on the parent index tuple, or NULL at the root level.
@@ -713,9 +724,14 @@ typedef struct spgInnerConsistentOut
713
724
necessarily so, so an array is used.)
714
725
If value reconstruction is needed, set
715
726
<structfield>reconstructedValues</structfield> to an array of the values
716
- of <structname>spgConfigOut</structname>.<structfield>leafType</structfield> type
717
727
reconstructed for each child node to be visited; otherwise, leave
718
728
<structfield>reconstructedValues</structfield> as NULL.
729
+ The reconstructed values are assumed to be of type
730
+ <structname>spgConfigOut</structname>.<structfield>leafType</structfield>.
731
+ (However, since the core system will do nothing with them except
732
+ possibly copy them, it is sufficient for them to have the
733
+ same <literal>typlen</literal> and <literal>typbyval</literal>
734
+ properties as <structfield>leafType</structfield>.)
719
735
If ordered search is performed, set <structfield>distances</structfield>
720
736
to an array of distance values according to <structfield>orderbys</structfield>
721
737
array (nodes with lowest distances will be processed first). Leave it
@@ -797,8 +813,7 @@ typedef struct spgLeafConsistentOut
797
813
<structfield>reconstructedValue</structfield> is the value reconstructed for the
798
814
parent tuple; it is <literal>(Datum) 0</literal> at the root level or if the
799
815
<function>inner_consistent</function> function did not provide a value at the
800
- parent level. <structfield>reconstructedValue</structfield> is always of
801
- <structname>spgConfigOut</structname>.<structfield>leafType</structfield> type.
816
+ parent level.
802
817
<structfield>traversalValue</structfield> is a pointer to any traverse data
803
818
passed down from the previous call of <function>inner_consistent</function>
804
819
on the parent index tuple, or NULL at the root level.
@@ -816,8 +831,8 @@ typedef struct spgLeafConsistentOut
816
831
The function must return <literal>true</literal> if the leaf tuple matches the
817
832
query, or <literal>false</literal> if not. In the <literal>true</literal> case,
818
833
if <structfield>returnData</structfield> is <literal>true</literal> then
819
- <structfield>leafValue</structfield> must be set to the value of
820
- <structname>spgConfigIn</structname>.<structfield>attType</structfield> type
834
+ <structfield>leafValue</structfield> must be set to the value (of type
835
+ <structname>spgConfigIn</structname>.<structfield>attType</structfield>)
821
836
originally supplied to be indexed for this leaf tuple. Also,
822
837
<structfield>recheck</structfield> may be set to <literal>true</literal> if the match
823
838
is uncertain and so the operator(s) must be re-applied to the actual
@@ -834,23 +849,30 @@ typedef struct spgLeafConsistentOut
834
849
</variablelist>
835
850
836
851
<para>
837
- The optional user-defined method are:
852
+ The optional user-defined methods are:
838
853
</para>
839
854
840
855
<variablelist>
841
856
<varlistentry>
842
857
<term><function>Datum compress(Datum in)</function></term>
843
858
<listitem>
844
859
<para>
845
- Converts the data item into a format suitable for physical storage in
846
- a leaf tuple of index page . It accepts
860
+ Converts a data item into a format suitable for physical storage in
861
+ a leaf tuple of the index . It accepts a value of type
847
862
<structname>spgConfigIn</structname>.<structfield>attType</structfield>
848
- value and returns
849
- <structname>spgConfigOut</structname>.<structfield>leafType</structfield>
850
- value. Output value should not be toasted.
863
+ and returns a value of type
864
+ <structname>spgConfigOut</structname>.<structfield>leafType</structfield>.
865
+ The output value must not contain an out-of-line TOAST pointer.
866
+ </para>
867
+
868
+ <para>
869
+ Note: the <function>compress</function> method is only applied to
870
+ values to be stored. The consistent methods receive query scankeys
871
+ unchanged, without transformation using <function>compress</function>.
851
872
</para>
852
873
</listitem>
853
874
</varlistentry>
875
+
854
876
<varlistentry>
855
877
<term><function>options</function></term>
856
878
<listitem>
0 commit comments