Home Explore Blog CI



postgresql

7th chunk of `doc/src/sgml/rangetypes.sgml`
43a5b2d60b3d726da1bd0699ed6573f59c31c5925749199b0000000100000921
 linkend="sql-createtype"/> for more information about creating
   range types.
  </para>
 </sect2>

 <sect2 id="rangetypes-indexing">
  <title>Indexing</title>

  <indexterm>
    <primary>range type</primary>
    <secondary>indexes on</secondary>
  </indexterm>

  <para>
   GiST and SP-GiST indexes can be created for table columns of range types.
   GiST indexes can be also created for table columns of multirange types.
   For instance, to create a GiST index:
<programlisting>
CREATE INDEX reservation_idx ON reservation USING GIST (during);
</programlisting>
   A GiST or SP-GiST index on ranges can accelerate queries involving these
   range operators:
   <literal>=</literal>,
   <literal>&amp;&amp;</literal>,
   <literal>&lt;@</literal>,
   <literal>@&gt;</literal>,
   <literal>&lt;&lt;</literal>,
   <literal>&gt;&gt;</literal>,
   <literal>-|-</literal>,
   <literal>&amp;&lt;</literal>, and
   <literal>&amp;&gt;</literal>.
   A GiST index on multiranges can accelerate queries involving the same
   set of multirange operators.
   A GiST index on ranges and GiST index on multiranges can also accelerate
   queries involving these cross-type range to multirange and multirange to
   range operators correspondingly:
   <literal>&amp;&amp;</literal>,
   <literal>&lt;@</literal>,
   <literal>@&gt;</literal>,
   <literal>&lt;&lt;</literal>,
   <literal>&gt;&gt;</literal>,
   <literal>-|-</literal>,
   <literal>&amp;&lt;</literal>, and
   <literal>&amp;&gt;</literal>.
   See <xref linkend="range-operators-table"/> for more information.
  </para>

  <para>
   In addition, B-tree and hash indexes can be created for table columns of
   range types.  For these index types, basically the only useful range
   operation is equality.  There is a B-tree sort ordering defined for range
   values, with corresponding <literal>&lt;</literal> and <literal>&gt;</literal> operators,
   but the ordering is rather arbitrary and not usually useful in the real
   world.  Range types' B-tree and hash support is primarily meant to
   allow sorting and hashing internally in queries, rather than creation of
   actual indexes.
  </para>
 </sect2>

 <sect2 id="rangetypes-constraint">
  <title>Constraints on Ranges</title>

  <indexterm>
    <primary>range type</primary>
    <secondary>exclude</secondary>
  </indexterm>

  <para>

Title: Indexing and Constraints on Range Types in PostgreSQL
Summary
This section discusses indexing capabilities for range types in PostgreSQL, including GiST, SP-GiST, B-tree, and hash indexes. GiST and SP-GiST indexes can accelerate queries involving various range operators, while B-tree and hash indexes are primarily useful for equality operations due to the arbitrary nature of range value sorting. Furthermore, the section introduces constraints on ranges, covering exclusion constraints to prevent overlapping range values. It references range operators and the SQL CREATE TYPE command for more information.