LP1811689 TRUNCATE when rebuilding simple record
authorBill Erickson <berickxx@gmail.com>
Fri, 1 Feb 2019 17:28:58 +0000 (12:28 -0500)
committerBill Erickson <berickxx@gmail.com>
Fri, 8 Mar 2019 14:55:46 +0000 (09:55 -0500)
TRUNCATE reporter.materialized_simple_record for more efficient
rebuilding of the table.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Rogan Hamby <rogan.hamby@gmail.com>
Open-ILS/src/sql/Pg/reporter-schema.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.reporter-simple-rec-truncate.sql [new file with mode: 0644]

index 3dd0c39..8d0897d 100644 (file)
@@ -214,7 +214,7 @@ $$ LANGUAGE SQL;
 
 CREATE OR REPLACE FUNCTION reporter.enable_materialized_simple_record_trigger () RETURNS VOID AS $$
 
-    DELETE FROM reporter.materialized_simple_record;
+    TRUNCATE TABLE reporter.materialized_simple_record;
 
     INSERT INTO reporter.materialized_simple_record
         (id,fingerprint,quality,tcn_source,tcn_value,title,author,publisher,pubdate,isbn,issn)
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.reporter-simple-rec-truncate.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.reporter-simple-rec-truncate.sql
new file mode 100644 (file)
index 0000000..b64b22c
--- /dev/null
@@ -0,0 +1,20 @@
+BEGIN;
+
+-- SELECT evergreen.upgrade_deps_block_check('TODO', :eg_version);
+
+CREATE OR REPLACE FUNCTION reporter.enable_materialized_simple_record_trigger () RETURNS VOID AS $$
+
+    TRUNCATE TABLE reporter.materialized_simple_record;
+
+    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.old_super_simple_record;
+
+    CREATE TRIGGER bbb_simple_rec_trigger
+        AFTER INSERT OR UPDATE OR DELETE ON biblio.record_entry
+        FOR EACH ROW EXECUTE PROCEDURE reporter.simple_rec_trigger();
+
+$$ LANGUAGE SQL;
+
+
+COMMIT;