-- This appears to be the most common explain plan result Unique (cost=4892.35..4892.35 rows=1 width=64) -> Sort (cost=4892.35..4892.35 rows=1 width=64) Sort Key: ((c_1.conname)::information_schema.sql_identifier) -> Nested Loop (cost=1891.31..4892.34 rows=1 width=64) -> Hash Semi Join (cost=1891.03..4892.00 rows=1 width=104) Hash Cond: (c_1.conname = ("*SELECT* 1".constraint_name)::name) -> ProjectSet (cost=156.09..1086.55 rows=164000 width=341) -> Hash Join (cost=156.09..224.73 rows=164 width=95) Hash Cond: (c_1.connamespace = nc.oid) -> Hash Join (cost=155.00..222.75 rows=164 width=99) Hash Cond: (r.relnamespace = nr.oid) -> Hash Join (cost=153.91..220.49 rows=218 width=103) Hash Cond: (c_1.conrelid = r.oid) -> Seq Scan on pg_constraint c_1 (cost=0.00..63.63 rows=1121 width=95) Filter: (contype = ANY ('{p,u,f}'::"char"[])) -> Hash (cost=147.25..147.25 rows=533 width=12) -> Seq Scan on pg_class r (cost=0.00..147.25 rows=533 width=12) Filter: (relkind = ANY ('{r,p}'::"char"[])) -> Hash (cost=1.05..1.05 rows=3 width=4) -> Seq Scan on pg_namespace nr (cost=0.00..1.05 rows=3 width=4) Filter: (NOT pg_is_other_temp_schema(oid)) -> Hash (cost=1.04..1.04 rows=4 width=4) -> Seq Scan on pg_namespace nc (cost=0.00..1.04 rows=4 width=4) -> Hash (cost=1734.93..1734.93 rows=1 width=128) -> Nested Loop (cost=593.86..1734.93 rows=1 width=128) Join Filter: (pkc.conname = ("*SELECT* 1_1".constraint_name)::name) -> Nested Loop (cost=593.58..1606.28 rows=1 width=192) Join Filter: (d2.refobjid = pkc.oid) -> Nested Loop (cost=593.30..1605.51 rows=1 width=136) -> Nested Loop (cost=593.02..1604.26 rows=1 width=140) -> Nested Loop (cost=592.89..1604.09 rows=1 width=144) -> Hash Join (cost=592.60..1552.20 rows=29 width=144) Hash Cond: (("*SELECT* 1".constraint_name)::name = con.conname) -> Append (cost=236.31..1193.35 rows=606 width=64) -> Subquery Scan on "*SELECT* 1" (cost=236.31..304.16 rows=117 width=64) -> Hash Join (cost=236.31..302.99 rows=117 width=512) Hash Cond: (c_2.connamespace = nc_1.oid) -> Hash Join (cost=235.22..301.27 rows=117 width=68) Hash Cond: (r_1.relnamespace = nr_1.oid) -> Hash Join (cost=234.14..299.33 rows=156 width=72) Hash Cond: (c_2.conrelid = r_1.oid) -> Seq Scan on pg_constraint c_2 (cost=0.00..62.21 rows=1137 width=72) Filter: (contype <> ALL ('{t,x}'::"char"[])) -> Hash (cost=229.45..229.45 rows=375 width=8) -> Seq Scan on pg_class r_1 (cost=0.00..229.45 rows=375 width=8) Filter: ((relkind = ANY ('{r,p}'::"char"[])) AND (pg_has_role(relowner, 'USAGE'::text) OR has_table_privilege(oid, 'INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER'::text) OR has_any_column_privilege(oid, 'INSERT, UPDATE, REFERENCES'::text))) -> Hash (cost=1.05..1.05 rows=3 width=4) -> Seq Scan on pg_namespace nr_1 (cost=0.00..1.05 rows=3 width=4) Filter: (NOT pg_is_other_temp_schema(oid)) -> Hash (cost=1.04..1.04 rows=4 width=4) -> Seq Scan on pg_namespace nc_1 (cost=0.00..1.04 rows=4 width=4) -> Subquery Scan on "*SELECT* 2" (cost=235.22..886.16 rows=489 width=64) -> Hash Join (cost=235.22..881.27 rows=489 width=512) Hash Cond: (r_2.relnamespace = nr_2.oid) -> Hash Join (cost=234.14..861.99 rows=653 width=10) Hash Cond: (a_1.attrelid = r_2.oid) -> Seq Scan on pg_attribute a_1 (cost=0.00..615.31 rows=4768 width=6) Filter: (attnotnull AND (NOT attisdropped) AND (attnum > 0)) -> Hash (cost=229.45..229.45 rows=375 width=8) -> Seq Scan on pg_class r_2 (cost=0.00..229.45 rows=375 width=8) Filter: ((relkind = ANY ('{r,p}'::"char"[])) AND (pg_has_role(relowner, 'USAGE'::text) OR has_table_privilege(oid, 'INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER'::text) OR has_any_column_privilege(oid, 'INSERT, UPDATE, REFERENCES'::text))) -> Hash (cost=1.05..1.05 rows=3 width=4) -> Seq Scan on pg_namespace nr_2 (cost=0.00..1.05 rows=3 width=4) Filter: (NOT pg_is_other_temp_schema(oid)) -> Hash (cost=355.61..355.61 rows=54 width=80) -> Hash Join (cost=148.76..355.61 rows=54 width=80) Hash Cond: (d1.objid = con.oid) -> Bitmap Heap Scan on pg_depend d1 (cost=79.31..284.29 rows=713 width=8) Recheck Cond: (classid = '2606'::oid) Filter: ((refclassid = '1259'::oid) AND (refobjsubid = 0)) -> Bitmap Index Scan on pg_depend_depender_index (cost=0.00..79.13 rows=2513 width=0) Index Cond: (classid = '2606'::oid) -> Hash (cost=62.21..62.21 rows=579 width=80) -> Seq Scan on pg_constraint con (cost=0.00..62.21 rows=579 width=80) Filter: (contype = 'f'::"char") -> Index Scan using pg_depend_depender_index on pg_depend d2 (cost=0.29..1.78 rows=1 width=8) Index Cond: ((classid = '1259'::oid) AND (objid = d1.refobjid) AND (objsubid = 0)) Filter: ((refclassid = '2606'::oid) AND (deptype = 'i'::"char")) -> Index Only Scan using pg_namespace_oid_index on pg_namespace ncon (cost=0.13..0.16 rows=1 width=4) Index Cond: (oid = con.connamespace) -> Index Scan using pg_class_oid_index on pg_class c (cost=0.28..1.25 rows=1 width=4) Index Cond: (oid = con.conrelid) Filter: (pg_has_role(relowner, 'USAGE'::text) OR has_table_privilege(oid, 'INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER'::text) OR has_any_column_privilege(oid, 'INSERT, UPDATE, REFERENCES'::text)) -> Index Scan using pg_constraint_conrelid_contypid_conname_index on pg_constraint pkc (cost=0.28..0.75 rows=1 width=76) Index Cond: (conrelid = con.confrelid) Filter: (contype = ANY ('{p,u}'::"char"[])) -> Subquery Scan on "*SELECT* 1_1" (cost=0.28..128.64 rows=1 width=64) -> Nested Loop (cost=0.28..128.63 rows=1 width=512) Join Filter: (r_3.relnamespace = nr_3.oid) -> Nested Loop (cost=0.28..127.54 rows=1 width=68) Join Filter: (c_3.connamespace = nc_2.oid) -> Nested Loop (cost=0.28..126.45 rows=1 width=72) -> Seq Scan on pg_constraint c_3 (cost=0.00..76.42 rows=6 width=72) Filter: ((contype <> ALL ('{t,x}'::"char"[])) AND ((CASE contype WHEN 'c'::"char" THEN 'CHECK'::text WHEN 'f'::"char" THEN 'FOREIGN KEY'::text WHEN 'p'::"char" THEN 'PRIMARY KEY'::text WHEN 'u'::"char" THEN 'UNIQUE'::text ELSE NULL::text END)::text = 'PRIMARY KEY'::text)) -> Index Scan using pg_class_oid_index on pg_class r_3 (cost=0.28..8.33 rows=1 width=8) Index Cond: (oid = c_3.conrelid) Filter: ((relkind = ANY ('{r,p}'::"char"[])) AND (pg_has_role(relowner, 'USAGE'::text) OR has_table_privilege(oid, 'INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER'::text) OR has_any_column_privilege(oid, 'INSERT, UPDATE, REFERENCES'::text))) -> Seq Scan on pg_namespace nc_2 (cost=0.00..1.04 rows=4 width=4) -> Seq Scan on pg_namespace nr_3 (cost=0.00..1.05 rows=3 width=4) Filter: (NOT pg_is_other_temp_schema(oid)) -> Index Scan using pg_attribute_relid_attnum_index on pg_attribute a (cost=0.29..0.33 rows=1 width=6) Index Cond: ((attrelid = r.oid) AND (attnum = ((information_schema._pg_expandarray(c_1.conkey))).x)) Filter: ((NOT attisdropped) AND (pg_has_role(r.relowner, 'USAGE'::text) OR has_column_privilege(r.oid, attnum, 'SELECT, INSERT, UPDATE, REFERENCES'::text)) AND (lower(((attname)::information_schema.sql_identifier)::text) ~~ 'xxx_%'::text))