Modify the code that deletes orphaned asset.uri table entries in the
upgrade script to use IN logic on the subquery, because IN is much
faster than NOT IN. Also take into account the link between
serial.item and asset.uri so that we don't accidentally delete URIs
used by serial items.
Signed-off-by: Jason Stephenson <jason@sigio.com>
Signed-off-by: Jessica Woolford <jwoolford@biblio.org>
Signed-off-by: Michele Morgan <mmorgan@noblenet.org>
-- Remove existing orphaned URIs from the database.
DELETE FROM asset.uri
-WHERE id NOT IN
+WHERE id IN
(
-SELECT uri
-FROM asset.uri_call_number_map
+SELECT uri.id
+FROM asset.uri
+LEFT JOIN asset.uri_call_number_map
+ON uri_call_number_map.uri = uri.id
+LEFT JOIN serial.item
+ON item.uri = uri.id
+WHERE uri_call_number_map IS NULL
+AND item IS NULL
);
COMMIT;