From 15b2e41d7ad83f1d9d6b4dcae9529dc082d851f2 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 16 Oct 2020 23:22:42 +0800 Subject: [PATCH] [td-1720] --- src/client/src/tscLocalMerge.c | 20 ++++++++++++++------ src/client/src/tscSQLParser.c | 9 ++------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/client/src/tscLocalMerge.c b/src/client/src/tscLocalMerge.c index 35114d2aca..05d416377b 100644 --- a/src/client/src/tscLocalMerge.c +++ b/src/client/src/tscLocalMerge.c @@ -573,12 +573,20 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm // the first column is the timestamp, handles queries like "interval(10m) group by tags" orderColIndexList[numOfGroupByCols - 1] = PRIMARYKEY_TIMESTAMP_COL_INDEX; //TODO ??? } - } else { // it is the orderby ts asc/desc projection query for super table - size_t size = tscSqlExprNumOfExprs(pQueryInfo); - for (int32_t i = 0; i < size; ++i) { - SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i); - if (pExpr->functionId == TSDB_FUNC_PRJ && pExpr->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) { - orderColIndexList[0] = i; + } else { + /* + * 1. the orderby ts asc/desc projection query for the super table + * 2. interval query without groupby clause + */ + if (pQueryInfo->interval.interval != 0) { + orderColIndexList[0] = PRIMARYKEY_TIMESTAMP_COL_INDEX; + } else { + size_t size = tscSqlExprNumOfExprs(pQueryInfo); + for (int32_t i = 0; i < size; ++i) { + SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i); + if (pExpr->functionId == TSDB_FUNC_PRJ && pExpr->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) { + orderColIndexList[0] = i; + } } } diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 64812c8981..ea63696516 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4384,15 +4384,10 @@ int32_t parseFillClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuery static void setDefaultOrderInfo(SQueryInfo* pQueryInfo) { /* set default timestamp order information for all queries */ - pQueryInfo->order.order = TSDB_ORDER_ASC; STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - if (isTopBottomQuery(pQueryInfo)) { - pQueryInfo->order.order = TSDB_ORDER_ASC; - pQueryInfo->order.orderColId = PRIMARYKEY_TIMESTAMP_COL_INDEX; - } else { - pQueryInfo->order.orderColId = -1; - } + pQueryInfo->order.order = TSDB_ORDER_ASC; + pQueryInfo->order.orderColId = PRIMARYKEY_TIMESTAMP_COL_INDEX; /* for super table query, set default ascending order for group output */ if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { -- GitLab