aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2002-06-23 21:20:38 +0000
committerBruce Momjian <bruce@momjian.us>2002-06-23 21:20:38 +0000
commiteb4e4fd2629e1ded5e88234935fe8705ee5ba6bf (patch)
tree8dda53517dc150ac8ba76fe198c9abdf7fde940f
parent407bd1c29b66f7e007288455982f428e7f26b7f9 (diff)
downloadpostgresql-eb4e4fd2629e1ded5e88234935fe8705ee5ba6bf.tar.gz
postgresql-eb4e4fd2629e1ded5e88234935fe8705ee5ba6bf.zip
Add indexing for isbn and issn.
Dan Weston
-rw-r--r--contrib/isbn_issn/isbn_issn.sql.in190
1 files changed, 188 insertions, 2 deletions
diff --git a/contrib/isbn_issn/isbn_issn.sql.in b/contrib/isbn_issn/isbn_issn.sql.in
index f837fad3789..816bced206b 100644
--- a/contrib/isbn_issn/isbn_issn.sql.in
+++ b/contrib/isbn_issn/isbn_issn.sql.in
@@ -1,7 +1,7 @@
--
-- PostgreSQL code for ISSNs.
--
--- $Id: isbn_issn.sql.in,v 1.2 2000/06/19 13:53:39 momjian Exp $
+-- $Id: isbn_issn.sql.in,v 1.3 2002/06/23 21:20:38 momjian Exp $
--
@@ -116,7 +116,7 @@ create operator <> (
--
-- PostgreSQL code for ISBNs.
--
--- $Id: isbn_issn.sql.in,v 1.2 2000/06/19 13:53:39 momjian Exp $
+-- $Id: isbn_issn.sql.in,v 1.3 2002/06/23 21:20:38 momjian Exp $
--
--
-- Input and output functions and the type itself:
@@ -223,6 +223,192 @@ create operator <> (
procedure = isbn_ne
);
+
+-------------------------------------------------
+-- 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';
+
+-- 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 '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;
+
+-- 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
--