From cc8702cf3973eadbc3a37a9422921178308c0405 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Sun, 21 Jan 2024 17:58:18 -0800 Subject: [PATCH] Added tests for like [skip ci] --- test/t/018_hnsw_filtering.pl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/t/018_hnsw_filtering.pl b/test/t/018_hnsw_filtering.pl index 0a960ca..3053f56 100644 --- a/test/t/018_hnsw_filtering.pl +++ b/test/t/018_hnsw_filtering.pl @@ -17,9 +17,9 @@ $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);"); +$node->safe_psql("postgres", "CREATE TABLE tst (i int4, v vector($dim), c int4, t text);"); $node->safe_psql("postgres", - "INSERT INTO tst SELECT i, ARRAY[$array_sql], i % $nc FROM generate_series(1, 10000) i;" + "INSERT INTO tst SELECT i, ARRAY[$array_sql], i % $nc, 'test ' || i 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;"); @@ -57,6 +57,18 @@ $explain = $node->safe_psql("postgres", qq( )); like($explain, qr/Seq Scan/); +# Test attribute filtering with few rows removed like +$explain = $node->safe_psql("postgres", qq( + EXPLAIN ANALYZE SELECT i FROM tst WHERE t LIKE '%%test%%' ORDER BY v <-> '$query' LIMIT $limit; +)); +like($explain, qr/Index Scan using idx/); + +# Test attribute filtering with many rows removed like +$explain = $node->safe_psql("postgres", qq( + EXPLAIN ANALYZE SELECT i FROM tst WHERE t LIKE '%%other%%' 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;