Home Explore Blog CI



postgresql

3rd chunk of `doc/src/sgml/gin.sgml`
de002efccb93a07c8127f4907e51bcb12744141c6e84a8d80000000100000fa0
 an item to be indexed.  The
       number of returned keys must be stored into <literal>*nkeys</literal>.
       If any of the keys can be null, also palloc an array of
       <literal>*nkeys</literal> <type>bool</type> fields, store its address at
       <literal>*nullFlags</literal>, and set these null flags as needed.
       <literal>*nullFlags</literal> can be left <symbol>NULL</symbol> (its initial value)
       if all keys are non-null.
       The return value can be <symbol>NULL</symbol> if the item contains no keys.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry>
     <term><function>Datum *extractQuery(Datum query, int32 *nkeys,
        StrategyNumber n, bool **pmatch, Pointer **extra_data,
        bool **nullFlags, int32 *searchMode)</function></term>
     <listitem>
      <para>
       Returns a palloc'd array of keys given a value to be queried; that is,
       <literal>query</literal> is the value on the right-hand side of an
       indexable operator whose left-hand side is the indexed column.
       <literal>n</literal> is the strategy number of the operator within the
       operator class (see <xref linkend="xindex-strategies"/>).
       Often, <function>extractQuery</function> will need
       to consult <literal>n</literal> to determine the data type of
       <literal>query</literal> and the method it should use to extract key values.
       The number of returned keys must be stored into <literal>*nkeys</literal>.
       If any of the keys can be null, also palloc an array of
       <literal>*nkeys</literal> <type>bool</type> fields, store its address at
       <literal>*nullFlags</literal>, and set these null flags as needed.
       <literal>*nullFlags</literal> can be left <symbol>NULL</symbol> (its initial value)
       if all keys are non-null.
       The return value can be <symbol>NULL</symbol> if the <literal>query</literal> contains no keys.
      </para>

      <para>
       <literal>searchMode</literal> is an output argument that allows
       <function>extractQuery</function> to specify details about how the search
       will be done.
       If <literal>*searchMode</literal> is set to
       <literal>GIN_SEARCH_MODE_DEFAULT</literal> (which is the value it is
       initialized to before call), only items that match at least one of
       the returned keys are considered candidate matches.
       If <literal>*searchMode</literal> is set to
       <literal>GIN_SEARCH_MODE_INCLUDE_EMPTY</literal>, then in addition to items
       containing at least one matching key, items that contain no keys at
       all are considered candidate matches.  (This mode is useful for
       implementing is-subset-of operators, for example.)
       If <literal>*searchMode</literal> is set to <literal>GIN_SEARCH_MODE_ALL</literal>,
       then all non-null items in the index are considered candidate
       matches, whether they match any of the returned keys or not.  (This
       mode is much slower than the other two choices, since it requires
       scanning essentially the entire index, but it may be necessary to
       implement corner cases correctly.  An operator that needs this mode
       in most cases is probably not a good candidate for a GIN operator
       class.)
       The symbols to use for setting this mode are defined in
       <filename>access/gin.h</filename>.
      </para>

      <para>
       <literal>pmatch</literal> is an output argument for use when partial match
       is supported.  To use it, <function>extractQuery</function> must allocate
       an array of <literal>*nkeys</literal> <type>bool</type>s and store its address at
       <literal>*pmatch</literal>.  Each element of the array should be set to true
       if the corresponding key requires partial match, false if not.
       If <literal>*pmatch</literal> is set to <symbol>NULL</symbol> then GIN assumes partial match
       is not required.  The variable is initialized to <symbol>NULL</symbol> before call,

Title: GIN Indexes: Operator Class Implementation
Summary
To implement a GIN operator class, two functions must be defined: extractValue, which extracts keys from an item to be indexed, and extractQuery, which extracts keys from a query value, with the latter also specifying search mode and partial match requirements.