From 961757ffca9a5f047a593d7f67a2951f028ce452 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 16 Nov 2020 13:21:47 +0000 Subject: [PATCH 1/2] [TD-2096]: apercentile on super table crash --- src/client/src/tscFunctionImpl.c | 9 +++++---- src/query/inc/qHistogram.h | 5 ++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/client/src/tscFunctionImpl.c b/src/client/src/tscFunctionImpl.c index f5a27311f2..35dc94f37b 100644 --- a/src/client/src/tscFunctionImpl.c +++ b/src/client/src/tscFunctionImpl.c @@ -2695,17 +2695,18 @@ static void apercentile_func_second_merge(SQLFunctionCtx *pCtx) { } SAPercentileInfo *pOutput = getAPerctInfo(pCtx); - SHistogramInfo * pHisto = pOutput->pHisto; + SHistogramInfo *pHisto = pOutput->pHisto; if (pHisto->numOfElems <= 0) { memcpy(pHisto, pInput->pHisto, sizeof(SHistogramInfo) + sizeof(SHistBin) * (MAX_HISTOGRAM_BIN + 1)); pHisto->elems = (SHistBin*) ((char *)pHisto + sizeof(SHistogramInfo)); } else { + //TODO(dengyihao): avoid memcpy pHisto->elems = (SHistBin*) ((char *)pHisto + sizeof(SHistogramInfo)); - SHistogramInfo *pRes = tHistogramMerge(pHisto, pInput->pHisto, MAX_HISTOGRAM_BIN); - tHistogramDestroy(&pOutput->pHisto); - pOutput->pHisto = pRes; + memcpy(pHisto, pRes, sizeof(SHistogramInfo) + sizeof(SHistBin) * MAX_HISTOGRAM_BIN); + pHisto->elems = (SHistBin*) ((char *)pHisto + sizeof(SHistogramInfo)); + tHistogramDestroy(&pRes); } SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); diff --git a/src/query/inc/qHistogram.h b/src/query/inc/qHistogram.h index bb058449e8..3f2cef5616 100644 --- a/src/query/inc/qHistogram.h +++ b/src/query/inc/qHistogram.h @@ -44,6 +44,8 @@ typedef struct SHistogramInfo { int32_t numOfEntries; int32_t maxEntries; + double min; + double max; #if defined(USE_ARRAYLIST) SHistBin* elems; #else @@ -52,9 +54,6 @@ typedef struct SHistogramInfo { int32_t maxIndex; bool ordered; #endif - - double min; - double max; } SHistogramInfo; SHistogramInfo* tHistogramCreate(int32_t numOfBins); From f4a92907f2670ef84d3af1f9d2955bf66f83d47e Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 16 Nov 2020 13:48:11 +0000 Subject: [PATCH 2/2] fix compile bug --- src/query/inc/qHistogram.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/query/inc/qHistogram.h b/src/query/inc/qHistogram.h index e3aa966464..442e61750b 100644 --- a/src/query/inc/qHistogram.h +++ b/src/query/inc/qHistogram.h @@ -45,9 +45,6 @@ typedef struct SHistogramInfo { int32_t maxEntries; double min; double max; - - double min; - double max; #if defined(USE_ARRAYLIST) SHistBin* elems; #else