Skip to content

Commit c10da38

Browse files
committed
Amend vector index queries
1 parent 3b2cf89 commit c10da38

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

enginetest/queries/vector_index_queries.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,38 @@ var VectorIndexQueries = []ScriptTest{
2525
SetUpScript: []string{
2626
"create table vectors (id int primary key, v json);",
2727
`insert into vectors values (1, '[3.0,4.0]'), (2, '[0.0,0.0]'), (3, '[1.0,-1.0]'), (4, '[-2.0,0.0]');`,
28+
`create vector index v_idx on vectors(v);`,
2829
},
2930
Assertions: []ScriptTestAssertion{
3031
{
31-
Query: `create vector index v_idx on vectors(v);`,
32+
Query: "show create table vectors",
3233
Expected: []sql.Row{
33-
{types.OkResult{RowsAffected: 0}},
34+
{"vectors", "CREATE TABLE `vectors` (\n `id` int NOT NULL,\n `v` json,\n PRIMARY KEY (`id`),\n VECTOR KEY `v_idx` (`v`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"},
3435
},
3536
},
3637
{
37-
Query: "show create table vectors",
38+
Query: "select * from vectors order by VEC_DISTANCE('[0.0,0.0]', v) limit 4",
3839
Expected: []sql.Row{
39-
{"vectors", "CREATE TABLE `vectors` (\n `id` int NOT NULL,\n `v` json,\n PRIMARY KEY (`id`),\n VECTOR KEY `v_idx` (`v`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"},
40+
{2, types.MustJSON(`[0.0, 0.0]`)},
41+
{3, types.MustJSON(`[1.0, -1.0]`)},
42+
{4, types.MustJSON(`[-2.0, 0.0]`)},
43+
{1, types.MustJSON(`[3.0, 4.0]`)},
4044
},
45+
ExpectedIndexes: []string{"v_idx"},
4146
},
4247
{
48+
// Only queries with a limit can use a vector index.
4349
Query: "select * from vectors order by VEC_DISTANCE('[0.0,0.0]', v)",
4450
Expected: []sql.Row{
4551
{2, types.MustJSON(`[0.0, 0.0]`)},
4652
{3, types.MustJSON(`[1.0, -1.0]`)},
4753
{4, types.MustJSON(`[-2.0, 0.0]`)},
4854
{1, types.MustJSON(`[3.0, 4.0]`)},
4955
},
50-
ExpectedIndexes: []string{"v_idx"},
56+
ExpectedIndexes: []string{""},
5157
},
5258
{
53-
Query: "select * from vectors order by VEC_DISTANCE_L2_SQUARED('[-2.0,0.0]', v)",
59+
Query: "select * from vectors order by VEC_DISTANCE_L2_SQUARED('[-2.0,0.0]', v) limit 4",
5460
Expected: []sql.Row{
5561
{4, types.MustJSON(`[-2.0, 0.0]`)},
5662
{2, types.MustJSON(`[0.0, 0.0]`)},

0 commit comments

Comments
 (0)