enh: optimize count(1) performance
This commit is contained in:
parent
948a603513
commit
f45f3b460f
|
@ -1331,6 +1331,32 @@ static int32_t rewriteCountStar(STranslateContext* pCxt, SFunctionNode* pCount)
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool isCountNotNullValue(SFunctionNode* pFunc) {
|
||||||
|
if (FUNCTION_TYPE_COUNT != pFunc->funcType || 1 != LIST_LENGTH(pFunc->pParameterList)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0);
|
||||||
|
return (QUERY_NODE_VALUE == nodeType(pPara) && !((SValueNode*)pPara)->isNull);
|
||||||
|
}
|
||||||
|
|
||||||
|
// count(1) is rewritten as count(ts) for scannning optimization
|
||||||
|
static int32_t rewriteCountNotNullValue(STranslateContext* pCxt, SFunctionNode* pCount) {
|
||||||
|
SValueNode* pValue = (SValueNode*)nodesListGetNode(pCount->pParameterList, 0);
|
||||||
|
STableNode* pTable = NULL;
|
||||||
|
int32_t code = findTable(pCxt, NULL, &pTable);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
|
||||||
|
if (NULL == pCol) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
} else {
|
||||||
|
setColumnInfoBySchema((SRealTableNode*)pTable, ((SRealTableNode*)pTable)->pMeta->schema, -1, pCol);
|
||||||
|
NODES_DESTORY_LIST(pCount->pParameterList);
|
||||||
|
code = nodesListMakeAppend(&pCount->pParameterList, (SNode*)pCol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
static bool isCountTbname(SFunctionNode* pFunc) {
|
static bool isCountTbname(SFunctionNode* pFunc) {
|
||||||
if (FUNCTION_TYPE_COUNT != pFunc->funcType || 1 != LIST_LENGTH(pFunc->pParameterList)) {
|
if (FUNCTION_TYPE_COUNT != pFunc->funcType || 1 != LIST_LENGTH(pFunc->pParameterList)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1396,6 +1422,9 @@ static int32_t translateAggFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||||
if (isCountStar(pFunc)) {
|
if (isCountStar(pFunc)) {
|
||||||
return rewriteCountStar(pCxt, pFunc);
|
return rewriteCountStar(pCxt, pFunc);
|
||||||
}
|
}
|
||||||
|
if (isCountNotNullValue(pFunc)) {
|
||||||
|
return rewriteCountNotNullValue(pCxt, pFunc);
|
||||||
|
}
|
||||||
if (isCountTbname(pFunc)) {
|
if (isCountTbname(pFunc)) {
|
||||||
return rewriteCountTbname(pCxt, pFunc);
|
return rewriteCountTbname(pCxt, pFunc);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue