Skip to content

perf: add indexes on all foreign key columns#3762

Merged
davidleomay merged 1 commit into
developfrom
perf/add-fk-indexes
May 26, 2026
Merged

perf: add indexes on all foreign key columns#3762
davidleomay merged 1 commit into
developfrom
perf/add-fk-indexes

Conversation

@davidleomay
Copy link
Copy Markdown
Member

Summary

  • Add @Index() to all @ManyToOne relations across 66 entity files
  • Generates 139 new indexes on FK columns

Context

PostgreSQL does not auto-create indexes on FK columns (unlike what's commonly assumed). Without them, every JOIN or WHERE on a FK column does a sequential full table scan. This is the primary cause of the performance degradation after the MSSQL → PostgreSQL migration, especially on support endpoints that load many relations per request.

Test plan

  • Migration runs without errors
  • Support endpoint response times improve
  • No regressions on write-heavy operations (trading, payins)

@davidleomay davidleomay requested a review from TaprootFreak as a code owner May 26, 2026 13:21
@davidleomay davidleomay force-pushed the perf/add-fk-indexes branch from 86d0810 to 5ddf9c9 Compare May 26, 2026 13:34
PostgreSQL does not auto-create indexes on FK columns.
Without them, every JOIN/WHERE on a FK does a sequential scan.
This adds @Index() to all @manytoone relations (139 indexes).
@davidleomay davidleomay force-pushed the perf/add-fk-indexes branch from 5ddf9c9 to 9278233 Compare May 26, 2026 13:34
@davidleomay davidleomay merged commit faa359e into develop May 26, 2026
8 checks passed
@davidleomay davidleomay deleted the perf/add-fk-indexes branch May 26, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant