LP#928896 improve row estimate for action.usr_visible_circ_copies()
authorGalen Charlton <gmc@esilibrary.com>
Wed, 8 Feb 2012 15:01:24 +0000 (10:01 -0500)
committerBill Erickson <berick@esilibrary.com>
Wed, 8 Feb 2012 15:25:54 +0000 (10:25 -0500)
Fixes problem where use of this function by the tagging circs in search
results feature can result in sequential scans of asset.call_number.

Thanks to Mike Rylander for the suggestion.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/sql/Pg/090.schema.action.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.usr_visible_circ_copies_row_estimates.sql [new file with mode: 0644]

index 715c64a..1af6e89 100644 (file)
@@ -699,7 +699,7 @@ $func$ 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;
+$$ LANGUAGE SQL ROWS 10;
 
 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/XXXX.schema.usr_visible_circ_copies_row_estimates.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.usr_visible_circ_copies_row_estimates.sql
new file mode 100644 (file)
index 0000000..a191fb4
--- /dev/null
@@ -0,0 +1,10 @@
+BEGIN;
+
+-- set expected row count to low value to avoid problem
+-- where use of this function by the circ tagging feature
+-- results in full scans of asset.call_number
+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 ROWS 10;
+
+COMMIT;