Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteb4e4fd

Browse files
committed
Add indexing for isbn and issn.
Dan Weston
1 parent407bd1c commiteb4e4fd

File tree

1 file changed

+188
-2
lines changed

1 file changed

+188
-2
lines changed

‎contrib/isbn_issn/isbn_issn.sql.in

Lines changed: 188 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--
22
--PostgreSQL code for ISSNs.
33
--
4-
--$Id: isbn_issn.sql.in,v 1.2 2000/06/19 13:53:39 momjian Exp $
4+
--$Id: isbn_issn.sql.in,v 1.3 2002/06/23 21:20:38 momjian Exp $
55
--
66

77

@@ -116,7 +116,7 @@ create operator <> (
116116
--
117117
--PostgreSQL code for ISBNs.
118118
--
119-
--$Id: isbn_issn.sql.in,v 1.2 2000/06/19 13:53:39 momjian Exp $
119+
--$Id: isbn_issn.sql.in,v 1.3 2002/06/23 21:20:38 momjian Exp $
120120
--
121121
--
122122
--Input and output functions and the type itself:
@@ -223,6 +223,192 @@ create operator <> (
223223
procedure = isbn_ne
224224
);
225225

226+
227+
-------------------------------------------------
228+
-- Create default operator class for 'isbn' --
229+
-- Needed to create index or primary key --
230+
-------------------------------------------------
231+
232+
-- Register new operator class with system catalog pg_opclass
233+
insert into pg_opclass
234+
(opcamid, opcname, opcintype, opcdefault, opckeytype)
235+
values ((select oid from pg_am where amname = 'btree'),
236+
'isbn_ops',
237+
(select oid from pg_type where typname = 'isbn'),
238+
true,
239+
0);
240+
241+
-- Verify that new operator class was added to pg_opclass
242+
-- select oid,* from pg_opclass where opcname = 'isbn_ops';
243+
244+
-- Identify comparison operators for 'isbn' type
245+
select o.oid as opoid, o.oprname
246+
into temp table isbn_ops_tmp
247+
from pg_operator o, pg_type t
248+
where o.oprleft = t.oid
249+
and o.oprright = t.oid
250+
and t.typname = 'isbn';
251+
252+
-- Make sure all 5 needed order ops are there (<, <=, =, >=, >)
253+
-- Operator <> will be present but is not needed
254+
-- select * from isbn_ops_tmp order by opoid;
255+
256+
-- Associate B-tree strategy 1 with <
257+
insert into pg_amop
258+
(amopclaid, amopstrategy, amopreqcheck, amopopr)
259+
select opcl.oid, 1, false, c.opoid
260+
from pg_opclass opcl, isbn_ops_tmp c
261+
where opcamid = (select oid from pg_am where amname = 'btree')
262+
and opcname = 'isbn_ops'
263+
and c.oprname = '<';
264+
265+
-- Associate B-tree strategy 2 with <=
266+
insert into pg_amop
267+
(amopclaid, amopstrategy, amopreqcheck, amopopr)
268+
select opcl.oid, 2, false, c.opoid
269+
from pg_opclass opcl, isbn_ops_tmp c
270+
where opcamid = (select oid from pg_am where amname = 'btree')
271+
and opcname = 'isbn_ops'
272+
and c.oprname = '<=';
273+
274+
-- Associate B-tree strategy 3 with =
275+
insert into pg_amop
276+
(amopclaid, amopstrategy, amopreqcheck, amopopr)
277+
select opcl.oid, 3, false, c.opoid
278+
from pg_opclass opcl, isbn_ops_tmp c
279+
where opcamid = (select oid from pg_am where amname = 'btree')
280+
and opcname = 'isbn_ops'
281+
and c.oprname = '=';
282+
283+
-- Associate B-tree strategy 4 with >=
284+
insert into pg_amop
285+
(amopclaid, amopstrategy, amopreqcheck, amopopr)
286+
select opcl.oid, 4, false, c.opoid
287+
from pg_opclass opcl, isbn_ops_tmp c
288+
where opcamid = (select oid from pg_am where amname = 'btree')
289+
and opcname = 'isbn_ops'
290+
and c.oprname = '>=';
291+
292+
-- Associate B-tree strategy 5 with >
293+
insert into pg_amop
294+
(amopclaid, amopstrategy, amopreqcheck, amopopr)
295+
select opcl.oid, 5, false, c.opoid
296+
from pg_opclass opcl, isbn_ops_tmp c
297+
where opcamid = (select oid from pg_am where amname = 'btree')
298+
and opcname = 'isbn_ops'
299+
and c.oprname = '>';
300+
301+
-- Register 'isbn' comparison function
302+
create function isbn_cmp(isbn, isbn)
303+
returns integer
304+
as '$libdir/isbn_issn'
305+
language c;
306+
307+
-- Make sure that function was correctly registered
308+
-- select oid, proname from pg_proc where proname = 'isbn_cmp';
309+
310+
-- Associate default btree operator class with 'isbn' comparison function
311+
insert into pg_amproc
312+
(amopclaid, amprocnum, amproc)
313+
select opcl.oid, 1, p.oid
314+
from pg_opclass opcl, pg_proc p
315+
where opcamid = (select oid from pg_am where amname = 'btree')
316+
and opcname = 'isbn_ops'
317+
and p.proname = 'isbn_cmp';
318+
319+
320+
-------------------------------------------------
321+
-- Create default operator class for 'issn' --
322+
-- Needed to create index or primary key --
323+
-------------------------------------------------
324+
325+
-- Register new operator class with system catalog pg_opclass
326+
insert into pg_opclass
327+
(opcamid, opcname, opcintype, opcdefault, opckeytype)
328+
values ((select oid from pg_am where amname = 'btree'),
329+
'issn_ops',
330+
(select oid from pg_type where typname = 'issn'),
331+
true,
332+
0);
333+
334+
-- Verify that new operator class was added to pg_opclass
335+
-- select oid,* from pg_opclass where opcname = 'issn_ops';
336+
337+
-- Identify comparison operators for 'issn' type
338+
select o.oid as opoid, o.oprname
339+
into temp table issn_ops_tmp
340+
from pg_operator o, pg_type t
341+
where o.oprleft = t.oid
342+
and o.oprright = t.oid
343+
and t.typname = 'issn';
344+
345+
-- Make sure all 5 needed order ops are there (<, <=, =, >=, >)
346+
-- Operator <> will be present but is not needed
347+
-- select * from issn_ops_tmp order by opoid;
348+
349+
-- Associate B-tree strategy 1 with <
350+
insert into pg_amop
351+
(amopclaid, amopstrategy, amopreqcheck, amopopr)
352+
select opcl.oid, 1, false, c.opoid
353+
from pg_opclass opcl, issn_ops_tmp c
354+
where opcamid = (select oid from pg_am where amname = 'btree')
355+
and opcname = 'issn_ops'
356+
and c.oprname = '<';
357+
358+
-- Associate B-tree strategy 2 with <=
359+
insert into pg_amop
360+
(amopclaid, amopstrategy, amopreqcheck, amopopr)
361+
select opcl.oid, 2, false, c.opoid
362+
from pg_opclass opcl, issn_ops_tmp c
363+
where opcamid = (select oid from pg_am where amname = 'btree')
364+
and opcname = 'issn_ops'
365+
and c.oprname = '<=';
366+
367+
-- Associate B-tree strategy 3 with =
368+
insert into pg_amop
369+
(amopclaid, amopstrategy, amopreqcheck, amopopr)
370+
select opcl.oid, 3, false, c.opoid
371+
from pg_opclass opcl, issn_ops_tmp c
372+
where opcamid = (select oid from pg_am where amname = 'btree')
373+
and opcname = 'issn_ops'
374+
and c.oprname = '=';
375+
376+
-- Associate B-tree strategy 4 with >=
377+
insert into pg_amop
378+
(amopclaid, amopstrategy, amopreqcheck, amopopr)
379+
select opcl.oid, 4, false, c.opoid
380+
from pg_opclass opcl, issn_ops_tmp c
381+
where opcamid = (select oid from pg_am where amname = 'btree')
382+
and opcname = 'issn_ops'
383+
and c.oprname = '>=';
384+
385+
-- Associate B-tree strategy 5 with >
386+
insert into pg_amop
387+
(amopclaid, amopstrategy, amopreqcheck, amopopr)
388+
select opcl.oid, 5, false, c.opoid
389+
from pg_opclass opcl, issn_ops_tmp c
390+
where opcamid = (select oid from pg_am where amname = 'btree')
391+
and opcname = 'issn_ops'
392+
and c.oprname = '>';
393+
394+
-- Register 'issn' comparison function
395+
create function issn_cmp(issn, issn)
396+
returns integer
397+
as '$libdir/issn_issn'
398+
language c;
399+
400+
-- Make sure that function was correctly registered
401+
-- select oid, proname from pg_proc where proname = 'issn_cmp';
402+
403+
-- Associate default btree operator class with 'issn' comparison function
404+
insert into pg_amproc
405+
(amopclaid, amprocnum, amproc)
406+
select opcl.oid, 1, p.oid
407+
from pg_opclass opcl, pg_proc p
408+
where opcamid = (select oid from pg_am where amname = 'btree')
409+
and opcname = 'issn_ops'
410+
and p.proname = 'issn_cmp';
411+
226412
--
227413
--eof
228414
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp