From: VladlenPopolitov (@VladlenPopolitov) <noreply+VladlenPopolitov@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] PR #679: Hnsw streamed tests
Date: Mon, 23 Sep 2024 12:05:07 +0000
Message-ID: <gh-pgvector-pgvector-679@github.com> (raw)
Added tests fro hnsw streaming. Currently test crashes the server after TRUNCATE TABLE with active index and hnsw.streaming=ON.
inline patch 1: test/expected/hnsw_streaming.out, test/sql/hnsw_streaming.sql (+147/-0 lines) download inline-1.patchdiff --git a/test/expected/hnsw_streaming.out b/test/expected/hnsw_streaming.outnew file mode 100644index 000000000..91b852a6c--- /dev/null+++ b/test/expected/hnsw_streaming.out@@ -0,0 +1,100 @@+SELECT t,+Array[t,t+1,t+2]::vector(3) AS val+INTO test_where+FROM generate_series(1, 2000) as t;+SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;+ t +------+ 1501+ 1502+(2 rows)++CREATE INDEX test_where_idx ON test_where USING hnsw (val vector_l2_ops) WITH (m=10);+set hnsw.streaming=off;+set hnsw.ef_search=100;+SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;+ t +---+(0 rows)++set hnsw.streaming=on;+SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;+ t +------+ 1501+ 1502+(2 rows)++SELECT t FROM test_where WHERE t>2000 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;+ t +---+(0 rows)++DELETE FROM test_where;+SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;+ t +---+(0 rows)++TRUNCATE test_where;+SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;+ t +---+(0 rows)++DROP TABLE test_where;+SET enable_seqscan = off;+CREATE TABLE t (val vector(3));+INSERT INTO t (val) VALUES ('[0,0,0]'), ('[1,2,3]'), ('[1,1,1]'), (NULL);+CREATE INDEX t_idx ON t USING hnsw (val vector_l2_ops);+INSERT INTO t (val) VALUES ('[1,2,4]');+SELECT * FROM t ORDER BY val <-> '[3,3,3]';+ val +---------+ [1,2,3]+ [1,2,4]+ [1,1,1]+ [0,0,0]+(4 rows)++SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <-> (SELECT NULL::vector)) t2;+ count +-------+ 4+(1 row)++SELECT COUNT(*) FROM t;+ count +-------+ 5+(1 row)++TRUNCATE t;+SELECT * FROM t ORDER BY val <-> '[3,3,3]';+ val +-----+(0 rows)++DROP TABLE t;+SET enable_seqscan = off;+CREATE TABLE t (val vector(3));+INSERT INTO t (val) VALUES ('[0,0,0]'), ('[1,2,3]'), ('[1,1,1]'), (NULL);+CREATE INDEX t_idx ON t USING hnsw (val vector_ip_ops);+INSERT INTO t (val) VALUES ('[1,2,4]');+SELECT * FROM t ORDER BY val <#> '[3,3,3]';+ val +---------+ [1,2,4]+ [1,2,3]+ [1,1,1]+ [0,0,0]+(4 rows)++SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <#> (SELECT NULL::vector)) t2;+ count +-------+ 4+(1 row)++DROP TABLE t;+set hnsw.streaming=off;diff --git a/test/sql/hnsw_streaming.sql b/test/sql/hnsw_streaming.sqlnew file mode 100644index 000000000..75f4a3855--- /dev/null+++ b/test/sql/hnsw_streaming.sql@@ -0,0 +1,47 @@+SELECT t,+Array[t,t+1,t+2]::vector(3) AS val+INTO test_where+FROM generate_series(1, 2000) as t;+SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;+CREATE INDEX test_where_idx ON test_where USING hnsw (val vector_l2_ops) WITH (m=10);+set hnsw.streaming=off;+set hnsw.ef_search=100;+SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;+set hnsw.streaming=on;+SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;+SELECT t FROM test_where WHERE t>2000 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;+DELETE FROM test_where;+SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;+TRUNCATE test_where;+SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;+DROP TABLE test_where;+SET enable_seqscan = off;++CREATE TABLE t (val vector(3));+INSERT INTO t (val) VALUES ('[0,0,0]'), ('[1,2,3]'), ('[1,1,1]'), (NULL);+CREATE INDEX t_idx ON t USING hnsw (val vector_l2_ops);++INSERT INTO t (val) VALUES ('[1,2,4]');++SELECT * FROM t ORDER BY val <-> '[3,3,3]';+SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <-> (SELECT NULL::vector)) t2;+SELECT COUNT(*) FROM t;++TRUNCATE t;+SELECT * FROM t ORDER BY val <-> '[3,3,3]';++DROP TABLE t;+SET enable_seqscan = off;++CREATE TABLE t (val vector(3));+INSERT INTO t (val) VALUES ('[0,0,0]'), ('[1,2,3]'), ('[1,1,1]'), (NULL);+CREATE INDEX t_idx ON t USING hnsw (val vector_ip_ops);++INSERT INTO t (val) VALUES ('[1,2,4]');++SELECT * FROM t ORDER BY val <#> '[3,3,3]';+SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <#> (SELECT NULL::vector)) t2;++DROP TABLE t;++set hnsw.streaming=off;