LP#1482757: Speed Up the Delete of Orphaned URIs in upgrade script
authorJason Stephenson <jason@sigio.com>
Thu, 24 Sep 2020 16:31:23 +0000 (12:31 -0400)
committerMichele Morgan <mmorgan@noblenet.org>
Fri, 25 Feb 2022 19:56:58 +0000 (14:56 -0500)
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>
Open-ILS/src/sql/Pg/upgrade/XXXX.function.biblio.extract_located_uris.sql

index 2e82c2e..edcb152 100644 (file)
@@ -147,10 +147,16 @@ $func$ LANGUAGE PLPGSQL;
 
 -- 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;