Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Invalid
-
None
-
None
-
None
Description
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
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
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]])
where LogicalSort is performed at the end.
Union-All has the same behavior also.