[
https://issues.apache.org/jira/browse/CALCITE-7761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18111036#comment-18111036
]
Kirill Tkalenko commented on CALCITE-7761:
------------------------------------------
Thanks. The {{ROWNUM}} rewrite is only the downstream context in which I
encountered this issue; I am not proposing it as a Calcite feature.
I tried a SQL-only case with inner {{OFFSET/FETCH}} and outer {{{}ORDER BY{}}},
but it does not exercise this condition. Calcite parses {{OFFSET/FETCH}} as
{{{}SqlOrderBy{}}}, and the normal rewrite gives the {{SqlSelect}} a non-null
order list, possibly empty. Therefore, the old code already takes a different
path.
The problematic state — a {{SqlSelect}} with {{FETCH}} or {{OFFSET}} but
without {{ORDER BY}} — is produced by an external rewrite. Given the
maintenance cost, I can remove the custom validator test and keep the small
defensive fix without it.
> Preserve OFFSET and FETCH when rewriting outer ORDER BY
> -------------------------------------------------------
>
> Key: CALCITE-7761
> URL: https://issues.apache.org/jira/browse/CALCITE-7761
> Project: Calcite
> Issue Type: Improvement
> Reporter: Kirill Tkalenko
> Assignee: Kirill Tkalenko
> Priority: Major
> Labels: pull-request-available
>
> {{SqlValidatorImpl.performUnconditionalRewrites}} may overwrite {{OFFSET}} or
> {{FETCH}} previously added to an inner {{SELECT}} during query rewriting.
> Merge the outer {{SqlOrderBy}} only when the inner {{SELECT}} has no
> {{{}ORDER BY{}}}, {{{}OFFSET{}}}, or {{{}FETCH{}}}.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)