From 72247c21e89d77b2ea71d62077473fe6a9e20249 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Fri, 11 Mar 2022 14:27:33 +0800 Subject: [PATCH] [TS-207](query):simple sortGroupbyColumn --- src/query/src/qExecutor.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 0153a9674f..ed2e93956f 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -284,40 +284,30 @@ static int compareRowData(const void *a, const void *b, const void *userData) { } static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, SQueryRuntimeEnv *pRuntimeEnv, SSDataBlock* pDataBlock, SQLFunctionCtx *pCtx) { - // get groupby first column index - SColIndex* pColIndex = taosArrayGet(pRuntimeEnv->pQueryAttr->pGroupbyExpr->columnInfo, 0); - if (pColIndex == NULL) { + // first groupby column is sort column + SColIndex* pFirstGroupCol = taosArrayGet(pRuntimeEnv->pQueryAttr->pGroupbyExpr->columnInfo, 0); + if (pFirstGroupCol == NULL) { return; } - // search group by col index - int32_t orderIndex = -1; - for (int32_t j = 0; j < pDataBlock->info.numOfCols; ++j) { - if (pCtx[j].colId == pColIndex->colId) { - orderIndex = j; - break; - } - } - if (orderIndex == -1) { - return; - } - - // get dataOffset - bool found = false; + // get dataOffset and index on pRuntimeEnv->pQueryAttr->pExpr1 + int32_t idxGroup = -1; int16_t dataOffset = 0; for (int32_t j = 0; j < pDataBlock->info.numOfCols; ++j) { SColumnInfoData* pColInfoData = (SColumnInfoData *)taosArrayGet(pDataBlock->pDataBlock, j); - if (orderIndex == j) { - found = true; + if (pCtx[j].colId == pFirstGroupCol->colId) { + idxGroup = j; break; } dataOffset += pColInfoData->info.bytes; } - if (found == false) { + // check found + if (idxGroup == -1) { + qError("sort groupby not found first column. first colId=%d", pFirstGroupCol->colId); return; } - int16_t type = pRuntimeEnv->pQueryAttr->pExpr1[orderIndex].base.resType; + int16_t type = pRuntimeEnv->pQueryAttr->pExpr1[idxGroup].base.resType; SRowCompSupporter support = {.pRuntimeEnv = pRuntimeEnv, .dataOffset = dataOffset, .comFunc = getComparFunc(type, 0)}; taosArraySortPWithExt(pGroupResInfo->pRows, compareRowData, &support); } -- GitLab