[
https://issues.apache.org/jira/browse/CALCITE-737?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14549575#comment-14549575
]
Julian Hyde commented on CALCITE-737:
-------------------------------------
bq. Since union is a set operator, the Order-By is supposed to be associated
with the second subquery
Really? What does the SQL standard say?
> When being used with Union, Order by is wrongly associated with the outer
> query
> -------------------------------------------------------------------------------
>
> Key: CALCITE-737
> URL: https://issues.apache.org/jira/browse/CALCITE-737
> Project: Calcite
> Issue Type: Bug
> Reporter: Sean Hsuan-Yi Chu
> Assignee: Julian Hyde
>
> {code}
> select empno from emp t1 where empno = 1
> union
> select empno from emp t2 where empno is not null
> group by empno
> order by empno
> {code}
> Since union is a set operator, the Order-By is supposed to be associated with
> the second subquery. However, the Rel Tree generated by Calcite is
> {code}
> LogicalSort(sort0=[$0], dir0=[ASC])
> LogicalProject(EMPNO=[$0])
> LogicalUnion(all=[false])
> LogicalProject(EMPNO=[$0])
> LogicalFilter(condition=[=($0, 1)])
> LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> LogicalAggregate(group=[{0}])
> LogicalProject(EMPNO=[$0])
> LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> {code}
> where LogicalSort is performed at the end.
> Union-All has the same behavior also.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)