From 098813c483e55e758b0c967fbb93ce21bc23e46c Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Fri, 11 Aug 2023 18:33:01 -0700 Subject: [PATCH] Improved concurrent inserts test for HNSW [skip ci] --- test/t/014_hnsw_inserts.pl | 46 +++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/test/t/014_hnsw_inserts.pl b/test/t/014_hnsw_inserts.pl index f9f18f5..755feb1 100644 --- a/test/t/014_hnsw_inserts.pl +++ b/test/t/014_hnsw_inserts.pl @@ -17,22 +17,8 @@ $node->start; # Create table and index $node->safe_psql("postgres", "CREATE EXTENSION vector;"); $node->safe_psql("postgres", "CREATE TABLE tst (v vector($dim));"); -$node->safe_psql("postgres", - "INSERT INTO tst SELECT ARRAY[$array_sql] FROM generate_series(1, 100) i;" -); $node->safe_psql("postgres", "CREATE INDEX ON tst USING hnsw (v vector_l2_ops);"); -$node->pgbench( - "--no-vacuum --client=5 --transactions=100", - 0, - [qr{actually processed}], - [qr{^$}], - "concurrent INSERTs", - { - "014_hnsw_inserts" => "INSERT INTO tst SELECT ARRAY[$array_sql] FROM generate_series(1, 10) i;" - } -); - sub idx_scan { # Stats do not update instantaneously @@ -41,18 +27,28 @@ sub idx_scan $node->safe_psql("postgres", "SELECT idx_scan FROM pg_stat_user_indexes WHERE indexrelid = 'tst_v_idx'::regclass;"); } -my $expected = 100 + 5 * 100 * 10; +for my $i (1 .. 20) +{ + $node->pgbench( + "--no-vacuum --client=10 --transactions=1", + 0, + [qr{actually processed}], + [qr{^$}], + "concurrent INSERTs", + { + "014_hnsw_inserts_$i" => "INSERT INTO tst VALUES (ARRAY[$array_sql]);" + } + ); -my $count = $node->safe_psql("postgres", "SELECT COUNT(*) FROM tst;"); -is($count, $expected); -is(idx_scan(), 0); + my $count = $node->safe_psql("postgres", qq( + SET enable_seqscan = off; + SELECT COUNT(*) FROM (SELECT v FROM tst ORDER BY v <-> (SELECT v FROM tst LIMIT 1)) t; + )); + is($count, 10); -$count = $node->safe_psql("postgres", qq( - SET enable_seqscan = off; - SET hnsw.ef_search = 400; - SELECT COUNT(*) FROM (SELECT v FROM tst ORDER BY v <-> (SELECT v FROM tst LIMIT 1)) t; -)); -is($count, 400); -is(idx_scan(), 1); + $node->safe_psql("postgres", "TRUNCATE tst;"); +} + +is(idx_scan(), 20); done_testing();