This commit is contained in:
Konstantin Knizhnik
2024-09-13 11:39:12 +01:00
parent 580946de44
commit 16b0e57d11
2 changed files with 5 additions and 5 deletions

View File

@@ -1280,7 +1280,7 @@ approximate_working_set_size(PG_FUNCTION_ARGS)
int32 dc;
bool reset = PG_GETARG_BOOL(0);
LWLockAcquire(lfc_lock, reset ? LW_EXCLUSIVE : LW_SHARED);
dc = (int32) estimateSHLL(&lfc_ctl->wss_estimation, (time_t)-1, 0);
dc = (int32) estimateSHLL(&lfc_ctl->wss_estimation, (time_t)-1, 1.0);
if (reset)
memset(lfc_ctl->wss_estimation.regs, 0, sizeof lfc_ctl->wss_estimation.regs);
LWLockRelease(lfc_lock);
@@ -1298,7 +1298,7 @@ approximate_optimal_cache_size(PG_FUNCTION_ARGS)
{
int32 dc;
time_t duration = PG_ARGISNULL(0) ? (time_t)-1 : PG_GETARG_INT32(0);
double min_hit_ratio = PG_ARGISNULL(1) ? 0 : PG_GETARG_FLOAT8(1);
double min_hit_ratio = PG_ARGISNULL(1) ? 1.0 : PG_GETARG_FLOAT8(1);
LWLockAcquire(lfc_lock, LW_SHARED);
dc = (int32) estimateSHLL(&lfc_ctl->wss_estimation, duration, min_hit_ratio);
LWLockRelease(lfc_lock);

View File

@@ -133,7 +133,7 @@ addSHLL(HyperLogLogState *cState, uint32 hash)
uint32_t new_histogram[HIST_SIZE] = {0};
for (int i = 0; i < HIST_SIZE; i++) {
/* Use average point of interval */
uint32 interval_log2 = pg_ceil_log2_32((delta + (HIST_MIN_INTERVAL*((i+1) + ((1<<i)/2))/2)) / HIST_MIN_INTERVAL);
uint32 interval_log2 = pg_ceil_log2_32((delta + (HIST_MIN_INTERVAL*((1<<i) + ((1<<i)/2))/2)) / HIST_MIN_INTERVAL);
uint32 cell = Min(interval_log2, HIST_SIZE-1);
new_histogram[cell] += cState->regs[index][count].histogram[i];
}
@@ -147,7 +147,7 @@ static uint32_t
getAccessCount(const HyperLogLogRegister* reg, time_t duration)
{
uint32_t count = 0;
for (size_t i = 0; i < HIST_SIZE && (HIST_MIN_INTERVAL << i) <= duration; i++) {
for (size_t i = 0; i < HIST_SIZE && HIST_MIN_INTERVAL*((1 << i)/2) <= duration; i++) {
count += reg->histogram[i];
}
return count;
@@ -166,7 +166,7 @@ getMaximum(const HyperLogLogRegister* reg, TimestampTz since, time_t duration, d
{
for (i = 0; i < HLL_C_BITS + 1; i++)
{
if (reg[i].ts >= since && 1.0 - getAccessCount(reg, duration) / total_count >= min_hit_ratio)
if (reg[i].ts >= since && 1.0 - getAccessCount(reg, duration) / total_count <= min_hit_ratio)
{
max = i;
}