Merge pull request #21606 from taosdata/szhou/fix-ts3498
fix: rewrite count(*) to count(1) for temp table
This commit is contained in:
commit
a4f5bac344
|
@ -174,6 +174,7 @@ void destroyEWindowOperatorInfo(void* param) {
|
||||||
colDataDestroy(&pInfo->twAggSup.timeWindowData);
|
colDataDestroy(&pInfo->twAggSup.timeWindowData);
|
||||||
|
|
||||||
cleanupAggSup(&pInfo->aggSup);
|
cleanupAggSup(&pInfo->aggSup);
|
||||||
|
cleanupExprSupp(&pInfo->scalarSup);
|
||||||
taosMemoryFreeClear(param);
|
taosMemoryFreeClear(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1352,13 +1352,33 @@ static bool isCountStar(SFunctionNode* pFunc) {
|
||||||
return (QUERY_NODE_COLUMN == nodeType(pPara) && 0 == strcmp(((SColumnNode*)pPara)->colName, "*"));
|
return (QUERY_NODE_COLUMN == nodeType(pPara) && 0 == strcmp(((SColumnNode*)pPara)->colName, "*"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t rewriteCountStarAsCount1(STranslateContext* pCxt, SFunctionNode* pCount) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||||
|
if (NULL == pVal) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
pVal->node.resType.type = TSDB_DATA_TYPE_INT;
|
||||||
|
pVal->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_INT].bytes;
|
||||||
|
const int32_t val = 1;
|
||||||
|
nodesSetValueNodeValue(pVal, (void*)&val);
|
||||||
|
pVal->translate = true;
|
||||||
|
nodesListErase(pCount->pParameterList, nodesListGetCell(pCount->pParameterList, 0));
|
||||||
|
code = nodesListAppend(pCount->pParameterList, (SNode*)pVal);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
// count(*) is rewritten as count(ts) for scannning optimization
|
// count(*) is rewritten as count(ts) for scannning optimization
|
||||||
static int32_t rewriteCountStar(STranslateContext* pCxt, SFunctionNode* pCount) {
|
static int32_t rewriteCountStar(STranslateContext* pCxt, SFunctionNode* pCount) {
|
||||||
SColumnNode* pCol = (SColumnNode*)nodesListGetNode(pCount->pParameterList, 0);
|
SColumnNode* pCol = (SColumnNode*)nodesListGetNode(pCount->pParameterList, 0);
|
||||||
STableNode* pTable = NULL;
|
STableNode* pTable = NULL;
|
||||||
int32_t code = findTable(pCxt, ('\0' == pCol->tableAlias[0] ? NULL : pCol->tableAlias), &pTable);
|
int32_t code = findTable(pCxt, ('\0' == pCol->tableAlias[0] ? NULL : pCol->tableAlias), &pTable);
|
||||||
if (TSDB_CODE_SUCCESS == code && QUERY_NODE_REAL_TABLE == nodeType(pTable)) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
setColumnInfoBySchema((SRealTableNode*)pTable, ((SRealTableNode*)pTable)->pMeta->schema, -1, pCol);
|
if (QUERY_NODE_REAL_TABLE == nodeType(pTable)) {
|
||||||
|
setColumnInfoBySchema((SRealTableNode*)pTable, ((SRealTableNode*)pTable)->pMeta->schema, -1, pCol);
|
||||||
|
} else {
|
||||||
|
code = rewriteCountStarAsCount1(pCxt, pCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,4 +42,12 @@ endi
|
||||||
if $data00 != 4 then
|
if $data00 != 4 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
sql create table ctcount(ts timestamp, f int);
|
||||||
|
sql insert into ctcount(ts) values(now)(now+1s);
|
||||||
|
sql select count(*) from (select f from ctcount);
|
||||||
|
print $data00
|
||||||
|
if $data00 != 2 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
||||||
|
|
Loading…
Reference in New Issue