Fix SearchParameter pagination bug - move TOP to outer query#5362
Merged
jestradaMS merged 1 commit intomainfrom Jan 30, 2026
Merged
Fix SearchParameter pagination bug - move TOP to outer query#5362jestradaMS merged 1 commit intomainfrom
jestradaMS merged 1 commit intomainfrom
Conversation
The subquery wrapper introduced in commit 6dd540c placed TOP inside the inner SELECT without ORDER BY, causing SQL Server to return arbitrary rows in clustered index order before the outer ORDER BY reordered them. This caused pagination to skip resources when continuation tokens filtered by ResourceSurrogateId > lastValue, as rows with high GUIDs but low surrogate IDs were excluded from the initial TOP N selection. Fix: Move TOP to the outer SELECT so it applies after ORDER BY, ensuring correct row selection for pagination. Fixes ICM 2601260050003542
| // When there are no SearchParamTableExpressions, we need TOP on the outer SELECT (after ORDER BY) | ||
| // to ensure pagination works correctly. Previously TOP was in the inner subquery without ORDER BY, | ||
| // causing SQL Server to return arbitrary rows before the outer ORDER BY reordered them. | ||
| // Fix for pagination bug introduced in commit 6dd540c7d. |
Contributor
There was a problem hiding this comment.
Nit: I don't think we need references to specific commits in the code.
Contributor
Author
There was a problem hiding this comment.
I blame co-pilot for that, haha
LTA-Thinking
approved these changes
Jan 30, 2026
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.
Summary
Fixes a pagination bug introduced in commit 6dd540c that caused custom SearchParameters to become "unsupported" after pod restarts.
Problem
The subquery wrapper introduced in #5297 placed
TOPinside the inner SELECT withoutORDER BY:This caused SQL Server to return arbitrary rows in clustered index order before the outer
ORDER BYreordered them. When pagination continued withResourceSurrogateId > lastValue, rows with high GUIDs but low surrogate IDs were skipped.Solution
Move
TOPto the outer SELECT so it applies afterORDER BY:Impact
Testing
TOPon outer queryRelated
AB#182301