[DB] [Migration Needed] Add indexes on _portal_domain (domain, app_id)#5724
Open
pkong-ds wants to merge 1 commit into
Open
[DB] [Migration Needed] Add indexes on _portal_domain (domain, app_id)#5724pkong-ds wants to merge 1 commit into
_portal_domain (domain, app_id)#5724pkong-ds wants to merge 1 commit into
Conversation
GetAppIDByDomain (WHERE domain = ?) and GetDomainsByAppID (WHERE app_id = ?) both do full table scans on _portal_domain because no index exists on either column. The table grows with tenant count; at 50k rows (in shared buffers) the domain lookup costs 1788 planner units vs 8 with the index (~210x). Uses CREATE INDEX CONCURRENTLY + notransaction so the build holds no ShareLock and writes are uninterrupted — safe to apply without a downtime window. Drop also uses DROP INDEX CONCURRENTLY.
_portal_domain (domain, app_id)
Contributor
|
Just curious what makes you find this out? Given the size of that table I think having an index should have not much performance gain? |
tung2744
approved these changes
May 18, 2026
Contributor
Author
I was profiling authgear locally, to see long loading of Turns out code-level no problem - and this very, very little optimization is the only problem that claude found. So I thought, ok, doesn't hurt to open a PR for this fix, however trivial this is. Other suspects of long loading?
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
GetAppIDByDomain(WHERE domain = ?)andGetDomainsByAppID(WHERE app_id = ?)both do full table scans on_portal_domainbecause no index exists on either column.The table
_portal_domaingrows with tenant countDowntime
CREATE INDEX CONCURRENTLY+notransactionso the build holds no ShareLock and writes are uninterrupted — safe to apply without a downtime window.DROP INDEX CONCURRENTLY.Tests
I asked claude to write some integration tests - which was TDD and highly detailed.'
But I think those are maintenance burden rather than helpful, so did not include in this PR