mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-01 10:11:20 +08:00
Skip dead tuples for search with HNSW
This commit is contained in:
@@ -38,8 +38,9 @@ sub test_index_replay
|
||||
);
|
||||
|
||||
# Run test queries and compare their result
|
||||
my $primary_result = $node_primary->safe_psql("postgres", $queries);
|
||||
# Query replica first since index scan on primary can generate WAL removing tuples
|
||||
my $replica_result = $node_replica->safe_psql("postgres", $queries);
|
||||
my $primary_result = $node_primary->safe_psql("postgres", $queries);
|
||||
|
||||
is($primary_result, $replica_result, "$test_name: query result matches");
|
||||
return;
|
||||
|
||||
@@ -23,25 +23,27 @@ sub insert_vectors
|
||||
|
||||
sub test_duplicates
|
||||
{
|
||||
my ($exp) = @_;
|
||||
|
||||
my $res = $node->safe_psql("postgres", qq(
|
||||
SET enable_seqscan = off;
|
||||
SET hnsw.ef_search = 1;
|
||||
SELECT COUNT(*) FROM (SELECT * FROM tst ORDER BY v <-> '[1,1,1]') t;
|
||||
));
|
||||
is($res, 10);
|
||||
is($res, $exp);
|
||||
}
|
||||
|
||||
# Test duplicates with build
|
||||
insert_vectors();
|
||||
$node->safe_psql("postgres", "CREATE INDEX idx ON tst USING hnsw (v vector_l2_ops);");
|
||||
test_duplicates();
|
||||
test_duplicates(10);
|
||||
|
||||
# Reset
|
||||
$node->safe_psql("postgres", "TRUNCATE tst;");
|
||||
|
||||
# Test duplicates with inserts
|
||||
insert_vectors();
|
||||
test_duplicates();
|
||||
test_duplicates(10);
|
||||
|
||||
# Test fallback path for inserts
|
||||
$node->pgbench(
|
||||
@@ -55,4 +57,15 @@ $node->pgbench(
|
||||
}
|
||||
);
|
||||
|
||||
# Reset
|
||||
$node->safe_psql("postgres", "TRUNCATE tst;");
|
||||
|
||||
# Test deletes with index scan
|
||||
$node->safe_psql("postgres", "INSERT INTO tst SELECT '[1,1,1]' FROM generate_series(1, 10) i;");
|
||||
$node->safe_psql("postgres", "DELETE FROM tst WHERE ctid IN (SELECT ctid FROM tst ORDER BY random() LIMIT 5);");
|
||||
for (1 .. 3)
|
||||
{
|
||||
test_duplicates(5);
|
||||
}
|
||||
|
||||
done_testing();
|
||||
|
||||
Reference in New Issue
Block a user