From 3f7626e9f2821ba084f3c31fddd9777ba7be6018 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 14 Feb 2009 20:48:36 +0000 Subject: [PATCH] A couple of marginal performance hacks for the information_schema views: 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 | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/backend/catalog/information_schema.sql b/src/backend/catalog/information_schema.sql index d03083aac3..4206e9eaf5 100644 --- a/src/backend/catalog/information_schema.sql +++ b/src/backend/catalog/information_schema.sql @@ -4,7 +4,7 @@ * * Copyright (c) 2003-2009, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/backend/catalog/information_schema.sql,v 1.51 2009/02/06 21:15:11 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/information_schema.sql,v 1.52 2009/02/14 20:48:36 tgl Exp $ */ /* @@ -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