diff --git a/source/libs/executor/src/eventwindowoperator.c b/source/libs/executor/src/eventwindowoperator.c index b5dea6d94d..f7dddf6b29 100644 --- a/source/libs/executor/src/eventwindowoperator.c +++ b/source/libs/executor/src/eventwindowoperator.c @@ -174,6 +174,7 @@ void destroyEWindowOperatorInfo(void* param) { colDataDestroy(&pInfo->twAggSup.timeWindowData); cleanupAggSup(&pInfo->aggSup); + cleanupExprSupp(&pInfo->scalarSup); taosMemoryFreeClear(param); } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 9ebbecd148..f5454dba23 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -1352,13 +1352,33 @@ static bool isCountStar(SFunctionNode* pFunc) { return (QUERY_NODE_COLUMN == nodeType(pPara) && 0 == strcmp(((SColumnNode*)pPara)->colName, "*")); } +static int32_t rewriteCountStarAsCount1(STranslateContext* pCxt, SFunctionNode* pCount) { + int32_t code = TSDB_CODE_SUCCESS; + SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); + if (NULL == pVal) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pVal->node.resType.type = TSDB_DATA_TYPE_INT; + pVal->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_INT].bytes; + const int32_t val = 1; + nodesSetValueNodeValue(pVal, (void*)&val); + pVal->translate = true; + nodesListErase(pCount->pParameterList, nodesListGetCell(pCount->pParameterList, 0)); + code = nodesListAppend(pCount->pParameterList, (SNode*)pVal); + return code; +} + // count(*) is rewritten as count(ts) for scannning optimization static int32_t rewriteCountStar(STranslateContext* pCxt, SFunctionNode* pCount) { SColumnNode* pCol = (SColumnNode*)nodesListGetNode(pCount->pParameterList, 0); STableNode* pTable = NULL; int32_t code = findTable(pCxt, ('\0' == pCol->tableAlias[0] ? NULL : pCol->tableAlias), &pTable); - if (TSDB_CODE_SUCCESS == code && QUERY_NODE_REAL_TABLE == nodeType(pTable)) { - setColumnInfoBySchema((SRealTableNode*)pTable, ((SRealTableNode*)pTable)->pMeta->schema, -1, pCol); + if (TSDB_CODE_SUCCESS == code) { + if (QUERY_NODE_REAL_TABLE == nodeType(pTable)) { + setColumnInfoBySchema((SRealTableNode*)pTable, ((SRealTableNode*)pTable)->pMeta->schema, -1, pCol); + } else { + code = rewriteCountStarAsCount1(pCxt, pCount); + } } return code; } diff --git a/tests/script/tsim/query/unionall_as_table.sim b/tests/script/tsim/query/unionall_as_table.sim index 4d8f990718..f8145d4e97 100644 --- a/tests/script/tsim/query/unionall_as_table.sim +++ b/tests/script/tsim/query/unionall_as_table.sim @@ -42,4 +42,12 @@ endi if $data00 != 4 then return -1 endi + +sql create table ctcount(ts timestamp, f int); +sql insert into ctcount(ts) values(now)(now+1s); +sql select count(*) from (select f from ctcount); +print $data00 +if $data00 != 2 then + return -1 +endi system sh/exec.sh -n dnode1 -s stop -x SIGINT