114
114
</row>
115
115
<row>
116
116
<entry><literal>box_ops</></entry>
117
- <entry>box</entry>
117
+ <entry><type> box</> </entry>
118
118
<entry>
119
119
<literal><<</>
120
120
<literal>&<</>
183
183
Inner tuples are more complex, since they are branching points in the
184
184
search tree. Each inner tuple contains a set of one or more
185
185
<firstterm>nodes</>, which represent groups of similar leaf values.
186
- A node contains a downlink that leads to either another, lower-level inner
187
- tuple, or a short list of leaf tuples that all lie on the same index page.
188
- Each node has a <firstterm>label</> that describes it; for example,
186
+ A node contains a downlink that leads either to another, lower-level inner
187
+ tuple, or to a short list of leaf tuples that all lie on the same index page.
188
+ Each node normally has a <firstterm>label</> that describes it; for example,
189
189
in a radix tree the node label could be the next character of the string
190
- value. Optionally, an inner tuple can have a <firstterm>prefix</> value
190
+ value. (Alternatively, an operator class can omit the node labels, if it
191
+ works with a fixed set of nodes for all inner tuples;
192
+ see <xref linkend="spgist-null-labels">.)
193
+ Optionally, an inner tuple can have a <firstterm>prefix</> value
191
194
that describes all its members. In a radix tree this could be the common
192
195
prefix of the represented strings. The prefix value is not necessarily
193
196
really a prefix, but can be any data needed by the operator class;
202
205
tuple, so the <acronym>SP-GiST</acronym> core provides the possibility for
203
206
operator classes to manage level counting while descending the tree.
204
207
There is also support for incrementally reconstructing the represented
205
- value when that is needed.
208
+ value when that is needed, and for passing down additional data (called
209
+ <firstterm>traverse values</>) during a tree descent.
206
210
</para>
207
211
208
212
<note>
@@ -492,9 +496,8 @@ typedef struct spgPickSplitOut
492
496
<structfield>prefixDatum</> to the prefix value.
493
497
Set <structfield>nNodes</> to indicate the number of nodes that
494
498
the new inner tuple will contain, and
495
- set <structfield>nodeLabels</> to an array of their label values.
496
- (If the nodes do not require labels, set <structfield>nodeLabels</>
497
- to NULL; see <xref linkend="spgist-null-labels"> for details.)
499
+ set <structfield>nodeLabels</> to an array of their label values,
500
+ or to NULL if node labels are not required.
498
501
Set <structfield>mapTuplesToNodes</> to an array that gives the index
499
502
(from zero) of the node that each leaf tuple should be assigned to.
500
503
Set <structfield>leafTupleDatums</> to an array of the values to
@@ -561,7 +564,7 @@ typedef struct spgInnerConsistentIn
561
564
562
565
Datum reconstructedValue; /* value reconstructed at parent */
563
566
void *traversalValue; /* opclass-specific traverse value */
564
- MemoryContext traversalMemoryContext;
567
+ MemoryContext traversalMemoryContext; /* put new traverse values here */
565
568
int level; /* current level (counting from zero) */
566
569
bool returnData; /* original data must be returned? */
567
570
@@ -580,7 +583,6 @@ typedef struct spgInnerConsistentOut
580
583
int *levelAdds; /* increment level by this much for each */
581
584
Datum *reconstructedValues; /* associated reconstructed values */
582
585
void **traversalValues; /* opclass-specific traverse values */
583
-
584
586
} spgInnerConsistentOut;
585
587
</programlisting>
586
588
@@ -599,6 +601,11 @@ typedef struct spgInnerConsistentOut
599
601
parent tuple; it is <literal>(Datum) 0</> at the root level or if the
600
602
<function>inner_consistent</> function did not provide a value at the
601
603
parent level.
604
+ <structfield>traversalValue</> is a pointer to any traverse data
605
+ passed down from the previous call of <function>inner_consistent</>
606
+ on the parent index tuple, or NULL at the root level.
607
+ <structfield>traversalMemoryContext</> is the memory context in which
608
+ to store output traverse values (see below).
602
609
<structfield>level</> is the current inner tuple's level, starting at
603
610
zero for the root level.
604
611
<structfield>returnData</> is <literal>true</> if reconstructed data is
@@ -615,9 +622,6 @@ typedef struct spgInnerConsistentOut
615
622
inner tuple, and
616
623
<structfield>nodeLabels</> is an array of their label values, or
617
624
NULL if the nodes do not have labels.
618
- <structfield>traversalValue</> is a pointer to data that
619
- <function>inner_consistent</> gets when called on child nodes from an
620
- outer call of <function>inner_consistent</> on parent nodes.
621
625
</para>
622
626
623
627
<para>
@@ -633,17 +637,20 @@ typedef struct spgInnerConsistentOut
633
637
<structfield>reconstructedValues</> to an array of the values
634
638
reconstructed for each child node to be visited; otherwise, leave
635
639
<structfield>reconstructedValues</> as NULL.
640
+ If it is desired to pass down additional out-of-band information
641
+ (<quote>traverse values</>) to lower levels of the tree search,
642
+ set <structfield>traversalValues</> to an array of the appropriate
643
+ traverse values, one for each child node to be visited; otherwise,
644
+ leave <structfield>traversalValues</> as NULL.
636
645
Note that the <function>inner_consistent</> function is
637
646
responsible for palloc'ing the
638
- <structfield>nodeNumbers</>, <structfield>levelAdds</> and
639
- <structfield>reconstructedValues</> arrays.
640
- Sometimes accumulating some information is needed, while
641
- descending from parent to child node was happened. In this case
642
- <structfield>traversalValues</> array keeps pointers to
643
- specific data you need to accumulate for every child node.
644
- Memory for <structfield>traversalValues</> should be allocated in
645
- the default context, but each element of it should be allocated in
646
- <structfield>traversalMemoryContext</>.
647
+ <structfield>nodeNumbers</>, <structfield>levelAdds</>,
648
+ <structfield>reconstructedValues</>, and
649
+ <structfield>traversalValues</> arrays in the current memory context.
650
+ However, any output traverse values pointed to by
651
+ the <structfield>traversalValues</> array should be allocated
652
+ in <structfield>traversalMemoryContext</>.
653
+ Each traverse value must be a single palloc'd chunk.
647
654
</para>
648
655
</listitem>
649
656
</varlistentry>
@@ -700,6 +707,9 @@ typedef struct spgLeafConsistentOut
700
707
parent tuple; it is <literal>(Datum) 0</> at the root level or if the
701
708
<function>inner_consistent</> function did not provide a value at the
702
709
parent level.
710
+ <structfield>traversalValue</> is a pointer to any traverse data
711
+ passed down from the previous call of <function>inner_consistent</>
712
+ on the parent index tuple, or NULL at the root level.
703
713
<structfield>level</> is the current leaf tuple's level, starting at
704
714
zero for the root level.
705
715
<structfield>returnData</> is <literal>true</> if reconstructed data is
@@ -859,11 +869,10 @@ typedef struct spgLeafConsistentOut
859
869
860
870
<para>
861
871
The <productname>PostgreSQL</productname> source distribution includes
862
- several examples of index operator classes for
863
- <acronym>SP-GiST</acronym>. The core system currently provides radix
864
- trees over text columns and two types of trees over points: quad-tree and
865
- k-d tree. Look into <filename>src/backend/access/spgist/</> to see the
866
- code.
872
+ several examples of index operator classes for <acronym>SP-GiST</acronym>,
873
+ as described in <xref linkend="spgist-builtin-opclasses-table">. Look
874
+ into <filename>src/backend/access/spgist/</>
875
+ and <filename>src/backend/utils/adt/</> to see the code.
867
876
</para>
868
877
869
878
</sect1>
0 commit comments