OPERATOR CLASS commands. Further tweaking of documentation for same.
begin transaction;
--- create type of int4 key
+-- Adjust this setting to control where the objects get created.
+SET search_path = public;
+
+-- create type of int4 key
CREATE FUNCTION int4key_in(opaque)
RETURNS opaque
AS 'MODULE_PATHNAME'
create function gint4_same(opaque, opaque, opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
--- add a new opclass
-INSERT INTO pg_opclass (opcamid, opcname, opcnamespace, opcowner, opcintype, opcdefault, opckeytype)
- VALUES (
- (SELECT oid FROM pg_am WHERE amname = 'gist'),
- 'gist_int4_ops',
- (SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog'),
- 1, -- UID of superuser is hardwired to 1 as of PG 7.3
- (SELECT oid FROM pg_type WHERE typname = 'int4'),
- true,
- (SELECT oid FROM pg_type WHERE typname = 'int4key'));
-
-
-SELECT o.oid AS opoid, o.oprname
-INTO TABLE int_ops_tmp
-FROM pg_operator o, pg_type t
-WHERE o.oprleft = t.oid and o.oprright = t.oid
- and t.typname = 'int4';
-
--- get the comparators for int4es and store them in a tmp table
-INSERT INTO pg_amop (amopclaid, amopopr, amopstrategy, amopreqcheck)
- SELECT opcl.oid, c.opoid, 1, 'f'
- FROM pg_opclass opcl, int_ops_tmp c
- WHERE opcname = 'gist_int4_ops'
- and c.oprname = '<';
-
-INSERT INTO pg_amop (amopclaid, amopopr, amopstrategy, amopreqcheck)
- SELECT opcl.oid, c.opoid, 2, 'f'
- FROM pg_opclass opcl, int_ops_tmp c
- WHERE opcname = 'gist_int4_ops'
- and c.oprname = '<=';
-
-INSERT INTO pg_amop (amopclaid, amopopr, amopstrategy, amopreqcheck)
- SELECT opcl.oid, c.opoid, 3, 'f'
- FROM pg_opclass opcl, int_ops_tmp c
- WHERE opcname = 'gist_int4_ops'
- and c.oprname = '=';
-
-INSERT INTO pg_amop (amopclaid, amopopr, amopstrategy, amopreqcheck)
- SELECT opcl.oid, c.opoid, 4, 'f'
- FROM pg_opclass opcl, int_ops_tmp c
- WHERE opcname = 'gist_int4_ops'
- and c.oprname = '>=';
-
-INSERT INTO pg_amop (amopclaid, amopopr, amopstrategy, amopreqcheck)
- SELECT opcl.oid, c.opoid, 5, 'f'
- FROM pg_opclass opcl, int_ops_tmp c
- WHERE opcname = 'gist_int4_ops'
- and c.oprname = '>';
-
-
-DROP table int_ops_tmp;
-
--- add the entries to amproc for the support methods
--- note the amprocnum numbers associated with each are specific!
-INSERT INTO pg_amproc (amopclaid, amproc, amprocnum)
- SELECT opcl.oid, pro.oid, 1
- FROM pg_opclass opcl, pg_proc pro
- WHERE opcname = 'gist_int4_ops'
- and proname = 'gint4_consistent';
-
-INSERT INTO pg_amproc (amopclaid, amproc, amprocnum)
- SELECT opcl.oid, pro.oid, 2
- FROM pg_opclass opcl, pg_proc pro
- WHERE opcname = 'gist_int4_ops'
- and proname = 'gint4_union';
-
-INSERT INTO pg_amproc (amopclaid, amproc, amprocnum)
- SELECT opcl.oid, pro.oid, 3
- FROM pg_opclass opcl, pg_proc pro
- WHERE opcname = 'gist_int4_ops'
- and proname = 'gint4_compress';
-
-INSERT INTO pg_amproc (amopclaid, amproc, amprocnum)
- SELECT opcl.oid, pro.oid, 4
- FROM pg_opclass opcl, pg_proc pro
- WHERE opcname = 'gist_int4_ops'
- and proname = 'btree_decompress';
+-- Create the operator class
+CREATE OPERATOR CLASS gist_int4_ops
+ DEFAULT FOR TYPE int4 USING gist AS
+ OPERATOR 1 < ,
+ OPERATOR 2 <= ,
+ OPERATOR 3 = ,
+ OPERATOR 4 >= ,
+ OPERATOR 5 > ,
+ FUNCTION 1 gint4_consistent (opaque, int4, int2),
+ FUNCTION 2 gint4_union (bytea, opaque),
+ FUNCTION 3 gint4_compress (opaque),
+ FUNCTION 4 btree_decompress (opaque),
+ FUNCTION 5 gint4_penalty (opaque, opaque, opaque),
+ FUNCTION 6 gint4_picksplit (opaque, opaque),
+ FUNCTION 7 gint4_same (opaque, opaque, opaque),
+ STORAGE int4key;
-INSERT INTO pg_amproc (amopclaid, amproc, amprocnum)
- SELECT opcl.oid, pro.oid, 5
- FROM pg_opclass opcl, pg_proc pro
- WHERE opcname = 'gist_int4_ops'
- and proname = 'gint4_penalty';
-
-INSERT INTO pg_amproc (amopclaid, amproc, amprocnum)
- SELECT opcl.oid, pro.oid, 6
- FROM pg_opclass opcl, pg_proc pro
- WHERE opcname = 'gist_int4_ops'
- and proname = 'gint4_picksplit';
-
-INSERT INTO pg_amproc (amopclaid, amproc, amprocnum)
- SELECT opcl.oid, pro.oid, 7
- FROM pg_opclass opcl, pg_proc pro
- WHERE opcname = 'gist_int4_ops'
- and proname = 'gint4_same';
--
--
create function gts_same(opaque, opaque, opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
--- add a new opclass
-INSERT INTO pg_opclass (opcamid, opcname, opcnamespace, opcowner, opcintype, opcdefault, opckeytype)
- VALUES (
- (SELECT oid FROM pg_am WHERE amname = 'gist'),
- 'gist_timestamp_ops',
- (SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog'),
- 1, -- UID of superuser is hardwired to 1 as of PG 7.3
- (SELECT oid FROM pg_type WHERE typname = 'timestamp'),
- true,
- (SELECT oid FROM pg_type WHERE typname = 'tskey'));
-
-SELECT o.oid AS opoid, o.oprname
-INTO TABLE timestamp_ops_tmp
-FROM pg_operator o, pg_type t
-WHERE o.oprleft = t.oid and o.oprright = t.oid
- and t.typname = 'timestamp';
-
-INSERT INTO pg_amop (amopclaid, amopopr, amopstrategy, amopreqcheck)
- SELECT opcl.oid, c.opoid, 1, 'f'
- FROM pg_opclass opcl, timestamp_ops_tmp c
- WHERE opcname = 'gist_timestamp_ops'
- and c.oprname = '<';
-
-INSERT INTO pg_amop (amopclaid, amopopr, amopstrategy, amopreqcheck)
- SELECT opcl.oid, c.opoid, 2, 'f'
- FROM pg_opclass opcl, timestamp_ops_tmp c
- WHERE opcname = 'gist_timestamp_ops'
- and c.oprname = '<=';
-
-INSERT INTO pg_amop (amopclaid, amopopr, amopstrategy, amopreqcheck)
- SELECT opcl.oid, c.opoid, 3, 'f'
- FROM pg_opclass opcl, timestamp_ops_tmp c
- WHERE opcname = 'gist_timestamp_ops'
- and c.oprname = '=';
-
-INSERT INTO pg_amop (amopclaid, amopopr, amopstrategy, amopreqcheck)
- SELECT opcl.oid, c.opoid, 4, 'f'
- FROM pg_opclass opcl, timestamp_ops_tmp c
- WHERE opcname = 'gist_timestamp_ops'
- and c.oprname = '>=';
-
-INSERT INTO pg_amop (amopclaid, amopopr, amopstrategy, amopreqcheck)
- SELECT opcl.oid, c.opoid, 5, 'f'
- FROM pg_opclass opcl, timestamp_ops_tmp c
- WHERE opcname = 'gist_timestamp_ops'
- and c.oprname = '>';
+-- Create the operator class
+CREATE OPERATOR CLASS gist_timestamp_ops
+ DEFAULT FOR TYPE timestamp USING gist AS
+ OPERATOR 1 < ,
+ OPERATOR 2 <= ,
+ OPERATOR 3 = ,
+ OPERATOR 4 >= ,
+ OPERATOR 5 > ,
+ FUNCTION 1 gts_consistent (opaque, timestamp, int2),
+ FUNCTION 2 gts_union (bytea, opaque),
+ FUNCTION 3 gts_compress (opaque),
+ FUNCTION 4 btree_decompress (opaque),
+ FUNCTION 5 gts_penalty (opaque, opaque, opaque),
+ FUNCTION 6 gts_picksplit (opaque, opaque),
+ FUNCTION 7 gts_same (opaque, opaque, opaque),
+ STORAGE tskey;
-DROP table timestamp_ops_tmp;
-
--- add the entries to amproc for the support methods
--- note the amprocnum numbers associated with each are specific!
-INSERT INTO pg_amproc (amopclaid, amproc, amprocnum)
- SELECT opcl.oid, pro.oid, 1
- FROM pg_opclass opcl, pg_proc pro
- WHERE opcname = 'gist_timestamp_ops'
- and proname = 'gts_consistent';
-
-INSERT INTO pg_amproc (amopclaid, amproc, amprocnum)
- SELECT opcl.oid, pro.oid, 2
- FROM pg_opclass opcl, pg_proc pro
- WHERE opcname = 'gist_timestamp_ops'
- and proname = 'gts_union';
-
-INSERT INTO pg_amproc (amopclaid, amproc, amprocnum)
- SELECT opcl.oid, pro.oid, 3
- FROM pg_opclass opcl, pg_proc pro
- WHERE opcname = 'gist_timestamp_ops'
- and proname = 'gts_compress';
-
-INSERT INTO pg_amproc (amopclaid, amproc, amprocnum)
- SELECT opcl.oid, pro.oid, 4
- FROM pg_opclass opcl, pg_proc pro
- WHERE opcname = 'gist_timestamp_ops'
- and proname = 'btree_decompress';
-
-INSERT INTO pg_amproc (amopclaid, amproc, amprocnum)
- SELECT opcl.oid, pro.oid, 5
- FROM pg_opclass opcl, pg_proc pro
- WHERE opcname = 'gist_timestamp_ops'
- and proname = 'gts_penalty';
-
-INSERT INTO pg_amproc (amopclaid, amproc, amprocnum)
- SELECT opcl.oid, pro.oid, 6
- FROM pg_opclass opcl, pg_proc pro
- WHERE opcname = 'gist_timestamp_ops'
- and proname = 'gts_picksplit';
-
-INSERT INTO pg_amproc (amopclaid, amproc, amprocnum)
- SELECT opcl.oid, pro.oid, 7
- FROM pg_opclass opcl, pg_proc pro
- WHERE opcname = 'gist_timestamp_ops'
- and proname = 'gts_same';
end transaction;
-
--
BEGIN TRANSACTION;
+-- Adjust this setting to control where the objects get created.
+SET search_path = public;
+
CREATE FUNCTION cube_in(opaque)
RETURNS opaque
AS 'MODULE_PATHNAME'
AS 'MODULE_PATHNAME' LANGUAGE 'c';
--- register the default opclass for indexing
-INSERT INTO pg_opclass (opcamid, opcname, opcnamespace, opcowner, opcintype, opcdefault, opckeytype)
- VALUES (
- (SELECT oid FROM pg_am WHERE amname = 'gist'),
- 'gist_cube_ops',
- (SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog'),
- 1, -- UID of superuser is hardwired to 1 as of PG 7.3
- (SELECT oid FROM pg_type WHERE typname = 'cube'),
- true,
- 0);
-
-
--- get the comparators for boxes and store them in a tmp table
-SELECT o.oid AS opoid, o.oprname
-INTO TEMP TABLE gist_cube_ops_tmp
-FROM pg_operator o, pg_type t
-WHERE o.oprleft = t.oid and o.oprright = t.oid
- and t.typname = 'cube';
-
--- make sure we have the right operators
--- SELECT * from gist_cube_ops_tmp;
-
--- using the tmp table, generate the amop entries
-
--- cube_left
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 1, false, c.opoid
- FROM pg_opclass opcl, gist_cube_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_cube_ops'
- and c.oprname = '<<';
-
--- cube_over_left
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 2, false, c.opoid
- FROM pg_opclass opcl, gist_cube_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_cube_ops'
- and c.oprname = '&<';
-
--- cube_overlap
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 3, false, c.opoid
- FROM pg_opclass opcl, gist_cube_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_cube_ops'
- and c.oprname = '&&';
-
--- cube_over_right
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 4, false, c.opoid
- FROM pg_opclass opcl, gist_cube_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_cube_ops'
- and c.oprname = '&>';
-
--- cube_right
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 5, false, c.opoid
- FROM pg_opclass opcl, gist_cube_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_cube_ops'
- and c.oprname = '>>';
-
--- cube_same
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 6, false, c.opoid
- FROM pg_opclass opcl, gist_cube_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_cube_ops'
- and c.oprname = '=';
-
--- cube_contains
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 7, false, c.opoid
- FROM pg_opclass opcl, gist_cube_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_cube_ops'
- and c.oprname = '@';
-
--- cube_contained
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 8, false, c.opoid
- FROM pg_opclass opcl, gist_cube_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_cube_ops'
- and c.oprname = '~';
-
-DROP TABLE gist_cube_ops_tmp;
-
-
--- add the entries to amproc for the support methods
--- note the amprocnum numbers associated with each are specific!
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 1, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_cube_ops'
- and proname = 'g_cube_consistent';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 2, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_cube_ops'
- and proname = 'g_cube_union';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 3, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_cube_ops'
- and proname = 'g_cube_compress';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 4, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_cube_ops'
- and proname = 'g_cube_decompress';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 5, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_cube_ops'
- and proname = 'g_cube_penalty';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 6, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_cube_ops'
- and proname = 'g_cube_picksplit';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 7, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_cube_ops'
- and proname = 'g_cube_same';
+-- Create the operator class for indexing
+
+CREATE OPERATOR CLASS gist_cube_ops
+ DEFAULT FOR TYPE cube USING gist AS
+ OPERATOR 1 << ,
+ OPERATOR 2 &< ,
+ OPERATOR 3 && ,
+ OPERATOR 4 &> ,
+ OPERATOR 5 >> ,
+ OPERATOR 6 = ,
+ OPERATOR 7 @ ,
+ OPERATOR 8 ~ ,
+ FUNCTION 1 g_cube_consistent (opaque, cube, int4),
+ FUNCTION 2 g_cube_union (bytea, opaque),
+ FUNCTION 3 g_cube_compress (opaque),
+ FUNCTION 4 g_cube_decompress (opaque),
+ FUNCTION 5 g_cube_penalty (opaque, opaque, opaque),
+ FUNCTION 6 g_cube_picksplit (opaque, opaque),
+ FUNCTION 7 g_cube_same (cube, cube, opaque);
+
END TRANSACTION;
--
-- PostgreSQL code for ISSNs.
--
--- $Id: isbn_issn.sql.in,v 1.4 2002/07/16 00:48:30 momjian Exp $
+-- $Id: isbn_issn.sql.in,v 1.5 2002/07/30 17:34:37 tgl Exp $
--
+-- Adjust this setting to control where the objects get created.
+SET search_path = public;
+
--
-- Input and output functions and the type itself:
--
-- PostgreSQL code for ISBNs.
--
--- $Id: isbn_issn.sql.in,v 1.4 2002/07/16 00:48:30 momjian Exp $
+-- $Id: isbn_issn.sql.in,v 1.5 2002/07/30 17:34:37 tgl Exp $
--
--
-- Input and output functions and the type itself:
);
--------------------------------------------------
--- Create default operator class for 'isbn' --
--- Needed to create index or primary key --
--------------------------------------------------
-
--- Register new operator class with system catalog pg_opclass
-insert into pg_opclass
- (opcamid, opcname, opcintype, opcdefault, opckeytype)
- values ((select oid from pg_am where amname = 'btree'),
- 'isbn_ops',
- (select oid from pg_type where typname = 'isbn'),
- true,
- 0);
-
--- Verify that new operator class was added to pg_opclass
--- select oid,* from pg_opclass where opcname = 'isbn_ops';
-
--- Identify comparison operators for 'isbn' type
-select o.oid as opoid, o.oprname
- into temp table isbn_ops_tmp
- from pg_operator o, pg_type t
- where o.oprleft = t.oid
- and o.oprright = t.oid
- and t.typname = 'isbn';
-
--- Make sure all 5 needed order ops are there (<, <=, =, >=, >)
--- Operator <> will be present but is not needed
--- select * from isbn_ops_tmp order by opoid;
-
--- Associate B-tree strategy 1 with <
-insert into pg_amop
- (amopclaid, amopstrategy, amopreqcheck, amopopr)
- select opcl.oid, 1, false, c.opoid
- from pg_opclass opcl, isbn_ops_tmp c
- where opcamid = (select oid from pg_am where amname = 'btree')
- and opcname = 'isbn_ops'
- and c.oprname = '<';
-
--- Associate B-tree strategy 2 with <=
-insert into pg_amop
- (amopclaid, amopstrategy, amopreqcheck, amopopr)
- select opcl.oid, 2, false, c.opoid
- from pg_opclass opcl, isbn_ops_tmp c
- where opcamid = (select oid from pg_am where amname = 'btree')
- and opcname = 'isbn_ops'
- and c.oprname = '<=';
-
--- Associate B-tree strategy 3 with =
-insert into pg_amop
- (amopclaid, amopstrategy, amopreqcheck, amopopr)
- select opcl.oid, 3, false, c.opoid
- from pg_opclass opcl, isbn_ops_tmp c
- where opcamid = (select oid from pg_am where amname = 'btree')
- and opcname = 'isbn_ops'
- and c.oprname = '=';
-
--- Associate B-tree strategy 4 with >=
-insert into pg_amop
- (amopclaid, amopstrategy, amopreqcheck, amopopr)
- select opcl.oid, 4, false, c.opoid
- from pg_opclass opcl, isbn_ops_tmp c
- where opcamid = (select oid from pg_am where amname = 'btree')
- and opcname = 'isbn_ops'
- and c.oprname = '>=';
-
--- Associate B-tree strategy 5 with >
-insert into pg_amop
- (amopclaid, amopstrategy, amopreqcheck, amopopr)
- select opcl.oid, 5, false, c.opoid
- from pg_opclass opcl, isbn_ops_tmp c
- where opcamid = (select oid from pg_am where amname = 'btree')
- and opcname = 'isbn_ops'
- and c.oprname = '>';
-
-- Register 'isbn' comparison function
create function isbn_cmp(isbn, isbn)
returns integer
as '$libdir/isbn_issn'
language c;
--- Make sure that function was correctly registered
--- select oid, proname from pg_proc where proname = 'isbn_cmp';
+-- Register 'issn' comparison function
+create function issn_cmp(issn, issn)
+ returns integer
+ as '$libdir/isbn_issn'
+ language c;
--- Associate default btree operator class with 'isbn' comparison function
-insert into pg_amproc
- (amopclaid, amprocnum, amproc)
- select opcl.oid, 1, p.oid
- from pg_opclass opcl, pg_proc p
- where opcamid = (select oid from pg_am where amname = 'btree')
- and opcname = 'isbn_ops'
- and p.proname = 'isbn_cmp';
+-------------------------------------------------
+-- Create default operator class for 'isbn' --
+-- Needed to create index or primary key --
+-------------------------------------------------
+CREATE OPERATOR CLASS isbn_ops
+ DEFAULT FOR TYPE isbn USING btree AS
+ OPERATOR 1 < ,
+ OPERATOR 2 <= ,
+ OPERATOR 3 = ,
+ OPERATOR 4 >= ,
+ OPERATOR 5 > ,
+ FUNCTION 1 isbn_cmp(isbn, isbn);
-------------------------------------------------
-- Create default operator class for 'issn' --
-- Needed to create index or primary key --
-------------------------------------------------
--- Register new operator class with system catalog pg_opclass
-insert into pg_opclass
- (opcamid, opcname, opcintype, opcdefault, opckeytype)
- values ((select oid from pg_am where amname = 'btree'),
- 'issn_ops',
- (select oid from pg_type where typname = 'issn'),
- true,
- 0);
-
--- Verify that new operator class was added to pg_opclass
--- select oid,* from pg_opclass where opcname = 'issn_ops';
-
--- Identify comparison operators for 'issn' type
-select o.oid as opoid, o.oprname
- into temp table issn_ops_tmp
- from pg_operator o, pg_type t
- where o.oprleft = t.oid
- and o.oprright = t.oid
- and t.typname = 'issn';
-
--- Make sure all 5 needed order ops are there (<, <=, =, >=, >)
--- Operator <> will be present but is not needed
--- select * from issn_ops_tmp order by opoid;
-
--- Associate B-tree strategy 1 with <
-insert into pg_amop
- (amopclaid, amopstrategy, amopreqcheck, amopopr)
- select opcl.oid, 1, false, c.opoid
- from pg_opclass opcl, issn_ops_tmp c
- where opcamid = (select oid from pg_am where amname = 'btree')
- and opcname = 'issn_ops'
- and c.oprname = '<';
-
--- Associate B-tree strategy 2 with <=
-insert into pg_amop
- (amopclaid, amopstrategy, amopreqcheck, amopopr)
- select opcl.oid, 2, false, c.opoid
- from pg_opclass opcl, issn_ops_tmp c
- where opcamid = (select oid from pg_am where amname = 'btree')
- and opcname = 'issn_ops'
- and c.oprname = '<=';
-
--- Associate B-tree strategy 3 with =
-insert into pg_amop
- (amopclaid, amopstrategy, amopreqcheck, amopopr)
- select opcl.oid, 3, false, c.opoid
- from pg_opclass opcl, issn_ops_tmp c
- where opcamid = (select oid from pg_am where amname = 'btree')
- and opcname = 'issn_ops'
- and c.oprname = '=';
-
--- Associate B-tree strategy 4 with >=
-insert into pg_amop
- (amopclaid, amopstrategy, amopreqcheck, amopopr)
- select opcl.oid, 4, false, c.opoid
- from pg_opclass opcl, issn_ops_tmp c
- where opcamid = (select oid from pg_am where amname = 'btree')
- and opcname = 'issn_ops'
- and c.oprname = '>=';
-
--- Associate B-tree strategy 5 with >
-insert into pg_amop
- (amopclaid, amopstrategy, amopreqcheck, amopopr)
- select opcl.oid, 5, false, c.opoid
- from pg_opclass opcl, issn_ops_tmp c
- where opcamid = (select oid from pg_am where amname = 'btree')
- and opcname = 'issn_ops'
- and c.oprname = '>';
-
--- Register 'issn' comparison function
-create function issn_cmp(issn, issn)
- returns integer
- as '$libdir/issn_issn'
- language c;
+CREATE OPERATOR CLASS issn_ops
+ DEFAULT FOR TYPE issn USING btree AS
+ OPERATOR 1 < ,
+ OPERATOR 2 <= ,
+ OPERATOR 3 = ,
+ OPERATOR 4 >= ,
+ OPERATOR 5 > ,
+ FUNCTION 1 issn_cmp(issn, issn);
--- Make sure that function was correctly registered
--- select oid, proname from pg_proc where proname = 'issn_cmp';
-
--- Associate default btree operator class with 'issn' comparison function
-insert into pg_amproc
- (amopclaid, amprocnum, amproc)
- select opcl.oid, 1, p.oid
- from pg_opclass opcl, pg_proc p
- where opcamid = (select oid from pg_am where amname = 'btree')
- and opcname = 'issn_ops'
- and p.proname = 'issn_cmp';
--
-- eof
begin transaction;
+
+-- Adjust this setting to control where the objects get created.
+SET search_path = public;
+
--
--
--
create function gbox_same(box, box, opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
--- add a new opclass
-INSERT INTO pg_opclass (opcamid, opcname, opcnamespace, opcowner, opcintype, opcdefault, opckeytype)
- VALUES (
- (SELECT oid FROM pg_am WHERE amname = 'gist'),
- 'gist_box_ops',
- (SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog'),
- 1, -- UID of superuser is hardwired to 1 as of PG 7.3
- (SELECT oid FROM pg_type WHERE typname = 'box'),
- true,
- 0);
-
--- get the comparators for boxes and store them in a tmp table
-SELECT o.oid AS opoid, o.oprname
-INTO TEMP TABLE rt_ops_tmp
-FROM pg_operator o, pg_type t
-WHERE o.oprleft = t.oid
- and t.typname = 'box';
-
--- using the tmp table, generate the amop entries
--- box_left
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 1, false, c.opoid
- FROM pg_opclass opcl, rt_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_box_ops'
- and c.oprname = '<<';
-
--- box_overleft
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 2, false, c.opoid
- FROM pg_opclass opcl, rt_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_box_ops'
- and c.oprname = '&<';
-
--- box_overlap
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 3, false, c.opoid
- FROM pg_opclass opcl, rt_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_box_ops'
- and c.oprname = '&&';
-
--- box_overright
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 4, false, c.opoid
- FROM pg_opclass opcl, rt_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_box_ops'
- and c.oprname = '&>';
-
--- box_right
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 5, false, c.opoid
- FROM pg_opclass opcl, rt_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_box_ops'
- and c.oprname = '>>';
-
--- box_same
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 6, false, c.opoid
- FROM pg_opclass opcl, rt_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_box_ops'
- and c.oprname = '~=';
-
--- box_contains
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 7, false, c.opoid
- FROM pg_opclass opcl, rt_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_box_ops'
- and c.oprname = '~';
-
--- box_contained
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 8, false, c.opoid
- FROM pg_opclass opcl, rt_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_box_ops'
- and c.oprname = '@';
-
-DROP table rt_ops_tmp;
-
--- add the entries to amproc for the support methods
--- note the amprocnum numbers associated with each are specific!
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 1, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_box_ops'
- and proname = 'gbox_consistent';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 2, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_box_ops'
- and proname = 'gbox_union';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 3, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_box_ops'
- and proname = 'gbox_compress';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 4, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_box_ops'
- and proname = 'rtree_decompress';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 5, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_box_ops'
- and proname = 'gbox_penalty';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 6, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_box_ops'
- and proname = 'gbox_picksplit';
+-- create the operator class
+CREATE OPERATOR CLASS gist_box_ops
+ DEFAULT FOR TYPE box USING gist AS
+ OPERATOR 1 << ,
+ OPERATOR 2 &< ,
+ OPERATOR 3 && ,
+ OPERATOR 4 &> ,
+ OPERATOR 5 >> ,
+ OPERATOR 6 ~= ,
+ OPERATOR 7 ~ ,
+ OPERATOR 8 @ ,
+ FUNCTION 1 gbox_consistent (opaque, box, int4),
+ FUNCTION 2 gbox_union (bytea, opaque),
+ FUNCTION 3 gbox_compress (opaque),
+ FUNCTION 4 rtree_decompress (opaque),
+ FUNCTION 5 gbox_penalty (opaque, opaque, opaque),
+ FUNCTION 6 gbox_picksplit (opaque, opaque),
+ FUNCTION 7 gbox_same (box, box, opaque);
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 7, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_box_ops'
- and proname = 'gbox_same';
--
--
create function gpoly_compress(opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
--- add a new opclass
-INSERT INTO pg_opclass (opcamid, opcname, opcnamespace, opcowner, opcintype, opcdefault, opckeytype)
- VALUES (
- (SELECT oid FROM pg_am WHERE amname = 'gist'),
- 'gist_poly_ops',
- (SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog'),
- 1, -- UID of superuser is hardwired to 1 as of PG 7.3
- (SELECT oid FROM pg_type WHERE typname = 'polygon'),
- true,
- (SELECT oid FROM pg_type WHERE typname = 'box'));
+-- create the operator class
+CREATE OPERATOR CLASS gist_poly_ops
+ DEFAULT FOR TYPE polygon USING gist AS
+ OPERATOR 1 << RECHECK ,
+ OPERATOR 2 &< RECHECK ,
+ OPERATOR 3 && RECHECK ,
+ OPERATOR 4 &> RECHECK ,
+ OPERATOR 5 >> RECHECK ,
+ OPERATOR 6 ~= RECHECK ,
+ OPERATOR 7 ~ RECHECK ,
+ OPERATOR 8 @ RECHECK ,
+ FUNCTION 1 gpoly_consistent (opaque, polygon, int4),
+ FUNCTION 2 gbox_union (bytea, opaque),
+ FUNCTION 3 gpoly_compress (opaque),
+ FUNCTION 4 rtree_decompress (opaque),
+ FUNCTION 5 gbox_penalty (opaque, opaque, opaque),
+ FUNCTION 6 gbox_picksplit (opaque, opaque),
+ FUNCTION 7 gbox_same (box, box, opaque),
+ STORAGE box;
--- get the comparators for polygons and store them in a tmp table
--- hack for 757 (poly_contain_pt) Teodor
-SELECT o.oid AS opoid, o.oprname
-INTO TEMP TABLE rt_ops_tmp
-FROM pg_operator o, pg_type t
-WHERE o.oprleft = t.oid and o.oid <> 757
- and t.typname = 'polygon';
-
--- using the tmp table, generate the amop entries
--- poly_left
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 1, true, c.opoid
- FROM pg_opclass opcl, rt_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_poly_ops'
- and c.oprname = '<<';
-
--- poly_overleft
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 2, true, c.opoid
- FROM pg_opclass opcl, rt_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_poly_ops'
- and c.oprname = '&<';
-
--- poly_overlap
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 3, true, c.opoid
- FROM pg_opclass opcl, rt_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_poly_ops'
- and c.oprname = '&&';
-
--- poly_overright
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 4, true, c.opoid
- FROM pg_opclass opcl, rt_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_poly_ops'
- and c.oprname = '&>';
-
--- poly_right
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 5, true, c.opoid
- FROM pg_opclass opcl, rt_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_poly_ops'
- and c.oprname = '>>';
-
--- poly_same
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 6, true, c.opoid
- FROM pg_opclass opcl, rt_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_poly_ops'
- and c.oprname = '~=';
-
--- poly_contains
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 7, true, c.opoid
- FROM pg_opclass opcl, rt_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_poly_ops'
- and c.oprname = '~';
-
--- poly_contained
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 8, true, c.opoid
- FROM pg_opclass opcl, rt_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_poly_ops'
- and c.oprname = '@';
-
-DROP table rt_ops_tmp;
-
--- add the entries to amproc for the support methods
--- note the amprocnum numbers associated with each are specific!
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 1, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_poly_ops'
- and proname = 'gpoly_consistent';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 2, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_poly_ops'
- and proname = 'gbox_union';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 3, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_poly_ops'
- and proname = 'gpoly_compress';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 4, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_poly_ops'
- and proname = 'rtree_decompress';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 5, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_poly_ops'
- and proname = 'gbox_penalty';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 6, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_poly_ops'
- and proname = 'gbox_picksplit';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 7, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_poly_ops'
- and proname = 'gbox_same';
end transaction;
-
--
BEGIN TRANSACTION;
+-- Adjust this setting to control where the objects get created.
+SET search_path = public;
+
CREATE FUNCTION seg_in(opaque)
RETURNS opaque
AS 'MODULE_PATHNAME'
AS 'MODULE_PATHNAME' LANGUAGE 'c';
--- register the default opclass for indexing
-INSERT INTO pg_opclass (opcamid, opcname, opcnamespace, opcowner, opcintype, opcdefault, opckeytype)
- VALUES (
- (SELECT oid FROM pg_am WHERE amname = 'gist'),
- 'gist_seg_ops',
- (SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog'),
- 1, -- UID of superuser is hardwired to 1 as of PG 7.3
- (SELECT oid FROM pg_type WHERE typname = 'seg'),
- true,
- 0);
-
-
--- get the comparators for segments and store them in a tmp table
-SELECT o.oid AS opoid, o.oprname
-INTO TEMP TABLE seg_ops_tmp
-FROM pg_operator o, pg_type t
-WHERE o.oprleft = t.oid and o.oprright = t.oid
- and t.typname = 'seg';
-
--- make sure we have the right operators
--- SELECT * from seg_ops_tmp;
-
--- using the tmp table, generate the amop entries
-
--- seg_left
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 1, false, c.opoid
- FROM pg_opclass opcl, seg_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_seg_ops'
- and c.oprname = '<<';
-
--- seg_overleft
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 2, false, c.opoid
- FROM pg_opclass opcl, seg_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_seg_ops'
- and c.oprname = '&<';
-
--- seg_overlap
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 3, false, c.opoid
- FROM pg_opclass opcl, seg_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_seg_ops'
- and c.oprname = '&&';
-
--- seg_overright
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 4, false, c.opoid
- FROM pg_opclass opcl, seg_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_seg_ops'
- and c.oprname = '&>';
-
--- seg_right
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 5, false, c.opoid
- FROM pg_opclass opcl, seg_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_seg_ops'
- and c.oprname = '>>';
-
--- seg_same
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 6, false, c.opoid
- FROM pg_opclass opcl, seg_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_seg_ops'
- and c.oprname = '=';
-
--- seg_contains
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 7, false, c.opoid
- FROM pg_opclass opcl, seg_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_seg_ops'
- and c.oprname = '@';
-
--- seg_contained
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 8, false, c.opoid
- FROM pg_opclass opcl, seg_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_seg_ops'
- and c.oprname = '~';
-
-DROP TABLE seg_ops_tmp;
-
-
--- add the entries to amproc for the support methods
--- note the amprocnum numbers associated with each are specific!
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 1, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_seg_ops'
- and proname = 'gseg_consistent';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 2, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_seg_ops'
- and proname = 'gseg_union';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 3, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_seg_ops'
- and proname = 'gseg_compress';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 4, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_seg_ops'
- and proname = 'gseg_decompress';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 5, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_seg_ops'
- and proname = 'gseg_penalty';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 6, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_seg_ops'
- and proname = 'gseg_picksplit';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 7, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_seg_ops'
- and proname = 'gseg_same';
+-- Create the operator class for indexing
+
+CREATE OPERATOR CLASS gist_seg_ops
+ DEFAULT FOR TYPE seg USING gist AS
+ OPERATOR 1 << ,
+ OPERATOR 2 &< ,
+ OPERATOR 3 && ,
+ OPERATOR 4 &> ,
+ OPERATOR 5 >> ,
+ OPERATOR 6 = ,
+ OPERATOR 7 @ ,
+ OPERATOR 8 ~ ,
+ FUNCTION 1 gseg_consistent (opaque, seg, int4),
+ FUNCTION 2 gseg_union (bytea, opaque),
+ FUNCTION 3 gseg_compress (opaque),
+ FUNCTION 4 gseg_decompress (opaque),
+ FUNCTION 5 gseg_penalty (opaque, opaque, opaque),
+ FUNCTION 6 gseg_picksplit (opaque, opaque),
+ FUNCTION 7 gseg_same (seg, seg, opaque);
+
END TRANSACTION;
BEGIN TRANSACTION;
+-- Adjust this setting to control where the objects get created.
+SET search_path = public;
+
-- TXTIDX type
CREATE FUNCTION txtidx_in(opaque)
output = gtxtidx_out
);
+-- support functions
CREATE FUNCTION gtxtidx_consistent(gtxtidx,opaque,int4) RETURNS bool
AS 'MODULE_PATHNAME' LANGUAGE 'c';
CREATE FUNCTION gtxtidx_same(gtxtidx, gtxtidx, opaque) RETURNS opaque
AS 'MODULE_PATHNAME' LANGUAGE 'c';
-INSERT INTO pg_opclass (opcamid, opcname, opcnamespace, opcowner, opcintype, opcdefault, opckeytype)
- VALUES (
- (SELECT oid FROM pg_am WHERE amname = 'gist'),
- 'gist_txtidx_ops',
- (SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog'),
- 1, -- UID of superuser is hardwired to 1 as of PG 7.3
- (SELECT oid FROM pg_type WHERE typname = 'txtidx'),
- true,
- (SELECT oid FROM pg_type WHERE typname = 'gtxtidx'));
-
-SELECT o.oid AS opoid, o.oprname
-INTO TEMP TABLE txtidx_ops_tmp
-FROM pg_operator o, pg_type t, pg_type tq
-WHERE o.oprleft = t.oid and o.oprright=tq.oid
- and t.typname = 'txtidx'
- and ( tq.typname='query_txt' or tq.typname='mquery_txt' );
-
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 1, true, c.opoid
- FROM pg_opclass opcl, txtidx_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_txtidx_ops'
- and c.oprname = '@@';
-
-INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
- SELECT opcl.oid, 2, true, c.opoid
- FROM pg_opclass opcl, txtidx_ops_tmp c
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_txtidx_ops'
- and c.oprname = '##';
-
-DROP TABLE txtidx_ops_tmp;
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 1, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_txtidx_ops'
- and proname = 'gtxtidx_consistent';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 2, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_txtidx_ops'
- and proname = 'gtxtidx_union';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 3, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_txtidx_ops'
- and proname = 'gtxtidx_compress';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 4, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_txtidx_ops'
- and proname = 'gtxtidx_decompress';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 5, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_txtidx_ops'
- and proname = 'gtxtidx_penalty';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 6, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_txtidx_ops'
- and proname = 'gtxtidx_picksplit';
-
-INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
- SELECT opcl.oid, 7, pro.oid
- FROM pg_opclass opcl, pg_proc pro
- WHERE
- opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
- and opcname = 'gist_txtidx_ops'
- and proname = 'gtxtidx_same';
-
+-- create the operator class
+CREATE OPERATOR CLASS gist_txtidx_ops
+ DEFAULT FOR TYPE txtidx USING gist AS
+ OPERATOR 1 @@ (txtidx, query_txt) RECHECK ,
+ OPERATOR 2 ## (txtidx, mquery_txt) RECHECK ,
+ FUNCTION 1 gtxtidx_consistent (gtxtidx, opaque, int4),
+ FUNCTION 2 gtxtidx_union (bytea, opaque),
+ FUNCTION 3 gtxtidx_compress (opaque),
+ FUNCTION 4 gtxtidx_decompress (opaque),
+ FUNCTION 5 gtxtidx_penalty (opaque, opaque, opaque),
+ FUNCTION 6 gtxtidx_picksplit (opaque, opaque),
+ FUNCTION 7 gtxtidx_same (gtxtidx, gtxtidx, opaque),
+ STORAGE gtxtidx;
END TRANSACTION;
<!--
-$Header: /cvsroot/pgsql/doc/src/sgml/extend.sgml,v 1.15 2002/01/07 02:29:11 petere Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/extend.sgml,v 1.16 2002/07/30 17:34:37 tgl Exp $
-->
<chapter id="extend">
There are many columns and relationships that
have obvious meanings, but there are many
(particularly those that have to do with access
- methods) that do not. The relationships between
- <classname>pg_am</>, <classname>pg_amop</>, <classname>pg_amproc</>, <classname>pg_operator</>, and
- <classname>pg_opclass</> are particularly hard to understand
- and will be described in depth (in <xref linkend="xindex">)
- after we have discussed basic extensions.
+ methods) that do not.
</para>
</listitem>
</itemizedlist>
-<!-- $Header: /cvsroot/pgsql/doc/src/sgml/indices.sgml,v 1.34 2002/06/21 19:06:44 momjian Exp $ -->
+<!-- $Header: /cvsroot/pgsql/doc/src/sgml/indices.sgml,v 1.35 2002/07/30 17:34:37 tgl Exp $ -->
<chapter id="indexes">
<title id="indexes-title">Indexes</title>
</para>
<para>
- The following query shows all defined operator classes:
-<programlisting>
+ The following query shows all defined operator classes:
+
+ <programlisting>
+SELECT am.amname AS acc_method,
+ opc.opcname AS ops_name
+ FROM pg_am am, pg_opclass opc
+ WHERE opc.opcamid = am.oid
+ ORDER BY acc_method, ops_name;
+ </programlisting>
+
+ It can be extended to show all the operators included in each class:
+ <programlisting>
SELECT am.amname AS acc_method,
opc.opcname AS ops_name,
opr.oprname AS ops_comp
WHERE opc.opcamid = am.oid AND
amop.amopclaid = opc.oid AND
amop.amopopr = opr.oid
- ORDER BY acc_method, ops_name, ops_comp
-</programlisting>
+ ORDER BY acc_method, ops_name, ops_comp;
+ </programlisting>
</para>
</sect1>
<!--
-$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_index.sgml,v 1.34 2002/06/21 19:06:44 momjian Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_index.sgml,v 1.35 2002/07/30 17:34:37 tgl Exp $
PostgreSQL documentation
-->
<programlisting>
SELECT am.amname AS acc_method,
- opc.opcname AS ops_name,
- opr.oprname AS ops_comp
- FROM pg_am am, pg_opclass opc, pg_amop amop, pg_operator opr
- WHERE opc.opcamid = am.oid AND
- amop.amopclaid = opc.oid AND
- amop.amopopr = opr.oid
- ORDER BY acc_method, ops_name, ops_comp;
+ opc.opcname AS ops_name
+ FROM pg_am am, pg_opclass opc
+ WHERE opc.opcamid = am.oid
+ ORDER BY acc_method, ops_name;
</programlisting>
</para>
</refsect2>
<!--
-$Header: /cvsroot/pgsql/doc/src/sgml/xindex.sgml,v 1.27 2002/07/30 05:24:56 tgl Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/xindex.sgml,v 1.28 2002/07/30 17:34:37 tgl Exp $
PostgreSQL documentation
-->
Because
<productname>PostgreSQL</productname> allows the user to define operators,
<productname>PostgreSQL</productname> cannot look at the name of an operator
- (e.g., <literal>></> or <literal><</>) and tell what kind of
+ (e.g., <literal><</> or <literal>>=</>) and tell what kind of
comparison it is. Instead, the index access method defines a set of
<quote>strategies</>, which can be thought of as generalized operators.
Each operator class shows which actual operator corresponds to each
<tgroup cols="2">
<thead>
<row>
- <entry>Operation</entry>
+ <entry>Function</entry>
<entry>Support Number</entry>
</row>
</thead>
<tbody>
<row>
<entry>
- Compare two keys and return -1, 0,
- or +1, depending on whether the first key is less than, equal to,
- or greater than the second. (Actually, this routine can
- return any negative int32 value (< 0), zero, or any non-zero positive
- int32 value (> 0).)
+ Compare two keys and return an integer less than zero, zero, or
+ greater than zero, indicating whether the first key is less than, equal to,
+ or greater than the second.
</entry>
<entry>1</entry>
</row>
<tgroup cols="2">
<thead>
<row>
- <entry>Operation</entry>
+ <entry>Function</entry>
<entry>Support Number</entry>
</row>
</thead>
<tbody>
<row>
- <entry>compute the hash value for a key</entry>
+ <entry>Compute the hash value for a key</entry>
<entry>1</entry>
</row>
</tbody>
<tgroup cols="2">
<thead>
<row>
- <entry>Operation</entry>
+ <entry>Function</entry>
<entry>Support Number</entry>
</row>
</thead>
<tgroup cols="2">
<thead>
<row>
- <entry>Operation</entry>
+ <entry>Function</entry>
<entry>Support Number</entry>
</row>
</thead>
return (amag==bmag);
}
</programlisting>
- (Note that we will only show the equality operator for the rest of
- the examples. The other four operators are very similar. Refer to
+ (Note that we will only show the equality operator in this text.
+ The other four operators are very similar. Refer to
<filename>complex.c</filename> or
<filename>complex.source</filename> for the details.)
</para>
<programlisting>
CREATE OPERATOR CLASS complex_abs_ops
DEFAULT FOR TYPE complex USING btree AS
- OPERATOR 1 < ,
- OPERATOR 2 <= ,
+ OPERATOR 1 < ,
+ OPERATOR 2 <= ,
OPERATOR 3 = ,
- OPERATOR 4 >= ,
- OPERATOR 5 > ,
+ OPERATOR 4 >= ,
+ OPERATOR 5 > ,
FUNCTION 1 complex_abs_cmp(complex, complex);
</programlisting>
</para>
<para>
We could have written the operator entries more verbosely, as in
<programlisting>
- OPERATOR 1 < (complex, complex) ,
+ OPERATOR 1 < (complex, complex) ,
</programlisting>
but there is no need to do so when the operators take the same datatype
we are defining the operator class for.
that the index access method can retrieve exactly the set of rows
that satisfy a WHERE condition using the operator. For example,
<programlisting>
-SELECT * FROM table WHERE integer_column < 4;
+SELECT * FROM table WHERE integer_column < 4;
</programlisting>
can be satisfied exactly by a B-tree index on the integer column.
But there are cases where an index is useful as an inexact guide to
box overlaps the bounding box of the target object, and then do the
exact overlap test only on the objects found by the index. If this
scenario applies, the index is said to be <quote>lossy</> for the
- operator, and we mark the <literal>OPERATOR</> clause in the
- <command>CREATE OPERATOR CLASS</> command with <literal>RECHECK</>.
+ operator, and we add <literal>RECHECK</> to the <literal>OPERATOR</> clause
+ in the <command>CREATE OPERATOR CLASS</> command.
<literal>RECHECK</> is valid if the index is guaranteed to return
all the required tuples, plus perhaps some additional tuples, which
can be eliminated by performing the original operator comparison.