2 * Copyright (C) 2008 Equinox Software, Inc.
3 * Mike Rylander <miker@esilibrary.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
20 -- To avoid any updates while we're doin' our thing...
21 SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
23 -- This index, right here, is the reason for this change.
24 DROP INDEX metabib.metabib_full_rec_value_idx;
27 -- Move the table out of the way ...
28 ALTER TABLE metabib.full_rec RENAME TO real_full_rec;
30 -- ... and let the trigger management functions know about the change ...
31 CREATE OR REPLACE FUNCTION reporter.disable_materialized_simple_record_trigger () RETURNS VOID AS $$
32 DROP TRIGGER zzz_update_materialized_simple_record_tgr ON metabib.real_full_rec;
35 CREATE OR REPLACE FUNCTION reporter.enable_materialized_simple_record_trigger () RETURNS VOID AS $$
37 TRUNCATE TABLE reporter.materialized_simple_record;
39 INSERT INTO reporter.materialized_simple_record
40 (id,fingerprint,quality,tcn_source,tcn_value,title,author,publisher,pubdate,isbn,issn)
41 SELECT DISTINCT ON (id) * FROM reporter.old_super_simple_record;
43 CREATE TRIGGER zzz_update_materialized_simple_record_tgr
44 AFTER INSERT OR UPDATE OR DELETE ON metabib.real_full_rec
45 FOR EACH ROW EXECUTE PROCEDURE reporter.simple_rec_sync();
49 -- ... replace the table with a suitable view, which applies the index contstraint we'll use ...
50 CREATE OR REPLACE VIEW metabib.full_rec AS
57 SUBSTRING(value,1,1024) AS value,
59 FROM metabib.real_full_rec;
61 -- ... now some rules to transform DML against the view into DML against the underlying table ...
62 CREATE OR REPLACE RULE metabib_full_rec_insert_rule
63 AS ON INSERT TO metabib.full_rec
65 INSERT INTO metabib.real_full_rec VALUES (
66 COALESCE(NEW.id, NEXTVAL('metabib.full_rec_id_seq'::REGCLASS)),
76 CREATE OR REPLACE RULE metabib_full_rec_update_rule
77 AS ON UPDATE TO metabib.full_rec
79 UPDATE metabib.real_full_rec SET
85 subfield = NEW.subfield,
87 index_vector = NEW.index_vector
90 CREATE OR REPLACE RULE metabib_full_rec_delete_rule
91 AS ON DELETE TO metabib.full_rec
93 DELETE FROM metabib.real_full_rec WHERE id = OLD.id;
95 -- ... and last, but not least, create a fore-shortened index on the value column.
96 CREATE INDEX metabib_full_rec_value_idx ON metabib.real_full_rec (substring(value,1,1024));