Home Explore Blog CI



postgresql

13th chunk of `doc/src/sgml/spgist.sgml`
5cfa5d93f11c1655d28c24be8d19999e8d23e65cc84817810000000100000fa0
     marked <quote>all-the-same</quote>; in this case all the nodes have the
       same label (if any) and so either all or none of them match the query
       (see <xref linkend="spgist-all-the-same"/>).
       <structfield>hasPrefix</structfield> is true if the current inner tuple contains
       a prefix; if so,
       <structfield>prefixDatum</structfield> is its value.
       <structfield>nNodes</structfield> is the number of child nodes contained in the
       inner tuple, and
       <structfield>nodeLabels</structfield> is an array of their label values, or
       NULL if the nodes do not have labels.
      </para>

      <para>
       <structfield>nNodes</structfield> must be set to the number of child nodes that
       need to be visited by the search, and
       <structfield>nodeNumbers</structfield> must be set to an array of their indexes.
       If the operator class keeps track of levels, set
       <structfield>levelAdds</structfield> to an array of the level increments
       required when descending to each node to be visited.  (Often these
       increments will be the same for all the nodes, but that's not
       necessarily so, so an array is used.)
       If value reconstruction is needed, set
       <structfield>reconstructedValues</structfield> to an array of the values
       reconstructed for each child node to be visited; otherwise, leave
       <structfield>reconstructedValues</structfield> as NULL.
       The reconstructed values are assumed to be of type
       <structname>spgConfigOut</structname>.<structfield>leafType</structfield>.
       (However, since the core system will do nothing with them except
       possibly copy them, it is sufficient for them to have the
       same <literal>typlen</literal> and <literal>typbyval</literal>
       properties as <structfield>leafType</structfield>.)
       If ordered search is performed, set <structfield>distances</structfield>
       to an array of distance values according to <structfield>orderbys</structfield>
       array (nodes with lowest distances will be processed first).  Leave it
       NULL otherwise.
       If it is desired to pass down additional out-of-band information
       (<quote>traverse values</quote>) to lower levels of the tree search,
       set <structfield>traversalValues</structfield> to an array of the appropriate
       traverse values, one for each child node to be visited; otherwise,
       leave <structfield>traversalValues</structfield> as NULL.
       Note that the <function>inner_consistent</function> function is
       responsible for palloc'ing the
       <structfield>nodeNumbers</structfield>, <structfield>levelAdds</structfield>,
       <structfield>distances</structfield>,
       <structfield>reconstructedValues</structfield>, and
       <structfield>traversalValues</structfield> arrays in the current memory context.
       However, any output traverse values pointed to by
       the <structfield>traversalValues</structfield> array should be allocated
       in <structfield>traversalMemoryContext</structfield>.
       Each traverse value must be a single palloc'd chunk.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><function>leaf_consistent</function></term>
     <listitem>
      <para>
       Returns true if a leaf tuple satisfies a query.
      </para>

      <para>
       The <acronym>SQL</acronym> declaration of the function must look like this:
<programlisting>
CREATE FUNCTION my_leaf_consistent(internal, internal) RETURNS bool ...
</programlisting>
      The first argument is a pointer to a <structname>spgLeafConsistentIn</structname>
      C struct, containing input data for the function.
      The second argument is a pointer to a <structname>spgLeafConsistentOut</structname>
      C struct, which the function must fill with result data.
<programlisting>
typedef struct spgLeafConsistentIn
{
    ScanKey     scankeys;       /* array of operators and comparison values */
 

Title: SP-GiST Leaf Consistent Function and Input/Output Structures
Summary
The leaf_consistent function determines if a leaf tuple satisfies a query, using input from the spgLeafConsistentIn struct, which contains scan keys and comparison values, and returns a boolean result, while also utilizing the spgLeafConsistentOut struct to store output data, with the function declaration requiring specific SQL syntax and argument types.