diff --git a/source/libs/parser/src/parCalcConst.c b/source/libs/parser/src/parCalcConst.c index c7219c4788..76d7e902ec 100644 --- a/source/libs/parser/src/parCalcConst.c +++ b/source/libs/parser/src/parCalcConst.c @@ -202,9 +202,25 @@ static int32_t calcConstProject(SNode* pProject, bool dual, SNode** pNew) { return code; } +typedef struct SIsUselessColCtx { + bool isUseless; +} SIsUselessColCtx ; + +EDealRes checkUselessCol(SNode *pNode, void *pContext) { + SIsUselessColCtx *ctx = (SIsUselessColCtx *)pContext; + if (QUERY_NODE_FUNCTION == nodeType(pNode) && !fmIsScalarFunc(((SFunctionNode*)pNode)->funcId) && + !fmIsPseudoColumnFunc(((SFunctionNode*)pNode)->funcId)) { + ctx->isUseless = false; + return DEAL_RES_END; + } + + return DEAL_RES_CONTINUE; +} + static bool isUselessCol(SExprNode* pProj) { - if (QUERY_NODE_FUNCTION == nodeType(pProj) && !fmIsScalarFunc(((SFunctionNode*)pProj)->funcId) && - !fmIsPseudoColumnFunc(((SFunctionNode*)pProj)->funcId)) { + SIsUselessColCtx ctx = {.isUseless = true}; + nodesWalkExpr((SNode*)pProj, checkUselessCol, (void *)&ctx); + if (!ctx.isUseless) { return false; } return NULL == ((SExprNode*)pProj)->pAssociation; diff --git a/tests/system-test/2-query/nestedQuery.py b/tests/system-test/2-query/nestedQuery.py index 1b843defce..3ea839a03c 100755 --- a/tests/system-test/2-query/nestedQuery.py +++ b/tests/system-test/2-query/nestedQuery.py @@ -6082,8 +6082,18 @@ class TDTestCase: tdLog.info(len(sql)) tdSql.error(sql) - #special sql + #6 tdSql.query("select 6-1 from stable_1;") + for i in range(self.fornum): + sql = "select count(*) from (select avg(q_int)/1000 from stable_1); " + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + #special sql + tdSql.query("select 7-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select _block_dist() from stable_1);" tdSql.error(sql)