Home Explore Blog CI



postgresql

2nd chunk of `doc/src/sgml/btree-gist.sgml`
629565cfee1c983578ce9b9d357d5f77f900bf91a406c7e00000000100000d69
 wherein some of the columns
  are of data types that are only indexable with GiST but other columns
  are just simple data types.  Lastly, these operator classes are useful for
  GiST testing and as a base for developing other GiST operator classes.
 </para>

 <para>
  In addition to the typical B-tree search operators, <filename>btree_gist</filename>
  also provides index support for <literal>&lt;&gt;</literal> (<quote>not
  equals</quote>). This may be useful in combination with an
  <link linkend="sql-createtable-exclude">exclusion constraint</link>,
  as described below.
 </para>

 <para>
  Also, for data types for which there is a natural distance metric,
  <filename>btree_gist</filename> defines a distance operator <literal>&lt;-&gt;</literal>,
  and provides GiST index support for nearest-neighbor searches using
  this operator.  Distance operators are provided for
  <type>int2</type>, <type>int4</type>, <type>int8</type>, <type>float4</type>,
  <type>float8</type>, <type>timestamp with time zone</type>,
  <type>timestamp without time zone</type>,
  <type>time without time zone</type>, <type>date</type>, <type>interval</type>,
  <type>oid</type>, and <type>money</type>.
 </para>

 <para>
  By default <filename>btree_gist</filename> builds <acronym>GiST</acronym> index with
  <function>sortsupport</function> in <firstterm>sorted</firstterm> mode. This usually results in
  much faster index built speed. It is still possible to revert to buffered built strategy
  by using the <literal>buffering</literal> parameter when creating the index.
 </para>

 <para>
  This module is considered <quote>trusted</quote>, that is, it can be
  installed by non-superusers who have <literal>CREATE</literal> privilege
  on the current database.
 </para>

 <sect2 id="btree-gist-example-usage">
  <title>Example Usage</title>

  <para>
   Simple example using <literal>btree_gist</literal> instead of <literal>btree</literal>:
  </para>

<programlisting>
CREATE TABLE test (a int4);
-- create index
CREATE INDEX testidx ON test USING GIST (a);
-- query
SELECT * FROM test WHERE a &lt; 10;
-- nearest-neighbor search: find the ten entries closest to "42"
SELECT *, a &lt;-&gt; 42 AS dist FROM test ORDER BY a &lt;-&gt; 42 LIMIT 10;
</programlisting>

  <para>
   Use an <link linkend="sql-createtable-exclude">exclusion
   constraint</link> to enforce the rule that a cage at a zoo
   can contain only one kind of animal:
  </para>

<programlisting>
=&gt; CREATE TABLE zoo (
  cage   INTEGER,
  animal TEXT,
  EXCLUDE USING GIST (cage WITH =, animal WITH &lt;&gt;)
);

=&gt; INSERT INTO zoo VALUES(123, 'zebra');
INSERT 0 1
=&gt; INSERT INTO zoo VALUES(123, 'zebra');
INSERT 0 1
=&gt; INSERT INTO zoo VALUES(123, 'lion');
ERROR:  conflicting key value violates exclusion constraint "zoo_cage_animal_excl"
DETAIL:  Key (cage, animal)=(123, lion) conflicts with existing key (cage, animal)=(123, zebra).
=&gt; INSERT INTO zoo VALUES(124, 'lion');
INSERT 0 1
</programlisting>

 </sect2>

 <sect2 id="btree-gist-authors">
  <title>Authors</title>

  <para>
   Teodor Sigaev (<email>teodor@stack.net</email>),
   Oleg Bartunov (<email>oleg@sai.msu.su</email>),
   Janko Richter (<email>jankorichter@yahoo.de</email>), and
   Paul Jungwirth (<email>pj@illuminatedcomputing.com</email>).  See
   <ulink url="http://www.sai.msu.su/~megera/postgres/gist/"></ulink>
   for additional information.
  </para>

 </sect2>

</sect1>

Title: Btree_Gist: Example Usage and Authors
Summary
The btree_gist module provides examples of its usage, including creating indexes and performing nearest-neighbor searches, as well as exclusion constraints to enforce rules such as uniqueness, and lists its authors, including Teodor Sigaev, Oleg Bartunov, Janko Richter, and Paul Jungwirth.