From 77b3d1f2a8e08aa6ca2545eddd9fb51796c32ea1 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 24 Sep 2024 23:21:34 -0700 Subject: [PATCH] Added test for join with attribute filtering [skip ci] --- test/t/017_hnsw_filtering.pl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/t/017_hnsw_filtering.pl b/test/t/017_hnsw_filtering.pl index 4ec8721..0896d32 100644 --- a/test/t/017_hnsw_filtering.pl +++ b/test/t/017_hnsw_filtering.pl @@ -18,12 +18,12 @@ $node->start; # Create table and index $node->safe_psql("postgres", "CREATE EXTENSION vector;"); $node->safe_psql("postgres", "CREATE TABLE tst (i int4, v vector($dim), c int4, t text);"); -$node->safe_psql("postgres", "CREATE TABLE cat (i int4 PRIMARY KEY, t text);"); +$node->safe_psql("postgres", "CREATE TABLE cat (i int4 PRIMARY KEY, t text, b boolean);"); $node->safe_psql("postgres", "INSERT INTO tst SELECT i, ARRAY[$array_sql], i % $nc, 'test ' || i FROM generate_series(1, 10000) i;" ); $node->safe_psql("postgres", - "INSERT INTO cat SELECT i, 'cat ' || i FROM generate_series(1, $nc) i;" + "INSERT INTO cat SELECT i, 'cat ' || i, i % 5 = 0 FROM generate_series(1, $nc) i;" ); $node->safe_psql("postgres", "CREATE INDEX idx ON tst USING hnsw (v vector_l2_ops);"); $node->safe_psql("postgres", "ANALYZE tst;"); @@ -106,6 +106,12 @@ $explain = $node->safe_psql("postgres", qq( )); like($explain, qr/Index Scan using idx/); +# Test join with attribute filtering +$explain = $node->safe_psql("postgres", qq( + EXPLAIN ANALYZE SELECT cat.t FROM cat INNER JOIN tst ON cat.i = tst.c WHERE cat.b = 't' ORDER BY v <-> '$query' LIMIT $limit; +)); +like($explain, qr/Index Scan using idx/); + # Test attribute index $node->safe_psql("postgres", "CREATE INDEX attribute_idx ON tst (c);"); $explain = $node->safe_psql("postgres", qq(