Skip dead tuples for search with HNSW

This commit is contained in:
Andrew Kane
2023-09-02 17:48:44 -07:00
parent 9ebec1529b
commit d6ac7b93bb
5 changed files with 129 additions and 22 deletions

View File

@@ -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;

View File

@@ -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();