yangzhg commented on a change in pull request #3806:
URL: https://github.com/apache/incubator-doris/pull/3806#discussion_r442589390



##########
File path: fe/src/main/java/org/apache/doris/analysis/QueryStmt.java
##########
@@ -285,27 +285,29 @@ protected void createSortInfo(Analyzer analyzer) throws 
AnalysisException {
         }
 
         sortInfo = new SortInfo(orderingExprs, isAscOrder, nullsFirstParams);
-        // order by w/o limit and offset in inline views, union operands and 
insert statements
+        // order by w/o limit and offset in inline views, set operands and 
insert statements
         // are ignored.
-        // TODO chenhao, open this when we don't limit rows subquery returns 
by SortNode.
-        /*if (!hasLimit() && !hasOffset() && !analyzer.isRootAnalyzer()) {
-         *   evaluateOrderBy = false;
-         *   // Return a warning that the order by was ignored.
-         *   StringBuilder strBuilder = new StringBuilder();
-         *   strBuilder.append("Ignoring ORDER BY clause without LIMIT or 
OFFSET: ");
-         *   strBuilder.append("ORDER BY ");
-         *   strBuilder.append(orderByElements.get(0).toSql());
-         *   for (int i = 1; i < orderByElements.size(); ++i) {
-         *       strBuilder.append(", 
").append(orderByElements.get(i).toSql());
-         *   }
-         *   strBuilder.append(".\nAn ORDER BY appearing in a view, subquery, 
union operand, ");
-         *   strBuilder.append("or an insert/ctas statement has no effect on 
the query result ");
-         *   strBuilder.append("unless a LIMIT and/or OFFSET is used in 
conjunction ");
-         *   strBuilder.append("with the ORDER BY.");
-         * } else {
-         */
-        evaluateOrderBy = true;
-        //}
+        boolean allowIgnore = false;
+        if (ConnectContext.get() != null && 
ConnectContext.get().getSessionVariable().isAllowIgnoreOrderBy()) {
+            allowIgnore = true;
+        }
+        if (allowIgnore && !hasLimit() && !hasOffset() && 
!analyzer.isRootAnalyzer()) {
+            evaluateOrderBy = false;
+            // Return a warning that the order by was ignored.
+            StringBuilder strBuilder = new StringBuilder();
+            strBuilder.append("Ignoring ORDER BY clause without LIMIT or 
OFFSET: ");
+            strBuilder.append("ORDER BY ");
+            strBuilder.append(orderByElements.get(0).toSql());
+            for (int i = 1; i < orderByElements.size(); ++i) {
+                strBuilder.append(", ").append(orderByElements.get(i).toSql());
+            }
+            strBuilder.append(".\nAn ORDER BY appearing in a view, subquery, 
union operand, ");
+            strBuilder.append("or an insert/ctas statement has no effect on 
the query result ");
+            strBuilder.append("unless a LIMIT and/or OFFSET is used in 
conjunction ");
+            strBuilder.append("with the ORDER BY.");

Review comment:
       `strBuilder` is mainly used in the `for` loop, and this code is 
consistent with impala, in case there is a need for merge mpala code in the 
future, it is also more convenient 




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



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

Reply via email to