Skip to content

[OPENJPA-2964] Honour the query range on set operations - #172

Open
rzo1 wants to merge 1 commit into
masterfrom
OPENJPA-2964
Open

[OPENJPA-2964] Honour the query range on set operations#172
rzo1 wants to merge 1 commit into
masterfrom
OPENJPA-2964

Conversation

@rzo1

@rzo1 rzo1 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

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 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.

testSetOperatorRange covers 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.

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.
@rzo1 rzo1 self-assigned this Sep 2, 2026
@rzo1
rzo1 requested review from cristof and solomax September 2, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants