From fe7f945b3b849686db1238548b225fed6f1c7e45 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 29 Jul 2024 17:26:35 +0800 Subject: [PATCH] fix(query): add the table uid after check if it is existed hash map in the first place. --- source/libs/executor/src/executil.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 596487f0de..d810cf2428 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -2300,21 +2300,29 @@ int32_t tableListAddTableInfo(STableListInfo* pTableList, uint64_t uid, uint64_t } STableKeyInfo keyInfo = {.uid = uid, .groupId = gid}; - void* tmp = taosArrayPush(pTableList->pTableList, &keyInfo); + void* p = taosHashGet(pTableList->map, &uid, sizeof(uid)); + if (p != NULL) { + qInfo("table:%" PRId64 " already in tableIdList, ignore it", uid); + goto _end; + } + + void* tmp = taosArrayPush(pTableList->pTableList, &keyInfo); QUERY_CHECK_NULL(tmp, code, lino, _end, terrno); int32_t slot = (int32_t)taosArrayGetSize(pTableList->pTableList) - 1; code = taosHashPut(pTableList->map, &uid, sizeof(uid), &slot, sizeof(slot)); - if (code == TSDB_CODE_DUP_KEY) { - code = TSDB_CODE_SUCCESS; + if (code != TSDB_CODE_SUCCESS) { + ASSERT(code != TSDB_CODE_DUP_KEY); // we have checked the existence of uid in hash map above + taosArrayPopTailBatch(pTableList->pTableList, 1); // let's pop the last element in the array list } - QUERY_CHECK_CODE(code, lino, _end); _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } else { + qDebug("uid:%" PRIu64 ", groupId:%" PRIu64 " added into table list, slot:%d, total:%d", uid, gid, slot, slot + 1); } - qDebug("uid:%" PRIu64 ", groupId:%" PRIu64 " added into table list, slot:%d, total:%d", uid, gid, slot, slot + 1); + return code; }