morrySnow commented on code in PR #19438: URL: https://github.com/apache/doris/pull/19438#discussion_r1190896107
########## fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java: ########## @@ -631,6 +631,24 @@ public void analyze(Analyzer analyzer) throws UserException { tableRef.setOnClause(rewriteQueryExprByMvColumnExpr(tableRef.getOnClause(), analyzer)); } + // if the query contains limit clause but not order by clause, order by keys by default. + if (ConnectContext.get() != null && ConnectContext.get().getSessionVariable() != null + && ConnectContext.get().getSessionVariable().isEnableDefaultOrder() && analyzer.isNeedAddOrderBy()) { + orderByElements = Lists.newArrayList(); + for (TableRef ref : getTableRefs()) { + if (ref instanceof BaseTableRef + && ref.getTable().getType() == TableType.OLAP) { + OlapTable olapTable = ((OlapTable) ref.getTable()); + int num = olapTable.getKeysNum(); + for (int i = 0; i < num; ++i) { + String colName = olapTable.getFullSchema().get(i).getName(); + SlotRef slotRef = new SlotRef(null, colName); + orderByElements.add(new OrderByElement(slotRef, true, true)); Review Comment: i think it will failed when we have agg, window function, ... we only process SPJ is enough. -- 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