@@ -26,6 +26,7 @@ var VectorIndexQueries = []ScriptTest{
2626 "create table vectors (id int primary key, v json);" ,
2727 `insert into vectors values (1, '[4.0,3.0]'), (2, '[0.0,0.0]'), (3, '[-1.0,1.0]'), (4, '[0.0,-2.0]');` ,
2828 `create vector index v_idx on vectors(v);` ,
29+ `set @query_vec = '[0.0,0.0]';` ,
2930 },
3031 Assertions : []ScriptTestAssertion {
3132 {
@@ -44,6 +45,17 @@ var VectorIndexQueries = []ScriptTest{
4445 },
4546 ExpectedIndexes : []string {"v_idx" },
4647 },
48+ {
49+ // Queries against a user var can be optimized.
50+ Query : "select * from vectors order by VEC_DISTANCE(@query_vec, v) limit 4" ,
51+ Expected : []sql.Row {
52+ {2 , types .MustJSON (`[0.0, 0.0]` )},
53+ {3 , types .MustJSON (`[-1.0, 1.0]` )},
54+ {4 , types .MustJSON (`[0.0, -2.0]` )},
55+ {1 , types .MustJSON (`[4.0, 3.0]` )},
56+ },
57+ ExpectedIndexes : []string {"v_idx" },
58+ },
4759 {
4860 // Only queries with a limit can use a vector index.
4961 Query : "select * from vectors order by VEC_DISTANCE('[0.0,0.0]', v)" ,
0 commit comments