Skip to content

Add indexes for unindexed foreign keys #176

Closed

Description

@thinkclay

Summary

The Supabase performance advisor reported foreign key constraints that do not have a covering index. This can cause slow joins and cascades. Adding indexes on the FK columns improves performance.

Affected objects

Run the performance advisor for the full list: Supabase MCP get_advisors with type: "performance", filter by unindexed_foreign_keys.

Example: core.account_deletions — foreign key account_deletions_requested_by_user_id_fkey without a covering index.

Remediation

  1. For each reported table and FK column(s), add an index, e.g. CREATE INDEX CONCURRENTLY idx_<table>_<fk_column> ON <schema>.<table> (<fk_column>);
  2. Prefer CONCURRENTLY in production to avoid long locks.
  3. See Unindexed foreign keys.

References

Activity

  1. thinkclay commented on Mar 10, 2026

    @thinkclay
    ContributorAuthor

    Done.

    • Added migration 407_index_unindexed_foreign_keys.sql with 193 indexes on FK columns from Supabase performance advisor (core, data, engagement, onet). forsured schema skipped (dropped in 400).
    • All indexes use IF NOT EXISTS for idempotency.
    • Note: Local migration up failed at an earlier migration (401 – column braingrid_sync_status missing). Once the migration chain is fixed, 407 will apply. You can also apply 407 manually against a DB that has all prior migrations applied.
  2. added a commit that references this issue on Mar 10, 2026
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