From 9c1fee4799c045b1cd74e61cafe1da9a43de156d Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Wed, 14 Feb 2024 15:45:12 -0800 Subject: [PATCH] Added more operators [skip ci] --- sql/vector--0.6.1--0.7.0.sql | 18 +++++++++++++++--- sql/vector.sql | 18 +++++++++++++++--- test/t/020_hnsw_filtering.pl | 6 ++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/sql/vector--0.6.1--0.7.0.sql b/sql/vector--0.6.1--0.7.0.sql index 4e565bd..4b9ac6a 100644 --- a/sql/vector--0.6.1--0.7.0.sql +++ b/sql/vector--0.6.1--0.7.0.sql @@ -3,12 +3,24 @@ CREATE OPERATOR CLASS vector_bigint_ops DEFAULT FOR TYPE bigint USING hnsw AS - OPERATOR 2 = (bigint, bigint); + OPERATOR 2 < , + OPERATOR 3 <= , + OPERATOR 4 = , + OPERATOR 5 >= , + OPERATOR 6 > ; CREATE OPERATOR CLASS vector_integer_ops DEFAULT FOR TYPE integer USING hnsw AS - OPERATOR 2 = (integer, integer); + OPERATOR 2 < , + OPERATOR 3 <= , + OPERATOR 4 = , + OPERATOR 5 >= , + OPERATOR 6 > ; CREATE OPERATOR CLASS vector_text_ops DEFAULT FOR TYPE text USING hnsw AS - OPERATOR 2 = (text, text); + OPERATOR 2 < , + OPERATOR 3 <= , + OPERATOR 4 = , + OPERATOR 5 >= , + OPERATOR 6 > ; diff --git a/sql/vector.sql b/sql/vector.sql index e703784..1875021 100644 --- a/sql/vector.sql +++ b/sql/vector.sql @@ -295,12 +295,24 @@ CREATE OPERATOR CLASS vector_cosine_ops CREATE OPERATOR CLASS vector_bigint_ops DEFAULT FOR TYPE bigint USING hnsw AS - OPERATOR 2 = (bigint, bigint); + OPERATOR 2 < , + OPERATOR 3 <= , + OPERATOR 4 = , + OPERATOR 5 >= , + OPERATOR 6 > ; CREATE OPERATOR CLASS vector_integer_ops DEFAULT FOR TYPE integer USING hnsw AS - OPERATOR 2 = (integer, integer); + OPERATOR 2 < , + OPERATOR 3 <= , + OPERATOR 4 = , + OPERATOR 5 >= , + OPERATOR 6 > ; CREATE OPERATOR CLASS vector_text_ops DEFAULT FOR TYPE text USING hnsw AS - OPERATOR 2 = (text, text); + OPERATOR 2 < , + OPERATOR 3 <= , + OPERATOR 4 = , + OPERATOR 5 >= , + OPERATOR 6 > ; diff --git a/test/t/020_hnsw_filtering.pl b/test/t/020_hnsw_filtering.pl index 0102b8f..6bd0ed5 100644 --- a/test/t/020_hnsw_filtering.pl +++ b/test/t/020_hnsw_filtering.pl @@ -101,6 +101,12 @@ my $explain = $node->safe_psql("postgres", qq( )); like($explain, qr/Index Scan/); +# Test range +$explain = $node->safe_psql("postgres", qq( + EXPLAIN ANALYZE SELECT i FROM tst WHERE c >= '1' AND c <= '3' ORDER BY v <-> '$queries[0]' LIMIT $limit; +)); +like($explain, qr/Index Cond: \(\(c >= \S+\) AND \(c <= \S+\)\)/); + # Test multiple conditions $explain = $node->safe_psql("postgres", qq( EXPLAIN ANALYZE SELECT i FROM tst WHERE c = '$cs[0]' AND c2 = '$cs[0]' ORDER BY v <-> '$queries[0]' LIMIT $limit;