This commit is contained in:
Bob Liu 2023-12-24 23:48:37 +08:00
parent 651b681d4c
commit 52c244d9ec
3 changed files with 27 additions and 7 deletions

View File

@ -595,13 +595,25 @@ static bool calcNeedCountEmpty(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLog
}
// limit: root node is select
SNode* pRoot = pCxt->pPlanCxt->pAstRoot;
if (QUERY_NODE_SELECT_STMT == nodeType(pRoot)
&& pCxt->pNode && QUERY_NODE_LOGIC_PLAN_AGG == nodeType(pCxt->pNode)) {
SAggLogicNode* pNode = (SAggLogicNode*)pCxt->pNode;
if (pNode->isCountByTag) {
return true;
if (QUERY_NODE_SELECT_STMT == nodeType(pRoot)) {
// case1 root select
SSelectStmt* pSelect = (SSelectStmt*)pRoot;
if (pSelect->hasCountFunc) {
if (NULL != pSelect->pGroupByList) {
return !keysHasCol(pSelect->pGroupByList);
} else if (NULL != pSelect->pPartitionByList) {
return !keysHasCol(pSelect->pPartitionByList);
}
}
// case2 inner agg
if (pCxt->pNode && QUERY_NODE_LOGIC_PLAN_AGG == nodeType(pCxt->pNode)) {
SAggLogicNode* pNode = (SAggLogicNode*)pCxt->pNode;
if (pNode->isCountByTag) {
return true;
}
}
}
return false;
}

View File

@ -123,7 +123,7 @@ class TDTestCase:
tdSql.checkData(0, 1, 2)
elif 'hyperloglog' == function_name:
tdSql.checkData(0, 0, 0)
tdSql.checkData(0, 0, 0)
tdSql.checkData(0, 1, None)
def query_empty_ntb(self):
tdSql.query(f'select count(*) from {self.ntbname}')

View File

@ -83,6 +83,10 @@ class TDTestCase:
tdSql.query(f"select count(c1) from {self.dbname}.{self.stable} group by tbname ")
tdSql.checkRows(check_num)
#inner select
tdSql.query(f"select * from (select count(c1) from {self.dbname}.{self.stable} group by tbname) ")
tdSql.checkRows(check_num)
# count + sum(col)
tdSql.query(f"select count(*), sum(c1) from {self.dbname}.{self.stable} group by tbname ")
tdSql.checkRows(check_num)
@ -146,6 +150,10 @@ class TDTestCase:
tdSql.query(f"select count(c1) from {self.dbname}.{self.stable} partition by tbname ")
tdSql.checkRows(check_num)
#inner select
tdSql.query(f"select * from (select count(c1) from {self.dbname}.{self.stable} partition by tbname) ")
tdSql.checkRows(check_num)
tdSql.query(f"select count(c1) from {self.dbname}.{self.stable} partition by tbname interval(1d)")
tdSql.checkRows(real_num)
@ -196,4 +204,4 @@ class TDTestCase:
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())