From: miker Date: Tue, 6 Jul 2010 16:14:18 +0000 (+0000) Subject: use SQL function for speed, instead of PLPGSQL X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=8a88be6c8d146009f27f7022b66a5c893cce4d23;p=evergreen%2Fbjwebb.git use SQL function for speed, instead of PLPGSQL git-svn-id: svn://svn.open-ils.org/ILS/trunk@16853 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql index 466860b5a..b14890ffe 100644 --- a/Open-ILS/src/sql/Pg/090.schema.action.sql +++ b/Open-ILS/src/sql/Pg/090.schema.action.sql @@ -616,15 +616,9 @@ BEGIN END; $func$ LANGUAGE PLPGSQL; -CREATE OR REPLACE FUNCTION action.usr_visible_circ_copies( user_id INTEGER ) RETURNS SETOF INTEGER AS $$ - DECLARE - copy INTEGER; - BEGIN - FOR copy IN SELECT DISTINCT(target_copy) FROM action.usr_visible_circs(user_id) LOOP - RETURN NEXT copy; - END LOOP; - END; -$$ LANGUAGE plpgsql; +CREATE OR REPLACE FUNCTION action.usr_visible_circ_copies( INTEGER ) RETURNS SETOF BIGINT AS $$ + SELECT DISTINCT(target_copy) FROM action.usr_visible_circs($1) +$$ LANGUAGE SQL; CREATE OR REPLACE FUNCTION action.usr_visible_holds (usr_id INT) RETURNS SETOF action.hold_request AS $func$ DECLARE diff --git a/Open-ILS/src/sql/Pg/upgrade/0324.schema.usr_visible_circ_copies.sql b/Open-ILS/src/sql/Pg/upgrade/0324.schema.usr_visible_circ_copies.sql index d4da54b6f..37baeffe4 100644 --- a/Open-ILS/src/sql/Pg/upgrade/0324.schema.usr_visible_circ_copies.sql +++ b/Open-ILS/src/sql/Pg/upgrade/0324.schema.usr_visible_circ_copies.sql @@ -1,16 +1,12 @@ +DROP FUNCTION action.usr_visible_circ_copies( INTEGER ); -- Ignore me if I fail + BEGIN; INSERT INTO config.upgrade_log (version) VALUES ('0324'); -- returns the distinct set of target copy IDs from a user's visible circulation history -CREATE OR REPLACE FUNCTION action.usr_visible_circ_copies( user_id INTEGER ) RETURNS SETOF INTEGER AS $$ - DECLARE - copy INTEGER; - BEGIN - FOR copy IN SELECT DISTINCT(target_copy) FROM action.usr_visible_circs(user_id) LOOP - RETURN NEXT copy; - END LOOP; - END; -$$ LANGUAGE plpgsql; +CREATE OR REPLACE FUNCTION action.usr_visible_circ_copies( INTEGER ) RETURNS SETOF BIGINT AS $$ + SELECT DISTINCT(target_copy) FROM action.usr_visible_circs($1) +$$ LANGUAGE SQL; COMMIT;