From 580946de442767918952701018e1b0db349f52de Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Fri, 13 Sep 2024 10:53:51 +0100 Subject: [PATCH] Fix test --- pgxn/neon/hll.c | 4 ++-- .../test_lfc_working_set_approximation.py | 18 +++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pgxn/neon/hll.c b/pgxn/neon/hll.c index 27b6182458..7e4969722d 100644 --- a/pgxn/neon/hll.c +++ b/pgxn/neon/hll.c @@ -137,7 +137,7 @@ addSHLL(HyperLogLogState *cState, uint32 hash) uint32 cell = Min(interval_log2, HIST_SIZE-1); new_histogram[cell] += cState->regs[index][count].histogram[i]; } - memcpy(cState->regs[index][count].histogram, new_histogram, sizeof new_hostogram); + memcpy(cState->regs[index][count].histogram, new_histogram, sizeof new_histogram); } cState->regs[index][count].ts = now; cState->regs[index][count].histogram[0] += 1; @@ -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_ration) + if (reg[i].ts >= since && 1.0 - getAccessCount(reg, duration) / total_count >= min_hit_ratio) { max = i; } diff --git a/test_runner/regress/test_lfc_working_set_approximation.py b/test_runner/regress/test_lfc_working_set_approximation.py index 3eea7a8b50..0c3b094c4f 100644 --- a/test_runner/regress/test_lfc_working_set_approximation.py +++ b/test_runner/regress/test_lfc_working_set_approximation.py @@ -130,7 +130,7 @@ def test_optimal_cache_size_approximation(neon_simple_env: NeonEnv): ) conn = endpoint.connect() cur = conn.cursor() - cur.execute("create extension neon") + cur.execute("create extension neon version '1.5'") cur.execute( "create table t_huge(pk integer primary key, count integer default 0, payload text default repeat('?', 128))" ) @@ -138,14 +138,18 @@ def test_optimal_cache_size_approximation(neon_simple_env: NeonEnv): "create table t_small(pk integer primary key, count integer default 0, payload text default repeat('?', 128))" ) cur.execute("insert into t_huge(pk) values (generate_series(1,1000000))") - cur.execute("insert into t_small (pk) values (generate_series(1,100000))") + cur.execute("insert into t_small(pk) values (generate_series(1,100000))") time.sleep(2) before = time.monotonic() - for _ in 1..100: + for _ in range(100): cur.execute("select sum(count) from t_small") cur.execute("select sum(count) from t_huge") after = time.monotonic() - cur.execute(f"select approximate_optimal_cache_size({int(after - before + 1, 0.99)})") - estimation = cur.fetchall()[0][0] - log.info(f"Working set size for selecting 1k records {estimation}") - assert estimation_1k >= 20 and estimation_1k <= 40 + cur.execute(f"select approximate_working_set_size_seconds({int(after - before + 1)})") + ws_estimation = cur.fetchall()[0][0] + log.info(f"Working set size estimaton {ws_estimation}") + cur.execute(f"select approximate_optimal_cache_size({int(after - before + 1)}, 0.99)") + optimal_cache_size = cur.fetchall()[0][0] + log.info(f"Optimal cache size for 99% hit rate {optimal_cache_size}") + assert ws_estimation >= 1000 and ws_estimation <= 2000 + assert optimal_cache_size >= 100 and optimal_cache_size <= 200