github.com/matrixorigin/matrixone@v1.2.0/test/distributed/cases/array/array_index.sql (about) 1 -- pre 2 drop database if exists vecdb2; 3 create database vecdb2; 4 use vecdb2; 5 SET GLOBAL experimental_ivf_index = 1; 6 7 8 -- create table 9 drop table if exists t1; 10 create table t1(a int primary key,b vecf32(3), c vecf64(5)); 11 insert into t1 values(1, "[1,2,3]" , "[1,2,3,4,5"); 12 insert into t1 values(2, "[1,2,4]", "[1,2,4,4,5]"); 13 insert into t1 values(3, "[1,2.4,4]", "[1,2.4,4,4,5]"); 14 insert into t1 values(4, "[1,2,5]", "[1,2,5,4,5]"); 15 insert into t1 values(5, "[1,3,5]", "[1,3,5,4,5]"); 16 insert into t1 values(6, "[100,44,50]", "[100,44,50,60,70]"); 17 insert into t1 values(7, "[120,50,70]", "[120,50,70,80,90]"); 18 insert into t1 values(8, "[130,40,90]", "[130,40,90,100,110]"); 19 20 -- 1. kmeans on vecf32 column 21 select a,b,normalize_l2(b) from t1; 22 select cluster_centers(b kmeans '2,vector_l2_ops') from t1; 23 select cluster_centers(b kmeans '2,vector_ip_ops') from t1; 24 select cluster_centers(b kmeans '2,vector_cosine_ops') from t1; 25 SELECT value FROM (SELECT cluster_centers(b kmeans '2,vector_l2_ops,kmeansplusplus,false') AS centers FROM t1) AS subquery CROSS JOIN UNNEST(subquery.centers) AS u; 26 27 -- 1.b spherical kmeans on vecf32 column 28 SELECT value FROM (SELECT cluster_centers(b kmeans '2,vector_l2_ops,kmeansplusplus,true') AS centers FROM t1) AS subquery CROSS JOIN UNNEST(subquery.centers) AS u; 29 30 -- 2. kmeans on vecf64 column 31 select a,c,normalize_l2(c) from t1; 32 select cluster_centers(c kmeans '2,vector_l2_ops') from t1; 33 select cluster_centers(c kmeans '2,vector_ip_ops') from t1; 34 select cluster_centers(c kmeans '2,vector_cosine_ops') from t1; 35 SELECT value FROM (SELECT cluster_centers(c kmeans '2,vector_l2_ops') AS centers FROM t1) AS subquery CROSS JOIN UNNEST(subquery.centers) AS u; 36 37 -- 2.b spherical kmeans on vecf64 column 38 SELECT value FROM (SELECT cluster_centers(c kmeans '2,vector_l2_ops,kmeansplusplus,true') AS centers FROM t1) AS subquery CROSS JOIN UNNEST(subquery.centers) AS u; 39 40 -- 3. Create Secondary Index with IVFFLAT. 41 drop table if exists tbl; 42 create table tbl(id int primary key, embedding vecf32(3)); 43 insert into tbl values(1, "[1,2,3]"); 44 insert into tbl values(2, "[1,2,4]"); 45 insert into tbl values(3, "[1,2.4,4]"); 46 insert into tbl values(4, "[1,2,5]"); 47 insert into tbl values(5, "[1,3,5]"); 48 insert into tbl values(6, "[100,44,50]"); 49 insert into tbl values(7, "[120,50,70]"); 50 insert into tbl values(8, "[130,40,90]"); 51 create index idx1 using IVFFLAT on tbl(embedding) lists = 2 op_type 'vector_l2_ops'; 52 show index from tbl; 53 show create table tbl; 54 select name, type, column_name, algo, algo_table_type,algo_params from mo_catalog.mo_indexes where name="idx1"; 55 56 -- 4. Reindex Secondary Index with IVFFLAT. 57 alter table tbl alter reindex idx1 ivfflat lists=3; 58 show index from tbl; 59 show create table tbl; 60 select name, type, column_name, algo, algo_table_type,algo_params from mo_catalog.mo_indexes where name="idx1"; 61 62 -- 5. Alter table add column with IVFFLAT. 63 alter table tbl add c vecf32(3); 64 show index from tbl; 65 show create table tbl; 66 select name, type, column_name, algo, algo_table_type,algo_params from mo_catalog.mo_indexes where name="idx1"; 67 68 -- 6. Create IVF index before table has data (we create the 3 hidden tables alone without populating them) 69 drop table if exists tbl; 70 create table tbl(a int primary key,b vecf32(3), c vecf64(5)); 71 create index idx2 using IVFFLAT on tbl(b) lists = 2 op_type 'vector_l2_ops'; 72 show index from tbl; 73 show create table tbl; 74 select name, type, column_name, algo, algo_table_type,algo_params from mo_catalog.mo_indexes where name="idx2"; 75 76 -- 7. [FAILURE] Create IVF index on non-vector types, multiple columns, lists=-ve, unknown op_type 77 drop table if exists tbl; 78 create table tbl(a int primary key,b vecf32(3), c vecf32(3)); 79 insert into tbl values(1, "[1,2,3]","[1,2,3]"); 80 insert into tbl values(2, "[1,2,4]","[1,2,4]"); 81 insert into tbl values(3, "[1,2.4,4]","[1,2.4,4]"); 82 insert into tbl values(4, "[1,2,5]","[1,2,5]"); 83 create index idx3 using IVFFLAT on tbl(a) lists = 2 op_type 'vector_l2_ops'; 84 create index idx4 using IVFFLAT on tbl(b,c) lists = 2 op_type 'vector_l2_ops'; 85 create index idx5 using IVFFLAT on tbl(b) lists = -1; 86 create index idx6 using IVFFLAT on tbl(b) lists = 1 op_type 'vector_l1_ops'; 87 88 -- 8. [Default] Create IVF index without any params -- will fail since we don't have lists argument. 89 drop table if exists tbl; 90 create table tbl(a int primary key,b vecf32(3), c vecf32(3)); 91 insert into tbl values(1, "[1,2,3]","[1,2,3]"); 92 insert into tbl values(2, "[1,2,4]","[1,2,4]"); 93 insert into tbl values(3, "[1,2.4,4]","[1,2.4,4]"); 94 insert into tbl values(4, "[1,2,5]","[1,2,5]"); 95 create index idx7 using IVFFLAT on tbl(b); 96 97 -- 9. duplicate rows 98 drop table if exists tbl; 99 create table tbl(a int primary key, b vecf32(3)); 100 insert into tbl values(1, "[1,2,3]"); 101 insert into tbl values(2, "[1,2,4]"); 102 insert into tbl values(3, "[1,2.4,4]"); 103 insert into tbl values(4, "[1,2,5]"); 104 insert into tbl values(5, "[1,3,5]"); 105 insert into tbl values(6, "[100,44,50]"); -- dup 106 insert into tbl values(7, "[100,44,50]"); 107 insert into tbl values(8, "[130,40,90]"); 108 create index idx8 using IVFFLAT on tbl(b) lists = 2 op_type 'vector_l2_ops'; 109 show index from tbl; 110 show create table tbl; 111 select name, type, column_name, algo, algo_table_type,algo_params from mo_catalog.mo_indexes where name="idx8"; 112 113 -- 10. Create IVF index within Create Table (this will create empty index hidden tables) 114 drop table if exists tbl; 115 create table tbl(a int primary key, b vecf32(3), index idx9 using ivfflat (b)); 116 117 -- 11. Delete column having IVFFLAT index 118 drop table if exists tbl; 119 create table tbl(a int primary key, b vecf32(3), index idx10 using ivfflat (b)); 120 insert into tbl values(1, "[1,2,3]"); 121 insert into tbl values(2, "[1,2,4]"); 122 show index from tbl; 123 show create table tbl; 124 select name, type, column_name, algo, algo_table_type,algo_params from mo_catalog.mo_indexes where name="idx10"; 125 alter table tbl drop column b; 126 show index from tbl; 127 show create table tbl; 128 select name, type, column_name, algo, algo_table_type,algo_params from mo_catalog.mo_indexes where name="idx10"; 129 130 -- 12. Drop IVFFLAT index 131 drop table if exists tbl; 132 create table tbl(a int primary key, b vecf32(3), index idx11 using ivfflat (b)); 133 insert into tbl values(1, "[1,2,3]"); 134 insert into tbl values(2, "[1,2,4]"); 135 show index from tbl; 136 show create table tbl; 137 select name, type, column_name, algo, algo_table_type,algo_params from mo_catalog.mo_indexes where name="idx11"; 138 alter table tbl drop index idx11; 139 show index from tbl; 140 show create table tbl; 141 select name, type, column_name, algo, algo_table_type,algo_params from mo_catalog.mo_indexes where name="idx11"; 142 143 -- 13. Insert into index table (with one PK) 144 drop table if exists tbl; 145 create table tbl(id int primary key, embedding vecf32(3)); 146 insert into tbl values(1, "[1,2,3]"); 147 insert into tbl values(2, "[1,2,4]"); 148 insert into tbl values(3, "[1,2.4,4]"); 149 insert into tbl values(4, "[1,2,5]"); 150 insert into tbl values(5, "[1,3,5]"); 151 insert into tbl values(6, "[100,44,50]"); 152 insert into tbl values(7, "[120,50,70]"); 153 insert into tbl values(8, "[130,40,90]"); 154 create index idx12 using ivfflat on tbl(embedding) lists=2 op_type "vector_l2_ops"; 155 show index from tbl; 156 show create table tbl; 157 insert into tbl values(15, "[1,3,5]"); -- inserted to centroid 1 of version 0 158 insert into tbl values(18, "[130,40,90]"); -- inserted to centroid 2 of version 0 159 alter table tbl alter reindex idx12 ivfflat lists=2; 160 insert into tbl values(25, "[2,4,5]"); -- inserted to cluster 1 of version 1 161 insert into tbl values(28, "[131,41,91]"); -- inserted to cluster 2 of version 1 162 163 -- 14. Insert into index table (with CP key) 164 drop table if exists tbl; 165 create table tbl(id int, age int, embedding vecf32(3), primary key(id, age)); 166 insert into tbl values(1, 10, "[1,2,3]"); 167 insert into tbl values(2, 20, "[1,2,4]"); 168 insert into tbl values(3, 30, "[1,2.4,4]"); 169 insert into tbl values(4, 40, "[1,2,5]"); 170 insert into tbl values(5, 50, "[1,3,5]"); 171 insert into tbl values(6, 60, "[100,44,50]"); 172 insert into tbl values(7, 70, "[120,50,70]"); 173 insert into tbl values(8, 80, "[130,40,90]"); 174 create index idx13 using ivfflat on tbl(embedding) lists=2 op_type "vector_l2_ops"; 175 show index from tbl; 176 show create table tbl; 177 insert into tbl values(15, 90, "[1,3,5]"); -- inserted to centroid 1 of version 0 178 insert into tbl values(18, 100, "[130,40,90]"); -- inserted to centroid 2 of version 0 179 alter table tbl alter reindex idx13 ivfflat lists=2; 180 insert into tbl values(25, 110, "[2,4,5]"); -- inserted to cluster 1 of version 1 181 insert into tbl values(28, 120, "[131,41,91]"); -- inserted to cluster 2 of version 1 182 183 184 -- 15. Insert into index table (with No PK so fake_pk is used) 185 drop table if exists tbl; 186 create table tbl(id int, embedding vecf32(3)); 187 insert into tbl values(1, "[1,2,3]"); 188 insert into tbl values(2, "[1,2,4]"); 189 insert into tbl values(3, "[1,2.4,4]"); 190 insert into tbl values(4, "[1,2,5]"); 191 insert into tbl values(5, "[1,3,5]"); 192 insert into tbl values(6, "[100,44,50]"); 193 insert into tbl values(7, "[120,50,70]"); 194 insert into tbl values(8, "[130,40,90]"); 195 create index idx14 using ivfflat on tbl(embedding) lists=2 op_type "vector_l2_ops"; 196 show index from tbl; 197 show create table tbl; 198 insert into tbl values(15, "[1,3,5]"); -- inserted to centroid 1 of version 0 199 insert into tbl values(18, "[130,40,90]"); -- inserted to centroid 2 of version 0 200 alter table tbl alter reindex idx14 ivfflat lists=2; 201 insert into tbl values(25, "[2,4,5]"); -- inserted to cluster 1 of version 1 202 insert into tbl values(28, "[131,41,91]"); -- inserted to cluster 2 of version 1 203 204 -- 16. Delete embedding from original table 205 -- 17. Delete PK from original table 206 ---18. Perform both 16 & 17 after alter reindex. 207 drop table if exists tbl; 208 create table tbl(id int primary key, embedding vecf32(3)); 209 insert into tbl values(1, "[1,2,3]"); 210 insert into tbl values(2, "[1,2,4]"); 211 insert into tbl values(3, "[1,2.4,4]"); 212 insert into tbl values(4, "[1,2,5]"); 213 insert into tbl values(5, "[1,3,5]"); 214 insert into tbl values(6, "[100,44,50]"); 215 insert into tbl values(7, "[120,50,70]"); 216 insert into tbl values(8, "[130,40,90]"); 217 create index idx15 using ivfflat on tbl(embedding) lists=2 op_type "vector_l2_ops"; 218 insert into tbl values(9, "[130,40,90]"); 219 delete from tbl where id=9; -- delete 9 220 delete from tbl where embedding="[130,40,90]"; -- delete 8 221 alter table tbl alter reindex idx15 ivfflat lists=2; 222 insert into tbl values(10, "[130,40,90]"); 223 delete from tbl where id=6; -- removes both (0,6) and (1,6) entries 224 delete from tbl where embedding="[1,3,5]"; -- removes both (0,5) and (1,5) entries 225 delete from tbl where id=10; -- removes (1,10) 226 227 -- 19. Delete from without condition 228 drop table if exists tbl; 229 create table tbl(id int primary key, embedding vecf32(3)); 230 insert into tbl values(1, "[1,2,3]"); 231 insert into tbl values(2, "[1,2,4]"); 232 insert into tbl values(3, "[1,2.4,4]"); 233 insert into tbl values(4, "[1,2,5]"); 234 insert into tbl values(5, "[1,3,5]"); 235 insert into tbl values(6, "[100,44,50]"); 236 insert into tbl values(7, "[120,50,70]"); 237 insert into tbl values(8, "[130,40,90]"); 238 create index idx16 using ivfflat on tbl(embedding) lists=2 op_type "vector_l2_ops"; 239 delete from tbl; 240 241 -- 20. Truncate tbl 242 drop table if exists tbl; 243 create table tbl(id int primary key, embedding vecf32(3)); 244 insert into tbl values(1, "[1,2,3]"); 245 insert into tbl values(2, "[1,2,4]"); 246 insert into tbl values(3, "[1,2.4,4]"); 247 insert into tbl values(4, "[1,2,5]"); 248 insert into tbl values(5, "[1,3,5]"); 249 insert into tbl values(6, "[100,44,50]"); 250 insert into tbl values(7, "[120,50,70]"); 251 insert into tbl values(8, "[130,40,90]"); 252 create index idx16 using ivfflat on tbl(embedding) lists=2 op_type "vector_l2_ops"; 253 truncate table tbl; 254 255 -- 21. Update embedding from original table 256 -- 22. Update PK from original table 257 drop table if exists tbl; 258 create table tbl(id int primary key, embedding vecf32(3)); 259 insert into tbl values(1, "[1,2,3]"); 260 insert into tbl values(2, "[1,2,4]"); 261 insert into tbl values(3, "[1,2.4,4]"); 262 insert into tbl values(4, "[1,2,5]"); 263 insert into tbl values(5, "[1,3,5]"); 264 insert into tbl values(6, "[100,44,50]"); 265 insert into tbl values(7, "[120,50,70]"); 266 insert into tbl values(8, "[130,40,90]"); 267 create index idx16 using ivfflat on tbl(embedding) lists=2 op_type "vector_l2_ops"; 268 update tbl set embedding="[1,2,3]" where id=8; -- update 8 to cluster 1 from cluster 2 269 update tbl set id=9 where id=8; -- update 8 to 9 270 alter table tbl alter reindex idx16 ivfflat lists=2; 271 update tbl set embedding="[1,2,3]" where id=7; -- update 7 to cluster 1 from cluster 2 for the latest versions 272 update tbl set id=10 where id=7; -- update 7 to 10 273 274 -- 23. Update & Delete with CP key 275 drop table if exists tbl; 276 create table tbl(id varchar(20), age varchar(20), embedding vecf32(3), primary key(id, age)); 277 insert into tbl values("1", "10", "[1,2,3]"); 278 insert into tbl values("2", "20", "[1,2,4]"); 279 insert into tbl values("3", "30", "[1,2.4,4]"); 280 insert into tbl values("4", "40", "[1,2,5]"); 281 insert into tbl values("5", "50", "[1,3,5]"); 282 insert into tbl values("6", "60", "[100,44,50]"); 283 insert into tbl values("7", "70", "[120,50,70]"); 284 insert into tbl values("8", "80", "[130,40,90]"); 285 create index idx17 using ivfflat on tbl(embedding) lists=2 op_type "vector_l2_ops"; 286 update tbl set embedding="[1,2,3]" where id="8"; 287 update tbl set embedding="[1,2,3]" where id="7" and age = "70"; 288 update tbl set id="70" where id="7"; 289 alter table tbl alter reindex idx17 ivfflat lists=2; 290 update tbl set embedding="[1,2,3]" where id="6"; 291 update tbl set id="60" where id="6"; 292 293 -- 24. Update & Delete with No PK so fake_pk is used 294 drop table if exists tbl; 295 create table tbl(id int, embedding vecf32(3)); 296 insert into tbl values(1, "[1,2,3]"); 297 insert into tbl values(2, "[1,2,4]"); 298 insert into tbl values(3, "[1,2.4,4]"); 299 insert into tbl values(4, "[1,2,5]"); 300 insert into tbl values(5, "[1,3,5]"); 301 insert into tbl values(6, "[100,44,50]"); 302 insert into tbl values(7, "[120,50,70]"); 303 insert into tbl values(8, "[130,40,90]"); 304 create index idx17 using ivfflat on tbl(embedding) lists=2 op_type "vector_l2_ops"; 305 update tbl set embedding="[1,2,3]" where id="8"; 306 delete from tbl where id="8"; 307 308 -- 25. create table with index def 309 drop table if exists tbl; 310 create table tbl(id int primary key, embedding vecf32(3), key idx18 using ivfflat (embedding) lists=2 op_type "vector_l2_ops"); 311 insert into tbl values(1, "[1,2,3]"); 312 insert into tbl values(2, "[1,2,4]"); 313 insert into tbl values(3, "[1,2.4,4]"); 314 insert into tbl values(4, "[1,2,5]"); 315 insert into tbl values(5, "[1,3,5]"); 316 insert into tbl values(6, "[100,44,50]"); 317 insert into tbl values(7, "[120,50,70]"); 318 insert into tbl values(8, "[130,40,90]"); 319 320 -- 26. Update table add new column 321 alter table tbl add column id2 VARCHAR(20); 322 --mysql> select * from `__mo_index_secondary_8ff07b6e-a483-11ee-b461-723e89f7b974`; 323 -- alter table --> create table --> insert into select * --> reindex 324 --+--------------------------------+---------------------------+--------------------+ 325 --| __mo_index_centroid_fk_version | __mo_index_centroid_fk_id | __mo_index_pri_col | 326 --+--------------------------------+---------------------------+--------------------+ 327 --| 0 | 1 | 1 | 328 --| 0 | 1 | 2 | 329 --| 0 | 1 | 3 | 330 --| 0 | 1 | 4 | 331 --| 0 | 1 | 5 | 332 --| 0 | 1 | 6 | 333 --| 0 | 1 | 7 | 334 --| 0 | 1 | 8 | 335 --| 1 | 1 | 1 | 336 --| 1 | 1 | 2 | 337 --| 1 | 1 | 3 | 338 --| 1 | 1 | 4 | 339 --| 1 | 1 | 5 | 340 --| 1 | 2 | 6 | 341 --| 1 | 2 | 7 | 342 --| 1 | 2 | 8 | 343 --+--------------------------------+---------------------------+--------------------+ 344 345 update tbl set id2 = id; 346 347 -- 27. Insert into table select (internally uses window row_number) 348 drop table if exists tbl1; 349 create table tbl1(id int primary key, data vecf32(3)); 350 insert into tbl1 values(1, "[1,2,3]"); 351 insert into tbl1 values(2, "[1,2,4]"); 352 insert into tbl1 values(3, "[1,2.4,4]"); 353 insert into tbl1 values(4, "[1,2,5]"); 354 insert into tbl1 values(5, "[1,3,5]"); 355 insert into tbl1 values(6, "[100,44,50]"); 356 insert into tbl1 values(7, "[120,50,70]"); 357 insert into tbl1 values(8, "[130,40,90]"); 358 create index idx19 using ivfflat on tbl1(data) lists=2 op_type "vector_l2_ops"; 359 insert into tbl1 values(9, "[130,40,90]"); 360 361 drop table if exists tbl2; 362 create table tbl2(id int primary key, data vecf32(3), key idx20 using ivfflat (data) lists=2 op_type "vector_l2_ops"); 363 insert into tbl2 select * from tbl1; 364 --mysql> select * from `__mo_index_secondary_0b0c1e94-a483-11ee-b45f-723e89f7b974`; 365 -- assigned all the rows to 1 giant null centroid 366 --+--------------------------------+---------------------------+--------------------+ 367 --| __mo_index_centroid_fk_version | __mo_index_centroid_fk_id | __mo_index_pri_col | 368 --+--------------------------------+---------------------------+--------------------+ 369 --| 0 | 1 | 1 | 370 --| 0 | 1 | 2 | 371 --| 0 | 1 | 3 | 372 --| 0 | 1 | 4 | 373 --| 0 | 1 | 5 | 374 --| 0 | 1 | 6 | 375 --| 0 | 1 | 7 | 376 --| 0 | 1 | 8 | 377 --| 0 | 1 | 9 | 378 --+--------------------------------+---------------------------+--------------------+ 379 380 381 -- 28. Create Index with no rows 382 drop table if exists tbl1; 383 create table tbl1(id int primary key, data vecf32(3)); 384 create index idx19 using ivfflat on tbl1(data) lists=2 op_type "vector_l2_ops"; 385 insert into tbl1 values(1, "[1,2,3]"); 386 insert into tbl1 values(2, "[1,2,4]"); 387 insert into tbl1 values(3, "[1,2.4,4]"); 388 insert into tbl1 values(4, "[1,2,5]"); 389 insert into tbl1 values(5, "[1,3,5]"); 390 insert into tbl1 values(6, "[100,44,50]"); 391 insert into tbl1 values(7, "[120,50,70]"); 392 insert into tbl1 values(8, "[130,40,90]"); 393 --mysql> select * from `__mo_index_secondary_0b0c1e94-a483-11ee-b45f-723e89f7b974`; 394 -- assigned all the rows to 1 giant null centroid 395 --+--------------------------------+---------------------------+--------------------+ 396 --| __mo_index_centroid_fk_version | __mo_index_centroid_fk_id | __mo_index_pri_col | 397 --+--------------------------------+---------------------------+--------------------+ 398 --| 0 | 1 | 1 | 399 --| 0 | 1 | 2 | 400 --| 0 | 1 | 3 | 401 --| 0 | 1 | 4 | 402 --| 0 | 1 | 5 | 403 --| 0 | 1 | 6 | 404 --| 0 | 1 | 7 | 405 --| 0 | 1 | 8 | 406 --| 0 | 1 | 9 | 407 --+--------------------------------+---------------------------+--------------------+ 408 --9 rows in set (0.00 sec) 409 410 -- 29. Handle Null embeddings 411 drop table if exists tbl; 412 create table tbl(id int primary key, data vecf32(3)); 413 insert into tbl values(1, NULL); 414 insert into tbl values(2, NULL); 415 insert into tbl values(3, NULL); 416 insert into tbl values(4, "[1,2,5]"); 417 insert into tbl values(5, "[1,3,5]"); 418 create index idx20 using ivfflat on tbl(data) lists=2 op_type "vector_l2_ops"; 419 insert into tbl values(6, NULL); 420 insert into tbl values(7, "[130,40,90]"); 421 --mysql> select * from `__mo_index_secondary_56ab082e-a483-11ee-b461-723e89f7b974`; 422 -- null are randomly assigned to clusters 423 --+--------------------------------+---------------------------+--------------------+ 424 --| __mo_index_centroid_fk_version | __mo_index_centroid_fk_id | __mo_index_pri_col | 425 --+--------------------------------+---------------------------+--------------------+ 426 --| 0 | 1 | 1 | 427 --| 0 | 1 | 2 | 428 --| 0 | 1 | 3 | 429 --| 0 | 1 | 4 | 430 --| 0 | 2 | 5 | 431 --| 0 | 1 | 6 | 432 --| 0 | 2 | 7 | 433 --+--------------------------------+---------------------------+--------------------+ 434 435 436 -- 30. create index with totalCnt < k 437 drop table if exists tbl; 438 create table tbl(id int primary key, data vecf32(3)); 439 insert into tbl values(1, "[1,2,3]"); 440 insert into tbl values(2, "[1,2,4]"); 441 create index idx21 using ivfflat on tbl(data) lists=3 op_type "vector_l2_ops"; 442 --mysql> select * from `__mo_index_secondary_ca68dc64-a483-11ee-b461-723e89f7b974`; 443 --+-----------------------------+------------------------+---------------------+ 444 --| __mo_index_centroid_version | __mo_index_centroid_id | __mo_index_centroid | 445 --+-----------------------------+------------------------+---------------------+ 446 --| 0 | 1 | NULL | 447 --+-----------------------------+------------------------+---------------------+ 448 449 450 -- 31. create index with totalCnt = 0 451 drop table if exists tbl; 452 create table tbl(id int primary key, data vecf32(3)); 453 create index idx22 using ivfflat on tbl(data) lists=3 op_type "vector_l2_ops"; 454 insert into tbl values(1, "[1,2,3]"); 455 insert into tbl values(2, "[1,2,4]"); 456 --mysql> select * from `__mo_index_secondary_ef84b932-a483-11ee-b462-723e89f7b974`; 457 --+-----------------------------+------------------------+---------------------+ 458 --| __mo_index_centroid_version | __mo_index_centroid_id | __mo_index_centroid | 459 --+-----------------------------+------------------------+---------------------+ 460 --| 0 | 1 | NULL | 461 --+-----------------------------+------------------------+---------------------+ 462 463 -- 32. Truncate table (does not remove centroids) 464 drop table if exists tbl; 465 create table tbl(id int, embedding vecf32(3)); 466 insert into tbl values(1, "[1,2,3]"); 467 insert into tbl values(2, "[1,2,4]"); 468 insert into tbl values(3, "[1,2.4,4]"); 469 insert into tbl values(4, "[1,2,5]"); 470 insert into tbl values(5, "[1,3,5]"); 471 insert into tbl values(6, "[100,44,50]"); 472 insert into tbl values(7, "[120,50,70]"); 473 insert into tbl values(8, "[130,40,90]"); 474 create index idx23 using ivfflat on tbl(embedding) lists=2 op_type "vector_l2_ops"; 475 alter table tbl alter reindex idx23 ivfflat lists=2; 476 truncate table tbl; 477 --mysql> select * from `__mo_index_secondary_c18d6262-a56a-11ee-8301-723e89f7b974`; 478 --+-----------------------------+------------------------+-----------------------------+ 479 --| __mo_index_centroid_version | __mo_index_centroid_id | __mo_index_centroid | 480 --+-----------------------------+------------------------+-----------------------------+ 481 --| 0 | 1 | [1, 2.28, 4.2] | 482 --| 0 | 2 | [116.666664, 44.666668, 70] | 483 --| 1 | 1 | [1, 2.28, 4.2] | 484 --| 1 | 2 | [116.666664, 44.666668, 70] | 485 --+-----------------------------+------------------------+-----------------------------+ 486 insert into tbl values(1, "[1,2,3]"); 487 insert into tbl values(2, "[1,2,4]"); 488 insert into tbl values(3, "[1,2.4,4]"); 489 insert into tbl values(4, "[1,2,5]"); 490 insert into tbl values(5, "[1,3,5]"); 491 insert into tbl values(6, "[100,44,50]"); 492 insert into tbl values(7, "[120,50,70]"); 493 insert into tbl values(8, "[130,40,90]"); 494 495 -- 33. Delete from tbl (without condition) 496 drop table if exists tbl; 497 create table tbl(id int, embedding vecf32(3)); 498 insert into tbl values(1, "[1,2,3]"); 499 insert into tbl values(2, "[1,2,4]"); 500 insert into tbl values(3, "[1,2.4,4]"); 501 insert into tbl values(4, "[1,2,5]"); 502 insert into tbl values(5, "[1,3,5]"); 503 insert into tbl values(6, "[100,44,50]"); 504 insert into tbl values(7, "[120,50,70]"); 505 insert into tbl values(8, "[130,40,90]"); 506 create index idx23 using ivfflat on tbl(embedding) lists=2 op_type "vector_l2_ops"; 507 alter table tbl alter reindex idx23 ivfflat lists=2; 508 delete from tbl; 509 --mysql> select * from `__mo_index_secondary_9aaa720c-a56a-11ee-8301-723e89f7b974`; 510 --+-----------------------------+------------------------+-----------------------------+ 511 --| __mo_index_centroid_version | __mo_index_centroid_id | __mo_index_centroid | 512 --+-----------------------------+------------------------+-----------------------------+ 513 --| 0 | 1 | [1, 2.28, 4.2] | 514 --| 0 | 2 | [116.666664, 44.666668, 70] | 515 --| 1 | 1 | [1, 2.28, 4.2] | 516 --| 1 | 2 | [116.666664, 44.666668, 70] | 517 --+-----------------------------+------------------------+-----------------------------+ 518 insert into tbl values(1, "[1,2,3]"); 519 insert into tbl values(2, "[1,2,4]"); 520 insert into tbl values(3, "[1,2.4,4]"); 521 insert into tbl values(4, "[1,2,5]"); 522 insert into tbl values(5, "[1,3,5]"); 523 insert into tbl values(6, "[100,44,50]"); 524 insert into tbl values(7, "[120,50,70]"); 525 insert into tbl values(8, "[130,40,90]"); 526 527 528 --- 34. 2 Vector Index on same column 529 drop table if exists tbl; 530 create table tbl(id int primary key, embedding vecf32(3)); 531 insert into tbl values(1, "[1,2,3]"); 532 insert into tbl values(2, "[1,2,4]"); 533 insert into tbl values(3, "[1,2.4,4]"); 534 insert into tbl values(4, "[1,2,5]"); 535 insert into tbl values(5, "[1,3,5]"); 536 insert into tbl values(6, "[100,44,50]"); 537 insert into tbl values(7, "[120,50,70]"); 538 insert into tbl values(8, "[130,40,90]"); 539 create index idx16 using ivfflat on tbl(embedding) lists=2 op_type "vector_l2_ops"; 540 create index idx17 using ivfflat on tbl(embedding) lists=2 op_type "vector_l2_ops"; 541 insert into tbl values(9, "[130,40,90]"); 542 543 -- 35. KNN using Vector Index (Single PK) 544 --QUERY PLAN 545 --Project 546 -- -> Sort 547 -- Sort Key: l2_distance(tbl.embedding, cast('[120,51,70]' AS VECF32)) ASC 548 -- Limit: 3 549 -- -> Join 550 -- Join Type: INNER hashOnPK 551 -- Join Cond: (cast(#[0,0] AS BIGINT) = tbl.id) 552 -- -> Join 553 -- Join Type: INNER 554 -- Join Cond: (#[0,0] = #[1,0]) 555 -- -> Project 556 -- -> Join 557 -- Join Type: SINGLE 558 -- Join Cond: (__mo_index_secondary_018db491-b45f-7ea7-a779-a350abdc16fe.__mo_index_centroid_fk_version = #[1,0]) 559 -- -> Table Scan on vecdb3.__mo_index_secondary_018db491-b45f-7ea7-a779-a350abdc16fe 560 -- -> Project 561 -- -> Filter 562 -- Filter Cond: (__mo_index_secondary_018db491-b45f-724d-9dea-3bbf4d8104bf.__mo_index_key = 'version') 563 -- -> Table Scan on vecdb3.__mo_index_secondary_018db491-b45f-724d-9dea-3bbf4d8104bf 564 -- -> Sort 565 -- Sort Key: #[0,1] ASC 566 -- Limit: CASE WHEN (@probe_limit IS NULL) THEN 1 ELSE cast(@probe_limit AS BIGINT) END 567 -- -> Project 568 -- -> Join 569 -- Join Type: SINGLE 570 -- Join Cond: (__mo_index_secondary_018db491-b45f-729f-8873-3a419dc30842.__mo_index_centroid_version = #[1,0]) 571 -- -> Table Scan on vecdb3.__mo_index_secondary_018db491-b45f-729f-8873-3a419dc30842 572 -- -> Project 573 -- -> Filter 574 -- Filter Cond: (__mo_index_secondary_018db491-b45f-724d-9dea-3bbf4d8104bf.__mo_index_key = 'version') 575 -- -> Table Scan on vecdb3.__mo_index_secondary_018db491-b45f-724d-9dea-3bbf4d8104bf 576 -- -> Table Scan on vecdb3.tbl 577 drop table if exists tbl; 578 SET @PROBE_LIMIT=1; 579 create table tbl(id int PRIMARY KEY, embedding vecf32(3)); 580 insert into tbl values(1, "[1,2,3]"); 581 insert into tbl values(2, "[1,2,4]"); 582 insert into tbl values(3, "[1,2.4,4]"); 583 insert into tbl values(4, "[1,2,5]"); 584 insert into tbl values(5, "[1,3,5]"); 585 insert into tbl values(6, "[100,44,50]"); 586 insert into tbl values(7, "[120,50,70]"); 587 insert into tbl values(8, "[130,40,90]"); 588 SELECT id, embedding FROM tbl ORDER BY l2_distance(embedding,'[120,51,70]') ASC LIMIT 3; 589 create index idx using ivfflat on tbl(embedding) lists=2 op_type "vector_l2_ops"; 590 SELECT id, embedding FROM tbl ORDER BY l2_distance(embedding,'[120,51,70]') ASC LIMIT 3; 591 592 -- 36. KNN using Vector Index (No PK) 593 drop table if exists tbl; 594 create table tbl(id int, embedding vecf32(3)); 595 insert into tbl values(1, "[1,2,3]"); 596 insert into tbl values(2, "[1,2,4]"); 597 insert into tbl values(3, "[1,2.4,4]"); 598 insert into tbl values(4, "[1,2,5]"); 599 insert into tbl values(5, "[1,3,5]"); 600 insert into tbl values(6, "[100,44,50]"); 601 insert into tbl values(7, "[120,50,70]"); 602 insert into tbl values(8, "[130,40,90]"); 603 SELECT id, embedding FROM tbl ORDER BY l2_distance(embedding,'[120,51,70]') ASC LIMIT 3; 604 create index idx using ivfflat on tbl(embedding) lists=2 op_type "vector_l2_ops"; 605 SELECT id, embedding FROM tbl ORDER BY l2_distance(embedding,'[120,51,70]') ASC LIMIT 3; 606 607 -- 37. KNN using Vector Index (2 PK) 608 drop table if exists tbl; 609 create table tbl(id int, id2 int, embedding vecf32(3), primary key(id, id2)); 610 insert into tbl values(1, 0,"[1,2,3]"); 611 insert into tbl values(2, 0, "[1,2,4]"); 612 insert into tbl values(3, 0,"[1,2.4,4]"); 613 insert into tbl values(4, 0, "[1,2,5]"); 614 insert into tbl values(5, 0, "[1,3,5]"); 615 insert into tbl values(6, 0, "[100,44,50]"); 616 insert into tbl values(7, 0, "[120,50,70]"); 617 insert into tbl values(8, 0, "[130,40,90]"); 618 SELECT id,id2, embedding FROM tbl ORDER BY l2_distance(embedding,'[120,51,70]') ASC LIMIT 3; 619 create index idx using ivfflat on tbl(embedding) lists=2 op_type "vector_l2_ops"; 620 SELECT id,id2, embedding FROM tbl ORDER BY l2_distance(embedding,'[120,51,70]') ASC LIMIT 3; 621 SET @test_limit = 3; 622 SELECT id from tbl LIMIT @test_limit; 623 624 -- 38. Alter Reindex on Empty Table 625 create table vector_index_05(a int primary key, b vecf32(3),c vecf32(4)); 626 create index idx01 using ivfflat on vector_index_05(c) lists=4 op_type "vector_l2_ops"; 627 show create table vector_index_05; 628 alter table vector_index_05 alter reindex idx01 ivfflat lists=5; 629 show create table vector_index_05; 630 631 -- 39. Alter Reindex Verify List update on `Show Create Table` 632 create table vector_index_04(a int primary key, b vecf32(3),c vecf32(4)); 633 insert into vector_index_04 values(1,"[56,23,6]","[0.25,0.14,0.88,0.0001]"),(2,"[77,45,3]","[1.25,5.25,8.699,4.25]"),(3,"[8,56,3]","[9.66,5.22,1.22,7.02]"); 634 create index idx01 using ivfflat on vector_index_04(c) lists=5 op_type "vector_l2_ops"; 635 insert into vector_index_04 values(4,"[156,213,61]","[10.25,0.14,0.88,10.0001]"),(5,"[177,425,30]","[11.25,51.25,80.699,44.25]"),(6,"[80,56,3]","[90.686,5.212,19.22,7.02]"); 636 show create table vector_index_04; 637 alter table vector_index_04 alter reindex idx01 ivfflat lists=8; 638 show create table vector_index_04; 639 640 -- 40. Add Index and Alter table add column 641 create table vector_index_08(a int primary key, b vecf32(128),c int,key c_k(c)); 642 create index idx01 using ivfflat on vector_index_08(b) lists=3 op_type "vector_l2_ops"; 643 alter table vector_index_08 add column d vecf32(3) not null after c; 644 645 -- 41. Create Index with no lists argument. However lists=0 will fail. 646 create table vector_index_07(a int primary key, b vecf32(128),c int,key c_k(c)); 647 create index idx01 using ivfflat on vector_index_07(b); 648 create index idx02 using ivfflat on vector_index_07(b) lists=0; 649 alter table vector_index_07 reindex idx01 ivfflat lists=0; 650 alter table vector_index_07 reindex idx01 ivfflat; 651 652 -- 42. Create Index on Table with Less than List's row count. Then call alter reindex. 653 create table vector_index_09(a int primary key, b vecf32(128),c int,key c_k(c)); 654 insert into vector_index_09 values(9774 ,NULL,3),(9775,NULL,10); 655 insert into vector_index_09(a,c) values(9777,4),(9778,9); 656 create index idx01 using ivfflat on vector_index_09(b) lists=3 op_type "vector_l2_ops"; 657 select * from vector_index_09 order by L2_DISTANCE(b,"[1, 0, 1, 6, 6, 17, 47]"); 658 insert into vector_index_09 values(97741 ,"[1, 0, 1, 6, 6, 17, 47, 39, 2, 0, 1, 25, 27, 10, 56, 130, 18, 5, 2, 6, 15, 2, 19, 130, 42, 28, 1, 1, 2, 1, 0, 5, 0, 2, 4, 4, 31, 34, 44, 35, 9, 3, 8, 11, 33, 12, 61, 130, 130, 17, 0, 1, 6, 2, 9, 130, 111, 36, 0, 0, 11, 9, 1, 12, 2, 100, 130, 28, 7, 2, 6, 7, 9, 27, 130, 83, 5, 0, 1, 18, 130, 130, 84, 9, 0, 0, 2, 24, 111, 24, 0, 1, 37, 24, 2, 10, 12, 62, 33, 3, 0, 0, 0, 1, 3, 16, 106, 28, 0, 0, 0, 0, 17, 46, 85, 10, 0, 0, 1, 4, 11, 4, 2, 2, 9, 14, 8, 8]",3),(97751,"[0, 1, 1, 3, 0, 3, 46, 20, 1, 4, 17, 9, 1, 17, 108, 15, 0, 3, 37, 17, 6, 15, 116, 16, 6, 1, 4, 7, 7, 7, 9, 6, 0, 8, 10, 4, 26, 129, 27, 9, 0, 0, 5, 2, 11, 129, 129, 12, 103, 4, 0, 0, 2, 31, 129, 129, 94, 4, 0, 0, 0, 3, 13, 42, 0, 15, 38, 2, 70, 129, 1, 0, 5, 10, 40, 12, 74, 129, 6, 1, 129, 39, 6, 1, 2, 22, 9, 33, 122, 13, 0, 0, 0, 0, 5, 23, 4, 11, 9, 12, 45, 38, 1, 0, 0, 4, 36, 38, 57, 32, 0, 0, 82, 22, 9, 5, 13, 11, 3, 94, 35, 3, 0, 0, 0, 1, 16, 97]",5),(9776,"[10, 3, 8, 5, 48, 26, 5, 16, 17, 0, 0, 2, 132, 53, 1, 16, 112, 6, 0, 0, 7, 2, 1, 48, 48, 15, 18, 31, 3, 0, 0, 9, 6, 10, 19, 27, 50, 46, 17, 9, 18, 1, 4, 48, 132, 23, 3, 5, 132, 9, 4, 3, 11, 0, 2, 46, 84, 12, 10, 10, 1, 0, 12, 76, 26, 22, 16, 26, 35, 15, 3, 16, 15, 1, 51, 132, 125, 8, 1, 2, 132, 51, 67, 91, 8, 0, 0, 30, 126, 39, 32, 38, 4, 0, 1, 12, 24, 2, 2, 2, 4, 7, 2, 19, 93, 19, 70, 92, 2, 3, 1, 21, 36, 58, 132, 94, 0, 0, 0, 0, 21, 25, 57, 48, 1, 0, 0, 1]",3); 659 insert into vector_index_09 values(97771, "[16, 15, 0, 0, 5, 46, 5, 5, 4, 0, 0, 0, 28, 118, 12, 5, 75, 44, 5, 0, 6, 32, 6, 49, 41, 74, 9, 1, 0, 0, 0, 9, 1, 9, 16, 41, 71, 80, 3, 0, 0, 4, 3, 5, 51, 106, 11, 3, 112, 28, 13, 1, 4, 8, 3, 104, 118, 14, 1, 1, 0, 0, 0, 88, 3, 27, 46, 118, 108, 49, 2, 0, 1, 46, 118, 118, 27, 12, 0, 0, 33, 118, 118, 8, 0, 0, 0, 4, 118, 95, 40, 0, 0, 0, 1, 11, 27, 38, 12, 12, 18, 29, 3, 2, 13, 30, 94, 78, 30, 19, 9, 3, 31, 45, 70, 42, 15, 1, 3, 12, 14, 22, 16, 2, 3, 17, 24, 13]",4),(97781,"[41, 0, 0, 7, 1, 1, 20, 67, 9, 0, 0, 0, 0, 31, 120, 61, 25, 0, 0, 0, 0, 10, 120, 90, 32, 0, 0, 1, 13, 11, 22, 50, 4, 0, 2, 93, 40, 15, 37, 18, 12, 2, 2, 19, 8, 44, 120, 25, 120, 5, 0, 0, 0, 2, 48, 97, 102, 14, 3, 3, 11, 9, 34, 41, 0, 0, 4, 120, 56, 3, 4, 5, 6, 15, 37, 116, 28, 0, 0, 3, 120, 120, 24, 6, 2, 0, 1, 28, 53, 90, 51, 11, 11, 2, 12, 14, 8, 6, 4, 30, 9, 1, 4, 22, 25, 79, 120, 66, 5, 0, 0, 6, 42, 120, 91, 43, 15, 2, 4, 39, 12, 9, 9, 12, 15, 5, 24, 36]",4); 660 alter table vector_index_09 alter reindex idx01 ivfflat lists=2; 661 662 -- 43. Invalid vector inside L2_distance Query. 663 drop table if exists vector_index_07; 664 create table vector_index_07(a int primary key, b vecf32(128),c int,key c_k(c)); 665 create index idx01 using ivfflat on vector_index_07(b) lists=5 op_type "vector_l2_ops"; 666 insert into vector_index_07 values(9774 ,"[1, 0, 1, 6, 6, 17, 47, 39, 2, 0, 1, 25, 27, 10, 56, 130, 18, 5, 2, 6, 15, 2, 19, 130, 42, 28, 1, 1, 2, 1, 0, 5, 0, 2, 4, 4, 31, 34, 44, 35, 9, 3, 8, 11, 33, 12, 61, 130, 130, 17, 0, 1, 6, 2, 9, 130, 111, 36, 0, 0, 11, 9, 1, 12, 2, 100, 130, 28, 7, 2, 6, 7, 9, 27, 130, 83, 5, 0, 1, 18, 130, 130, 84, 9, 0, 0, 2, 24, 111, 24, 0, 1, 37, 24, 2, 10, 12, 62, 33, 3, 0, 0, 0, 1, 3, 16, 106, 28, 0, 0, 0, 0, 17, 46, 85, 10, 0, 0, 1, 4, 11, 4, 2, 2, 9, 14, 8, 8]",3),(9775,"[0, 1, 1, 3, 0, 3, 46, 20, 1, 4, 17, 9, 1, 17, 108, 15, 0, 3, 37, 17, 6, 15, 116, 16, 6, 1, 4, 7, 7, 7, 9, 6, 0, 8, 10, 4, 26, 129, 27, 9, 0, 0, 5, 2, 11, 129, 129, 12, 103, 4, 0, 0, 2, 31, 129, 129, 94, 4, 0, 0, 0, 3, 13, 42, 0, 15, 38, 2, 70, 129, 1, 0, 5, 10, 40, 12, 74, 129, 6, 1, 129, 39, 6, 1, 2, 22, 9, 33, 122, 13, 0, 0, 0, 0, 5, 23, 4, 11, 9, 12, 45, 38, 1, 0, 0, 4, 36, 38, 57, 32, 0, 0, 82, 22, 9, 5, 13, 11, 3, 94, 35, 3, 0, 0, 0, 1, 16, 97]",5),(9776,"[10, 3, 8, 5, 48, 26, 5, 16, 17, 0, 0, 2, 132, 53, 1, 16, 112, 6, 0, 0, 7, 2, 1, 48, 48, 15, 18, 31, 3, 0, 0, 9, 6, 10, 19, 27, 50, 46, 17, 9, 18, 1, 4, 48, 132, 23, 3, 5, 132, 9, 4, 3, 11, 0, 2, 46, 84, 12, 10, 10, 1, 0, 12, 76, 26, 22, 16, 26, 35, 15, 3, 16, 15, 1, 51, 132, 125, 8, 1, 2, 132, 51, 67, 91, 8, 0, 0, 30, 126, 39, 32, 38, 4, 0, 1, 12, 24, 2, 2, 2, 4, 7, 2, 19, 93, 19, 70, 92, 2, 3, 1, 21, 36, 58, 132, 94, 0, 0, 0, 0, 21, 25, 57, 48, 1, 0, 0, 1]",3); 667 insert into vector_index_07 values(9777, " [16, 15, 0, 0, 5, 46, 5, 5, 4, 0, 0, 0, 28, 118, 12, 5, 75, 44, 5, 0, 6, 32, 6, 49, 41, 74, 9, 1, 0, 0, 0, 9, 1, 9, 16, 41, 71, 80, 3, 0, 0, 4, 3, 5, 51, 106, 11, 3, 112, 28, 13, 1, 4, 8, 3, 104, 118, 14, 1, 1, 0, 0, 0, 88, 3, 27, 46, 118, 108, 49, 2, 0, 1, 46, 118, 118, 27, 12, 0, 0, 33, 118, 118, 8, 0, 0, 0, 4, 118, 95, 40, 0, 0, 0, 1, 11, 27, 38, 12, 12, 18, 29, 3, 2, 13, 30, 94, 78, 30, 19, 9, 3, 31, 45, 70, 42, 15, 1, 3, 12, 14, 22, 16, 2, 3, 17, 24, 13]",4),(9778,"[41, 0, 0, 7, 1, 1, 20, 67, 9, 0, 0, 0, 0, 31, 120, 61, 25, 0, 0, 0, 0, 10, 120, 90, 32, 0, 0, 1, 13, 11, 22, 50, 4, 0, 2, 93, 40, 15, 37, 18, 12, 2, 2, 19, 8, 44, 120, 25, 120, 5, 0, 0, 0, 2, 48, 97, 102, 14, 3, 3, 11, 9, 34, 41, 0, 0, 4, 120, 56, 3, 4, 5, 6, 15, 37, 116, 28, 0, 0, 3, 120, 120, 24, 6, 2, 0, 1, 28, 53, 90, 51, 11, 11, 2, 12, 14, 8, 6, 4, 30, 9, 1, 4, 22, 25, 79, 120, 66, 5, 0, 0, 6, 42, 120, 91, 43, 15, 2, 4, 39, 12, 9, 9, 12, 15, 5, 24, 36]",4); 668 select * from vector_index_07 order by L2_DISTANCE(b, "abc") ASC LIMIT 2; 669 670 -- 44. Auto Increment PK type 671 drop table if exists vector_index_08; 672 create table vector_index_08(a int auto_increment primary key, b vecf32(128),c int,key c_k(c)); 673 insert into vector_index_08 values(9774 ,"[1, 0, 1, 6, 6, 17, 47, 39, 2, 0, 1, 25, 27, 10, 56, 130, 18, 5, 2, 6, 15, 2, 19, 130, 42, 28, 1, 1, 2, 1, 0, 5, 0, 2, 4, 4, 31, 34, 44, 35, 9, 3, 8, 11, 33, 12, 61, 130, 130, 17, 0, 1, 6, 2, 9, 130, 111, 36, 0, 0, 11, 9, 1, 12, 2, 100, 130, 28, 7, 2, 6, 7, 9, 27, 130, 83, 5, 0, 1, 18, 130, 130, 84, 9, 0, 0, 2, 24, 111, 24, 0, 1, 37, 24, 2, 10, 12, 62, 33, 3, 0, 0, 0, 1, 3, 16, 106, 28, 0, 0, 0, 0, 17, 46, 85, 10, 0, 0, 1, 4, 11, 4, 2, 2, 9, 14, 8, 8]",3),(9775,"[0, 1, 1, 3, 0, 3, 46, 20, 1, 4, 17, 9, 1, 17, 108, 15, 0, 3, 37, 17, 6, 15, 116, 16, 6, 1, 4, 7, 7, 7, 9, 6, 0, 8, 10, 4, 26, 129, 27, 9, 0, 0, 5, 2, 11, 129, 129, 12, 103, 4, 0, 0, 2, 31, 129, 129, 94, 4, 0, 0, 0, 3, 13, 42, 0, 15, 38, 2, 70, 129, 1, 0, 5, 10, 40, 12, 74, 129, 6, 1, 129, 39, 6, 1, 2, 22, 9, 33, 122, 13, 0, 0, 0, 0, 5, 23, 4, 11, 9, 12, 45, 38, 1, 0, 0, 4, 36, 38, 57, 32, 0, 0, 82, 22, 9, 5, 13, 11, 3, 94, 35, 3, 0, 0, 0, 1, 16, 97]",5),(9776,"[10, 3, 8, 5, 48, 26, 5, 16, 17, 0, 0, 2, 132, 53, 1, 16, 112, 6, 0, 0, 7, 2, 1, 48, 48, 15, 18, 31, 3, 0, 0, 9, 6, 10, 19, 27, 50, 46, 17, 9, 18, 1, 4, 48, 132, 23, 3, 5, 132, 9, 4, 3, 11, 0, 2, 46, 84, 12, 10, 10, 1, 0, 12, 76, 26, 22, 16, 26, 35, 15, 3, 16, 15, 1, 51, 132, 125, 8, 1, 2, 132, 51, 67, 91, 8, 0, 0, 30, 126, 39, 32, 38, 4, 0, 1, 12, 24, 2, 2, 2, 4, 7, 2, 19, 93, 19, 70, 92, 2, 3, 1, 21, 36, 58, 132, 94, 0, 0, 0, 0, 21, 25, 57, 48, 1, 0, 0, 1]",3); 674 insert into vector_index_08 values(9777, "[16, 15, 0, 0, 5, 46, 5, 5, 4, 0, 0, 0, 28, 118, 12, 5, 75, 44, 5, 0, 6, 32, 6, 49, 41, 74, 9, 1, 0, 0, 0, 9, 1, 9, 16, 41, 71, 80, 3, 0, 0, 4, 3, 5, 51, 106, 11, 3, 112, 28, 13, 1, 4, 8, 3, 104, 118, 14, 1, 1, 0, 0, 0, 88, 3, 27, 46, 118, 108, 49, 2, 0, 1, 46, 118, 118, 27, 12, 0, 0, 33, 118, 118, 8, 0, 0, 0, 4, 118, 95, 40, 0, 0, 0, 1, 11, 27, 38, 12, 12, 18, 29, 3, 2, 13, 30, 94, 78, 30, 19, 9, 3, 31, 45, 70, 42, 15, 1, 3, 12, 14, 22, 16, 2, 3, 17, 24, 13]",4),(9778,"[41, 0, 0, 7, 1, 1, 20, 67, 9, 0, 0, 0, 0, 31, 120, 61, 25, 0, 0, 0, 0, 10, 120, 90, 32, 0, 0, 1, 13, 11, 22, 50, 4, 0, 2, 93, 40, 15, 37, 18, 12, 2, 2, 19, 8, 44, 120, 25, 120, 5, 0, 0, 0, 2, 48, 97, 102, 14, 3, 3, 11, 9, 34, 41, 0, 0, 4, 120, 56, 3, 4, 5, 6, 15, 37, 116, 28, 0, 0, 3, 120, 120, 24, 6, 2, 0, 1, 28, 53, 90, 51, 11, 11, 2, 12, 14, 8, 6, 4, 30, 9, 1, 4, 22, 25, 79, 120, 66, 5, 0, 0, 6, 42, 120, 91, 43, 15, 2, 4, 39, 12, 9, 9, 12, 15, 5, 24, 36]",4); 675 create index idx01 using ivfflat on vector_index_08(b) lists=3 op_type "vector_l2_ops"; 676 select * from vector_index_08 ; 677 update vector_index_08 set b="[16, 15, 0, 0, 5, 46, 5, 5, 4, 0, 0, 0, 28, 118, 12, 5, 75, 44, 5, 0, 6, 32, 6, 49, 41, 74, 9, 1, 0, 0, 0, 9, 1, 9, 16, 41, 71, 80, 3, 0, 0, 4, 3, 5, 51, 106, 11, 3, 112, 28, 13, 1, 4, 8, 3, 104, 118, 14, 1, 1, 0, 0, 0, 88, 3, 27, 46, 118, 108, 49, 2, 0, 1, 46, 118, 118, 27, 12, 0, 0, 33, 118, 118, 8, 0, 0, 0, 4, 118, 95, 40, 0, 0, 0, 1, 11, 27, 38, 12, 12, 18, 29, 3, 2, 13, 30, 94, 78, 30, 19, 9, 3, 31, 45, 70, 42, 15, 1, 3, 12, 14, 22, 16, 2, 3, 17, 24, 13]" where a=9774; 678 select * from vector_index_08 where a=9774; 679 delete from vector_index_08 where a=9777; 680 select * from vector_index_08 where a=9777; 681 truncate table vector_index_08; 682 select * from vector_index_08; 683 insert into vector_index_08 values(9774 ,"[1, 0, 1, 6, 6, 17, 47, 39, 2, 0, 1, 25, 27, 10, 56, 130, 18, 5, 2, 6, 15, 2, 19, 130, 42, 28, 1, 1, 2, 1, 0, 5, 0, 2, 4, 4, 31, 34, 44, 35, 9, 3, 8, 11, 33, 12, 61, 130, 130, 17, 0, 1, 6, 2, 9, 130, 111, 36, 0, 0, 11, 9, 1, 12, 2, 100, 130, 28, 7, 2, 6, 7, 9, 27, 130, 83, 5, 0, 1, 18, 130, 130, 84, 9, 0, 0, 2, 24, 111, 24, 0, 1, 37, 24, 2, 10, 12, 62, 33, 3, 0, 0, 0, 1, 3, 16, 106, 28, 0, 0, 0, 0, 17, 46, 85, 10, 0, 0, 1, 4, 11, 4, 2, 2, 9, 14, 8, 8]",3),(9775,"[0, 1, 1, 3, 0, 3, 46, 20, 1, 4, 17, 9, 1, 17, 108, 15, 0, 3, 37, 17, 6, 15, 116, 16, 6, 1, 4, 7, 7, 7, 9, 6, 0, 8, 10, 4, 26, 129, 27, 9, 0, 0, 5, 2, 11, 129, 129, 12, 103, 4, 0, 0, 2, 31, 129, 129, 94, 4, 0, 0, 0, 3, 13, 42, 0, 15, 38, 2, 70, 129, 1, 0, 5, 10, 40, 12, 74, 129, 6, 1, 129, 39, 6, 1, 2, 22, 9, 33, 122, 13, 0, 0, 0, 0, 5, 23, 4, 11, 9, 12, 45, 38, 1, 0, 0, 4, 36, 38, 57, 32, 0, 0, 82, 22, 9, 5, 13, 11, 3, 94, 35, 3, 0, 0, 0, 1, 16, 97]",5),(9776,"[10, 3, 8, 5, 48, 26, 5, 16, 17, 0, 0, 2, 132, 53, 1, 16, 112, 6, 0, 0, 7, 2, 1, 48, 48, 15, 18, 31, 3, 0, 0, 9, 6, 10, 19, 27, 50, 46, 17, 9, 18, 1, 4, 48, 132, 23, 3, 5, 132, 9, 4, 3, 11, 0, 2, 46, 84, 12, 10, 10, 1, 0, 12, 76, 26, 22, 16, 26, 35, 15, 3, 16, 15, 1, 51, 132, 125, 8, 1, 2, 132, 51, 67, 91, 8, 0, 0, 30, 126, 39, 32, 38, 4, 0, 1, 12, 24, 2, 2, 2, 4, 7, 2, 19, 93, 19, 70, 92, 2, 3, 1, 21, 36, 58, 132, 94, 0, 0, 0, 0, 21, 25, 57, 48, 1, 0, 0, 1]",3); 684 alter table vector_index_08 add column d vecf32(3) not null after c; 685 select * from vector_index_08; 686 687 -- 45. Auto Incr PK type vs non-auto Incr PK type 688 drop table if exists vector_index_08; 689 create table vector_index_08(a int primary key, b vecf32(3),c int); 690 insert into vector_index_08 values(1 ,"[1, 2, 3]",11); 691 insert into vector_index_08 values(2 ,"[1, 2, 3]",12); 692 insert into vector_index_08 values(3 ,"[1, 2, 3]",13); 693 create index idx01 using ivfflat on vector_index_08(b) lists = 2 op_type 'vector_l2_ops'; 694 alter table vector_index_08 add column d vecf32(3) not null after c; 695 select * from vector_index_08; 696 697 drop table if exists vector_index_08; 698 create table vector_index_08(a int auto_increment primary key, b vecf32(3),c int); 699 insert into vector_index_08 values(1 ,"[1, 2, 3]",11); 700 insert into vector_index_08 values(2 ,"[1, 2, 3]",12); 701 insert into vector_index_08 values(3 ,"[1, 2, 3]",13); 702 create index idx01 using ivfflat on vector_index_08(b) lists = 2 op_type 'vector_l2_ops'; 703 alter table vector_index_08 add column d vecf32(3) not null after c; 704 select * from vector_index_08; 705 706 -- Vector Default Non Null Value 707 drop table if exists vector_index_08; 708 create table vector_index_08(a int primary key, b vecf32(128),c int,key c_k(c)); 709 create index idx01 using ivfflat on vector_index_08(b) lists=3 op_type "vector_l2_ops"; 710 insert into vector_index_08 values(9774 ,"[1, 0, 1, 6, 6, 17, 47, 39, 2, 0, 1, 25, 27, 10, 56, 130, 18, 5, 2, 6, 15, 2, 19, 130, 42, 28, 1, 1, 2, 1, 0, 5, 0, 2, 4, 4, 31, 34, 44, 35, 9, 3, 8, 11, 33, 12, 61, 130, 130, 17, 0, 1, 6, 2, 9, 130, 111, 36, 0, 0, 11, 9, 1, 12, 2, 100, 130, 28, 7, 2, 6, 7, 9, 27, 130, 83, 5, 0, 1, 18, 130, 130, 84, 9, 0, 0, 2, 24, 111, 24, 0, 1, 37, 24, 2, 10, 12, 62, 33, 3, 0, 0, 0, 1, 3, 16, 106, 28, 0, 0, 0, 0, 17, 46, 85, 10, 0, 0, 1, 4, 11, 4, 2, 2, 9, 14, 8, 8]",3),(9775,"[0, 1, 1, 3, 0, 3, 46, 20, 1, 4, 17, 9, 1, 17, 108, 15, 0, 3, 37, 17, 6, 15, 116, 16, 6, 1, 4, 7, 7, 7, 9, 6, 0, 8, 10, 4, 26, 129, 27, 9, 0, 0, 5, 2, 11, 129, 129, 12, 103, 4, 0, 0, 2, 31, 129, 129, 94, 4, 0, 0, 0, 3, 13, 42, 0, 15, 38, 2, 70, 129, 1, 0, 5, 10, 40, 12, 74, 129, 6, 1, 129, 39, 6, 1, 2, 22, 9, 33, 122, 13, 0, 0, 0, 0, 5, 23, 4, 11, 9, 12, 45, 38, 1, 0, 0, 4, 36, 38, 57, 32, 0, 0, 82, 22, 9, 5, 13, 11, 3, 94, 35, 3, 0, 0, 0, 1, 16, 97]",5),(9776,"[10, 3, 8, 5, 48, 26, 5, 16, 17, 0, 0, 2, 132, 53, 1, 16, 112, 6, 0, 0, 7, 2, 1, 48, 48, 15, 18, 31, 3, 0, 0, 9, 6, 10, 19, 27, 50, 46, 17, 9, 18, 1, 4, 48, 132, 23, 3, 5, 132, 9, 4, 3, 11, 0, 2, 46, 84, 12, 10, 10, 1, 0, 12, 76, 26, 22, 16, 26, 35, 15, 3, 16, 15, 1, 51, 132, 125, 8, 1, 2, 132, 51, 67, 91, 8, 0, 0, 30, 126, 39, 32, 38, 4, 0, 1, 12, 24, 2, 2, 2, 4, 7, 2, 19, 93, 19, 70, 92, 2, 3, 1, 21, 36, 58, 132, 94, 0, 0, 0, 0, 21, 25, 57, 48, 1, 0, 0, 1]",3); 711 insert into vector_index_08 values(9777, "[16, 15, 0, 0, 5, 46, 5, 5, 4, 0, 0, 0, 28, 118, 12, 5, 75, 44, 5, 0, 6, 32, 6, 49, 41, 74, 9, 1, 0, 0, 0, 9, 1, 9, 16, 41, 71, 80, 3, 0, 0, 4, 3, 5, 51, 106, 11, 3, 112, 28, 13, 1, 4, 8, 3, 104, 118, 14, 1, 1, 0, 0, 0, 88, 3, 27, 46, 118, 108, 49, 2, 0, 1, 46, 118, 118, 27, 12, 0, 0, 33, 118, 118, 8, 0, 0, 0, 4, 118, 95, 40, 0, 0, 0, 1, 11, 27, 38, 12, 12, 18, 29, 3, 2, 13, 30, 94, 78, 30, 19, 9, 3, 31, 45, 70, 42, 15, 1, 3, 12, 14, 22, 16, 2, 3, 17, 24, 13]",4),(9778,"[41, 0, 0, 7, 1, 1, 20, 67, 9, 0, 0, 0, 0, 31, 120, 61, 25, 0, 0, 0, 0, 10, 120, 90, 32, 0, 0, 1, 13, 11, 22, 50, 4, 0, 2, 93, 40, 15, 37, 18, 12, 2, 2, 19, 8, 44, 120, 25, 120, 5, 0, 0, 0, 2, 48, 97, 102, 14, 3, 3, 11, 9, 34, 41, 0, 0, 4, 120, 56, 3, 4, 5, 6, 15, 37, 116, 28, 0, 0, 3, 120, 120, 24, 6, 2, 0, 1, 28, 53, 90, 51, 11, 11, 2, 12, 14, 8, 6, 4, 30, 9, 1, 4, 22, 25, 79, 120, 66, 5, 0, 0, 6, 42, 120, 91, 43, 15, 2, 4, 39, 12, 9, 9, 12, 15, 5, 24, 36]",4); 712 alter table vector_index_08 add column d vecf32(3) not null after c; 713 select * from vector_index_08; 714 715 -- post 716 SET GLOBAL experimental_ivf_index = 0; 717 drop database vecdb2;