-- I saw this plan once Unique (cost=5818.30..5818.30 rows=1 width=64) -> Sort (cost=5818.30..5818.30 rows=1 width=64) Sort Key: ((c_1.conname)::information_schema.sql_identifier) -> Nested Loop (cost=2130.47..5818.29 rows=1 width=64) -> Hash Semi Join (cost=2130.18..5817.95 rows=1 width=104) Hash Cond: (c_1.conname = ("*SELECT* 1".constraint_name)::name) -> ProjectSet (cost=180.20..1317.71 rows=202000 width=341) -> Hash Join (cost=180.20..256.20 rows=202 width=95) Hash Cond: (c_1.connamespace = nc.oid) -> Hash Join (cost=179.11..254.02 rows=202 width=99) Hash Cond: (r.relnamespace = nr.oid) -> Hash Join (cost=178.02..251.48 rows=269 width=103) Hash Cond: (c_1.conrelid = r.oid) -> Seq Scan on pg_constraint c_1 (cost=0.00..69.49 rows=1510 width=95) Filter: (contype = ANY ('{p,u,f}'::"char"[])) -> Hash (cost=168.20..168.20 rows=786 width=12) -> Seq Scan on pg_class r (cost=0.00..168.20 rows=786 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=1949.97..1949.97 rows=1 width=128) -> Nested Loop (cost=435.35..1949.97 rows=1 width=128) Join Filter: (pkc.conname = ("*SELECT* 1_1".constraint_name)::name) -> Nested Loop (cost=435.06..1798.00 rows=1 width=192) Join Filter: (con.conname = ("*SELECT* 1".constraint_name)::name) -> Nested Loop (cost=125.29..326.60 rows=1 width=128) -> Nested Loop (cost=125.01..325.61 rows=1 width=132) -> Nested Loop (cost=124.88..325.44 rows=1 width=136) Join Filter: (pkc.conrelid = con.confrelid) -> Nested Loop (cost=124.60..324.37 rows=1 width=72) -> Hash Join (cost=124.31..316.71 rows=1 width=72) Hash Cond: (d2.refobjid = pkc.oid) -> Bitmap Heap Scan on pg_depend d2 (cost=48.04..240.36 rows=30 width=8) Recheck Cond: (refclassid = '2606'::oid) Filter: ((classid = '1259'::oid) AND (objsubid = 0) AND (deptype = 'i'::"char")) -> Bitmap Index Scan on pg_depend_reference_index (cost=0.00..48.03 rows=1566 width=0) Index Cond: (refclassid = '2606'::oid) -> Hash (cost=67.54..67.54 rows=699 width=76) -> Seq Scan on pg_constraint pkc (cost=0.00..67.54 rows=699 width=76) Filter: (contype = ANY ('{p,u}'::"char"[])) -> Index Scan using pg_depend_reference_index on pg_depend d1 (cost=0.29..7.65 rows=1 width=8) Index Cond: ((refclassid = '1259'::oid) AND (refobjid = d2.objid) AND (refobjsubid = 0)) Filter: (classid = '2606'::oid) -> Index Scan using pg_constraint_oid_index on pg_constraint con (cost=0.28..1.06 rows=1 width=80) Index Cond: (oid = d1.objid) Filter: (contype = 'f'::"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..0.99 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)) -> Append (cost=309.77..1460.73 rows=854 width=64) -> Subquery Scan on "*SELECT* 1" (cost=309.77..384.74 rows=147 width=64) -> Hash Join (cost=309.77..383.27 rows=147 width=512) Hash Cond: (c_2.connamespace = nc_1.oid) -> Hash Join (cost=308.68..381.38 rows=147 width=68) Hash Cond: (r_1.relnamespace = nr_1.oid) -> Hash Join (cost=307.59..379.23 rows=196 width=72) Hash Cond: (c_2.conrelid = r_1.oid) -> Seq Scan on pg_constraint c_2 (cost=0.00..67.54 rows=1563 width=72) Filter: (contype <> ALL ('{t,x}'::"char"[])) -> Hash (cost=300.68..300.68 rows=553 width=8) -> Seq Scan on pg_class r_1 (cost=0.00..300.68 rows=553 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=308.68..1071.72 rows=707 width=64) -> Hash Join (cost=308.68..1064.65 rows=707 width=512) Hash Cond: (r_2.relnamespace = nr_2.oid) -> Hash Join (cost=307.59..1037.26 rows=942 width=10) Hash Cond: (a_1.attrelid = r_2.oid) -> Seq Scan on pg_attribute a_1 (cost=0.00..709.89 rows=7525 width=6) Filter: (attnotnull AND (NOT attisdropped) AND (attnum > 0)) -> Hash (cost=300.68..300.68 rows=553 width=8) -> Seq Scan on pg_class r_2 (cost=0.00..300.68 rows=553 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)) -> Subquery Scan on "*SELECT* 1_1" (cost=0.28..151.95 rows=1 width=64) -> Nested Loop (cost=0.28..151.94 rows=1 width=512) Join Filter: (r_3.relnamespace = nr_3.oid) -> Nested Loop (cost=0.28..150.85 rows=1 width=68) Join Filter: (c_3.connamespace = nc_2.oid) -> Nested Loop (cost=0.28..149.76 rows=1 width=72) -> Seq Scan on pg_constraint c_3 (cost=0.00..87.08 rows=8 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..7.83 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))