fix: remove redundant ORDER BY in QueryForCredentials#4522
Open
wyh0626 wants to merge 1 commit intoory:masterfrom
Open
fix: remove redundant ORDER BY in QueryForCredentials#4522wyh0626 wants to merge 1 commit intoory:masterfrom
wyh0626 wants to merge 1 commit intoory:masterfrom
Conversation
The database-level ORDER BY is redundant since identifiers are already sorted in-memory (line 919-923). Removing this improves PostgreSQL performance as it cannot use index hints. Fixes ory#4520
Contributor
|
The query plan seems ok for this specific query. I'm not sure if this will do much since the average returning rows is 1. |
5 tasks
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.
The database-level ORDER BY is redundant since identifiers are already sorted in-memory (line 917-921 in persistence/sql/identity/persister_identity.go) Removing this improves PostgreSQL performance as it cannot use index hints.
Fixes #4520
Related issue(s)
Fixes #4520
This PR addresses a performance regression reported after upgrading from v1.3.0 to v25.4.0. Users observed:
Root cause: The
ORDER BY identifier ASCclause in QueryForCredentials is redundant because identifiers are already sorted in-memory usingsort.Strings(). Additionally, PostgreSQL cannot use index hints (unlike MySQL/CockroachDB/SQLite), causing the optimizer to potentially choose suboptimal execution plans.Checklist
Further Comments
This is a minimal fix that removes redundant database sorting. The in-memory
sort.Strings()already guarantees deterministic ordering for testing purposes (as noted in the existing code comment).No new tests are added because: