diff --git a/pgxn/neon/file_cache.c b/pgxn/neon/file_cache.c index 0040f0cca9..463d2e94c7 100644 --- a/pgxn/neon/file_cache.c +++ b/pgxn/neon/file_cache.c @@ -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); diff --git a/pgxn/neon/hll.c b/pgxn/neon/hll.c index 7e4969722d..90a46deb06 100644 --- a/pgxn/neon/hll.c +++ b/pgxn/neon/hll.c @@ -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<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; }