[open-ils-commits] r19932 - in branches/rel_2_0/Open-ILS/src/sql/Pg: . upgrade (miker)

svn at svn.open-ils.org svn at svn.open-ils.org
Sat Apr 2 13:10:25 EDT 2011


Author: miker
Date: 2011-04-02 13:10:21 -0400 (Sat, 02 Apr 2011)
New Revision: 19932

Added:
   branches/rel_2_0/Open-ILS/src/sql/Pg/upgrade/0506.schema.tree-ish_function_row_estimates.sql
Modified:
   branches/rel_2_0/Open-ILS/src/sql/Pg/006.schema.permissions.sql
   branches/rel_2_0/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; includes four functions backported from 2.1 for simplicity when it comes to upgrading

Modified: branches/rel_2_0/Open-ILS/src/sql/Pg/006.schema.permissions.sql
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/006.schema.permissions.sql	2011-04-02 17:07:48 UTC (rev 19931)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/006.schema.permissions.sql	2011-04-02 17:10:21 UTC (rev 19932)
@@ -98,8 +98,29 @@
 			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 (
+            SELECT $1, 0
+        UNION
+            SELECT pgt.parent, gad.distance+1
+            FROM permission.grp_tree pgt JOIN grp_ancestors_distance gad ON (pgt.id = gad.id)
+            WHERE pgt.parent IS NOT NULL
+    )
+    SELECT * FROM grp_ancestors_distance;
+$$ 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 (
+            SELECT $1, 0
+        UNION
+            SELECT pgt.id, gdd.distance+1
+            FROM permission.grp_tree pgt JOIN grp_descendants_distance gdd ON (pgt.parent = gdd.id)
+    )
+    SELECT * FROM grp_descendants_distance;
+$$ 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) *
 	  FROM	(
@@ -119,7 +140,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,
@@ -505,7 +526,7 @@
 	RETURN;
 	--
 END;
-$$ LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql' ROWS 1;
 
 
 CREATE OR REPLACE FUNCTION permission.usr_has_perm_at_all_nd(
@@ -561,7 +582,7 @@
 	RETURN;
 	--
 END;
-$$ LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql' ROWS 1;
 
 
 CREATE OR REPLACE FUNCTION permission.usr_has_perm_at(
@@ -570,7 +591,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(
@@ -579,7 +600,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_0/Open-ILS/src/sql/Pg/020.schema.functions.sql
===================================================================
--- branches/rel_2_0/Open-ILS/src/sql/Pg/020.schema.functions.sql	2011-04-02 17:07:48 UTC (rev 19931)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/020.schema.functions.sql	2011-04-02 17:10:21 UTC (rev 19932)
@@ -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,8 +222,18 @@
                 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 (
+            SELECT $1, 0
+        UNION
+            SELECT ou.id, oudd.distance+1
+            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 ROWS 1;
+
 CREATE OR REPLACE FUNCTION actor.org_unit_ancestors( INT ) RETURNS SETOF actor.org_unit AS $$
     WITH RECURSIVE anscestor_depth AS (
         SELECT  ou.id,
@@ -236,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.*
@@ -247,17 +257,28 @@
 					ON x.ou_type = y.id AND y.depth = $2);
 $$ LANGUAGE SQL STABLE;
 
+CREATE OR REPLACE FUNCTION actor.org_unit_ancestors_distance( INT ) RETURNS TABLE (id INT, distance INT) AS $$
+    WITH RECURSIVE org_unit_ancestors_distance(id, distance) AS (
+            SELECT $1, 0
+        UNION
+            SELECT ou.parent_ou, ouad.distance+1
+            FROM actor.org_unit ou JOIN org_unit_ancestors_distance ouad ON (ou.id = ouad.id)
+            WHERE ou.parent_ou IS NOT NULL
+    )
+    SELECT * FROM org_unit_ancestors_distance;
+$$ LANGUAGE SQL STABLE ROWS 1;
+
 CREATE OR REPLACE FUNCTION actor.org_unit_full_path ( INT ) RETURNS SETOF actor.org_unit AS $$
 	SELECT	*
 	  FROM	actor.org_unit_ancestors($1)
 			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	*
@@ -265,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	*
@@ -273,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 (
@@ -299,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_0/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_0/Open-ILS/src/sql/Pg/upgrade/0506.schema.tree-ish_function_row_estimates.sql	                        (rev 0)
+++ branches/rel_2_0/Open-ILS/src/sql/Pg/upgrade/0506.schema.tree-ish_function_row_estimates.sql	2011-04-02 17:10:21 UTC (rev 19932)
@@ -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