[OPENJPA-2964] Honour the query range on set operations - #172
Open
rzo1 wants to merge 1 commit into
Open
Conversation
executeSetOperatorQuery() received the StoreQuery.Range but never used it, so setFirstResult()/setMaxResults() were silently ignored on a UNION, INTERSECT or EXCEPT query. The range is applied in memory over the compound result, through RangeResultObjectProvider, which is the same fallback the ordinary path uses when the dictionary cannot express a range in SQL. It cannot be pushed into the statement: DBDictionary.toSelect() renders the first operand in full, including any limit derived from the select's start and end index, and only then appends the set operator buffer, so a range on the main select would bind to the first operand instead of to the compound result. A javadoc on the method records that, since the optimisation is tempting and silently wrong. testSetOperatorRange covers UNION ALL, UNION, INTERSECT and EXCEPT, and both provider branches. It asserts cardinality only: JPQL attaches an ORDER BY to an individual select, so the row order of a compound set operation is undefined.
solomax
approved these changes
Sep 3, 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.
executeSetOperatorQuery()received theStoreQuery.Rangebut never used it, sosetFirstResult()/setMaxResults()were silently ignored on a UNION, INTERSECT or EXCEPT query.The range is applied in memory through
RangeResultObjectProvider, the same fallback the ordinary path uses when the dictionary cannot express a range in SQL. It cannot be pushed into the statement:DBDictionary.toSelect()renders the first operand in full, including any limit derived from the select's start and end index, and only then appends the set-operator buffer — so a range on the main select would bind to the first operand instead of to the compound result, returning wrong rows rather than none. A javadoc on the method records that, since the optimisation is tempting and silently wrong.testSetOperatorRangecovers UNION ALL, UNION, INTERSECT and EXCEPT and both provider branches, asserting cardinality only: JPQL attaches ORDER BY to an individual select, so the row order of a compound set operation is undefined.