enhance: refact code

This commit is contained in:
shenglian zhou 2023-11-03 14:12:04 +08:00
parent 865b28c6bd
commit bab886b229
1 changed files with 26 additions and 15 deletions

View File

@ -3886,35 +3886,46 @@ static bool isOperatorEqTbnameCond(STranslateContext* pCxt, SOperatorNode* pOper
return true; return true;
} }
static int32_t findEqCondTbNameInOperatorNode(STranslateContext* pCxt, SNode* pWhere, SArray* aTables) { static bool findEqCondTbNameInOperatorNode(STranslateContext* pCxt, SNode* pWhere, SEqCondTbNameTableInfo* pInfo) {
int32_t code = TSDB_CODE_SUCCESS;
char* pTableAlias = NULL; char* pTableAlias = NULL;
char* pTbNameVal = NULL; char* pTbNameVal = NULL;
if (isOperatorEqTbnameCond(pCxt, (SOperatorNode*)pWhere, &pTableAlias, &pTbNameVal)) { if (isOperatorEqTbnameCond(pCxt, (SOperatorNode*)pWhere, &pTableAlias, &pTbNameVal)) {
STableNode* pTable; STableNode* pTable;
if (pTableAlias == NULL) { if (pTableAlias == NULL) {
pTable = (STableNode*)((SSelectStmt*)(pCxt->pCurrStmt))->pFromTable; pTable = (STableNode*)((SSelectStmt*)(pCxt->pCurrStmt))->pFromTable;
} else { } else {
findTable(pCxt, pTableAlias, &pTable); code = findTable(pCxt, pTableAlias, &pTable);
} }
if (nodeType(pTable) == QUERY_NODE_REAL_TABLE) { if (code == TSDB_CODE_SUCCESS && nodeType(pTable) == QUERY_NODE_REAL_TABLE) {
SEqCondTbNameTableInfo info = {0}; strcpy(pInfo->tbName, pTbNameVal);
strcpy(info.tbName, pTbNameVal); pInfo->pRealTable = (SRealTableNode*)pTable;
info.pRealTable = (SRealTableNode*)pTable; return true;
taosArrayPush(aTables, &info);
} }
} }
return TSDB_CODE_SUCCESS; return false;
} }
static int32_t findEqualCondTbname(STranslateContext* pCxt, SNode* pWhere, SArray* aTables) { static int32_t findEqualCondTbname(STranslateContext* pCxt, SNode* pWhere, SArray* aTables) {
if (nodeType(pWhere) == QUERY_NODE_OPERATOR) { if (nodeType(pWhere) == QUERY_NODE_OPERATOR) {
findEqCondTbNameInOperatorNode(pCxt, pWhere, aTables); SEqCondTbNameTableInfo info = {0};
} else if (nodeType(pWhere) == QUERY_NODE_LOGIC_CONDITION && bool bIsEqTbnameCond = findEqCondTbNameInOperatorNode(pCxt, pWhere, &info);
((SLogicConditionNode*)pWhere)->condType == LOGIC_COND_TYPE_AND) { if (bIsEqTbnameCond) {
SNode* pTmpNode = NULL; taosArrayPush(aTables, &info);
FOREACH(pTmpNode, ((SLogicConditionNode*)pWhere)->pParameterList) { }
if (nodeType(pWhere) == QUERY_NODE_OPERATOR) { } else if (nodeType(pWhere) == QUERY_NODE_LOGIC_CONDITION) {
findEqCondTbNameInOperatorNode(pCxt, pTmpNode, aTables); if (((SLogicConditionNode*)pWhere)->condType == LOGIC_COND_TYPE_AND) {
SNode* pTmpNode = NULL;
FOREACH(pTmpNode, ((SLogicConditionNode*)pWhere)->pParameterList) {
if (nodeType(pWhere) == QUERY_NODE_OPERATOR) {
SEqCondTbNameTableInfo info = {0};
bool bIsEqTbnameCond = findEqCondTbNameInOperatorNode(pCxt, pTmpNode, &info);
if (bIsEqTbnameCond) {
taosArrayPush(aTables, &info);
break;
}
}
} }
} }
} }