[CALCITE-7761] Preserve OFFSET and FETCH when rewriting outer ORDER BY - #5238
[CALCITE-7761] Preserve OFFSET and FETCH when rewriting outer ORDER BY#5238tkalkirill wants to merge 3 commits into
Conversation
|
Seriously, is this the test case you want to merge to main? |
You’re right, the previous test was too synthetic. I’ve replaced it with a SQL-level regression test based on the reported ROWNUM case. It simulates the ROWNUM-to-FETCH rewrite and verifies that the outer ORDER BY preserves the rewritten FETCH. |
|
| if (select.getOrderList() == null) { | ||
| // Don't clobber existing ORDER BY, OFFSET, or FETCH. ORDER BY may be | ||
| // needed for an order-sensitive function like RANK; OFFSET and FETCH | ||
| // establish a separate pagination level. |
There was a problem hiding this comment.
I don't know what "pagination" means. this term does not appear in the codebase.
The fix looks safe, though.
| } | ||
| } | ||
|
|
||
| /** Validator that simulates rewriting a ROWNUM predicate to FETCH. */ |
There was a problem hiding this comment.
I think @julianhyde asked for a quidem test: a SQL program in a .iq file.
If that exercises this case, it's better than a test such as this one.



Jira Link
CALCITE-7761
Changes Proposed
Preserves OFFSET and FETCH added during query rewriting when an outer ORDER BY is present.
For example, the limit in this query is no longer lost during validation: