Bug
INDEXES_SQL joins pg_indexes only on index name:
JOIN pg_indexes ix ON c.relname = ix.indexname
Index names are unique per schema, not globally. When two schemas have tables with the same primary-key / index name (very common: users_pkey, dup_idx_pkey), the join matches every schema's pg_indexes row. Because ix.indexdef is in the GROUP BY, GET /indexes returns multiple API rows for one OID, and some of them carry the other schema's index_definition.
Reproduce
create schema private;
create table public.dup_idx (id int primary key);
create table private.dup_idx (id int primary key);
Against the current query, filtering to private.dup_idx_pkey yields 2 rows — one with ON private.dup_idx and one with ON public.dup_idx.
Expected
One row per index OID, with index_definition matching that index's schema.
Suggested fix
JOIN pg_indexes ix ON c.relname = ix.indexname AND n.nspname = ix.schemaname
This is independent of #1108 / PR #1109 (which fixes pg_attribute/indkey matching).
Impact
Studio and any client listing indexes in multi-schema databases silently show wrong DDL / duplicate indexes whenever schemas share naming conventions.
Bug
INDEXES_SQLjoinspg_indexesonly on index name:Index names are unique per schema, not globally. When two schemas have tables with the same primary-key / index name (very common:
users_pkey,dup_idx_pkey), the join matches every schema'spg_indexesrow. Becauseix.indexdefis in theGROUP BY,GET /indexesreturns multiple API rows for one OID, and some of them carry the other schema'sindex_definition.Reproduce
Against the current query, filtering to
private.dup_idx_pkeyyields 2 rows — one withON private.dup_idxand one withON public.dup_idx.Expected
One row per index OID, with
index_definitionmatching that index's schema.Suggested fix
This is independent of #1108 / PR #1109 (which fixes
pg_attribute/indkeymatching).Impact
Studio and any client listing indexes in multi-schema databases silently show wrong DDL / duplicate indexes whenever schemas share naming conventions.