diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index a2dd266db5b0898c226621e30f6b4237d39fc1e8..0387d916ea2977e3e72f335c537597581c2c2079 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -5278,21 +5278,23 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq } if (isTopBottomQuery(pQueryInfo)) { - /* order of top/bottom query in interval is not valid */ - SExprInfo* pExpr = tscExprGet(pQueryInfo, 0); - assert(pExpr->base.functionId == TSDB_FUNC_TS); - - pExpr = tscExprGet(pQueryInfo, 1); - //if (pExpr->base.colInfo.colIndex != index.columnIndex && index.columnIndex != PRIMARYKEY_TIMESTAMP_COL_INDEX) { - // return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); - //} - bool validOrder = false; SArray *columnInfo = pQueryInfo->groupbyExpr.columnInfo; if (columnInfo != NULL && taosArrayGetSize(columnInfo) > 0) { SColIndex* pColIndex = taosArrayGet(columnInfo, 0); validOrder = (pColIndex->colIndex == index.columnIndex); - } + } else { + /* order of top/bottom query in interval is not valid */ + SExprInfo* pExpr = tscExprGet(pQueryInfo, 0); + assert(pExpr->base.functionId == TSDB_FUNC_TS); + + pExpr = tscExprGet(pQueryInfo, 1); + if (pExpr->base.colInfo.colIndex != index.columnIndex && index.columnIndex != PRIMARYKEY_TIMESTAMP_COL_INDEX) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); + } + validOrder = true; + } + if (!validOrder) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); }