Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
enh: Relax the criteria for determining external windows.
  • Loading branch information
Simon9997 committed Nov 5, 2025
commit 3d564665a7bcab26d4c872ca3eeb04a61b7820b0
86 changes: 55 additions & 31 deletions source/libs/planner/src/planLogicCreater.c
Original file line number Diff line number Diff line change
Expand Up @@ -2156,59 +2156,83 @@ static bool placeHolderCanMakeExternalWindow(int32_t startType, int32_t endType)
}
}

static bool filterHasPlaceHolderRange(SOperatorNode *pStart, SOperatorNode *pEnd) {
SNode* pStartLeft = pStart->pLeft;
SNode* pStartRight = pStart->pRight;
SNode* pEndLeft = pEnd->pLeft;
SNode* pEndRight = pEnd->pRight;
static bool filterHasPlaceHolderRange(SOperatorNode *pOperator) {
SNode* pOpLeft = pOperator->pLeft;
SNode* pOpRight = pOperator->pRight;

if (pStartLeft == NULL || pStartRight == NULL || pEndLeft == NULL || pEndRight == NULL) {
if (pOpLeft == NULL || pOpRight == NULL) {
return false;
}

if (nodeType(pStartLeft) == QUERY_NODE_COLUMN && nodeType(pEndLeft) == QUERY_NODE_COLUMN) {
SColumnNode* pLeftCol = (SColumnNode*)pStartLeft;
SColumnNode* pRightCol = (SColumnNode*)pEndLeft;
if (pLeftCol->colType != COLUMN_TYPE_COLUMN || pLeftCol->colId != PRIMARYKEY_TIMESTAMP_COL_ID ||
pRightCol->colType != COLUMN_TYPE_COLUMN || pRightCol->colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
if (nodeType(pOpLeft) == QUERY_NODE_COLUMN) {
SColumnNode* pTsCol = (SColumnNode*)pOpLeft;
if (pTsCol->colType != COLUMN_TYPE_COLUMN || pTsCol->colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
return false;
}
} else {
return false;
}

SConditionCheckContext startCxt = {.hasNotBasicOp = false,
.hasNegativeConst = false,
.hasOtherFunc = false,
.placeholderAtRight = false,
.placeholderType = 0};
SConditionCheckContext opCxt = {.hasNotBasicOp = false,
.hasNegativeConst = false,
.hasOtherFunc = false,
.placeholderAtRight = false,
.placeholderType = 0};

SConditionCheckContext endCxt = {.hasNotBasicOp = false,
.hasNegativeConst = false,
.hasOtherFunc = false,
.placeholderAtRight = false,
.placeholderType = 0};
nodesWalkExpr(pOpRight, conditionOnlyPhAndConstImpl, &opCxt);
if (opCxt.hasNotBasicOp || opCxt.hasNegativeConst || opCxt.hasOtherFunc || opCxt.placeholderAtRight) {
return false;
}
return true;
}

nodesWalkExpr(pStartRight, conditionOnlyPhAndConstImpl, &startCxt);
nodesWalkExpr(pEndRight, conditionOnlyPhAndConstImpl, &endCxt);
if (startCxt.hasNotBasicOp || startCxt.hasNegativeConst || startCxt.hasOtherFunc || startCxt.placeholderAtRight ||
endCxt.hasNotBasicOp || endCxt.hasNegativeConst || endCxt.hasOtherFunc || endCxt.placeholderAtRight) {
static bool logicConditionSatisfyExternalWindow(SLogicConditionNode *pLogicCond) {
if (pLogicCond->condType != LOGIC_COND_TYPE_AND || LIST_LENGTH(pLogicCond->pParameterList) == 0) {
return false;
}
SNode *pOperator = NULL;
FOREACH(pOperator, pLogicCond->pParameterList) {
if (nodeType(pOperator) != QUERY_NODE_OPERATOR) {
return false;
}
if (!filterHasPlaceHolderRange((SOperatorNode*)pOperator)) {
return false;
}
}
return true;
}


static bool timeRangeSatisfyExternalWindow(STimeRangeNode* pTimeRange) {
if (!pTimeRange || !pTimeRange->pStart || !pTimeRange->pEnd ||
nodeType(pTimeRange->pStart) != QUERY_NODE_OPERATOR ||
nodeType(pTimeRange->pEnd) != QUERY_NODE_OPERATOR) {
if (!pTimeRange || !pTimeRange->pStart || !pTimeRange->pEnd) {
return false;
}

if (nodeType(pTimeRange->pStart) == QUERY_NODE_OPERATOR) {
if (!filterHasPlaceHolderRange((SOperatorNode*)pTimeRange->pStart)) {
return false;
}
} else if (nodeType(pTimeRange->pStart) == QUERY_NODE_LOGIC_CONDITION) {
if (!logicConditionSatisfyExternalWindow((SLogicConditionNode*)pTimeRange->pStart)) {
return false;
}
} else {
return false;
}

SOperatorNode *pStart = (SOperatorNode *)(pTimeRange->pStart);
SOperatorNode *pEnd = (SOperatorNode *)(pTimeRange->pEnd);
if (nodeType(pTimeRange->pEnd) == QUERY_NODE_OPERATOR) {
if (!filterHasPlaceHolderRange((SOperatorNode*)pTimeRange->pEnd)) {
return false;
}
} else if (nodeType(pTimeRange->pEnd) == QUERY_NODE_LOGIC_CONDITION) {
if (!logicConditionSatisfyExternalWindow((SLogicConditionNode*)pTimeRange->pEnd)) {
return false;
}
} else {
return false;
}

return filterHasPlaceHolderRange(pStart, pEnd);
return true;
}

static int32_t conditionHasPlaceHolder(SNode* pNode, bool* pHasPlaceHolder) {
Expand Down