index column analysis - postgres is OK, still fails for cockroach

This commit is contained in:
Jan Prochazka
2021-08-20 22:24:31 +02:00
parent 820044b489
commit 10e63f3e77

View File

@@ -5,31 +5,25 @@ module.exports = `
i.relname as "index_name", i.relname as "index_name",
ix.indisprimary as "is_primary", ix.indisprimary as "is_primary",
ix.indisunique as "is_unique", ix.indisunique as "is_unique",
array_to_string(array_agg(a.attname), '|') as "column_names" (
select
array_to_string(array_agg((select a.attname from pg_attribute a where ord = a.attnum and a.attrelid = t.oid)), '|')
from
unnest(ix.indkey) ord
) as "column_names"
from from
pg_class t, pg_class t,
pg_class i, pg_class i,
pg_index ix, pg_index ix,
pg_attribute a,
pg_namespace c pg_namespace c
where where
t.oid = ix.indrelid t.oid = ix.indrelid
and i.oid = ix.indexrelid and i.oid = ix.indexrelid
and a.attrelid = t.oid
and a.attnum = ANY(ix.indkey)
and t.relkind = 'r' and t.relkind = 'r'
and ix.indisprimary = false and ix.indisprimary = false
and t.relnamespace = c.oid and t.relnamespace = c.oid
and c.nspname != 'pg_catalog' and c.nspname != 'pg_catalog'
and ('tables:' || c.nspname || '.' || t.relname) =OBJECT_ID_CONDITION and ('tables:' || c.nspname || '.' || t.relname) =OBJECT_ID_CONDITION
group by
i.oid,
t.relname,
i.relname,
c.nspname,
ix.indisprimary,
ix.indisunique
order by order by
t.relname, t.relname
i.relname
`; `;