Debloat by removing duplicate metabib index entries user/dbs/reduce_index_bloat
authorDan Scott <dscott@laurentian.ca>
Thu, 16 Aug 2012 03:56:20 +0000 (23:56 -0400)
committerDan Scott <dscott@laurentian.ca>
Thu, 16 Aug 2012 04:01:34 +0000 (00:01 -0400)
The bloaty indexer added rows like so:

 id  | source | field |                                value
-----+--------+-------+----------------------------------------------------------------------
 178 |     47 |     5 | Concertos, piano
 179 |     47 |     5 | Rapsodie sur un thème de Paganini, piano, orchestra
 180 |     47 |     5 | Concertos, piano Rapsodie sur un thème de Paganini, piano, orchestra

Remove all but the last row for every matching source/field rows.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/sql/Pg/upgrade/XXXX.function.extract_metabib_field_entry.sql

index 251796e..d8c0828 100644 (file)
@@ -132,3 +132,31 @@ END;
 
 $func$ LANGUAGE PLPGSQL;
 
+-- Delete all of the duplicate rows that might have been added in 2.2
+DELETE FROM metabib.author_field_entry
+  WHERE id NOT IN (
+    SELECT MAX(id) FROM metabib.author_field_entry
+    GROUP BY source, field
+  )
+;
+
+DELETE FROM metabib.series_field_entry
+  WHERE id NOT IN (
+    SELECT MAX(id) FROM metabib.series_field_entry
+    GROUP BY source, field
+  )
+;
+
+DELETE FROM metabib.subject_field_entry
+  WHERE id NOT IN (
+    SELECT MAX(id) FROM metabib.subject_field_entry
+    GROUP BY source, field
+  )
+;
+
+DELETE FROM metabib.title_field_entry
+  WHERE id NOT IN (
+    SELECT MAX(id) FROM metabib.title_field_entry
+    GROUP BY source, field
+  )
+;