From 44e9e26e6931f1cbbd6897cfbabc69e3029339fe Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Sun, 21 Jan 2024 16:10:37 -0800 Subject: [PATCH] Added more filtering tests [skip ci] --- test/t/018_hnsw_filtering.pl | 13 +++++++++++++ test/t/019_ivfflat_filtering.pl | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/test/t/018_hnsw_filtering.pl b/test/t/018_hnsw_filtering.pl index 184a2d1..0a960ca 100644 --- a/test/t/018_hnsw_filtering.pl +++ b/test/t/018_hnsw_filtering.pl @@ -22,6 +22,7 @@ $node->safe_psql("postgres", "INSERT INTO tst SELECT i, ARRAY[$array_sql], i % $nc FROM generate_series(1, 10000) i;" ); $node->safe_psql("postgres", "CREATE INDEX idx ON tst USING hnsw (v vector_l2_ops);"); +$node->safe_psql("postgres", "ANALYZE tst;"); # Generate query my @r = (); @@ -44,6 +45,18 @@ $explain = $node->safe_psql("postgres", qq( )); like($explain, qr/Index Scan using idx/); +# Test attribute filtering with few rows removed comparison +$explain = $node->safe_psql("postgres", qq( + EXPLAIN ANALYZE SELECT i FROM tst WHERE c >= 1 ORDER BY v <-> '$query' LIMIT $limit; +)); +like($explain, qr/Index Scan using idx/); + +# Test attribute filtering with many rows removed comparison +$explain = $node->safe_psql("postgres", qq( + EXPLAIN ANALYZE SELECT i FROM tst WHERE c < 1 ORDER BY v <-> '$query' LIMIT $limit; +)); +like($explain, qr/Seq Scan/); + # Test distance filtering $explain = $node->safe_psql("postgres", qq( EXPLAIN ANALYZE SELECT i FROM tst WHERE v <-> '$query' < 1 ORDER BY v <-> '$query' LIMIT $limit; diff --git a/test/t/019_ivfflat_filtering.pl b/test/t/019_ivfflat_filtering.pl index 3a3a6be..19c84f9 100644 --- a/test/t/019_ivfflat_filtering.pl +++ b/test/t/019_ivfflat_filtering.pl @@ -22,6 +22,7 @@ $node->safe_psql("postgres", "INSERT INTO tst SELECT i, ARRAY[$array_sql], i % $nc FROM generate_series(1, 10000) i;" ); $node->safe_psql("postgres", "CREATE INDEX idx ON tst USING ivfflat (v vector_l2_ops) WITH (lists = 100);"); +$node->safe_psql("postgres", "ANALYZE tst;"); # Generate query my @r = (); @@ -44,6 +45,18 @@ $explain = $node->safe_psql("postgres", qq( )); like($explain, qr/Index Scan using idx/); +# Test attribute filtering with few rows removed comparison +$explain = $node->safe_psql("postgres", qq( + EXPLAIN ANALYZE SELECT i FROM tst WHERE c >= 1 ORDER BY v <-> '$query' LIMIT $limit; +)); +like($explain, qr/Index Scan using idx/); + +# Test attribute filtering with many rows removed comparison +$explain = $node->safe_psql("postgres", qq( + EXPLAIN ANALYZE SELECT i FROM tst WHERE c < 1 ORDER BY v <-> '$query' LIMIT $limit; +)); +like($explain, qr/Seq Scan/); + # Test distance filtering $explain = $node->safe_psql("postgres", qq( EXPLAIN ANALYZE SELECT i FROM tst WHERE v <-> '$query' < 1 ORDER BY v <-> '$query' LIMIT $limit;