Skip to content

Commit 7fce7c8

Browse files
author
Vladlen Popolitov
committed
Test for hnsw_streaming added
1 parent 1caa395 commit 7fce7c8

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

test/expected/hnsw_streaming.out

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
SELECT t,
2+
Array[t,t+1,t+2]::vector(3) AS val
3+
INTO test_where
4+
FROM generate_series(1, 2000) as t;
5+
SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;
6+
t
7+
------
8+
1501
9+
1502
10+
(2 rows)
11+
12+
CREATE INDEX test_where_idx ON test_where USING hnsw (val vector_l2_ops) WITH (m=10);
13+
set hnsw.streaming=off;
14+
set hnsw.ef_search=100;
15+
SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;
16+
t
17+
---
18+
(0 rows)
19+
20+
set hnsw.streaming=on;
21+
SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;
22+
t
23+
------
24+
1501
25+
1502
26+
(2 rows)
27+
28+
SELECT t FROM test_where WHERE t>2000 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;
29+
t
30+
---
31+
(0 rows)
32+
33+
DELETE FROM test_where;
34+
SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;
35+
t
36+
---
37+
(0 rows)
38+
39+
TRUNCATE test_where;
40+
SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;
41+
t
42+
---
43+
(0 rows)
44+
45+
DROP TABLE test_where;
46+
SET enable_seqscan = off;
47+
CREATE TABLE t (val vector(3));
48+
INSERT INTO t (val) VALUES ('[0,0,0]'), ('[1,2,3]'), ('[1,1,1]'), (NULL);
49+
CREATE INDEX t_idx ON t USING hnsw (val vector_l2_ops);
50+
INSERT INTO t (val) VALUES ('[1,2,4]');
51+
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
52+
val
53+
---------
54+
[1,2,3]
55+
[1,2,4]
56+
[1,1,1]
57+
[0,0,0]
58+
(4 rows)
59+
60+
SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <-> (SELECT NULL::vector)) t2;
61+
count
62+
-------
63+
4
64+
(1 row)
65+
66+
SELECT COUNT(*) FROM t;
67+
count
68+
-------
69+
5
70+
(1 row)
71+
72+
TRUNCATE t;
73+
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
74+
val
75+
-----
76+
(0 rows)
77+
78+
DROP TABLE t;
79+
SET enable_seqscan = off;
80+
CREATE TABLE t (val vector(3));
81+
INSERT INTO t (val) VALUES ('[0,0,0]'), ('[1,2,3]'), ('[1,1,1]'), (NULL);
82+
CREATE INDEX t_idx ON t USING hnsw (val vector_ip_ops);
83+
INSERT INTO t (val) VALUES ('[1,2,4]');
84+
SELECT * FROM t ORDER BY val <#> '[3,3,3]';
85+
val
86+
---------
87+
[1,2,4]
88+
[1,2,3]
89+
[1,1,1]
90+
[0,0,0]
91+
(4 rows)
92+
93+
SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <#> (SELECT NULL::vector)) t2;
94+
count
95+
-------
96+
4
97+
(1 row)
98+
99+
DROP TABLE t;
100+
set hnsw.streaming=off;

test/sql/hnsw_streaming.sql

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
SELECT t,
2+
Array[t,t+1,t+2]::vector(3) AS val
3+
INTO test_where
4+
FROM generate_series(1, 2000) as t;
5+
SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;
6+
CREATE INDEX test_where_idx ON test_where USING hnsw (val vector_l2_ops) WITH (m=10);
7+
set hnsw.streaming=off;
8+
set hnsw.ef_search=100;
9+
SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;
10+
set hnsw.streaming=on;
11+
SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;
12+
SELECT t FROM test_where WHERE t>2000 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;
13+
DELETE FROM test_where;
14+
SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;
15+
TRUNCATE test_where;
16+
SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2;
17+
DROP TABLE test_where;
18+
SET enable_seqscan = off;
19+
20+
CREATE TABLE t (val vector(3));
21+
INSERT INTO t (val) VALUES ('[0,0,0]'), ('[1,2,3]'), ('[1,1,1]'), (NULL);
22+
CREATE INDEX t_idx ON t USING hnsw (val vector_l2_ops);
23+
24+
INSERT INTO t (val) VALUES ('[1,2,4]');
25+
26+
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
27+
SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <-> (SELECT NULL::vector)) t2;
28+
SELECT COUNT(*) FROM t;
29+
30+
TRUNCATE t;
31+
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
32+
33+
DROP TABLE t;
34+
SET enable_seqscan = off;
35+
36+
CREATE TABLE t (val vector(3));
37+
INSERT INTO t (val) VALUES ('[0,0,0]'), ('[1,2,3]'), ('[1,1,1]'), (NULL);
38+
CREATE INDEX t_idx ON t USING hnsw (val vector_ip_ops);
39+
40+
INSERT INTO t (val) VALUES ('[1,2,4]');
41+
42+
SELECT * FROM t ORDER BY val <#> '[3,3,3]';
43+
SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <#> (SELECT NULL::vector)) t2;
44+
45+
DROP TABLE t;
46+
47+
set hnsw.streaming=off;

0 commit comments

Comments
 (0)