Skip to content

GET /indexes returns duplicate rows with the wrong schema's index_definition #1136

Description

@hsusul

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions