fix: rewrite count(*) to count(1) for temp table
This commit is contained in:
parent
b437024eca
commit
beb2b7b467
|
@ -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) {
|
||||||
|
if (QUERY_NODE_REAL_TABLE == nodeType(pTable)) {
|
||||||
setColumnInfoBySchema((SRealTableNode*)pTable, ((SRealTableNode*)pTable)->pMeta->schema, -1, pCol);
|
setColumnInfoBySchema((SRealTableNode*)pTable, ((SRealTableNode*)pTable)->pMeta->schema, -1, pCol);
|
||||||
|
} else {
|
||||||
|
code = rewriteCountStarAsCount1(pCxt, pCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue