Home Explore Blog CI



postgresql

2nd chunk of `doc/src/sgml/gin.sgml`
e481c8025fa089ec94007a99bdfdff209ada4c2143e2420c0000000100000fa8
 <entry>Name</entry>
      <entry>Indexable Operators</entry>
     </row>
    </thead>
    <tbody>
     <row>
      <entry morerows="3" valign="middle"><literal>array_ops</literal></entry>
      <entry><literal>&amp;&amp; (anyarray,anyarray)</literal></entry>
     </row>
     <row>
      <entry><literal>@&gt; (anyarray,anyarray)</literal></entry>
     </row>
     <row>
      <entry><literal>&lt;@ (anyarray,anyarray)</literal></entry>
     </row>
     <row>
      <entry><literal>= (anyarray,anyarray)</literal></entry>
     </row>
     <row>
      <entry morerows="5" valign="middle"><literal>jsonb_ops</literal></entry>
      <entry><literal>@&gt; (jsonb,jsonb)</literal></entry>
     </row>
     <row>
      <entry><literal>@? (jsonb,jsonpath)</literal></entry>
     </row>
     <row>
      <entry><literal>@@ (jsonb,jsonpath)</literal></entry>
     </row>
     <row>
      <entry><literal>? (jsonb,text)</literal></entry>
     </row>
     <row>
      <entry><literal>?| (jsonb,text[])</literal></entry>
     </row>
     <row>
      <entry><literal>?&amp; (jsonb,text[])</literal></entry>
     </row>
     <row>
      <entry morerows="2" valign="middle"><literal>jsonb_path_ops</literal></entry>
      <entry><literal>@&gt; (jsonb,jsonb)</literal></entry>
     </row>
     <row>
      <entry><literal>@? (jsonb,jsonpath)</literal></entry>
     </row>
     <row>
      <entry><literal>@@ (jsonb,jsonpath)</literal></entry>
     </row>
     <row>
      <entry valign="middle"><literal>tsvector_ops</literal></entry>
      <entry><literal>@@ (tsvector,tsquery)</literal></entry>
     </row>
    </tbody>
   </tgroup>
  </table>

 <para>
  Of the two operator classes for type <type>jsonb</type>, <literal>jsonb_ops</literal>
  is the default.  <literal>jsonb_path_ops</literal> supports fewer operators but
  offers better performance for those operators.
  See <xref linkend="json-indexing"/> for details.
 </para>

</sect2>

<sect2 id="gin-extensibility">
 <title>Extensibility</title>

 <para>
   The <acronym>GIN</acronym> interface has a high level of abstraction,
   requiring the access method implementer only to implement the semantics of
   the data type being accessed.  The <acronym>GIN</acronym> layer itself
   takes care of concurrency, logging and searching the tree structure.
 </para>

 <para>
   All it takes to get a <acronym>GIN</acronym> access method working is to
   implement a few user-defined methods, which define the behavior of
   keys in the tree and the relationships between keys, indexed items,
   and indexable queries. In short, <acronym>GIN</acronym> combines
   extensibility with generality, code reuse, and a clean interface.
 </para>

 <para>
   There are two methods that an operator class for
   <acronym>GIN</acronym> must provide:

  <variablelist>
    <varlistentry>
     <term><function>Datum *extractValue(Datum itemValue, int32 *nkeys,
        bool **nullFlags)</function></term>
     <listitem>
      <para>
       Returns a palloc'd array of keys given 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

Title: GIN Indexes: Built-in Operator Classes and Extensibility
Summary
The GIN index includes several built-in operator classes, such as array_ops, jsonb_ops, and tsvector_ops, each supporting various indexable operators, and also provides an extensible interface allowing developers to implement custom operator classes by defining key extraction and query behavior.