enhance: prepare for or processing

This commit is contained in:
shenglian zhou 2023-11-03 16:35:43 +08:00
parent 81af550763
commit 893f7cc080
1 changed files with 16 additions and 4 deletions

View File

@ -3907,12 +3907,22 @@ static bool findEqCondTbNameInOperatorNode(STranslateContext* pCxt, SNode* pWher
return false; return false;
} }
static int32_t findEqualCondTbname(STranslateContext* pCxt, SNode* pWhere, SArray* aTables) { static bool isTableExistInTableTbnames(SArray* aTableTbNames, SRealTableNode* pTable) {
for (int i = 0; i < taosArrayGetSize(aTableTbNames); ++i) {
SEqCondTbNameTableInfo* info = taosArrayGet(aTableTbNames, i);
if (info->pRealTable == pTable) {
return true;
}
}
return false;
}
static int32_t findEqualCondTbname(STranslateContext* pCxt, SNode* pWhere, SArray* aTableTbnames) {
if (nodeType(pWhere) == QUERY_NODE_OPERATOR) { if (nodeType(pWhere) == QUERY_NODE_OPERATOR) {
SEqCondTbNameTableInfo info = {0}; SEqCondTbNameTableInfo info = {0};
bool bIsEqTbnameCond = findEqCondTbNameInOperatorNode(pCxt, pWhere, &info); bool bIsEqTbnameCond = findEqCondTbNameInOperatorNode(pCxt, pWhere, &info);
if (bIsEqTbnameCond) { if (bIsEqTbnameCond) {
taosArrayPush(aTables, &info); taosArrayPush(aTableTbnames, &info);
} }
} else if (nodeType(pWhere) == QUERY_NODE_LOGIC_CONDITION) { } else if (nodeType(pWhere) == QUERY_NODE_LOGIC_CONDITION) {
if (((SLogicConditionNode*)pWhere)->condType == LOGIC_COND_TYPE_AND) { if (((SLogicConditionNode*)pWhere)->condType == LOGIC_COND_TYPE_AND) {
@ -3921,12 +3931,14 @@ static int32_t findEqualCondTbname(STranslateContext* pCxt, SNode* pWhere, SArra
if (nodeType(pWhere) == QUERY_NODE_OPERATOR) { if (nodeType(pWhere) == QUERY_NODE_OPERATOR) {
SEqCondTbNameTableInfo info = {0}; SEqCondTbNameTableInfo info = {0};
bool bIsEqTbnameCond = findEqCondTbNameInOperatorNode(pCxt, pTmpNode, &info); bool bIsEqTbnameCond = findEqCondTbNameInOperatorNode(pCxt, pTmpNode, &info);
if (bIsEqTbnameCond) { if (bIsEqTbnameCond && !isTableExistInTableTbnames(aTableTbnames, info.pRealTable)) {
taosArrayPush(aTables, &info); taosArrayPush(aTableTbnames, &info);
break; break;
} }
} }
} }
} else if (((SLogicConditionNode*)pWhere)->condType == LOGIC_COND_TYPE_OR) {
// deal with or condition
} }
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;