2010-08-02 18:26:48 +02:00
|
|
|
<!-- $PostgreSQL: pgsql/doc/src/sgml/btree-gist.sgml,v 1.6 2010/08/02 16:26:48 rhaas Exp $ -->
|
2007-12-06 05:12:10 +01:00
|
|
|
|
2007-12-02 23:33:20 +01:00
|
|
|
<sect1 id="btree-gist">
|
|
|
|
<title>btree_gist</title>
|
2007-12-06 05:12:10 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<indexterm zone="btree-gist">
|
2007-12-02 23:33:20 +01:00
|
|
|
<primary>btree_gist</primary>
|
2007-11-11 00:30:46 +01:00
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<para>
|
2007-12-06 05:12:10 +01:00
|
|
|
<filename>btree_gist</> provides sample GiST operator classes that
|
|
|
|
implement B-Tree equivalent behavior for the data types
|
|
|
|
<type>int2</>, <type>int4</>, <type>int8</>, <type>float4</>,
|
|
|
|
<type>float8</>, <type>numeric</>, <type>timestamp with time zone</>,
|
|
|
|
<type>timestamp without time zone</>, <type>time with time zone</>,
|
|
|
|
<type>time without time zone</>, <type>date</>, <type>interval</>,
|
|
|
|
<type>oid</>, <type>money</>, <type>char</>,
|
|
|
|
<type>varchar</>, <type>text</>, <type>bytea</>, <type>bit</>,
|
|
|
|
<type>varbit</>, <type>macaddr</>, <type>inet</>, and <type>cidr</>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
In general, these operator classes will not outperform the equivalent
|
|
|
|
standard btree index methods, and they lack one major feature of the
|
|
|
|
standard btree code: the ability to enforce uniqueness. However,
|
|
|
|
they are useful for GiST testing and as a base for developing other
|
|
|
|
GiST operator classes.
|
2007-11-11 00:30:46 +01:00
|
|
|
</para>
|
|
|
|
|
2010-08-02 18:26:48 +02:00
|
|
|
<para>
|
|
|
|
In addition to the typical btree search operators, btree_gist also
|
|
|
|
provides search operators for <literal><></literal> ("not
|
|
|
|
equals"). This may be useful in combination with an
|
|
|
|
<link linkend="SQL-CREATETABLE-EXCLUDE">Exclusion Constraint</link>,
|
|
|
|
as descibed below.
|
|
|
|
</para>
|
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<sect2>
|
|
|
|
<title>Example usage</title>
|
2007-12-06 05:12:10 +01:00
|
|
|
|
2010-08-02 18:26:48 +02:00
|
|
|
<para>
|
|
|
|
Simple example using btree_gist instead of btree:
|
|
|
|
</para>
|
|
|
|
|
2007-12-06 05:12:10 +01:00
|
|
|
<programlisting>
|
|
|
|
CREATE TABLE test (a int4);
|
|
|
|
-- create index
|
|
|
|
CREATE INDEX testidx ON test USING gist (a);
|
|
|
|
-- query
|
|
|
|
SELECT * FROM test WHERE a < 10;
|
2010-08-02 18:26:48 +02:00
|
|
|
</programlisting>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Example using an <link linkend="SQL-CREATETABLE-EXCLUDE">Exclusion
|
|
|
|
Constraint</link> to enforce the constraint that a cage at a zoo
|
|
|
|
can contain only one kind of animal:
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
=> CREATE TABLE zoo (
|
|
|
|
cage INTEGER,
|
|
|
|
animal TEXT,
|
|
|
|
EXCLUDE USING gist (cage WITH =, animal WITH <>)
|
|
|
|
);
|
|
|
|
|
|
|
|
=> INSERT INTO zoo VALUES(123, 'zebra');
|
|
|
|
INSERT 0 1
|
|
|
|
=> INSERT INTO zoo VALUES(123, 'zebra');
|
|
|
|
INSERT 0 1
|
|
|
|
=> 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).
|
|
|
|
=> INSERT INTO zoo VALUES(124, 'lion');
|
|
|
|
INSERT 0 1
|
2007-12-06 05:12:10 +01:00
|
|
|
</programlisting>
|
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
</sect2>
|
2007-12-06 05:12:10 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<sect2>
|
|
|
|
<title>Authors</title>
|
2007-12-06 05:12:10 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<para>
|
2007-12-06 05:12:10 +01:00
|
|
|
Teodor Sigaev (<email>teodor@stack.net</email>) ,
|
|
|
|
Oleg Bartunov (<email>oleg@sai.msu.su</email>), and
|
|
|
|
Janko Richter (<email>jankorichter@yahoo.de</email>). See
|
2010-03-17 18:12:31 +01:00
|
|
|
<ulink url="http://www.sai.msu.su/~megera/postgres/gist/"></ulink>
|
2007-12-06 05:12:10 +01:00
|
|
|
for additional information.
|
2007-11-11 00:30:46 +01:00
|
|
|
</para>
|
2007-12-06 05:12:10 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
</sect2>
|
|
|
|
|
|
|
|
</sect1>
|