Home Explore Blog CI



postgresql

4th chunk of `doc/src/sgml/indices.sgml`
785c3b0373627c8ad3deaa365da872be6a00c536406120940000000100000fa1
 from the
   value of the indexed column. Hence,
   such indexes can only handle simple equality comparisons.
   The query planner will consider using a hash index whenever an
   indexed column is involved in a comparison using the
   equal operator:

<synopsis>
=
</synopsis>
  </para>
  </sect2>

  <sect2 id="indexes-type-gist">
   <title>GiST</title>

   <indexterm>
    <primary>index</primary>
    <secondary>GiST</secondary>
   </indexterm>
   <indexterm>
    <primary>GiST</primary>
    <see>index</see>
   </indexterm>

  <para>
   GiST indexes are not a single kind of index, but rather an infrastructure
   within which many different indexing strategies can be implemented.
   Accordingly, the particular operators with which a GiST index can be
   used vary depending on the indexing strategy (the <firstterm>operator
   class</firstterm>).  As an example, the standard distribution of
   <productname>PostgreSQL</productname> includes GiST operator classes
   for several two-dimensional geometric data types, which support indexed
   queries using these operators:

<synopsis>
&lt;&lt; &nbsp; &amp;&lt; &nbsp; &amp;&gt; &nbsp; &gt;&gt; &nbsp; &lt;&lt;| &nbsp; &amp;&lt;| &nbsp; |&amp;&gt; &nbsp; |&gt;&gt; &nbsp; @&gt; &nbsp; &lt;@ &nbsp; ~= &nbsp; &amp;&amp;
</synopsis>

   (See <xref linkend="functions-geometry"/> for the meaning of
   these operators.)
   The GiST operator classes included in the standard distribution are
   documented in <xref linkend="gist-builtin-opclasses-table"/>.
   Many other GiST operator
   classes are available in the <literal>contrib</literal> collection or as separate
   projects.  For more information see <xref linkend="gist"/>.
  </para>

  <para>
   GiST indexes are also capable of optimizing <quote>nearest-neighbor</quote>
   searches, such as
<programlisting><![CDATA[
SELECT * FROM places ORDER BY location <-> point '(101,456)' LIMIT 10;
]]>
</programlisting>
   which finds the ten places closest to a given target point.  The ability
   to do this is again dependent on the particular operator class being used.
   In <xref linkend="gist-builtin-opclasses-table"/>, operators that can be
   used in this way are listed in the column <quote>Ordering Operators</quote>.
  </para>
  </sect2>

  <sect2 id="indexes-type-spgist">
   <title>SP-GiST</title>

   <indexterm>
    <primary>index</primary>
    <secondary>SP-GiST</secondary>
   </indexterm>
   <indexterm>
    <primary>SP-GiST</primary>
    <see>index</see>
   </indexterm>

  <para>
   SP-GiST indexes, like GiST indexes, offer an infrastructure that supports
   various kinds of searches.  SP-GiST permits implementation of a wide range
   of different non-balanced disk-based data structures, such as quadtrees,
   k-d trees, and radix trees (tries).  As an example, the standard distribution of
   <productname>PostgreSQL</productname> includes SP-GiST operator classes
   for two-dimensional points, which support indexed
   queries using these operators:

<synopsis>
&lt;&lt; &nbsp; &gt;&gt; &nbsp; ~= &nbsp; &lt;@ &nbsp; &lt;&lt;| &nbsp; |&gt;&gt;
</synopsis>

   (See <xref linkend="functions-geometry"/> for the meaning of
   these operators.)
   The SP-GiST operator classes included in the standard distribution are
   documented in <xref linkend="spgist-builtin-opclasses-table"/>.
   For more information see <xref linkend="spgist"/>.
  </para>

  <para>
   Like GiST, SP-GiST supports <quote>nearest-neighbor</quote> searches.
   For SP-GiST operator classes that support distance ordering, the
   corresponding operator is listed in the <quote>Ordering Operators</quote>
   column in <xref linkend="spgist-builtin-opclasses-table"/>.
  </para>
  </sect2>

  <sect2 id="indexes-types-gin">
   <title>GIN</title>

   <indexterm>
    <primary>index</primary>
    <secondary>GIN</secondary>
   </indexterm>
   <indexterm>
    <primary>GIN</primary>
    <see>index</see>
   </indexterm>

  <para>
   GIN indexes are <quote>inverted indexes</quote> which are appropriate

Title: PostgreSQL Index Types: GiST, SP-GiST, and GIN
Summary
This section discusses GiST, SP-GiST, and GIN index types in PostgreSQL. GiST indexes provide a flexible infrastructure supporting various indexing strategies, with operator usage depending on the operator class. They support operators for geometric data types and nearest-neighbor searches. SP-GiST indexes, similar to GiST, enable the implementation of non-balanced data structures and also support nearest-neighbor searches. GIN indexes are inverted indexes suited for composite data types, detailed further in the next section.