Home Explore Blog CI



postgresql

6th chunk of `doc/src/sgml/gin.sgml`
e252a32e6dba33b14f2ad5121c8169ba6fa3209e97ec3f550000000100000fa4
 <function>triConsistent</function> is similar to <function>consistent</function>,
       but instead of Booleans in the <literal>check</literal> vector, there are
       three possible values for each
       key: <literal>GIN_TRUE</literal>, <literal>GIN_FALSE</literal> and
       <literal>GIN_MAYBE</literal>. <literal>GIN_FALSE</literal> and <literal>GIN_TRUE</literal>
       have the same meaning as regular Boolean values, while
       <literal>GIN_MAYBE</literal> means that the presence of that key is not known.
       When <literal>GIN_MAYBE</literal> values are present, the function should only
       return <literal>GIN_TRUE</literal> if the item certainly matches whether or
       not the index item contains the corresponding query keys. Likewise, the
       function must return <literal>GIN_FALSE</literal> only if the item certainly
       does not match, whether or not it contains the <literal>GIN_MAYBE</literal>
       keys. If the result depends on the <literal>GIN_MAYBE</literal> entries, i.e.,
       the match cannot be confirmed or refuted based on the known query keys,
       the function must return <literal>GIN_MAYBE</literal>.
      </para>
      <para>
       When there are no <literal>GIN_MAYBE</literal> values in the <literal>check</literal>
       vector, a <literal>GIN_MAYBE</literal> return value is the equivalent of
       setting the <literal>recheck</literal> flag in the
       Boolean <function>consistent</function> function.
      </para>
     </listitem>
    </varlistentry>
  </variablelist>
 </para>

 <para>
  In addition, GIN must have a way to sort the key values stored in the index.
  The operator class can define the sort ordering by specifying a comparison
  method:

  <variablelist>
    <varlistentry>
     <term><function>int compare(Datum a, Datum b)</function></term>
     <listitem>
      <para>
       Compares two keys (not indexed items!) and returns an integer less than
       zero, zero, or greater than zero, indicating whether the first key is
       less than, equal to, or greater than the second.  Null keys are never
       passed to this function.
      </para>
     </listitem>
    </varlistentry>
  </variablelist>

  Alternatively, if the operator class does not provide a <function>compare</function>
  method, GIN will look up the default btree operator class for the index
  key data type, and use its comparison function.  It is recommended to
  specify the comparison function in a GIN operator class that is meant for
  just one data type, as looking up the btree operator class costs a few
  cycles.  However, polymorphic GIN operator classes (such
  as <literal>array_ops</literal>) typically cannot specify a single comparison
  function.
 </para>

 <para>
  An operator class for <acronym>GIN</acronym> can optionally supply the
  following methods:

  <variablelist>
    <varlistentry>
     <term><function>int comparePartial(Datum partial_key, Datum key, StrategyNumber n,
                              Pointer extra_data)</function></term>
     <listitem>
      <para>
       Compare a partial-match query key to an index key.  Returns an integer
       whose sign indicates the result: less than zero means the index key
       does not match the query, but the index scan should continue; zero
       means that the index key does match the query; greater than zero
       indicates that the index scan should stop because no more matches
       are possible.  The strategy number <literal>n</literal> of the operator
       that generated the partial match query is provided, in case its
       semantics are needed to determine when to end the scan.  Also,
       <literal>extra_data</literal> is the corresponding element of the extra-data
       array made by <function>extractQuery</function>, or <symbol>NULL</symbol> if none.
       Null keys are never passed to this function.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><function>void options(local_relopts

Title: GIN Operator Class Methods
Summary
A GIN operator class can define several methods, including compare for sorting key values, comparePartial for partial-match queries, and options, to customize the behavior of the index, with some methods being required and others being optional.