From 281746c1395e6a294f7ace8d462503304988ec1d Mon Sep 17 00:00:00 2001 From: AlexDuan <417921451@qq.com> Date: Wed, 15 Sep 2021 19:18:34 +0800 Subject: [PATCH] addition 3 centriods and check overflow --- src/query/inc/tdigest.h | 2 +- src/query/src/tdigest.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/query/inc/tdigest.h b/src/query/inc/tdigest.h index 6a89ec301d..df57f983b1 100644 --- a/src/query/inc/tdigest.h +++ b/src/query/inc/tdigest.h @@ -27,7 +27,7 @@ #endif #define COMPRESSION 400 -#define GET_CENTROID(compression) (ceil(compression * M_PI / 2) + 1) +#define GET_CENTROID(compression) (ceil(compression * M_PI / 2) + 1 + 3) // addition 3 centroid #define GET_THRESHOLD(compression) (7.5 + 0.37 * compression - 2e-4 * pow(compression, 2)) #define TDIGEST_SIZE(compression) (sizeof(TDigest) + sizeof(SCentroid)*GET_CENTROID(compression) + sizeof(SPt)*GET_THRESHOLD(compression)) diff --git a/src/query/src/tdigest.c b/src/query/src/tdigest.c index 660a42e3d8..c10ae020e3 100644 --- a/src/query/src/tdigest.c +++ b/src/query/src/tdigest.c @@ -78,7 +78,9 @@ static void mergeCentroid(SMergeArgs *args, SCentroid *merge) { args->weight_so_far / args->t->total_weight); if (k2 - args->k1 > 1 && c->weight > 0) { - args->idx++; + if(args->idx + 1 < args->t->size) { // check avoid overflow + args->idx++; + } args->k1 = INTEGRATED_LOCATION(args->t->compression, (args->weight_so_far - merge->weight) / args->t->total_weight); } -- GitLab