hsyuan commented on a change in pull request #1985:
URL: https://github.com/apache/calcite/pull/1985#discussion_r428388218



##########
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:
       In many cases, Sort should always be put on top of Filter. But in this 
case, we might get better plan by pushing down sort requirement past Filter.




----------------------------------------------------------------
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


Reply via email to