enh: eliminate not null condition

This commit is contained in:
dapan1121 2024-05-06 13:45:16 +08:00
parent 90c0bb53c9
commit 7809533c79
2 changed files with 78 additions and 3 deletions

View File

@ -2660,7 +2660,6 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.name = "avg",
.type = FUNCTION_TYPE_AVG,
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED | FUNC_MGT_IGNORE_NULL_FUNC | FUNC_MGT_TSMA_FUNC,
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED| FUNC_MGT_IGNORE_NULL_FUNC,
.translateFunc = translateInNumOutDou,
.dataRequiredFunc = statisDataRequired,
.getEnvFunc = getAvgFuncEnv,
@ -2680,7 +2679,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.name = "_avg_partial",
.type = FUNCTION_TYPE_AVG_PARTIAL,
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_IGNORE_NULL_FUNC,
.classification = FUNC_MGT_AGG_FUNC,
.translateFunc = translateAvgPartial,
.dataRequiredFunc = statisDataRequired,
.getEnvFunc = getAvgFuncEnv,
@ -2695,7 +2694,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.name = "_avg_merge",
.type = FUNCTION_TYPE_AVG_MERGE,
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_IGNORE_NULL_FUNC,
.classification = FUNC_MGT_AGG_FUNC,
.translateFunc = translateAvgMerge,
.getEnvFunc = getAvgFuncEnv,
.initFunc = avgFunctionSetup,

View File

@ -1998,6 +1998,82 @@ static int32_t pdcOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubplan)
return pdcOptimizeImpl(pCxt, pLogicSubplan->pNode);
}
static bool eliminateNotNullCondMayBeOptimized(SLogicNode* pNode) {
if (QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode)) {
return false;
}
SAggLogicNode* pAgg = (SAggLogicNode*)pNode;
if (pNode->pChildren->length != 1 || NULL != pAgg->pGroupKeys) {
return false;
}
SLogicNode* pChild = (SLogicNode*)nodesListGetNode(pAgg->node.pChildren, 0);
if (QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(pChild)) {
return false;
}
SScanLogicNode* pScan = (SScanLogicNode*)pChild;
if (NULL == pScan->node.pConditions || QUERY_NODE_OPERATOR != nodeType(pScan->node.pConditions)) {
return false;
}
SOperatorNode* pOp = (SOperatorNode*)pScan->node.pConditions;
if (OP_TYPE_IS_NOT_NULL != pOp->opType) {
return false;
}
if (QUERY_NODE_COLUMN != nodeType(pOp->pLeft)) {
return false;
}
SNode* pTmp = NULL;
FOREACH(pTmp, pAgg->pAggFuncs) {
SFunctionNode* pFunc = (SFunctionNode*)pTmp;
if (!fmIsIgnoreNullFunc(pFunc->funcId)) {
return false;
}
if (fmIsMultiResFunc(pFunc->funcId)) {
SNode* pParam = NULL;
FOREACH(pParam, pFunc->pParameterList) {
if (QUERY_NODE_COLUMN != nodeType(pParam)) {
return false;
}
if (!nodesEqualNode(pParam, pOp->pLeft)) {
return false;
}
}
} else {
SNode* pParam = nodesListGetNode(pFunc->pParameterList, 0);
if (QUERY_NODE_COLUMN != nodeType(pParam)) {
return false;
}
if (!nodesEqualNode(pParam, pOp->pLeft)) {
return false;
}
}
}
return true;
}
static int32_t eliminateNotNullCondOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubplan) {
SLogicNode* pNode = (SLogicNode*)optFindPossibleNode(pLogicSubplan->pNode, eliminateNotNullCondMayBeOptimized);
if (NULL == pNode) {
return TSDB_CODE_SUCCESS;
}
SScanLogicNode* pScan = (SScanLogicNode*)nodesListGetNode(pNode->pChildren, 0);
nodesDestroyNode(pScan->node.pConditions);
pScan->node.pConditions = NULL;
pCxt->optimized = true;
return TSDB_CODE_SUCCESS;
}
static bool sortPriKeyOptIsPriKeyOrderBy(SNodeList* pSortKeys) {
if (1 != LIST_LENGTH(pSortKeys)) {
return false;