enhance: refact code
This commit is contained in:
parent
865b28c6bd
commit
bab886b229
|
@ -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) {
|
||||||
|
taosArrayPush(aTables, &info);
|
||||||
|
}
|
||||||
|
} else if (nodeType(pWhere) == QUERY_NODE_LOGIC_CONDITION) {
|
||||||
|
if (((SLogicConditionNode*)pWhere)->condType == LOGIC_COND_TYPE_AND) {
|
||||||
SNode* pTmpNode = NULL;
|
SNode* pTmpNode = NULL;
|
||||||
FOREACH(pTmpNode, ((SLogicConditionNode*)pWhere)->pParameterList) {
|
FOREACH(pTmpNode, ((SLogicConditionNode*)pWhere)->pParameterList) {
|
||||||
if (nodeType(pWhere) == QUERY_NODE_OPERATOR) {
|
if (nodeType(pWhere) == QUERY_NODE_OPERATOR) {
|
||||||
findEqCondTbNameInOperatorNode(pCxt, pTmpNode, aTables);
|
SEqCondTbNameTableInfo info = {0};
|
||||||
|
bool bIsEqTbnameCond = findEqCondTbNameInOperatorNode(pCxt, pTmpNode, &info);
|
||||||
|
if (bIsEqTbnameCond) {
|
||||||
|
taosArrayPush(aTables, &info);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue