fix:[TD-32855] Improve percentile function when calculating on a small amount of data.
This commit is contained in:
parent
1031a3487d
commit
f7a2c857f4
|
@ -26,7 +26,7 @@ extern "C" {
|
|||
struct tMemBucket;
|
||||
|
||||
int32_t tMemBucketCreate(int32_t nElemSize, int16_t dataType, double minval, double maxval, bool hasWindowOrGroup,
|
||||
struct tMemBucket **pBucket);
|
||||
struct tMemBucket **pBucket, int32_t numOfElements);
|
||||
|
||||
void tMemBucketDestroy(struct tMemBucket **pBucket);
|
||||
|
||||
|
|
|
@ -1805,7 +1805,7 @@ int32_t percentileFunction(SqlFunctionCtx* pCtx) {
|
|||
pResInfo->complete = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
} else {
|
||||
code = tMemBucketCreate(pCol->info.bytes, type, pInfo->minval, pInfo->maxval, pCtx->hasWindowOrGroup, &pInfo->pMemBucket);
|
||||
code = tMemBucketCreate(pCol->info.bytes, type, pInfo->minval, pInfo->maxval, pCtx->hasWindowOrGroup, &pInfo->pMemBucket, pInfo->numOfElems);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -269,18 +269,16 @@ static void resetSlotInfo(tMemBucket *pBucket) {
|
|||
}
|
||||
|
||||
int32_t tMemBucketCreate(int32_t nElemSize, int16_t dataType, double minval, double maxval, bool hasWindowOrGroup,
|
||||
tMemBucket **pBucket) {
|
||||
tMemBucket **pBucket, int32_t numOfElements) {
|
||||
*pBucket = (tMemBucket *)taosMemoryCalloc(1, sizeof(tMemBucket));
|
||||
if (*pBucket == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
if (hasWindowOrGroup) {
|
||||
// With window or group by, we need to shrink page size and reduce page num to save memory.
|
||||
(*pBucket)->numOfSlots = DEFAULT_NUM_OF_SLOT / 8 ; // 128 bucket
|
||||
// With window or group by, we need to shrink page size to save memory.
|
||||
(*pBucket)->bufPageSize = 4096; // 4k per page
|
||||
} else {
|
||||
(*pBucket)->numOfSlots = DEFAULT_NUM_OF_SLOT;
|
||||
(*pBucket)->bufPageSize = 16384 * 4; // 16k per page
|
||||
}
|
||||
|
||||
|
@ -302,6 +300,8 @@ int32_t tMemBucketCreate(int32_t nElemSize, int16_t dataType, double minval, dou
|
|||
}
|
||||
|
||||
(*pBucket)->elemPerPage = ((*pBucket)->bufPageSize - sizeof(SFilePage)) / (*pBucket)->bytes;
|
||||
(*pBucket)->numOfSlots = TMIN((int16_t)(numOfElements / ((*pBucket)->elemPerPage * 6)) + 1, DEFAULT_NUM_OF_SLOT);
|
||||
|
||||
(*pBucket)->comparFn = getKeyComparFunc((*pBucket)->type, TSDB_ORDER_ASC);
|
||||
|
||||
(*pBucket)->hashFunc = getHashFunc((*pBucket)->type);
|
||||
|
@ -587,7 +587,7 @@ int32_t getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction
|
|||
// try next round
|
||||
tMemBucket *tmpBucket = NULL;
|
||||
int32_t code = tMemBucketCreate(pMemBucket->bytes, pMemBucket->type, pSlot->range.dMinVal, pSlot->range.dMaxVal,
|
||||
false, &tmpBucket);
|
||||
false, &tmpBucket, pSlot->info.size);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tMemBucketDestroy(&tmpBucket);
|
||||
return code;
|
||||
|
|
Loading…
Reference in New Issue