Repository navigation
perf(web): index Email by team and date, so team email lists and counts stop scanning the whole table #522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
apps/web/prisma/migrations/20261117010000_email_team_created_at_index/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| -- CreateIndex | ||
| -- Built CONCURRENTLY so sending isn't blocked while it builds on a large | ||
| -- "Email" table. CONCURRENTLY can't run inside a transaction, so this must be | ||
| -- the only statement in the file. IF NOT EXISTS: on useSend cloud the index was | ||
| -- created by hand before this shipped. | ||
| CREATE INDEX CONCURRENTLY IF NOT EXISTS "Email_teamId_createdAt_idx" ON "Email"("teamId", "createdAt" DESC); | ||
6 changes: 6 additions & 0 deletions
6
apps/web/prisma/migrations/20261117010100_email_team_domain_created_at_index/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| -- CreateIndex | ||
| -- Built CONCURRENTLY so sending isn't blocked while it builds on a large | ||
| -- "Email" table. CONCURRENTLY can't run inside a transaction, so this must be | ||
| -- the only statement in the file. IF NOT EXISTS: on useSend cloud the index was | ||
| -- created by hand before this shipped. | ||
| CREATE INDEX CONCURRENTLY IF NOT EXISTS "Email_teamId_domainId_createdAt_idx" ON "Email"("teamId", "domainId", "createdAt" DESC); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Serialize startup before the concurrent index builds.
If two instances start together, the second Prisma 6.6.0 process waits for the migration advisory lock. The index build can deadlock with that waiting session. If PostgreSQL aborts the builder, Prisma records a failed migration and subsequent startups require operator recovery. The same risk applies to the second index. (github.com)
Run migrations as a single deployment step before starting replicas, or otherwise prevent competing migration sessions during the builds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. On useSend cloud this can't happen: a single instance runs migrations, and both indexes were built by hand before this merge, so CREATE INDEX CONCURRENTLY IF NOT EXISTS returns immediately without waiting. For self-hosters running several replicas, I added an upgrade note to the PR description (and it'll go in the release notes): start one instance and let it finish migrating before starting the others, plus recovery steps if a build gets cancelled. I'm keeping migrate-on-startup, since that's how self-hosters upgrade today.