From 3a4eed5c37e30a9e17dba582b9a187841e01faf2 Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Tue, 16 Jan 2024 10:46:22 +0800 Subject: [PATCH] fix: checkIsEmptyResult --- source/libs/parser/src/parTranslater.c | 15 +++++++++++---- tests/system-test/2-query/nestedQueryInterval.py | 4 ++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 03fa65ee49..6d173e8e7b 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -2744,6 +2744,14 @@ static EDealRes doCheckAggColCoexist(SNode** pNode, void* pContext) { return DEAL_RES_CONTINUE; } +static int32_t checkIsEmptyResult(STranslateContext* pCxt, SSelectStmt* pSelect) { + if (pSelect->timeRange.skey > pSelect->timeRange.ekey + && !pSelect->hasCountFunc) { + pSelect->isEmptyResult = true; + } + return TSDB_CODE_SUCCESS; +} + static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect) { if (NULL != pSelect->pGroupByList || NULL != pSelect->pWindow || (!pSelect->hasAggFuncs && !pSelect->hasIndefiniteRowsFunc && !pSelect->hasInterpFunc)) { @@ -4405,10 +4413,6 @@ static int32_t translateWhere(STranslateContext* pCxt, SSelectStmt* pSelect) { if (TSDB_CODE_SUCCESS == code) { code = getQueryTimeRange(pCxt, pSelect->pWhere, &pSelect->timeRange); } - // skip optimization, because need result meta info.(tbname,colname and so on) - // if (TSDB_CODE_SUCCESS == code && pSelect->timeRange.skey > pSelect->timeRange.ekey) { - // pSelect->isEmptyResult = true; - // } if (pSelect->pWhere != NULL) { setTableVgroupsFromEqualTbnameCond(pCxt, pSelect); } @@ -4573,6 +4577,9 @@ static int32_t translateSelectFrom(STranslateContext* pCxt, SSelectStmt* pSelect if (TSDB_CODE_SUCCESS == code) { code = translateOrderBy(pCxt, pSelect); } + if (TSDB_CODE_SUCCESS == code) { + code = checkIsEmptyResult(pCxt, pSelect); + } if (TSDB_CODE_SUCCESS == code) { code = checkAggColCoexist(pCxt, pSelect); } diff --git a/tests/system-test/2-query/nestedQueryInterval.py b/tests/system-test/2-query/nestedQueryInterval.py index 494e6bd371..1d36c65817 100644 --- a/tests/system-test/2-query/nestedQueryInterval.py +++ b/tests/system-test/2-query/nestedQueryInterval.py @@ -1470,6 +1470,10 @@ class TDTestCase: tdSql.checkRows(7) tdSql.query(f"select tbname,count(*) from nested.stable_1 where ts is null group by tbname order by tbname;") tdSql.checkRows(7) + tdSql.query(f"select tbname,last(*) from nested.stable_1 where ts is not null group by tbname order by tbname;") + tdSql.checkRows(3) + tdSql.query(f"select tbname,last(*) from nested.stable_1 where ts is null group by tbname order by tbname;") + tdSql.checkRows(0) #test stable