From 43cce095d0d278375b7408e6db1940b0a256cf5a Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 8 Feb 2023 14:26:04 +0800 Subject: [PATCH 1/2] fix(query): set correct group table size. --- source/libs/executor/src/executil.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 92d52fbb0a..96b73b1269 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -1831,9 +1831,9 @@ int32_t tableListGetGroupList(const STableListInfo* pTableList, int32_t ordinalG int32_t offset = pTableList->groupOffset[ordinalGroupIndex]; if (ordinalGroupIndex < total - 1) { - *size = pTableList->groupOffset[offset + 1] - pTableList->groupOffset[offset]; + *size = pTableList->groupOffset[ordinalGroupIndex + 1] - offset; } else { - *size = total - pTableList->groupOffset[offset] - 1; + *size = total - offset; } *pKeyInfo = taosArrayGet(pTableList->pTableList, offset); From d69b57fab9d63c527308e2aa4b5f790174ced8b8 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 8 Feb 2023 15:48:27 +0800 Subject: [PATCH 2/2] fix(query): set correct size for the last group. --- source/libs/executor/src/executil.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 96b73b1269..cdb5e845e3 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -1812,28 +1812,30 @@ int32_t tableListAddTableInfo(STableListInfo* pTableList, uint64_t uid, uint64_t int32_t tableListGetGroupList(const STableListInfo* pTableList, int32_t ordinalGroupIndex, STableKeyInfo** pKeyInfo, int32_t* size) { - int32_t total = tableListGetOutputGroups(pTableList); - if (ordinalGroupIndex < 0 || ordinalGroupIndex >= total) { + int32_t totalGroups = tableListGetOutputGroups(pTableList); + int32_t numOfTables = tableListGetSize(pTableList); + + if (ordinalGroupIndex < 0 || ordinalGroupIndex >= totalGroups) { return TSDB_CODE_INVALID_PARA; } // here handle two special cases: // 1. only one group exists, and 2. one table exists for each group. - if (total == 1) { - *size = tableListGetSize(pTableList); + if (totalGroups == 1) { + *size = numOfTables; *pKeyInfo = (*size == 0) ? NULL : taosArrayGet(pTableList->pTableList, 0); return TSDB_CODE_SUCCESS; - } else if (total == tableListGetSize(pTableList)) { + } else if (totalGroups == numOfTables) { *size = 1; *pKeyInfo = taosArrayGet(pTableList->pTableList, ordinalGroupIndex); return TSDB_CODE_SUCCESS; } int32_t offset = pTableList->groupOffset[ordinalGroupIndex]; - if (ordinalGroupIndex < total - 1) { + if (ordinalGroupIndex < totalGroups - 1) { *size = pTableList->groupOffset[ordinalGroupIndex + 1] - offset; } else { - *size = total - offset; + *size = numOfTables - offset; } *pKeyInfo = taosArrayGet(pTableList->pTableList, offset);