You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# test covering index on functional embedding column
27
+
query T
28
+
select id, text, power(distance, 2)::int from (select id, text, get_embedding('query') <-> get_embedding(text) as distance from no_index_mv order by distance limit 2) order by distance;
29
+
----
30
+
1 first 8
31
+
2 second 35
32
+
33
+
statement ok
34
+
create view query_view as select id, text, power(distance, 2)::int as distance from (select id, text, get_embedding('query') <-> get_embedding(text) as distance from items order by distance limit 2);
35
+
36
+
# ensure that vector index is used
37
+
query T
38
+
explain(verbose) select * from query_view;
39
+
----
40
+
<slt:ignore>BatchProject { exprs: [Field(Unnest($1), 1:Int32) as $expr1, Field(Unnest($1), 0:Int32) as $expr2, Pow(Field(Unnest($1), 2:Int32), 2:Float64)::Int32 as $expr3] }
# test non-covering index on functional embedding column
56
+
query T
57
+
select id, text, extra, power(distance, 2)::int from (select id, text, extra, get_embedding('query') <-> get_embedding(text) as distance from no_index_mv order by distance limit 2) order by distance;
58
+
----
59
+
1 first extra1 8
60
+
2 second extra2 35
61
+
62
+
statement ok
63
+
create view query_view as select id, text, extra, power(distance, 2)::int as distance from (select id, text, extra, get_embedding('query') <-> get_embedding(text) as distance from items order by distance limit 2);
create view query_view as select id, text, power(distance, 2)::int as distance from (select id, text, '[3,2,1]'::vector(3) <-> embedding as distance from items order by distance limit 2);
25
+
26
+
statement ok
27
+
set batch_hnsw_ef_search = default;
28
+
29
+
# ensure that vector index is used
30
+
query T
31
+
explain(verbose) select * from query_view;
32
+
----
33
+
<slt:ignore>BatchProject { exprs: [Field(Unnest($1), 1:Int32) as $expr1, Field(Unnest($1), 0:Int32) as $expr2, Pow(Field(Unnest($1), 2:Int32), 2:Float64)::Int32 as $expr3] }
select id, text, power(distance, 2)::int from (select id, text, '[3,2,1]'::vector(3) <-> embedding as distance from no_index_mv order by distance limit 2) order by distance;
29
+
----
30
+
1 first 8
31
+
2 second 35
32
+
33
+
statement ok
34
+
create view query_view as select id, text, power(distance, 2)::int as distance from (select id, text, '[3,2,1]'::vector(3) <-> embedding as distance from items order by distance limit 2);
35
+
36
+
# ensure that vector index is used
37
+
query T
38
+
explain(verbose) select * from query_view;
39
+
----
40
+
<slt:ignore>BatchProject { exprs: [Field(Unnest($1), 1:Int32) as $expr1, Field(Unnest($1), 0:Int32) as $expr2, Pow(Field(Unnest($1), 2:Int32), 2:Float64)::Int32 as $expr3] }
select id, text, extra, power(distance, 2)::int from (select id, text, extra, get_embedding('query') <-> embedding as distance from no_index_mv order by distance limit 2) order by distance;
58
+
----
59
+
1 first extra1 8
60
+
2 second extra2 35
61
+
62
+
statement ok
63
+
create view query_view as select id, text, extra, power(distance, 2)::int as distance from (select id, text, extra, get_embedding('query') <-> embedding as distance from items order by distance limit 2);
create table items (id int primary key, extra string, text string, embedding vector(3)) append only;
3
+
4
+
statement ok
5
+
insert into items values (2, 'extra2', 'second', get_embedding('second'));
6
+
7
+
statement ok
8
+
create index i on items using flat (embedding) include(text) with (distance_type = 'l2');
9
+
10
+
statement ok
11
+
insert into items values (3, 'extra3', 'third', '[7, 8, 9]'::vector(3));
12
+
13
+
statement ok
14
+
flush;
15
+
16
+
query T
17
+
select * from items order by id;
18
+
----
19
+
2 extra2 second [4,5,6]
20
+
3 extra3 third [7,8,9]
21
+
22
+
statement ok
23
+
create view cover_index_query_view as select id, text, power(distance, 2)::int as distance from (select id, text, '[3,2,1]'::vector(3) <-> embedding as distance from items FOR SYSTEM_TIME AS OF now() - '3' second order by distance limit 2);
24
+
25
+
# ensure that vector index is used
26
+
query T
27
+
explain(verbose) select * from cover_index_query_view;
28
+
----
29
+
<slt:ignore>BatchProject { exprs: [Field(Unnest($1), 1:Int32) as $expr1, Field(Unnest($1), 0:Int32) as $expr2, Pow(Field(Unnest($1), 2:Int32), 2:Float64)::Int32 as $expr3] }
create view non_cover_index_query_view as select id, text, extra, power(distance, 2)::int as distance from (select id, text, extra, get_embedding('query') <-> embedding as distance from items FOR SYSTEM_TIME AS OF now() - '3' second order by distance limit 2);
36
+
37
+
# ensure that vector index is used
38
+
query T
39
+
explain(verbose) select * from non_cover_index_query_view;
0 commit comments