From: Doug Kyle Date: Fri, 4 Apr 2014 14:05:50 +0000 (-0400) Subject: Performance tweak for loc_or_locgroup function X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=6ad48db2eda0c8375673d2fbc7590f551aff9be9;p=working%2FEvergreen.git Performance tweak for loc_or_locgroup function Still adding 400-1900ms depending on test server. Also removed GRPL specific org units. Signef-off-by: Doug Kyle --- diff --git a/Open-ILS/src/sql/Pg/smart_float.sql b/Open-ILS/src/sql/Pg/smart_float.sql index e7e0202e54..32fcaf4e0a 100644 --- a/Open-ILS/src/sql/Pg/smart_float.sql +++ b/Open-ILS/src/sql/Pg/smart_float.sql @@ -221,7 +221,7 @@ tto as ( select dest to_lib,count(dest) to_count from transits group by 1 order by 1 ), orgs as ( - select id from actor.org_unit where id between 10 and 17 + select id from actor.org_unit group by 1 ) select orgs.id as lib,coalesce(from_count,0),coalesce(to_count,0),coalesce(to_count,0)-coalesce(from_count,0) as transit_vector from orgs left join tto on orgs.id=to_lib left join tfrom on orgs.id=from_lib; END; @@ -248,17 +248,16 @@ $function$; -- !!! smart_float.loc_or_locgroup !!! CREATE OR REPLACE FUNCTION smart_float.loc_or_locgroup(loc integer) - RETURNS integer + RETURNS integer LANGUAGE plpgsql -AS $function$ -DECLARE + STABLE COST 10 AS $function$ DECLARE found_loc BOOLEAN; loc_group INT; BEGIN - SELECT INTO found_loc loc IN (select distinct(shelf_location) from config.smart_float where shelf_is_group is FALSE); + SELECT INTO found_loc loc IN (select shelf_location from config.smart_float where shelf_is_group is FALSE group by 1); IF found_loc IS FALSE THEN SELECT INTO loc_group lgroup from asset.copy_location_group_map where location = loc - and lgroup in (select distinct(shelf_location) from config.smart_float where shelf_is_group is TRUE); + and lgroup in (select shelf_location from config.smart_float where shelf_is_group is TRUE group by 1); IF FOUND THEN RETURN loc_group; END IF; @@ -267,6 +266,5 @@ BEGIN END; $function$; - -- !!! need some new indexes create index concurrently cp_location_idx on asset.copy (location);