amaliujia commented on a change in pull request #1985: URL: https://github.com/apache/calcite/pull/1985#discussion_r428430702
########## File path: core/src/test/resources/org/apache/calcite/test/TopDownOptTest.xml ########## @@ -35,6 +35,46 @@ EnumerableLimit(fetch=[5]) EnumerableSortedAggregate(group=[{3}], EXPR$1=[COUNT()]) EnumerableSort(sort0=[$3], dir0=[DESC-nulls-last]) EnumerableTableScan(table=[[CATALOG, SALES, EMP]]) +]]> + </Resource> + </TestCase> + <TestCase name="testSortProject"> + <Resource name="sql"> + <![CDATA[select mgr from sales.emp order by mgr desc nulls last]]> + </Resource> + <Resource name="planBefore"> + <![CDATA[ +LogicalSort(sort0=[$0], dir0=[DESC-nulls-last]) + LogicalProject(MGR=[$3]) + LogicalTableScan(table=[[CATALOG, SALES, EMP]]) +]]> + </Resource> + <Resource name="planAfter"> + <![CDATA[ +EnumerableProject(MGR=[$3]) + EnumerableSort(sort0=[$3], dir0=[DESC-nulls-last]) + EnumerableTableScan(table=[[CATALOG, SALES, EMP]]) +]]> + </Resource> + </TestCase> + <TestCase name="testSortFilter"> + <Resource name="sql"> + <![CDATA[select mgr from sales.emp where deptno > 10 order by mgr desc]]> + </Resource> + <Resource name="planBefore"> + <![CDATA[ +LogicalSort(sort0=[$0], dir0=[DESC]) + LogicalProject(MGR=[$3]) + LogicalFilter(condition=[>($7, 10)]) + LogicalTableScan(table=[[CATALOG, SALES, EMP]]) +]]> + </Resource> + <Resource name="planAfter"> + <![CDATA[ +EnumerableProject(MGR=[$3]) + EnumerableSort(sort0=[$3], dir0=[DESC]) + EnumerableFilter(condition=[>($7, 10)]) + EnumerableTableScan(table=[[CATALOG, SALES, EMP]]) Review comment: That's a good point that filter first then sort after, since filter will reduce volume of data thus reduce cost of sort. (not absolute but make senses). ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org