Commit 45e584a4 authored by Tom Lane's avatar Tom Lane

Replace ad-hoc insertions into pg_opclass and friends with CREATE

	OPERATOR CLASS commands.
parent ad63a551
BEGIN; BEGIN;
-- Adjust this setting to control where the objects get created.
SET search_path = public;
CREATE FUNCTION ltree_in(opaque) CREATE FUNCTION ltree_in(opaque)
RETURNS opaque RETURNS opaque
AS 'MODULE_PATHNAME' AS 'MODULE_PATHNAME'
...@@ -177,70 +180,16 @@ CREATE OPERATOR || ( ...@@ -177,70 +180,16 @@ CREATE OPERATOR || (
-- B-tree support -- B-tree support
INSERT INTO pg_opclass (opcamid, opcname, opcnamespace, opcowner, opcintype, opcdefault, opckeytype)
VALUES ( CREATE OPERATOR CLASS ltree_ops
(SELECT oid FROM pg_am WHERE amname = 'btree'), DEFAULT FOR TYPE ltree USING btree AS
'ltree_ops', OPERATOR 1 < ,
(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog'), OPERATOR 2 <= ,
1, -- UID of superuser is hardwired to 1 as of PG 7.3 OPERATOR 3 = ,
(SELECT oid FROM pg_type WHERE typname = 'ltree'), OPERATOR 4 >= ,
true, OPERATOR 5 > ,
0); FUNCTION 1 ltree_cmp(ltree, ltree);
SELECT o.oid AS opoid, o.oprname
INTO TEMP TABLE ltree_ops_tmp
FROM pg_operator o, pg_type t
WHERE o.oprleft = t.oid and o.oprright = t.oid
and t.typname = 'ltree';
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 1, false, c.opoid
FROM pg_opclass opcl, ltree_ops_tmp c
WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'btree') AND
opcname = 'ltree_ops' AND
c.oprname = '<';
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 2, false, c.opoid
FROM pg_opclass opcl, ltree_ops_tmp c
WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'btree') AND
opcname = 'ltree_ops' AND
c.oprname = '<=';
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 3, false, c.opoid
FROM pg_opclass opcl, ltree_ops_tmp c
WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'btree') AND
opcname = 'ltree_ops' AND
c.oprname = '=';
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 4, false, c.opoid
FROM pg_opclass opcl, ltree_ops_tmp c
WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'btree') AND
opcname = 'ltree_ops' AND
c.oprname = '>=';
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 5, false, c.opoid
FROM pg_opclass opcl, ltree_ops_tmp c
WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'btree') AND
opcname = 'ltree_ops' AND
c.oprname = '>';
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 = 'ltree_ops' AND
p.proname = 'ltree_cmp';
drop table ltree_ops_tmp;
--lquery type --lquery type
CREATE FUNCTION lquery_in(opaque) CREATE FUNCTION lquery_in(opaque)
...@@ -376,164 +325,28 @@ create function ltree_picksplit(opaque, opaque) returns opaque as 'MODULE_PATHNA ...@@ -376,164 +325,28 @@ create function ltree_picksplit(opaque, opaque) returns opaque as 'MODULE_PATHNA
create function ltree_union(bytea, opaque) returns int4 as 'MODULE_PATHNAME' language 'C'; create function ltree_union(bytea, opaque) returns int4 as 'MODULE_PATHNAME' language 'C';
create function ltree_same(opaque, opaque, opaque) returns opaque as 'MODULE_PATHNAME' language 'C'; create function ltree_same(opaque, opaque, opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
INSERT INTO pg_opclass (opcamid, opcname, opcnamespace, opcowner, opcintype, opckeytype, opcdefault) CREATE OPERATOR CLASS gist_ltree_ops
SELECT pg_am.oid, 'gist_ltree_ops', DEFAULT FOR TYPE ltree USING gist AS
(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog'), OPERATOR 1 < ,
1, -- UID of superuser is hardwired to 1 as of PG 7.3 OPERATOR 2 <= ,
pg_type.oid, pg_key.oid, true OPERATOR 3 = ,
FROM pg_type, pg_am, pg_type pg_key OPERATOR 4 >= ,
WHERE pg_type.typname = 'ltree' and OPERATOR 5 > ,
pg_am.amname='gist' and OPERATOR 10 @> ,
pg_key.typname = 'ltree_gist'; OPERATOR 11 <@ ,
OPERATOR 12 ~ (ltree, lquery) ,
SELECT o.oid AS opoid, o.oprname OPERATOR 13 ~ (lquery, ltree) ,
INTO TABLE ltree_ops_tmp OPERATOR 14 @ (ltree, ltxtquery) ,
FROM pg_operator o, pg_type t OPERATOR 15 @ (ltxtquery, ltree) ,
WHERE o.oprleft = t.oid and o.oprright = t.oid FUNCTION 1 ltree_consistent (opaque, opaque, int2),
and t.typname = 'ltree'; FUNCTION 2 ltree_union (bytea, opaque),
FUNCTION 3 ltree_compress (opaque),
INSERT INTO pg_amop (amopclaid, amopopr, amopstrategy, amopreqcheck) FUNCTION 4 ltree_decompress (opaque),
SELECT opcl.oid, c.opoid, 1, 'f' FUNCTION 5 ltree_penalty (opaque, opaque, opaque),
FROM pg_opclass opcl, ltree_ops_tmp c FUNCTION 6 ltree_picksplit (opaque, opaque),
WHERE opcname = 'gist_ltree_ops' FUNCTION 7 ltree_same (opaque, opaque, opaque),
and c.oprname = '<'; STORAGE ltree_gist;
INSERT INTO pg_amop (amopclaid, amopopr, amopstrategy, amopreqcheck)
SELECT opcl.oid, c.opoid, 2, 'f'
FROM pg_opclass opcl, ltree_ops_tmp c
WHERE opcname = 'gist_ltree_ops'
and c.oprname = '<=';
INSERT INTO pg_amop (amopclaid, amopopr, amopstrategy, amopreqcheck)
SELECT opcl.oid, c.opoid, 3, 'f'
FROM pg_opclass opcl, ltree_ops_tmp c
WHERE opcname = 'gist_ltree_ops'
and c.oprname = '=';
INSERT INTO pg_amop (amopclaid, amopopr, amopstrategy, amopreqcheck)
SELECT opcl.oid, c.opoid, 4, 'f'
FROM pg_opclass opcl, ltree_ops_tmp c
WHERE opcname = 'gist_ltree_ops'
and c.oprname = '>=';
INSERT INTO pg_amop (amopclaid, amopopr, amopstrategy, amopreqcheck)
SELECT opcl.oid, c.opoid, 5, 'f'
FROM pg_opclass opcl, ltree_ops_tmp c
WHERE opcname = 'gist_ltree_ops'
and c.oprname = '>';
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 10, false, c.opoid
FROM pg_opclass opcl, ltree_ops_tmp c
WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
and opcname = 'gist_ltree_ops'
and c.oprname = '@>';
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 11, false, c.opoid
FROM pg_opclass opcl, ltree_ops_tmp c
WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
and opcname = 'gist_ltree_ops'
and c.oprname = '<@';
DROP TABLE ltree_ops_tmp;
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 12, false, o.oid
FROM pg_opclass opcl, pg_operator o, pg_type t, pg_type tq
WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
and opcname = 'gist_ltree_ops'
and t.typname = 'ltree' and tq.typname = 'lquery'
and o.oprleft = t.oid and o.oprright = tq.oid
and o.oprname = '~';
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 13, false, o.oid
FROM pg_opclass opcl, pg_operator o, pg_type t, pg_type tq
WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
and opcname = 'gist_ltree_ops'
and t.typname = 'lquery' and tq.typname = 'ltree'
and o.oprleft = t.oid and o.oprright = tq.oid
and o.oprname = '~';
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 14, false, o.oid
FROM pg_opclass opcl, pg_operator o, pg_type t, pg_type tq
WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
and opcname = 'gist_ltree_ops'
and t.typname = 'ltree' and tq.typname = 'ltxtquery'
and o.oprleft = t.oid and o.oprright = tq.oid
and o.oprname = '@';
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 15, false, o.oid
FROM pg_opclass opcl, pg_operator o, pg_type t, pg_type tq
WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
and opcname = 'gist_ltree_ops'
and t.typname = 'ltxtquery' and tq.typname = 'ltree'
and o.oprleft = t.oid and o.oprright = tq.oid
and o.oprname = '@';
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_ltree_ops'
and proname = 'ltree_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_ltree_ops'
and proname = 'ltree_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_ltree_ops'
and proname = 'ltree_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_ltree_ops'
and proname = 'ltree_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_ltree_ops'
and proname = 'ltree_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_ltree_ops'
and proname = 'ltree_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_ltree_ops'
and proname = 'ltree_same';
-- arrays of ltree -- arrays of ltree
...@@ -720,130 +533,22 @@ create function _ltree_picksplit(opaque, opaque) returns opaque as 'MODULE_PATHN ...@@ -720,130 +533,22 @@ create function _ltree_picksplit(opaque, opaque) returns opaque as 'MODULE_PATHN
create function _ltree_union(bytea, opaque) returns int4 as 'MODULE_PATHNAME' language 'C'; create function _ltree_union(bytea, opaque) returns int4 as 'MODULE_PATHNAME' language 'C';
create function _ltree_same(opaque, opaque, opaque) returns opaque as 'MODULE_PATHNAME' language 'C'; create function _ltree_same(opaque, opaque, opaque) returns opaque as 'MODULE_PATHNAME' language 'C';
INSERT INTO pg_opclass (opcamid, opcname, opcnamespace, opcowner, opcintype, opckeytype, opcdefault) CREATE OPERATOR CLASS gist__ltree_ops
SELECT pg_am.oid, 'gist__ltree_ops', DEFAULT FOR TYPE _ltree USING gist AS
(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog'), OPERATOR 10 <@ (_ltree, ltree) RECHECK ,
1, -- UID of superuser is hardwired to 1 as of PG 7.3 OPERATOR 11 @> (ltree, _ltree) RECHECK ,
pg_type.oid, pg_key.oid, true OPERATOR 12 ~ (_ltree, lquery) RECHECK ,
FROM pg_type, pg_am, pg_type pg_key OPERATOR 13 ~ (lquery, _ltree) RECHECK ,
WHERE pg_type.typname = '_ltree' and OPERATOR 14 @ (_ltree, ltxtquery) RECHECK ,
pg_am.amname='gist' and OPERATOR 15 @ (ltxtquery, _ltree) RECHECK ,
pg_key.typname = 'ltree_gist'; FUNCTION 1 _ltree_consistent (opaque, opaque, int2),
FUNCTION 2 _ltree_union (bytea, opaque),
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr) FUNCTION 3 _ltree_compress (opaque),
SELECT opcl.oid, 12, true, o.oid FUNCTION 4 ltree_decompress (opaque),
FROM pg_opclass opcl, pg_operator o, pg_type t, pg_type tq FUNCTION 5 _ltree_penalty (opaque, opaque, opaque),
WHERE FUNCTION 6 _ltree_picksplit (opaque, opaque),
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist') FUNCTION 7 _ltree_same (opaque, opaque, opaque),
and opcname = 'gist__ltree_ops' STORAGE ltree_gist;
and t.typname = '_ltree' and tq.typname = 'lquery'
and o.oprleft = t.oid and o.oprright = tq.oid
and o.oprname = '~';
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 13, true, o.oid
FROM pg_opclass opcl, pg_operator o, pg_type t, pg_type tq
WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
and opcname = 'gist__ltree_ops'
and t.typname = 'lquery' and tq.typname = '_ltree'
and o.oprleft = t.oid and o.oprright = tq.oid
and o.oprname = '~';
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 14, true, o.oid
FROM pg_opclass opcl, pg_operator o, pg_type t, pg_type tq
WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
and opcname = 'gist__ltree_ops'
and t.typname = '_ltree' and tq.typname = 'ltxtquery'
and o.oprleft = t.oid and o.oprright = tq.oid
and o.oprname = '@';
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 15, true, o.oid
FROM pg_opclass opcl, pg_operator o, pg_type t, pg_type tq
WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
and opcname = 'gist__ltree_ops'
and t.typname = 'ltxtquery' and tq.typname = '_ltree'
and o.oprleft = t.oid and o.oprright = tq.oid
and o.oprname = '@';
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 10, true, o.oid
FROM pg_opclass opcl, pg_operator o, pg_type t, pg_type tq
WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
and opcname = 'gist__ltree_ops'
and t.typname = '_ltree' and tq.typname = 'ltree'
and o.oprleft = t.oid and o.oprright = tq.oid
and o.oprname = '<@';
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
SELECT opcl.oid, 11, true, o.oid
FROM pg_opclass opcl, pg_operator o, pg_type t, pg_type tq
WHERE
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
and opcname = 'gist__ltree_ops'
and t.typname = 'ltree' and tq.typname = '_ltree'
and o.oprleft = t.oid and o.oprright = tq.oid
and o.oprname = '@>';
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__ltree_ops'
and proname = '_ltree_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__ltree_ops'
and proname = '_ltree_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__ltree_ops'
and proname = '_ltree_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__ltree_ops'
and proname = 'ltree_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__ltree_ops'
and proname = '_ltree_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__ltree_ops'
and proname = '_ltree_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__ltree_ops'
and proname = '_ltree_same';
END; END;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment