-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathpartition.slt
54 lines (42 loc) · 1.31 KB
/
partition.slt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
statement ok
SET search_path TO pg_temp, vectors;
# partition table
statement ok
CREATE TABLE items (val vector(3), category_id int) PARTITION BY LIST(category_id);
statement ok
CREATE TABLE id_123 PARTITION OF items FOR VALUES IN (1, 2, 3);
statement ok
CREATE TABLE id_456 PARTITION OF items FOR VALUES IN (4, 5, 6);
statement ok
CREATE TABLE id_789 PARTITION OF items FOR VALUES IN (7, 8, 9);
statement ok
INSERT INTO items (val, category_id)
SELECT
ARRAY[random(), random(), random()]::real[],
(random() * 6 + 1)::int
FROM generate_series(1, 1000);
statement ok
CREATE INDEX ON items USING vectors (val vectors.vector_l2_ops)
WITH (options = "[indexing.hnsw]");
query I
SELECT COUNT(1) FROM (SELECT 1 FROM items ORDER BY val <-> '[0.5,0.5,0.5]' limit 10) t2;
----
10
statement ok
CREATE INDEX ON id_123 USING vectors (val vectors.vector_cos_ops)
WITH (options = "[indexing.hnsw]");
query I
SELECT COUNT(1) FROM (SELECT 1 FROM items ORDER BY val <=> '[0.5,0.5,0.5]' limit 10) t2;
----
10
# partial index
statement ok
CREATE INDEX ON items USING vectors (val vectors.vector_dot_ops)
WITH (options = "[indexing.hnsw]") WHERE (category_id = 1);
query I
SELECT COUNT(1) FROM
(SELECT 1 FROM items WHERE (category_id = 1) ORDER BY val <#> '[0.5,0.5,0.5]' limit 10) t2;
----
10
statement ok
DROP TABLE id_789, id_456, id_123, items;