[open-ils-commits] r9453 - trunk/Open-ILS/src/sql/Pg
svn at svn.open-ils.org
svn at svn.open-ils.org
Sat Apr 26 12:44:56 EDT 2008
Author: miker
Date: 2008-04-26 12:05:14 -0400 (Sat, 26 Apr 2008)
New Revision: 9453
Added:
trunk/Open-ILS/src/sql/Pg/upgrade_simple_record.sql
Log:
sql script for upgrading to a materialized version of the simple record view (reporting speed)
Added: trunk/Open-ILS/src/sql/Pg/upgrade_simple_record.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade_simple_record.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade_simple_record.sql 2008-04-26 16:05:14 UTC (rev 9453)
@@ -0,0 +1,30 @@
+
+BEGIN;
+
+CREATE TABLE reporter.materialized_simple_record AS SELECT * FROM reporter.simple_record WHERE 1=0;
+
+INSERT INTO reporter.materialized_simple_record
+ (id,fingerprint,quality,tcn_source,tcn_value,title,author,publisher,pubdate,isbn,issn)
+ SELECT DISTINCT ON (id) * FROM reporter.super_simple_record;
+
+ALTER TABLE reporter.materialized_simple_record ADD PRIMARY KEY (id);
+
+CREATE OR REPLACE FUNCTION reporter.simple_rec_sync () RETURNS TRIGGER AS $$
+BEGIN
+ IF TG_OP IN ('UPDATE','DELETE') THEN
+ DELETE FROM reporter.materialized_simple_record WHERE id = OLD.record;
+ END IF;
+
+ IF TG_OP IN ('INSERT','UPDATE') AND NOT NEW.deleted THEN
+ INSERT INTO reporter.materialized_simple_record SELECT * FROM reporter.simple_record WHERE id = NEW.record;
+ END IF;
+
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE TRIGGER zzz_update_materialized_simple_record_tgr
+ AFTER INSERT OR UPDATE OR DELETE ON metabib.full_rec
+ FOR EACH ROW EXECUTE PROCEDURE reporter.simple_rec_sync();
+
+COMMIT;
+
More information about the open-ils-commits
mailing list