From 1416efa5e3ebed5475e53fd3b1736bbf0a5820e0 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Mon, 18 Apr 2022 16:24:36 +0800 Subject: [PATCH] fix(query): fix tag col check with groupby expr --- src/client/src/tscSQLParser.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 2db808013f..f5b8879368 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -8267,6 +8267,24 @@ static void updateTagPrjFunction(SQueryInfo* pQueryInfo) { } } +/* + retrun false : expr is not in groupbu column. + return true : expr is in groupby column. +*/ +static bool check_expr_in_groupby_colum(SGroupbyExpr* pGroupbyExpr, SExprInfo* pExpr){ + SColIndex* pIndex = NULL; + assert( pExpr); + if (NULL == pGroupbyExpr) + return false; + for (int32_t k = 0; k < pGroupbyExpr->numOfGroupCols ; ++k) { + pIndex = taosArrayGet(pGroupbyExpr->columnInfo, k); + if (!strcmp(pIndex->name,&pExpr->base.colInfo.name[1])){ // notes:first char is dot, skip one char. + return true; + } + } + return false; +} + /* * check for selectivity function + tags column function both exist. * 1. tagprj functions are not compatible with aggregated function when missing "group by" clause @@ -8284,12 +8302,15 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) { int16_t numOfTimeWindow = 0; size_t numOfExprs = taosArrayGetSize(pQueryInfo->exprList); + SGroupbyExpr* pGroupbyExpr = &pQueryInfo->groupbyExpr; for (int32_t i = 0; i < numOfExprs; ++i) { SExprInfo* pExpr = taosArrayGetP(pQueryInfo->exprList, i); if (pExpr->base.functionId == TSDB_FUNC_TAGPRJ || (pExpr->base.functionId == TSDB_FUNC_PRJ && pExpr->base.colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX)) { - tagTsColExists = true; // selectivity + ts/tag column - break; + if (false == check_expr_in_groupby_colum(pGroupbyExpr,pExpr)) { + tagTsColExists = true; // selectivity + ts/tag column + break; + } } } -- GitLab