Performance tweak for loc_or_locgroup function
authorDoug Kyle <dkyle@grpl.org>
Fri, 4 Apr 2014 14:05:50 +0000 (10:05 -0400)
committerDoug Kyle <dkyle@grpl.org>
Fri, 4 Apr 2014 14:05:50 +0000 (10:05 -0400)
Still adding 400-1900ms depending on test server.

Also removed GRPL specific org units.

Signef-off-by: Doug Kyle <dkyle@grpl.org>
Open-ILS/src/sql/Pg/smart_float.sql

index e7e0202..32fcaf4 100644 (file)
@@ -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);