Backstage quarterly export query improvement
authorBill Erickson <berickxx@gmail.com>
Wed, 17 Jan 2018 15:07:03 +0000 (10:07 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Tweak the holdings-exists part of the query to use a JOIN instead of an
IN check.  Though the exact cause of the recent slow-down is unknown,
this change allows the query to complete in minutes instead of hours.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/authority-control/backstage/export-bibs.pl

index dee53a9..0799a9c 100755 (executable)
@@ -133,13 +133,13 @@ WITH viable_records AS (
     )
     WHERE vr.cataloging_date IS NOT NULL AND EXISTS (
         -- bib has at least one non-deleted copy
-        SELECT acp.id 
+        SELECT acp.id
         FROM asset.copy acp
-        WHERE call_number IN (
-            SELECT id FROM asset.call_number
-            WHERE record = vr.id AND NOT deleted
-        )
-        AND NOT deleted
+        JOIN asset.call_number acn ON (acn.id = acp.call_number)
+        WHERE
+            acn.record = vr.id
+            AND NOT acn.deleted
+            AND NOT acp.deleted
         LIMIT 1
     )