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>
)
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
)