Home Explore Blog CI



postgresql

8th chunk of `doc/src/sgml/spgist.sgml`
865e35c3c4c0136be90f41e7713ef678e2f792deecdc35ec0000000100000fa0
 value */
        }           splitTuple;
    }           result;
} spgChooseOut;
</programlisting>

       <structfield>datum</structfield> is the original datum of
       <structname>spgConfigIn</structname>.<structfield>attType</structfield>
       type that was to be inserted into the index.
       <structfield>leafDatum</structfield> is a value of
       <structname>spgConfigOut</structname>.<structfield>leafType</structfield>
       type, which is initially a result of method
       <function>compress</function> applied to <structfield>datum</structfield>
       when method <function>compress</function> is provided, or the same value as
       <structfield>datum</structfield> otherwise.
       <structfield>leafDatum</structfield> can change at lower levels of the tree
       if the <function>choose</function> or <function>picksplit</function>
       methods change it.  When the insertion search reaches a leaf page,
       the current value of <structfield>leafDatum</structfield> is what will be stored
       in the newly created leaf tuple.
       <structfield>level</structfield> is the current inner tuple's level, starting at
       zero for the root level.
       <structfield>allTheSame</structfield> is true if the current inner tuple is
       marked as containing multiple equivalent nodes
       (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 there are no labels.
      </para>

      <para>
       The <function>choose</function> function can determine either that
       the new value matches one of the existing child nodes, or that a new
       child node must be added, or that the new value is inconsistent with
       the tuple prefix and so the inner tuple must be split to create a
       less restrictive prefix.
      </para>

      <para>
       If the new value matches one of the existing child nodes,
       set <structfield>resultType</structfield> to <literal>spgMatchNode</literal>.
       Set <structfield>nodeN</structfield> to the index (from zero) of that node in
       the node array.
       Set <structfield>levelAdd</structfield> to the increment in
       <structfield>level</structfield> caused by descending through that node,
       or leave it as zero if the operator class does not use levels.
       Set <structfield>restDatum</structfield> to equal <structfield>leafDatum</structfield>
       if the operator class does not modify datums from one level to the
       next, or otherwise set it to the modified value to be used as
       <structfield>leafDatum</structfield> at the next level.
      </para>

      <para>
       If a new child node must be added,
       set <structfield>resultType</structfield> to <literal>spgAddNode</literal>.
       Set <structfield>nodeLabel</structfield> to the label to be used for the new
       node, and set <structfield>nodeN</structfield> to the index (from zero) at which
       to insert the node in the node array.
       After the node has been added, the <function>choose</function>
       function will be called again with the modified inner tuple;
       that call should result in an <literal>spgMatchNode</literal> result.
      </para>

      <para>
       If the new value is inconsistent with the tuple prefix,
       set <structfield>resultType</structfield> to <literal>spgSplitTuple</literal>.
       This action moves all the existing nodes into a new lower-level
       inner tuple, and replaces the existing inner tuple with a tuple
       having a single downlink pointing to the new lower-level inner tuple.
       Set <structfield>prefixHasPrefix</structfield> to indicate whether the new
 

Title: SP-GiST Choose Function Implementation Details
Summary
The choose function determines how to insert a new value into an inner tuple in an SP-GiST index, and returns one of three possible results: matching an existing node, adding a new node, or splitting the inner tuple to create a less restrictive prefix, with each result type requiring specific output values to be set, such as node indices, level increments, and modified datums.