mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Cross-data-type comparisons are now indexable by btrees, pursuant to my
pghackers proposal of 8-Nov. All the existing cross-type comparison operators (int2/int4/int8 and float4/float8) have appropriate support. The original proposal of storing the right-hand-side datatype as part of the primary key for pg_amop and pg_amproc got modified a bit in the event; it is easier to store zero as the 'default' case and only store a nonzero when the operator is actually cross-type. Along the way, remove the long-since-defunct bigbox_ops operator class.
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
<!--
|
||||
Documentation of the system catalogs, directed toward PostgreSQL developers
|
||||
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.78 2003/11/02 12:53:57 petere Exp $
|
||||
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.79 2003/11/12 21:15:42 tgl Exp $
|
||||
-->
|
||||
|
||||
<chapter id="catalogs">
|
||||
@ -499,6 +499,14 @@
|
||||
<entry>The index operator class this entry is for</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry><structfield>amopsubtype</structfield></entry>
|
||||
<entry><type>oid</type></entry>
|
||||
<entry><literal><link linkend="catalog-pg-type"><structname>pg_type</structname></link>.oid</literal></entry>
|
||||
<entry>Subtype to distinguish multiple entries for one strategy;
|
||||
zero for default</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry><structfield>amopstrategy</structfield></entry>
|
||||
<entry><type>int2</type></entry>
|
||||
@ -562,6 +570,13 @@
|
||||
<entry>The index operator class this entry is for</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry><structfield>amprocsubtype</structfield></entry>
|
||||
<entry><type>oid</type></entry>
|
||||
<entry><literal><link linkend="catalog-pg-type"><structname>pg_type</structname></link>.oid</literal></entry>
|
||||
<entry>Subtype, if cross-type routine, else zero</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry><structfield>amprocnum</structfield></entry>
|
||||
<entry><type>int2</type></entry>
|
||||
@ -2435,7 +2450,7 @@
|
||||
<entry><structfield>opcintype</structfield></entry>
|
||||
<entry><type>oid</type></entry>
|
||||
<entry><literal><link linkend="catalog-pg-type"><structname>pg_type</structname></link>.oid</literal></entry>
|
||||
<entry>Input data type of the operator class</entry>
|
||||
<entry>Data type that the operator class indexes</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
@ -2449,7 +2464,7 @@
|
||||
<entry><structfield>opckeytype</structfield></entry>
|
||||
<entry><type>oid</type></entry>
|
||||
<entry><literal><link linkend="catalog-pg-type"><structname>pg_type</structname></link>.oid</literal></entry>
|
||||
<entry>Type of index data, or zero if same as <structfield>opcintype</></entry>
|
||||
<entry>Type of data stored in index, or zero if same as <structfield>opcintype</></entry>
|
||||
</row>
|
||||
|
||||
</tbody>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
$Header: /cvsroot/pgsql/doc/src/sgml/xindex.sgml,v 1.34 2003/11/01 01:56:29 petere Exp $
|
||||
$Header: /cvsroot/pgsql/doc/src/sgml/xindex.sgml,v 1.35 2003/11/12 21:15:45 tgl Exp $
|
||||
-->
|
||||
|
||||
<sect1 id="xindex">
|
||||
@ -80,7 +80,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/xindex.sgml,v 1.34 2003/11/01 01:56:29 pete
|
||||
The same operator class name
|
||||
can be used for several different index methods (for example, both B-tree
|
||||
and hash index methods have operator classes named
|
||||
<literal>oid_ops</literal>), but each such class is an independent
|
||||
<literal>int4_ops</literal>), but each such class is an independent
|
||||
entity and must be defined separately.
|
||||
</para>
|
||||
</sect2>
|
||||
@ -589,6 +589,71 @@ CREATE OPERATOR CLASS complex_abs_ops
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
<sect2 id="xindex-opclass-crosstype">
|
||||
<title>Cross-Data-Type Operator Classes</title>
|
||||
|
||||
<para>
|
||||
So far we have implicitly assumed that an operator class deals with
|
||||
only one data type. While there certainly can be only one data type in
|
||||
a particular index column, it is often useful to index operations that
|
||||
compare an indexed column to a value of a different data type. This is
|
||||
presently supported by the B-tree and GiST index methods.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
B-trees require the left-hand operand of each operator to be the indexed
|
||||
data type, but the right-hand operand can be of a different type. There
|
||||
must be a support function having a matching signature. For example,
|
||||
the built-in operator class for type <type>bigint</> (<type>int8</>)
|
||||
allows cross-type comparisons to <type>int4</> and <type>int2</>. It
|
||||
could be duplicated by this definition:
|
||||
|
||||
<programlisting>
|
||||
CREATE OPERATOR CLASS int8_ops
|
||||
DEFAULT FOR TYPE int8 USING btree AS
|
||||
-- standard int8 comparisons
|
||||
OPERATOR 1 < ,
|
||||
OPERATOR 2 <= ,
|
||||
OPERATOR 3 = ,
|
||||
OPERATOR 4 >= ,
|
||||
OPERATOR 5 > ,
|
||||
FUNCTION 1 btint8cmp(int8, int8) ,
|
||||
|
||||
-- cross-type comparisons to int2 (smallint)
|
||||
OPERATOR 1 < (int8, int2) ,
|
||||
OPERATOR 2 <= (int8, int2) ,
|
||||
OPERATOR 3 = (int8, int2) ,
|
||||
OPERATOR 4 >= (int8, int2) ,
|
||||
OPERATOR 5 > (int8, int2) ,
|
||||
FUNCTION 1 btint82cmp(int8, int2) ,
|
||||
|
||||
-- cross-type comparisons to int4 (integer)
|
||||
OPERATOR 1 < (int8, int4) ,
|
||||
OPERATOR 2 <= (int8, int4) ,
|
||||
OPERATOR 3 = (int8, int4) ,
|
||||
OPERATOR 4 >= (int8, int4) ,
|
||||
OPERATOR 5 > (int8, int4) ,
|
||||
FUNCTION 1 btint84cmp(int8, int4) ;
|
||||
</programlisting>
|
||||
|
||||
Notice that this definition <quote>overloads</> the operator strategy and
|
||||
support function numbers. This is allowed (for B-tree operator classes
|
||||
only) so long as each instance of a particular number has a different
|
||||
right-hand data type. The instances that are not cross-type are the
|
||||
default or primary operators of the operator class.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
GiST indexes do not allow overloading of strategy or support function
|
||||
numbers, but it is still possible to get the effect of supporting
|
||||
multiple right-hand data types, by assigning a distinct strategy number
|
||||
to each operator that needs to be supported. The <literal>consistent</>
|
||||
support function must determine what it needs to do based on the strategy
|
||||
number, and must be prepared to accept comparison values of the appropriate
|
||||
data types.
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
<sect2 id="xindex-opclass-dependencies">
|
||||
<title>System Dependencies on Operator Classes</title>
|
||||
|
||||
|
Reference in New Issue
Block a user