diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2003-11-12 21:15:59 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2003-11-12 21:15:59 +0000 |
| commit | fa5c8a055a02e44f446e4593e397c33a572c4d67 (patch) | |
| tree | 9c0a7ded5a88c082c28dbe2b431660813abd72b8 /doc/src | |
| parent | 49f98fa833407b4e4252e42522e640ec8a0d08b2 (diff) | |
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.
Diffstat (limited to 'doc/src')
| -rw-r--r-- | doc/src/sgml/catalogs.sgml | 21 | ||||
| -rw-r--r-- | doc/src/sgml/xindex.sgml | 69 |
2 files changed, 85 insertions, 5 deletions
diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index bd208906dfe..37f8b9cd659 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -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"> @@ -500,6 +500,14 @@ </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> <entry></entry> @@ -563,6 +571,13 @@ </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> <entry></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> diff --git a/doc/src/sgml/xindex.sgml b/doc/src/sgml/xindex.sgml index 85aba8abe70..877709cee68 100644 --- a/doc/src/sgml/xindex.sgml +++ b/doc/src/sgml/xindex.sgml @@ -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> |
