Add regression tests for sorting native queries with a derived table containing ORDER BY … LIMIT#4276
Open
jewoodev wants to merge 1 commit into
Conversation
…containing `ORDER BY … LIMIT`. Applying a `Sort` to a native query whose `FROM` clause contains a derived table with its own `ORDER BY … LIMIT` used to corrupt the generated sort fragment: `QueryUtils.applySorting` matched the derived table's inner `ORDER BY` and appended the primary sort after the `WHERE` clause without an `order by` keyword (`… WHERE … = :status, n.name asc`), producing invalid SQL once pagination applied its `LIMIT`. Both native query enhancers now append the primary `ORDER BY` to the outer query while preserving the derived table's inner ordering, so this adds regression tests for the regex-based `DefaultQueryEnhancer` and the JSqlParser-based `JSqlParserQueryEnhancer`. Closes spring-projects#2395 Signed-off-by: jewoodev <jewoos15@naver.com>
73eb853 to
0c77518
Compare
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 broken sort fragment reported in #2395 reproduces on the version it was filed against (2.3.9):
QueryUtils.applySortingmatched the derived table's innerORDER BYand appended the primary sort after theWHEREclause without anorder bykeyword (… = :status, n.name asc), which becomes invalid SQL once pagination adds itsLIMIT. It is no longer reproducible onmain— both native query enhancers append the primaryORDER BYto the outer query while preserving the derived table's inner ordering.This PR adds a regression test for each native enhancer: the regex-based
DefaultQueryEnhancer, where the original breakage lived, and the JSqlParser-basedJSqlParserQueryEnhancer, the default once JSqlParser is on the classpath. Each sits next to the existingshouldApplySortingcoverage in its test class; both classes pass locally.Closes #2395