mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-13 08:06:54 +08:00
Improved concurrent inserts test for HNSW [skip ci]
This commit is contained in:
@@ -17,22 +17,8 @@ $node->start;
|
|||||||
# Create table and index
|
# Create table and index
|
||||||
$node->safe_psql("postgres", "CREATE EXTENSION vector;");
|
$node->safe_psql("postgres", "CREATE EXTENSION vector;");
|
||||||
$node->safe_psql("postgres", "CREATE TABLE tst (v vector($dim));");
|
$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->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
|
sub idx_scan
|
||||||
{
|
{
|
||||||
# Stats do not update instantaneously
|
# 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;");
|
$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;");
|
my $count = $node->safe_psql("postgres", qq(
|
||||||
is($count, $expected);
|
SET enable_seqscan = off;
|
||||||
is(idx_scan(), 0);
|
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(
|
$node->safe_psql("postgres", "TRUNCATE tst;");
|
||||||
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(idx_scan(), 20);
|
||||||
));
|
|
||||||
is($count, 400);
|
|
||||||
is(idx_scan(), 1);
|
|
||||||
|
|
||||||
done_testing();
|
done_testing();
|
||||||
|
|||||||
Reference in New Issue
Block a user