From: Josh Stompro Date: Tue, 22 Nov 2022 18:09:46 +0000 (-0600) Subject: LP#1971745 - speed up open-ils.storage.action.live_holds.wide_hash X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=e7acf4a00c3948fac5f270926c3838459d57434e;p=Evergreen.git LP#1971745 - speed up open-ils.storage.action.live_holds.wide_hash Postgresql 10 and EG 3.9.0 The query to grab holds on the hold shelf was taking 35-50 seconds on a test system to return 466 records. Explain analyze showed that the left join on asset.call_number was causing a sequential scan and reading all asset.call_number rows. Letting PG know that the two conditions of the join are mutually exclusive seems to let PG know that an index scan is faster. Signed-off-by: Josh Stompro Signed-off-by: Jason Stephenson --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm index 2b1fba28c4..c519e63ee0 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm @@ -2399,7 +2399,7 @@ SELECT h.id, h.request_time, h.capture_time, h.fulfillment_time, h.checkin_time SELECT *, (ROW_NUMBER() OVER (ORDER BY name) + 1000000) AS fallback_position FROM asset.copy_location ) acpl_ordered ON (acpl_ordered.id = cp.location) - LEFT JOIN asset.call_number cn ON (cn.id = cp.call_number OR (h.hold_type = 'V' AND cn.id = h.target)) + LEFT JOIN asset.call_number cn ON ((cn.id = cp.call_number AND h.hold_type != 'V' ) OR (h.hold_type = 'V' AND cn.id = h.target)) LEFT JOIN asset.call_number_prefix acnp ON (cn.prefix = acnp.id) LEFT JOIN asset.call_number_suffix acns ON (cn.suffix = acns.id) LEFT JOIN LATERAL (SELECT * FROM action.hold_transit_copy WHERE h.id = hold ORDER BY id DESC LIMIT 1) tr ON TRUE