From ed0d08192da06af1491c92a15fe7a40184dcf9d6 Mon Sep 17 00:00:00 2001 From: slzhou Date: Wed, 28 Sep 2022 16:39:06 +0800 Subject: [PATCH] fix: fix bugs of condition is null --- source/libs/executor/src/scanoperator.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index de3e66bf65..12b9a459f7 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -2355,24 +2355,25 @@ static bool sysTableIsOperatorCondOnOneTable(SNode* pCond, char* condTable) { } static bool sysTableIsCondOnOneTable(SNode* pCond, char* condTable) { + if (pCond == NULL) { + return false; + } if (nodeType(pCond) == QUERY_NODE_LOGIC_CONDITION) { SLogicConditionNode* node = (SLogicConditionNode*)pCond; if (LOGIC_COND_TYPE_AND == node->condType) { - SListCell* cell = node->pParameterList->pHead; - for (int32_t i = 0; i < node->pParameterList->length; ++i) { - SNode* pChild = cell->pNode; - if (QUERY_NODE_OPERATOR == nodeType(pChild)) { - if (sysTableIsOperatorCondOnOneTable(pChild, condTable)) { - return true; - } + SNode* pChild = NULL; + FOREACH(pChild, node->pParameterList) { + if (QUERY_NODE_OPERATOR == nodeType(pChild) && sysTableIsOperatorCondOnOneTable(pChild, condTable)) { + return true; } - cell = cell->pNext; } } } + if (QUERY_NODE_OPERATOR == nodeType(pCond)) { return sysTableIsOperatorCondOnOneTable(pCond, condTable); } + return false; } @@ -2401,8 +2402,8 @@ static SSDataBlock* sysTableScanUserTags(SOperatorInfo* pOperator) { varDataSetLen(dbname, strlen(varDataVal(dbname))); char condTableName[TSDB_TABLE_NAME_LEN] = {0}; - // optimize when sql like where table_name='tablename' and xxx. - if (sysTableIsCondOnOneTable(pInfo->pCondition, condTableName)) { + // optimize when sql like where table_name='tablename' and xxx. + if (pInfo->pCondition && sysTableIsCondOnOneTable(pInfo->pCondition, condTableName)) { char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; STR_TO_VARSTR(tableName, condTableName);