Home Explore Blog CI



postgresql

10th chunk of `doc/src/sgml/spgist.sgml`
3df1bbb3d9fbeabacbe696bbee9d5671be3d4dba2e70e0ae0000000100000fa0
 create a new inner tuple over a set of leaf tuples.
      </para>

      <para>
        The <acronym>SQL</acronym> declaration of the function must look like this:
<programlisting>
CREATE FUNCTION my_picksplit(internal, internal) RETURNS void ...
</programlisting>
      The first argument is a pointer to a <structname>spgPickSplitIn</structname>
      C struct, containing input data for the function.
      The second argument is a pointer to a <structname>spgPickSplitOut</structname>
      C struct, which the function must fill with result data.
<programlisting>
typedef struct spgPickSplitIn
{
    int         nTuples;        /* number of leaf tuples */
    Datum      *datums;         /* their datums (array of length nTuples) */
    int         level;          /* current level (counting from zero) */
} spgPickSplitIn;

typedef struct spgPickSplitOut
{
    bool        hasPrefix;      /* new inner tuple should have a prefix? */
    Datum       prefixDatum;    /* if so, its value */

    int         nNodes;         /* number of nodes for new inner tuple */
    Datum      *nodeLabels;     /* their labels (or NULL for no labels) */

    int        *mapTuplesToNodes;   /* node index for each leaf tuple */
    Datum      *leafTupleDatums;    /* datum to store in each new leaf tuple */
} spgPickSplitOut;
</programlisting>

       <structfield>nTuples</structfield> is the number of leaf tuples provided.
       <structfield>datums</structfield> is an array of their datum values of
       <structname>spgConfigOut</structname>.<structfield>leafType</structfield>
       type.
       <structfield>level</structfield> is the current level that all the leaf tuples
       share, which will become the level of the new inner tuple.
      </para>

      <para>
       Set <structfield>hasPrefix</structfield> to indicate whether the new inner
       tuple should have a prefix, and if so set
       <structfield>prefixDatum</structfield> to the prefix value.
       Set <structfield>nNodes</structfield> to indicate the number of nodes that
       the new inner tuple will contain, and
       set <structfield>nodeLabels</structfield> to an array of their label values,
       or to NULL if node labels are not required.
       Set <structfield>mapTuplesToNodes</structfield> to an array that gives the index
       (from zero) of the node that each leaf tuple should be assigned to.
       Set <structfield>leafTupleDatums</structfield> to an array of the values to
       be stored in the new leaf tuples (these will be the same as the
       input <structfield>datums</structfield> if the operator class does not modify
       datums from one level to the next).
       Note that the <function>picksplit</function> function is
       responsible for palloc'ing the
       <structfield>nodeLabels</structfield>, <structfield>mapTuplesToNodes</structfield> and
       <structfield>leafTupleDatums</structfield> arrays.
      </para>

      <para>
       If more than one leaf tuple is supplied, it is expected that the
       <function>picksplit</function> function will classify them into more than
       one node; otherwise it is not possible to split the leaf tuples
       across multiple pages, which is the ultimate purpose of this
       operation.  Therefore, if the <function>picksplit</function> function
       ends up placing all the leaf tuples in the same node, the core
       SP-GiST code will override that decision and generate an inner
       tuple in which the leaf tuples are assigned at random to several
       identically-labeled nodes.  Such a tuple is marked
       <literal>allTheSame</literal> to signify that this has happened.  The
       <function>choose</function> and <function>inner_consistent</function> functions
       must take suitable care with such inner tuples.
       See <xref linkend="spgist-all-the-same"/> for more information.
      </para>

      <para>
       <function>picksplit</function> can be applied to a single leaf tuple only
     

Title: SP-GiST PickSplit Function Details
Summary
The picksplit function is used in SP-GiST indexes to create a new inner tuple from a set of leaf tuples, taking into account the number of leaf tuples, their datums, and the current level, and returning information such as whether the new inner tuple should have a prefix, the number of nodes, node labels, and the mapping of leaf tuples to nodes, with the goal of efficiently organizing data across multiple pages.