[open-ils-commits] r19931 - in branches/rel_2_1/Open-ILS/src/sql/Pg: . upgrade (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Sat Apr 2 13:07:52 EDT 2011
Author: miker
Date: 2011-04-02 13:07:48 -0400 (Sat, 02 Apr 2011)
New Revision: 19931
Added:
branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0506.schema.tree-ish_function_row_estimates.sql
Modified:
branches/rel_2_1/Open-ILS/src/sql/Pg/006.schema.permissions.sql
branches/rel_2_1/Open-ILS/src/sql/Pg/020.schema.functions.sql
Log:
Add realistic row estimates to tree-ish functions (default is 1000) so that callers can make better plans in complex queries
Modified: branches/rel_2_1/Open-ILS/src/sql/Pg/006.schema.permissions.sql
===================================================================
--- branches/rel_2_1/Open-ILS/src/sql/Pg/006.schema.permissions.sql 2011-04-02 17:06:41 UTC (rev 19930)
+++ branches/rel_2_1/Open-ILS/src/sql/Pg/006.schema.permissions.sql 2011-04-02 17:07:48 UTC (rev 19931)
@@ -99,7 +99,7 @@
THEN 0
ELSE 1
END, a.name;
-$$ LANGUAGE SQL STABLE;
+$$ LANGUAGE SQL STABLE ROWS 1;
CREATE OR REPLACE FUNCTION permission.grp_ancestors_distance( INT ) RETURNS TABLE (id INT, distance INT) AS $$
WITH RECURSIVE grp_ancestors_distance(id, distance) AS (
@@ -110,7 +110,7 @@
WHERE pgt.parent IS NOT NULL
)
SELECT * FROM grp_ancestors_distance;
-$$ LANGUAGE SQL STABLE;
+$$ LANGUAGE SQL STABLE ROWS 1;
CREATE OR REPLACE FUNCTION permission.grp_descendants_distance( INT ) RETURNS TABLE (id INT, distance INT) AS $$
WITH RECURSIVE grp_descendants_distance(id, distance) AS (
@@ -120,7 +120,7 @@
FROM permission.grp_tree pgt JOIN grp_descendants_distance gdd ON (pgt.parent = gdd.id)
)
SELECT * FROM grp_descendants_distance;
-$$ LANGUAGE SQL STABLE;
+$$ LANGUAGE SQL STABLE ROWS 1;
CREATE OR REPLACE FUNCTION permission.usr_perms ( INT ) RETURNS SETOF permission.usr_perm_map AS $$
SELECT DISTINCT ON (usr,perm) *
@@ -141,7 +141,7 @@
WHERE p.grp IN (SELECT (permission.grp_ancestors(m.grp)).id FROM permission.usr_grp_map m WHERE usr = $1))
) AS x
ORDER BY 2, 3, 1 DESC, 5 DESC ;
-$$ LANGUAGE SQL STABLE;
+$$ LANGUAGE SQL STABLE ROWS 10;
CREATE TABLE permission.usr_work_ou_map (
id SERIAL PRIMARY KEY,
@@ -527,7 +527,7 @@
RETURN;
--
END;
-$$ LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql' ROWS 1;
CREATE OR REPLACE FUNCTION permission.usr_has_perm_at_all_nd(
@@ -583,7 +583,7 @@
RETURN;
--
END;
-$$ LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql' ROWS 1;
CREATE OR REPLACE FUNCTION permission.usr_has_perm_at(
@@ -592,7 +592,7 @@
)
RETURNS SETOF INTEGER AS $$
SELECT DISTINCT * FROM permission.usr_has_perm_at_nd( $1, $2 );
-$$ LANGUAGE 'sql';
+$$ LANGUAGE 'sql' ROWS 1;
CREATE OR REPLACE FUNCTION permission.usr_has_perm_at_all(
@@ -601,7 +601,7 @@
)
RETURNS SETOF INTEGER AS $$
SELECT DISTINCT * FROM permission.usr_has_perm_at_all_nd( $1, $2 );
-$$ LANGUAGE 'sql';
+$$ LANGUAGE 'sql' ROWS 1;
COMMIT;
Modified: branches/rel_2_1/Open-ILS/src/sql/Pg/020.schema.functions.sql
===================================================================
--- branches/rel_2_1/Open-ILS/src/sql/Pg/020.schema.functions.sql 2011-04-02 17:06:41 UTC (rev 19930)
+++ branches/rel_2_1/Open-ILS/src/sql/Pg/020.schema.functions.sql 2011-04-02 17:07:48 UTC (rev 19931)
@@ -204,7 +204,7 @@
JOIN actor.org_unit_type out ON (out.id = ou.ou_type)
JOIN anscestor_depth ot ON (ot.parent_ou = ou.id)
) SELECT ou.* FROM actor.org_unit ou JOIN descendant_depth USING (id);
-$$ LANGUAGE SQL;
+$$ LANGUAGE SQL ROWS 1;
CREATE OR REPLACE FUNCTION actor.org_unit_descendants( INT ) RETURNS SETOF actor.org_unit AS $$
WITH RECURSIVE descendant_depth AS (
@@ -222,7 +222,7 @@
JOIN actor.org_unit_type out ON (out.id = ou.ou_type)
JOIN descendant_depth ot ON (ot.id = ou.parent_ou)
) SELECT ou.* FROM actor.org_unit ou JOIN descendant_depth USING (id);
-$$ LANGUAGE SQL;
+$$ LANGUAGE SQL ROWS 1;
CREATE OR REPLACE FUNCTION actor.org_unit_descendants_distance( INT ) RETURNS TABLE (id INT, distance INT) AS $$
WITH RECURSIVE org_unit_descendants_distance(id, distance) AS (
@@ -232,7 +232,7 @@
FROM actor.org_unit ou JOIN org_unit_descendants_distance oudd ON (ou.parent_ou = oudd.id)
)
SELECT * FROM org_unit_descendants_distance;
-$$ LANGUAGE SQL STABLE;
+$$ LANGUAGE SQL STABLE ROWS 1;
CREATE OR REPLACE FUNCTION actor.org_unit_ancestors( INT ) RETURNS SETOF actor.org_unit AS $$
WITH RECURSIVE anscestor_depth AS (
@@ -246,7 +246,7 @@
FROM actor.org_unit ou
JOIN anscestor_depth ot ON (ot.parent_ou = ou.id)
) SELECT ou.* FROM actor.org_unit ou JOIN anscestor_depth USING (id);
-$$ LANGUAGE SQL;
+$$ LANGUAGE SQL ROWS 1;
CREATE OR REPLACE FUNCTION actor.org_unit_ancestor_at_depth ( INT,INT ) RETURNS actor.org_unit AS $$
SELECT a.*
@@ -266,7 +266,7 @@
WHERE ou.parent_ou IS NOT NULL
)
SELECT * FROM org_unit_ancestors_distance;
-$$ LANGUAGE SQL STABLE;
+$$ LANGUAGE SQL STABLE ROWS 1;
CREATE OR REPLACE FUNCTION actor.org_unit_full_path ( INT ) RETURNS SETOF actor.org_unit AS $$
SELECT *
@@ -274,11 +274,11 @@
UNION
SELECT *
FROM actor.org_unit_descendants($1);
-$$ LANGUAGE SQL STABLE;
+$$ LANGUAGE SQL STABLE ROWS 1;
CREATE OR REPLACE FUNCTION actor.org_unit_full_path ( INT, INT ) RETURNS SETOF actor.org_unit AS $$
SELECT * FROM actor.org_unit_full_path((actor.org_unit_ancestor_at_depth($1, $2)).id)
-$$ LANGUAGE SQL STABLE;
+$$ LANGUAGE SQL STABLE ROWS 1;
CREATE OR REPLACE FUNCTION actor.org_unit_combined_ancestors ( INT, INT ) RETURNS SETOF actor.org_unit AS $$
SELECT *
@@ -286,7 +286,7 @@
UNION
SELECT *
FROM actor.org_unit_ancestors($2);
-$$ LANGUAGE SQL STABLE;
+$$ LANGUAGE SQL STABLE ROWS 1;
CREATE OR REPLACE FUNCTION actor.org_unit_common_ancestors ( INT, INT ) RETURNS SETOF actor.org_unit AS $$
SELECT *
@@ -294,7 +294,7 @@
INTERSECT
SELECT *
FROM actor.org_unit_ancestors($2);
-$$ LANGUAGE SQL STABLE;
+$$ LANGUAGE SQL STABLE ROWS 1;
CREATE OR REPLACE FUNCTION actor.org_unit_proximity ( INT, INT ) RETURNS INT AS $$
SELECT COUNT(id)::INT FROM (
@@ -320,7 +320,7 @@
END LOOP;
RETURN;
END;
-$$ LANGUAGE plpgsql STABLE;
+$$ LANGUAGE plpgsql STABLE ROWS 1;
COMMENT ON FUNCTION actor.org_unit_ancestor_setting( TEXT, INT) IS $$
/**
Copied: branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0506.schema.tree-ish_function_row_estimates.sql (from rev 19930, trunk/Open-ILS/src/sql/Pg/upgrade/0506.schema.tree-ish_function_row_estimates.sql)
===================================================================
--- branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0506.schema.tree-ish_function_row_estimates.sql (rev 0)
+++ branches/rel_2_1/Open-ILS/src/sql/Pg/upgrade/0506.schema.tree-ish_function_row_estimates.sql 2011-04-02 17:07:48 UTC (rev 19931)
@@ -0,0 +1,25 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0506'); -- miker
+
+ALTER FUNCTION actor.org_unit_descendants( INT, INT ) ROWS 1;
+ALTER FUNCTION actor.org_unit_descendants( INT ) ROWS 1;
+ALTER FUNCTION actor.org_unit_descendants_distance( INT ) ROWS 1;
+ALTER FUNCTION actor.org_unit_ancestors( INT ) ROWS 1;
+ALTER FUNCTION actor.org_unit_ancestors_distance( INT ) ROWS 1;
+ALTER FUNCTION actor.org_unit_full_path ( INT ) ROWS 2;
+ALTER FUNCTION actor.org_unit_full_path ( INT, INT ) ROWS 2;
+ALTER FUNCTION actor.org_unit_combined_ancestors ( INT, INT ) ROWS 1;
+ALTER FUNCTION actor.org_unit_common_ancestors ( INT, INT ) ROWS 1;
+ALTER FUNCTION actor.org_unit_ancestor_setting( TEXT, INT ) ROWS 1;
+ALTER FUNCTION permission.grp_ancestors ( INT ) ROWS 1;
+ALTER FUNCTION permission.grp_ancestors_distance( INT ) ROWS 1;
+ALTER FUNCTION permission.grp_descendants_distance( INT ) ROWS 1;
+ALTER FUNCTION permission.usr_perms ( INT ) ROWS 10;
+ALTER FUNCTION permission.usr_has_perm_at_nd ( INT, TEXT) ROWS 1;
+ALTER FUNCTION permission.usr_has_perm_at_all_nd ( INT, TEXT ) ROWS 1;
+ALTER FUNCTION permission.usr_has_perm_at ( INT, TEXT ) ROWS 1;
+ALTER FUNCTION permission.usr_has_perm_at_all ( INT, TEXT ) ROWS 1;
+
+COMMIT;
+
More information about the open-ils-commits
mailing list