create temporary table t1 (id int auto_increment primary key, v vector(5) not null, vector index (v)); ERROR HY000: Cannot create VECTOR index on temporary MyISAM table
create table t1 (id int auto_increment primary key,
u vector(5) not null, vector index (u),
v vector(5) not null, vector index (v)); ERROR42000: This version of MariaDB doesn't yet support 'multiple VECTOR indexes'
create table t1 (id int auto_increment primary key, v vector(5) not null, vector index (v));
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
show keys from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
t1 0 PRIMARY 1 id A 0 NULL NULL BTREE NO
t1 1 v 1 v A NULL NULL NULL VECTOR NO
drop table t1; set mhnsw_default_m=@@mhnsw_default_m+1;
create table t1 (id int auto_increment primary key, v vector(5) not null, vector index (v));
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`) `m`='7'
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
show keys from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
t1 0 PRIMARY 1 id A 0 NULL NULL BTREE NO
t1 1 v 1 v A NULL NULL NULL VECTOR NO
drop table t1;
create table t1 (id int auto_increment primary key, v vector(5) not null,
vector index (v) m=5);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`) `m`='5'
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
show keys from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
t1 0 PRIMARY 1 id A 0 NULL NULL BTREE NO
t1 1 v 1 v A NULL NULL NULL VECTOR NO set mhnsw_default_m=default; set rand_seed1=1, rand_seed2=2;
select * from information_schema.statistics where table_name='t1';
TABLE_CATALOG def
TABLE_SCHEMA test
TABLE_NAME t1
NON_UNIQUE 0
INDEX_SCHEMA test
INDEX_NAME PRIMARY
SEQ_IN_INDEX 1
COLUMN_NAME id
COLLATION A
CARDINALITY 0
SUB_PART NULL
PACKED NULL
NULLABLE
INDEX_TYPE BTREE
COMMENT
INDEX_COMMENT
IGNORED NO
CREATE_OPTIONS
TABLE_CATALOG def
TABLE_SCHEMA test
TABLE_NAME t1
NON_UNIQUE 1
INDEX_SCHEMA test
INDEX_NAME v
SEQ_IN_INDEX 1
COLUMN_NAME v
COLLATION A
CARDINALITY NULL
SUB_PART NULL
PACKED NULL
NULLABLE
INDEX_TYPE VECTOR
COMMENT
INDEX_COMMENT
IGNORED NO
CREATE_OPTIONS `m`='5'
insert t1 (v) values (x'e360d63ebe554f3fcdbc523f4522193f5236083d'),
(x'f511303f72224a3fdd05fe3eb22a133ffae86a3f'),
(x'f09baa3ea172763f123def3e0c7fe53e288bf33e'),
(x'b97a523f2a193e3eb4f62e3f2d23583e9dd60d3f'),
(x'f7c5df3e984b2b3e65e59d3d7376db3eac63773e'),
(x'de01453ffa486d3f10aa4d3fdd66813c71cb163f'),
(x'76edfc3e4b57243f10f8423fb158713f020bda3e'),
(x'56926c3fdf098d3e2c8c5e3d1ad4953daa9d0b3e'),
(x'7b713f3e5258323f80d1113d673b2b3f66e3583f'),
(x'6ca1d43e9df91b3fe580da3e1c247d3f147cf33e');
select id, hex(v), vec_totext(v) from t1;
id hex(v) vec_totext(v) 1 E360D63EBE554F3FCDBC523F4522193F5236083D [0.418708,0.809902,0.823193,0.598179,0.0332549] 2 F511303F72224A3FDD05FE3EB22A133FFAE86A3F [0.687774,0.789588,0.496138,0.57487,0.917617] 3 F09BAA3EA172763F123DEF3E0C7FE53E288BF33E [0.333221,0.962687,0.467263,0.448235,0.475671] 4 B97A523F2A193E3EB4F62E3F2D23583E9DD60D3F [0.822185,0.185643,0.683452,0.211072,0.554056] 5 F7C5DF3E984B2B3E65E59D3D7376DB3EAC63773E [0.437057,0.167281,0.0770977,0.428638,0.241591] 6 DE01453FFA486D3F10AA4D3FDD66813C71CB163F [0.76956,0.926895,0.803376,0.0157961,0.589042] 776EDFC3E4B57243F10F8423FB158713F020BDA3E [0.493999,0.641957,0.761598,0.94276,0.425865] 856926C3FDF098D3E2C8C5E3D1AD4953DAA9D0B3E [0.924108,0.275466,0.0543329,0.0731585,0.136344] 97B713F3E5258323F80D1113D673B2B3F66E3583F [0.186956,0.69666,0.0356002,0.668875,0.84722] 106CA1D43E9DF91B3FE580DA3E1C247D3F147CF33E [0.415294,0.609278,0.426765,0.988832,0.475556]
flush tables;
select id,vec_distance_euclidean(v, x'B047263c9f87233fcfd27e3eae493e3f0329f43e') d from t1 order by d limit 3;
id d 90.47199 100.50690 30.58656
select id,vec_distance_euclidean(x'b047263C9f87233fcfd27e3eae493e3f0329f43e', v) d from t1 order by d limit 3;
id d 90.47199 100.50690 30.58656
select id>0,vec_distance_euclidean(v, NULL) d from t1 order by d limit 3;
id>0 d 1 NULL 1 NULL 1 NULL
select id>0,vec_distance_euclidean(v, x'123456') d from t1 order by d limit 3;
id>0 d 1 NULL 1 NULL 1 NULL
select t1.id as id1, t2.id as id2, vec_distance_euclidean(t1.v, t2.v) from t1, t1 as t2 order by 3,1,2;
id1 id2 vec_distance_euclidean(t1.v, t2.v) 110 220 330 440 550 660 770 880 990 10100 7100.35209 1070.35209 170.55726 710.55726 230.60651 320.60651 130.61282 310.61282 580.62199 850.62199 3100.65231 1030.65231 9100.67326 1090.67326 370.67998 730.67998 390.68207 930.68207 2100.69163 1020.69163 290.69666 920.69666 360.71028 630.71028 270.71202 720.71202 260.73516 620.73516 1100.73868 1010.73868 460.77843 640.77843 480.77958 840.77958 450.81320 540.81320 240.82609 420.82609 5100.82864 1050.82864 590.87693 950.87693 160.88614 610.88614 350.92242 530.92242 470.93479 740.93479 790.93642 970.93642 340.97571 430.97571 120.98102 210.98102 140.99654 410.99654 570.99768 750.99768 4101.01093 1041.01093 151.02083 511.02083 671.02213 761.02213 251.05076 521.05076 681.10342 861.10342 381.11703 831.11703 6101.15234 1061.15234 191.16377 911.16377 281.17365 821.17365 491.17468 941.17468 181.19099 811.19099 8101.20935 1081.20935 691.21452 961.21452 561.22727 651.22727 891.25752 981.25752 781.28823 871.28823
select id,vec_distance_euclidean(v, x'b047263C9F87233fcfd27e3eae493e3f0329f43e') d
from t1 order by d limit 9;
id d 90.47199 100.50690 30.58656 70.73444 50.76710 10.86251 20.87503 41.15881 61.22844
select id,vec_distance_euclidean(v, x'b047263C9F87233fcfd27e3eae493e3f0329f43e') d
from t1 where id % 3 = 0 order by d limit 3;
id d 90.47199 30.58656 61.22844
select * from (
select id,vec_distance_euclidean(v, x'b047263C9F87233fcfd27e3eae493e3f0329f43e') d
from t1 where id < 10
) u order by d limit 3;
id d 90.47199 30.58656 70.73444
flush session status;
select id,vec_distance_euclidean(v, x'B047263c9f87233fcfd27e3eae493e3f0329f43e') d from t1 order by d limit 3;
id d 90.47199 100.50690 30.58656
show status like 'handler_read_rnd_next';
Variable_name Value
Handler_read_rnd_next 0
select id,vec_distance_euclidean(v, x'B047263c9f87233fcfd27e3eae493e3f0329f43e') d from t1 use index () order by d limit 3;
id d 90.47199 100.50690 30.58656
show status like 'handler_read_rnd_next';
Variable_name Value
Handler_read_rnd_next 11
flush session status;
select id,vec_distance_cosine(v, x'B047263c9f87233fcfd27e3eae493e3f0329f43e') d from t1 order by d limit 3;
id d 100.05905 90.06546 30.10750
show status like 'handler_read_rnd_next';
Variable_name Value
Handler_read_rnd_next 11
delete from t1 where v = x'7b713f3e5258323f80d1113d673b2b3f66e3583f';
select id,vec_distance_euclidean(v, x'B047263C9f87233fcfd27e3eae493e3f0329f43e') d from t1 order by d limit 3;
id d 100.50690 30.58656 70.73444
insert t1 (v) values (x'7b713f3e5258323f80d1113d673b2b3f66e3583f');
select id,vec_distance_euclidean(v, x'b047263c9F87233fcfd27e3eae493e3f0329f43e') d from t1 order by d limit 3;
id d 110.47199 100.50690 30.58656
select id,vec_distance_euclidean(v, x'B047263c9F87233fcfd27e3eae493e3f0329f43e') d from t1 order by d limit 5;
id d 110.47199 100.50690 30.58656 70.73444 50.76710
update t1 set v=x'76EDFC3E4B57243F10F8423FB158713F020BAA3E' where v=x'6CA1D43E9DF91B3FE580DA3E1C247D3F147CF33E';
select id,vec_distance_euclidean(v, x'B047263C9F87233fcfd27e3eae493e3f0329f43e') d from t1 order by d limit 5;
id d 110.47199 30.58656 70.73444 100.74683 50.76710
delete from t1;
insert t1 (v) values (x'e360d63ebe554f3fcdbc523f4522193f5236083d'),
(x'f511303f72224a3fdd05fe3eb22a133ffae86a3f'),
(x'f09baa3ea172763f123def3e0c7fe53e288bf33e'),
(x'b97a523f2a193e3eb4f62e3f2d23583e9dd60d3f'),
(x'f7c5df3e984b2b3e65e59d3d7376db3eac63773e'),
(x'de01453ffa486d3f10aa4d3fdd66813c71cb163f'),
(x'76edfc3e4b57243f10f8423fb158713f020bda3e'),
(x'56926c3fdf098d3e2c8c5e3d1ad4953daa9d0b3e'),
(x'7b713f3e5258323f80d1113d673b2b3f66e3583f'),
(x'6ca1d43e9df91b3fe580da3e1c247d3f147cf33e');
select id,vec_distance_euclidean(v, x'b047263c9f87233Fcfd27e3eae493e3f0329f43e') d from t1 order by d limit 5;
id d 200.47199 210.50690 140.58656 180.73444 160.76710
insert t1 (v) values (''); ERROR22007: Incorrect vector value: '' for column `test`.`t1`.`v` at row 1
insert t1 (v) values (x'1234'); ERROR22007: Incorrect vector value: '\x124' for column `test`.`t1`.`v` at row 1
insert t1 (v) values (x'12345678'); ERROR22007: Incorrect vector value: '\x124Vx' for column `test`.`t1`.`v` at row 1
drop table t1;
db.opt
# Check if CREATE TABLE ... LIKE inherits VECTOR index
create table t1 (id int auto_increment primary key, v vector(5) not null, vector index (v));
create table t2 like t1;
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
drop table t1, t2;
db.opt
# Test insert ... select with vector index
create table t1 (id int auto_increment primary key, v vector(5) not null, vector index (v));
create table t2 like t1;
insert t1 (v) values (x'e360d63ebe554f3fcdbc523f4522193f5236083d'),
(x'f511303f72224a3fdd05fe3eb22a133ffae86a3f'),
(x'f09baa3ea172763f123def3e0c7fe53e288bf33e'),
(x'b97a523f2a193e3eb4f62e3f2d23583e9dd60d3f'),
(x'f7c5df3e984b2b3e65e59d3d7376db3eac63773e'),
(x'de01453ffa486d3f10aa4d3fdd66813c71cb163f'),
(x'76edfc3e4b57243f10f8423fb158713f020bda3e'),
(x'56926c3fdf098d3e2c8c5e3d1ad4953daa9d0b3e'),
(x'7b713f3e5258323f80d1113d673b2b3f66e3583f'),
(x'6ca1d43e9df91b3fe580da3e1c247d3f147cf33e');
insert into t2 select id+10, v from t1;
insert into t1 select * from t2;
select id, hex(v) from t1;
id hex(v) 1 E360D63EBE554F3FCDBC523F4522193F5236083D 2 F511303F72224A3FDD05FE3EB22A133FFAE86A3F 3 F09BAA3EA172763F123DEF3E0C7FE53E288BF33E 4 B97A523F2A193E3EB4F62E3F2D23583E9DD60D3F 5 F7C5DF3E984B2B3E65E59D3D7376DB3EAC63773E 6 DE01453FFA486D3F10AA4D3FDD66813C71CB163F 776EDFC3E4B57243F10F8423FB158713F020BDA3E 856926C3FDF098D3E2C8C5E3D1AD4953DAA9D0B3E 97B713F3E5258323F80D1113D673B2B3F66E3583F 106CA1D43E9DF91B3FE580DA3E1C247D3F147CF33E 11 E360D63EBE554F3FCDBC523F4522193F5236083D 12 F511303F72224A3FDD05FE3EB22A133FFAE86A3F 13 F09BAA3EA172763F123DEF3E0C7FE53E288BF33E 14 B97A523F2A193E3EB4F62E3F2D23583E9DD60D3F 15 F7C5DF3E984B2B3E65E59D3D7376DB3EAC63773E 16 DE01453FFA486D3F10AA4D3FDD66813C71CB163F 1776EDFC3E4B57243F10F8423FB158713F020BDA3E 1856926C3FDF098D3E2C8C5E3D1AD4953DAA9D0B3E 197B713F3E5258323F80D1113D673B2B3F66E3583F 206CA1D43E9DF91B3FE580DA3E1C247D3F147CF33E
drop table t1, t2;
db.opt
create table t1 (id int auto_increment primary key, v vector(5) not null, vector index (v));
insert t1 (id, v) values (1, x'e360d63ebe554f3fcdbc523f4522193f5236083d');
truncate table t1;
insert t1 (id, v) values (1, x'e360d63ebe554f3fcdbc523f4522193f5236083d');
truncate table t1;
insert t1 (id, v) values (1, x'e360d63ebe554f3fcdbc523f4522193f5236083d');
select id, hex(v) from t1;
id hex(v) 1 E360D63EBE554F3FCDBC523F4522193F5236083D
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
drop table t1;
db.opt
# Test RENAME TABLE with vector index
create table t1 (id int auto_increment primary key, v vector(5) not null, vector index (v));
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
rename table t1 to t2;
db.opt
t2#i#01.ibd
t2.frm
t2.ibd
create database test1;
rename table test.t2 to test1.t1;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
call mtr.add_suppression('InnoDB: Cannot rename.*because the source file does not exist');
call mtr.add_suppression('InnoDB: File ./test1/t1#i#01.ibd was not found');
rename table test1.t1 to test1.t2;
Got one of the listed errors
db.opt
t1.frm
t1.ibd
drop database test1;
db.opt
#
# Cosine distance
#
create table t1 (id int auto_increment primary key, v vector(5) not null,
vector index (v) distance=cosine);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`) `distance`='cosine'
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
insert t1 (v) values (x'e360d63ebe554f3fcdbc523f4522193f5236083d'),
(x'f511303f72224a3fdd05fe3eb22a133ffae86a3f'),
(x'f09baa3ea172763f123def3e0c7fe53e288bf33e'),
(x'b97a523f2a193e3eb4f62e3f2d23583e9dd60d3f'),
(x'f7c5df3e984b2b3e65e59d3d7376db3eac63773e'),
(x'de01453ffa486d3f10aa4d3fdd66813c71cb163f'),
(x'76edfc3e4b57243f10f8423fb158713f020bda3e'),
(x'56926c3fdf098d3e2c8c5e3d1ad4953daa9d0b3e'),
(x'7b713f3e5258323f80d1113d673b2b3f66e3583f'),
(x'6ca1d43e9df91b3fe580da3e1c247d3f147cf33e');
select id,vec_distance_cosine(v, x'B047263c9f87233fcfd27e3eae493e3f0329f43e') d from t1 order by d limit 3;
id d 100.05905 90.06546 30.10750
flush session status;
select id,vec_distance_cosine(v, x'B047263c9f87233fcfd27e3eae493e3f0329f43e') d from t1 order by d limit 3;
id d 100.05905 90.06546 30.10750
show status like 'handler_read_rnd_next';
Variable_name Value
Handler_read_rnd_next 0
select id,vec_distance_cosine(v, x'B047263c9f87233fcfd27e3eae493e3f0329f43e') d from t1 use index () order by d limit 3;
id d 100.05905 90.06546 30.10750
show status like 'handler_read_rnd_next';
Variable_name Value
Handler_read_rnd_next 11
flush session status;
select id,vec_distance_euclidean(v, x'B047263c9f87233fcfd27e3eae493e3f0329f43e') d from t1 order by d limit 3;
id d 90.47199 100.50690 30.58656
show status like 'handler_read_rnd_next';
Variable_name Value
Handler_read_rnd_next 11
drop table t1; set @a=vec_fromtext('[94.542572,8.735560,60.050098,74.043800,90.068710,28.212160,70.854660,69.636841,35.620232,69.190628]');
select vec_distance_cosine(@a, @a), vec_distance_euclidean(@a, @a);
vec_distance_cosine(@a, @a) vec_distance_euclidean(@a, @a) 00
# Test ALTER TABLE, CREATE/DROP INDEX
create table t1 (id int auto_increment primary key, v vector(5) not null, vector index (v));
insert t1 (v) values (x'e360d63ebe554f3fcdbc523f4522193f5236083d'),
(x'f511303f72224a3fdd05fe3eb22a133ffae86a3f'),
(x'f09baa3ea172763f123def3e0c7fe53e288bf33e'),
(x'b97a523f2a193e3eb4f62e3f2d23583e9dd60d3f'),
(x'f7c5df3e984b2b3e65e59d3d7376db3eac63773e'),
(x'de01453ffa486d3f10aa4d3fdd66813c71cb163f'),
(x'76edfc3e4b57243f10f8423fb158713f020bda3e'),
(x'56926c3fdf098d3e2c8c5e3d1ad4953daa9d0b3e'),
(x'7b713f3e5258323f80d1113d673b2b3f66e3583f'),
(x'6ca1d43e9df91b3fe580da3e1c247d3f147cf33e');
# ADD/DROP COLUMN, ALGORITHM=COPY
alter table t1 add column a int, algorithm=copy;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
`a` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t1 drop column a, algorithm=copy;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
# ADD/DROP INDEX, ALGORITHM=COPY (non-vector)
alter table t1 add index a(id), algorithm=copy;
db.opt
t1#i#02.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
KEY `a` (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t1 drop index a, algorithm=copy;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
# CREATE/DROP INDEX, ALGORITHM=COPY (non-vector)
create index a on t1(id) algorithm=copy;
db.opt
t1#i#02.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
KEY `a` (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
drop index a on t1;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
# ADD/DROP COLUMN IF [NOT] EXISTS, ALGORITHM=COPY (non-vector)
alter table t1 add column ifnot exists a int, algorithm=copy;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
`a` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t1 drop column if exists a, algorithm=copy;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
# ADD/DROP INDEX, ALGORITHM=COPY (vector)
alter table t1 drop index v, algorithm=copy;
db.opt
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t1 add vector index v(v), algorithm=copy;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
# CREATE/DROP INDEX, ALGORITHM=COPY (vector)
drop index v on t1;
db.opt
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
create vector index v on t1(v) algorithm=copy;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
# ADD/DROP INDEX, ALGORITHM=INPLACE (non-vector)
alter table t1 add index a(id), algorithm=inplace; ERROR0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY
alter table t1 add index a(id);
alter table t1 drop index a, algorithm=inplace; ERROR0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY
alter table t1 drop index a;
# ADD/DROP INDEX, ALGORITHM=INPLACE (vector)
alter table t1 drop index v, algorithm=inplace; ERROR0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY
alter table t1 drop index v;
alter table t1 add vector index v(v), algorithm=inplace; ERROR0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY
alter table t1 add vector index v(v);
# CHANGE/DROP/MODIFY COLUMN, ALGORITHM=INPLACE (vector)
alter table t1 change column v v vector(6) not null, algorithm=inplace; ERROR0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY
alter table t1 drop column v, algorithm=inplace; ERROR0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY
alter table t1 modify column v vector(7) not null, algorithm=inplace; ERROR0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY
# ADD/CHANGE/DROP/MODIFY COLUMN, ALGORITHM=INPLACE (non-vector)
alter table t1 add column a varchar(10), algorithm=inplace;
alter table t1 change column a a varchar(20), algorithm=inplace;
alter table t1 modify column a varchar(30), algorithm=inplace;
alter table t1 drop column a, algorithm=inplace;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
# ENABLE/DISABLE INDEXES
alter table t1 disable keys;
alter table t1 enable keys;
Warnings:
Note 1031 Storage engine InnoDB of the table `test`.`t1` doesn't have this option
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
# RENAME COLUMN (vector)
alter table t1 rename column v to w;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`w` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`w`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t1 rename column w to v;
# RENAME INDEX (vector)
alter table t1 rename key v to w;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `w` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t1 rename key w to v;
# IF [NOT] EXISTS
create vector index ifnot exists v on t1(v);
Warnings:
Note 1061 Duplicate key name 'v'
drop index if exists v on t1;
drop index if exists v on t1;
Warnings:
Note 1091 Can't DROP INDEX `v`; check that it exists
db.opt
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
create vector index ifnot exists v on t1(v);
alter table t1 rename key if exists v to w;
alter table t1 rename key if exists w to v;
alter table t1 alter key if exists v ignored;
alter table t1 alter key if exists v not ignored;
# ENGINE
alter table t1 engine=myisam;
db.opt
t1#i#01.MYD
t1#i#01.MYI
t1.MYD
t1.MYI
t1.frm
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t1 engine=innodb;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t1 rename to t2, engine=myisam;
db.opt
t2#i#01.MYD
t2#i#01.MYI
t2.MYD
t2.MYI
t2.frm
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t2 rename to t1, engine=innodb;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
# CHANGE/MODIFY/DROP COLUMN (vector)
alter table t1 modify column v int; ERROR HY000: Incorrect arguments to VECTOR INDEX
alter table t1 change column v v int; ERROR HY000: Incorrect arguments to VECTOR INDEX
alter table t1 modify column v vector(5); ERROR42000: All parts of a VECTOR index must be NOT NULL
alter table t1 change column v v vector(6); ERROR42000: All parts of a VECTOR index must be NOT NULL
alter table t1 modify column v vector(7) not null;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(7) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t1 change column v v vector(5) not null;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t1 drop column v;
db.opt
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
drop table t1;
create table t1(v vector(5) not null, vector index(v));
alter table t1 add column a int;
drop table t1;
#
# MDEV-35292 - ALTER TABLE re-creating vector key is no-op with
# non-copying alter algorithms (default)
#
create table t (v vector(1) not null, vector(v) distance=euclidean);
insert into t values (0x31313131);
alter table t drop index v, add vector(v) distance=cosine;
show create table t;
Table Create Table
t CREATE TABLE `t` (
`v` vector(1) NOT NULL,
VECTOR KEY `v` (`v`) `distance`='cosine'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
drop table t;
#
# MDEV-35821 - vector index sizes are not in INDEX_LENGTH
#
create table t1 (id int primary key, v vector(1) not null, vector index (v));
insert into t1 values (1, vec_fromtext('[1]'));
select index_length > 0 as has_index_length
from information_schema.tables
where table_schema = database() and table_name = 't1';
has_index_length 1
flush tables;
select index_length > 0 as has_index_length
from information_schema.tables
where table_schema = database() and table_name = 't1';
has_index_length 1
drop table t1;
#
# MDEV-34805 INFORMATION_SCHEMA.VECTOR_INDEXES
#
# No vector tables yet in this schema
SELECT COUNT(*) FROM INFORMATION_SCHEMA.VECTOR_INDEXES
WHERE TABLE_SCHEMA = DATABASE();
COUNT(*) 0
# On empty table
CREATE TABLE t_vec (id INT PRIMARY KEY, v VECTOR(4) NOT NULL, VECTOR INDEX vi(v));
SELECT *
FROM INFORMATION_SCHEMA.VECTOR_INDEXES
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_vec';
TABLE_CATALOG def
TABLE_SCHEMA test
TABLE_NAME t_vec
INDEX_NAME vi
VECTOR_DIMENSIONS 4
INDEX_SIZE 49152
TOTAL_NODES 1
CACHED_NODES 0
DELETED_ROWS 0
SUBDIST_ENABLED NO
MEMORY_SIZE 0
# After INSERT
INSERT INTO t_vec VALUES
(1, VEC_FromText('[1,1,1,1]')),
(2, VEC_FromText('[2,2,2,2]')),
(3, VEC_FromText('[3,3,3,3]'));
SELECT
INDEX_SIZE,
TOTAL_NODES,
CACHED_NODES,
DELETED_ROWS,
MEMORY_SIZE > 0 AS has_mem,
SUBDIST_ENABLED
FROM INFORMATION_SCHEMA.VECTOR_INDEXES
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_vec';
INDEX_SIZE 49152
TOTAL_NODES 3
CACHED_NODES 0
DELETED_ROWS 0
has_mem 0
SUBDIST_ENABLED NO
# After search
SELECT id FROM t_vec ORDER BY vec_distance_euclidean(v, VEC_FromText('[1,2,3,4]')) LIMIT 1;
id 3
SELECT TOTAL_NODES,
CACHED_NODES,
MEMORY_SIZE > 0 AS has_mem,
DELETED_ROWS
FROM INFORMATION_SCHEMA.VECTOR_INDEXES
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_vec';
TOTAL_NODES 3
CACHED_NODES 3
has_mem 1
DELETED_ROWS 0
# After FLUSH
FLUSH TABLES t_vec;
SELECT TABLE_NAME, INDEX_NAME, VECTOR_DIMENSIONS, SUBDIST_ENABLED, CACHED_NODES
FROM INFORMATION_SCHEMA.VECTOR_INDEXES
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_vec';
TABLE_NAME t_vec
INDEX_NAME vi
VECTOR_DIMENSIONS 4
SUBDIST_ENABLED NO
CACHED_NODES 0
# recover
SELECT id FROM t_vec ORDER BY vec_distance_euclidean(v, VEC_FromText('[1,2,3,4]')) LIMIT 1;
id 3
SELECT INDEX_SIZE,
TOTAL_NODES,
CACHED_NODES,
MEMORY_SIZE > 0 AS has_mem,
DELETED_ROWS
FROM INFORMATION_SCHEMA.VECTOR_INDEXES
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_vec';
INDEX_SIZE 49152
TOTAL_NODES 3
CACHED_NODES 3
has_mem 1
DELETED_ROWS 0
# DELETED_ROWS approximation
DELETE FROM t_vec WHERE id = 1;
SELECT TOTAL_NODES, CACHED_NODES, DELETED_ROWS
FROM INFORMATION_SCHEMA.VECTOR_INDEXES
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_vec';
TOTAL_NODES 3
CACHED_NODES 3
DELETED_ROWS 1
# VECTOR_DIMENSIONS
CREATE TABLE t_dim (pk INT PRIMARY KEY, v VECTOR(7) NOT NULL, VECTOR INDEX vi(v));
SELECT VECTOR_DIMENSIONS FROM INFORMATION_SCHEMA.VECTOR_INDEXES
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_dim';
VECTOR_DIMENSIONS 7
# SUBDIST_ENABLED=NO for dims below threshold (subdist_part*2=384)
SELECT SUBDIST_ENABLED FROM INFORMATION_SCHEMA.VECTOR_INDEXES
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_vec';
SUBDIST_ENABLED
NO
# SUBDIST_ENABLED=NULL (unknown) for dims >= 384
CREATE TABLE t_high (pk INT PRIMARY KEY, v VECTOR(384) NOT NULL, VECTOR INDEX vi(v));
INSERT INTO t_high VALUES (1, VEC_FromText(CONCAT('[', REPEAT('0,', 383), '0]')));
SELECT SUBDIST_ENABLED FROM INFORMATION_SCHEMA.VECTOR_INDEXES
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_high';
SUBDIST_ENABLED NULL
# Multiple tables visible and ordered
CREATE TABLE t_cos (pk INT PRIMARY KEY, v VECTOR(4) NOT NULL, VECTOR INDEX vi(v) distance=cosine);
INSERT INTO t_cos VALUES (1, VEC_FromText('[1,1,1,1]'));
SELECT TABLE_NAME, INDEX_NAME, VECTOR_DIMENSIONS
FROM INFORMATION_SCHEMA.VECTOR_INDEXES
WHERE TABLE_SCHEMA = DATABASE()
ORDER BY TABLE_NAME;
TABLE_NAME INDEX_NAME VECTOR_DIMENSIONS
t_cos vi 4
t_dim vi 7
t_high vi 384
t_vec vi 4
# get_all_tables optimization
FLUSH TABLES;
FLUSH STATUS;
SHOW STATUS LIKE 'open_table%';
Variable_name Value
Open_table_definitions 0
Open_tables 0
SELECT TABLE_SCHEMA, TABLE_NAME, INDEX_NAME
FROM INFORMATION_SCHEMA.VECTOR_INDEXES
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_cos';
TABLE_SCHEMA TABLE_NAME INDEX_NAME
test t_cos vi
SHOW STATUS LIKE 'open_table%';
Variable_name Value
Open_table_definitions 1
Open_tables 0
SELECT TABLE_SCHEMA, TABLE_NAME, INDEX_NAME, SUBDIST_ENABLED
FROM INFORMATION_SCHEMA.VECTOR_INDEXES
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_cos';
TABLE_SCHEMA TABLE_NAME INDEX_NAME SUBDIST_ENABLED
test t_cos vi NO
SHOW STATUS LIKE 'open_table%';
Variable_name Value
Open_table_definitions 1
Open_tables 1
# Dropping tables
DROP TABLE t_vec, t_cos, t_high, t_dim;
SELECT COUNT(*) FROM INFORMATION_SCHEMA.VECTOR_INDEXES
WHERE TABLE_SCHEMA = DATABASE();
COUNT(*) 0
# End of 13.1 tests
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.20 Sekunden
(vorverarbeitet am 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.