From: Bill Erickson Date: Wed, 2 Mar 2016 21:34:50 +0000 (-0500) Subject: JBAS-1263 Browse entry cleanup utility SQL X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=79624d89db0e38308b591f3b76808e4f5a7d62d1;p=working%2FEvergreen.git JBAS-1263 Browse entry cleanup utility SQL SQL to delete un-referenced (dangling) browse entries. Signed-off-by: Bill Erickson --- diff --git a/KCLS/utility-scripts/browse_cleanup/delete-stale-browse-entries.sql b/KCLS/utility-scripts/browse_cleanup/delete-stale-browse-entries.sql new file mode 100644 index 0000000000..a46672dda1 --- /dev/null +++ b/KCLS/utility-scripts/browse_cleanup/delete-stale-browse-entries.sql @@ -0,0 +1,60 @@ +/* +Remove all browse entries that are not linked to either a bib record +(via metabib.browse_*_entry_def_map) or an authority record (via +(metabib.browse_*_entry_simple_heading_map). + +Stale browse entries are never removed by the code. They just languish. +Run this script after a browse entry re-ingest, particularly if browse +indexes change, resulting in a lot of new browse entries. +*/ + +DELETE FROM metabib.browse_author_entry WHERE id IN ( + SELECT DISTINCT(entry.id) + FROM metabib.browse_author_entry entry + LEFT JOIN metabib.browse_author_entry_def_map map + ON (map.entry = entry.id) + LEFT JOIN metabib.browse_author_entry_simple_heading_map hmap + ON (hmap.entry = entry.id) + WHERE map.id IS NULL AND hmap.id IS NULL +); + +DELETE FROM metabib.browse_author_entry WHERE id IN ( + SELECT DISTINCT(entry.id) + FROM metabib.browse_author_entry entry + LEFT JOIN metabib.browse_author_entry_def_map map + ON (map.entry = entry.id) + LEFT JOIN metabib.browse_author_entry_simple_heading_map hmap + ON (hmap.entry = entry.id) + WHERE map.id IS NULL AND hmap.id IS NULL +); + +DELETE FROM metabib.browse_series_entry WHERE id IN ( + SELECT DISTINCT(entry.id) + FROM metabib.browse_series_entry entry + LEFT JOIN metabib.browse_series_entry_def_map map + ON (map.entry = entry.id) + LEFT JOIN metabib.browse_series_entry_simple_heading_map hmap + ON (hmap.entry = entry.id) + WHERE map.id IS NULL AND hmap.id IS NULL +); + +DELETE FROM metabib.browse_title_entry WHERE id IN ( + SELECT DISTINCT(entry.id) + FROM metabib.browse_title_entry entry + LEFT JOIN metabib.browse_title_entry_def_map map + ON (map.entry = entry.id) + LEFT JOIN metabib.browse_title_entry_simple_heading_map hmap + ON (hmap.entry = entry.id) + WHERE map.id IS NULL AND hmap.id IS NULL +); + + +DELETE FROM metabib.browse_call_number_entry WHERE id IN ( + SELECT DISTINCT(entry.id) + FROM metabib.browse_call_number_entry entry + LEFT JOIN metabib.browse_call_number_entry_def_map map + ON (map.entry = entry.id) + WHERE map.id IS NULL + -- no simple_heading_map for call numbers +); +