diff --git a/source/libs/parser/src/parCalcConst.c b/source/libs/parser/src/parCalcConst.c index 23ce3aa77d..0657f1a43d 100644 --- a/source/libs/parser/src/parCalcConst.c +++ b/source/libs/parser/src/parCalcConst.c @@ -285,7 +285,7 @@ static SNode* createConstantValue() { static int32_t calcConstProjections(SCalcConstContext* pCxt, SSelectStmt* pSelect, bool subquery) { SNode* pProj = NULL; WHERE_EACH(pProj, pSelect->pProjectionList) { - if (subquery && !pSelect->isDistinct && isUselessCol((SExprNode*)pProj)) { + if (subquery && !pSelect->isDistinct && !pSelect->tagScan && isUselessCol((SExprNode*)pProj)) { ERASE_NODE(pSelect->pProjectionList); continue; } diff --git a/tests/script/tsim/query/tag_scan.sim b/tests/script/tsim/query/tag_scan.sim index 3f0a23fbd6..7404bd37fe 100644 --- a/tests/script/tsim/query/tag_scan.sim +++ b/tests/script/tsim/query/tag_scan.sim @@ -140,4 +140,28 @@ if $data01 != @1aa@ then return -1 endi +sql create table stb34 (ts timestamp, f int) tags(t int); +sql insert into ctb34 using stb34 tags(1) values(now, 1)(now+1s, 2); +sql select 1 from (select tags t from stb34 order by t) +print $rows +if $rows != 1 then + return -1 +endi + +sql select count(*) from (select tags t from stb34) +if $data00 != 1 then + return -1 +endi + + +sql select 1 from (select tags ts from stb34) +print $rows +if $rows != 2 then + return -1 +endi + +sql select count(*) from (select tags ts from stb34) +if $data00 != 2 then + return -1 +endi system sh/exec.sh -n dnode1 -s stop -x SIGINT