A couple of marginal performance hacks for the information_schema views:
authorTom Lane <[email protected]>
Sat, 14 Feb 2009 20:48:36 +0000 (20:48 +0000)
committerTom Lane <[email protected]>
Sat, 14 Feb 2009 20:48:36 +0000 (20:48 +0000)
replace the old recursive-SQL-function implementation of _pg_keysequal()
with use of the built-in array containment operators, and change
table_constraints' UNION to UNION ALL.  Per discussion with Octavio Alvarez.

initdb not forced since this doesn't affect results, but you'd need to
initdb or reload the information_schema to see the new definitions.

src/backend/catalog/information_schema.sql

index 4256cd627d28d3620873b68096cecd7100e48a95..5b5e203339a11ae553e02e5507ab0c4d98b27799 100644 (file)
@@ -40,17 +40,9 @@ CREATE FUNCTION _pg_expandarray(IN anyarray, OUT x anyelement, OUT n int)
                                         pg_catalog.array_upper($1,1),
                                         1) as g(s)';
 
-CREATE FUNCTION _pg_keyissubset(smallint[], smallint[]) RETURNS boolean
-    LANGUAGE sql
-    IMMUTABLE
-    RETURNS NULL ON NULL INPUT
-    AS 'select $1[1] is null or ($1[1] = any ($2) and coalesce(information_schema._pg_keyissubset($1[2:pg_catalog.array_upper($1,1)], $2), true))';
-
 CREATE FUNCTION _pg_keysequal(smallint[], smallint[]) RETURNS boolean
-    LANGUAGE sql
-    IMMUTABLE
-    RETURNS NULL ON NULL INPUT
-    AS 'select information_schema._pg_keyissubset($1, $2) and information_schema._pg_keyissubset($2, $1)';
+    LANGUAGE sql IMMUTABLE  -- intentionally not STRICT, to allow inlining
+    AS 'select $1 <@ $2 and $2 <@ $1';
 
 /* Get the OID of the unique index that an FK constraint depends on */
 CREATE FUNCTION _pg_underlying_index(oid) RETURNS oid
@@ -1793,7 +1785,7 @@ CREATE VIEW table_constraints AS
                OR has_table_privilege(r.oid, 'INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER')
                OR has_any_column_privilege(r.oid, 'INSERT, UPDATE, REFERENCES') )
 
-    UNION
+    UNION ALL
 
     -- not-null constraints