xiaokang commented on code in PR #10647:
URL: https://github.com/apache/doris/pull/10647#discussion_r916498906


##########
fe/fe-core/src/main/java/org/apache/doris/planner/OriginalPlanner.java:
##########
@@ -316,6 +320,45 @@ private void pushDownResultFileSink(Analyzer analyzer) {
         
topPlanFragment.getPlanRoot().resetTupleIds(Lists.newArrayList(fileStatusDesc.getId()));
     }
 
+    /**
+     * Push sort down to olap scan.
+     */
+    private void pushSortToOlapScan() {
+        for (PlanFragment fragment : fragments) {
+            PlanNode node = fragment.getPlanRoot();
+            PlanNode parent = null;
+
+            // OlapScanNode is the last node.
+            // So, just get the last two node and check if they are SortNode 
and OlapScan.
+            while (node.getChildren().size() != 0) {
+                parent = node;
+                node = node.getChildren().get(0);
+            }
+
+            if (!(node instanceof OlapScanNode) || !(parent instanceof 
SortNode)) {
+                continue;
+            }
+
+            SortNode sortNode = (SortNode) parent;
+            // Ensure all isAscOrder is same, ande length != 0.
+            if 
(sortNode.getSortInfo().getIsAscOrder().stream().distinct().count() != 1) {
+                continue;
+            }
+            // If offset > 0, we can't push down sort to olap scan.

Review Comment:
   If offset > 0, maybe we can still push down sort to olap scan. Just set scan 
node's limit to limit + offset.



##########
fe/fe-core/src/main/java/org/apache/doris/planner/OriginalPlanner.java:
##########
@@ -316,6 +320,45 @@ private void pushDownResultFileSink(Analyzer analyzer) {
         
topPlanFragment.getPlanRoot().resetTupleIds(Lists.newArrayList(fileStatusDesc.getId()));
     }
 
+    /**
+     * Push sort down to olap scan.
+     */
+    private void pushSortToOlapScan() {
+        for (PlanFragment fragment : fragments) {
+            PlanNode node = fragment.getPlanRoot();
+            PlanNode parent = null;
+
+            // OlapScanNode is the last node.
+            // So, just get the last two node and check if they are SortNode 
and OlapScan.
+            while (node.getChildren().size() != 0) {
+                parent = node;
+                node = node.getChildren().get(0);
+            }
+
+            if (!(node instanceof OlapScanNode) || !(parent instanceof 
SortNode)) {
+                continue;
+            }
+
+            SortNode sortNode = (SortNode) parent;
+            // Ensure all isAscOrder is same, ande length != 0.
+            if 
(sortNode.getSortInfo().getIsAscOrder().stream().distinct().count() != 1) {

Review Comment:
   we can put all check to method checkPushSort



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

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to