From ecfe8ecabb32b12da52e1b28f7d2b97dcb182fed Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sun, 4 Apr 2021 15:33:18 +0800 Subject: [PATCH] [td-3662] --- src/client/src/tscLocalMerge.c | 9 +++++++-- tests/script/general/parser/select_with_tags.sim | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscLocalMerge.c b/src/client/src/tscLocalMerge.c index c28302895e..89642a067d 100644 --- a/src/client/src/tscLocalMerge.c +++ b/src/client/src/tscLocalMerge.c @@ -1159,7 +1159,7 @@ static void fillMultiRowsOfTagsVal(SQueryInfo *pQueryInfo, int32_t numOfRes, SLo memset(buf, 0, (size_t)maxBufSize); memcpy(buf, pCtx->pOutput, (size_t)pCtx->outputBytes); - for (int32_t i = 1; i < inc; ++i) { + for (int32_t i = 0; i < inc; ++i) { pCtx->pOutput += pCtx->outputBytes; memcpy(pCtx->pOutput, buf, (size_t)pCtx->outputBytes); } @@ -1449,6 +1449,11 @@ int32_t tscDoLocalMerge(SSqlObj *pSql) { SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); tFilePage *tmpBuffer = pLocalMerge->pTempBuffer; + int32_t remain = 1; + if (tscIsTopbotQuery(pQueryInfo)) { + remain = tscGetTopbotQueryParam(pQueryInfo); + } + if (doHandleLastRemainData(pSql)) { return TSDB_CODE_SUCCESS; } @@ -1537,7 +1542,7 @@ int32_t tscDoLocalMerge(SSqlObj *pSql) { * if the previous group does NOT generate any result (pResBuf->num == 0), * continue to process results instead of return results. */ - if ((!sameGroup && pResBuf->num > 0) || (pResBuf->num == pLocalMerge->resColModel->capacity)) { + if ((!sameGroup && pResBuf->num > 0) || (pResBuf->num + remain >= pLocalMerge->resColModel->capacity)) { // does not belong to the same group bool notSkipped = genFinalResults(pSql, pLocalMerge, !sameGroup); diff --git a/tests/script/general/parser/select_with_tags.sim b/tests/script/general/parser/select_with_tags.sim index 6d22332fb2..ab34713d90 100644 --- a/tests/script/general/parser/select_with_tags.sim +++ b/tests/script/general/parser/select_with_tags.sim @@ -162,6 +162,11 @@ endi #sql select top(c6, 3) from select_tags_mt0 interval(10a) #sql select top(c6, 3) from select_tags_mt0 interval(10a) group by tbname; +sql select top(c6, 10) from select_tags_mt0 interval(10a); +if $rows != 12800 then + return -1 +endi + sql select top(c1, 100), tbname, t1, t2 from select_tags_mt0; if $rows != 100 then return -1 -- GitLab