Merge pull request #26877 from taosdata/fix/3.0/TD-31133

fix:[TD-31133] Fix crash when using partition by with having clause.
This commit is contained in:
dapan1121 2024-07-31 10:31:57 +08:00 committed by GitHub
commit 4e62fda958
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 2 deletions

View File

@ -873,7 +873,7 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
_OVER:
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) {
mError("stream:%s, failed to create since %s", createReq.name, terrstr(code));
mError("stream:%s, failed to create since %s", createReq.name, terrstr());
} else {
mDebug("stream:%s create stream completed", createReq.name);
}

View File

@ -3439,7 +3439,7 @@ static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) {
bool partionByTbname = hasTbnameFunction(pSelect->pPartitionByList);
FOREACH(pPartKey, pSelect->pPartitionByList) {
if (nodesEqualNode(pPartKey, *pNode)) {
return rewriteExprToGroupKeyFunc(pCxt, pNode);
return pCxt->currClause == SQL_CLAUSE_HAVING ? DEAL_RES_IGNORE_CHILD : rewriteExprToGroupKeyFunc(pCxt, pNode);
}
if ((partionByTbname) && QUERY_NODE_COLUMN == nodeType(*pNode) &&
((SColumnNode*)*pNode)->colType == COLUMN_TYPE_TAG) {
@ -3658,6 +3658,7 @@ static int32_t checkHavingGroupBy(STranslateContext* pCxt, SSelectStmt* pSelect)
return code;
}
if (NULL != pSelect->pHaving) {
pCxt->currClause = SQL_CLAUSE_HAVING;
code = checkExprForGroupBy(pCxt, &pSelect->pHaving);
}
/*

View File

@ -80,6 +80,12 @@ class TDTestCase:
if nonempty_tb_num > 0:
num = self.row_nums
tdSql.checkRows(num)
tdSql.query(f"select c1, count(*), count(1), count(c1) from {self.dbname}.{self.stable} {keyword} by c1 having c1 >= 0")
num = 0
if nonempty_tb_num > 0:
num = self.row_nums
tdSql.checkRows(num)
tdSql.query(f"select ts, count(*) from {self.dbname}.{self.stable} {keyword} by ts ")
tdSql.checkRows(nonempty_tb_num * self.row_nums)