diff --git a/mysql-test/main/information_schema-big.result b/mysql-test/main/information_schema-big.result index 1989e04752512..1d716e01136cb 100644 --- a/mysql-test/main/information_schema-big.result +++ b/mysql-test/main/information_schema-big.result @@ -68,6 +68,7 @@ TRIGGERS TRIGGER_SCHEMA USERS USER USER_PRIVILEGES GRANTEE USER_STATISTICS USER +VECTOR_INDEXES TABLE_SCHEMA VIEWS TABLE_SCHEMA SELECT t.table_name, c1.column_name FROM information_schema.tables t @@ -136,4 +137,5 @@ TRIGGERS TRIGGER_SCHEMA USERS USER USER_PRIVILEGES GRANTEE USER_STATISTICS USER +VECTOR_INDEXES TABLE_SCHEMA VIEWS TABLE_SCHEMA diff --git a/mysql-test/main/information_schema-big_embedded.result b/mysql-test/main/information_schema-big_embedded.result index 9deca6caaec1c..4d7d67cdeeb17 100644 --- a/mysql-test/main/information_schema-big_embedded.result +++ b/mysql-test/main/information_schema-big_embedded.result @@ -67,6 +67,7 @@ TRIGGERS TRIGGER_SCHEMA USERS USER USER_PRIVILEGES GRANTEE USER_STATISTICS USER +VECTOR_INDEXES TABLE_SCHEMA VIEWS TABLE_SCHEMA SELECT t.table_name, c1.column_name FROM information_schema.tables t @@ -134,4 +135,5 @@ TRIGGERS TRIGGER_SCHEMA USERS USER USER_PRIVILEGES GRANTEE USER_STATISTICS USER +VECTOR_INDEXES TABLE_SCHEMA VIEWS TABLE_SCHEMA diff --git a/mysql-test/main/information_schema.result b/mysql-test/main/information_schema.result index f2796011ab538..67fbb15f1830e 100644 --- a/mysql-test/main/information_schema.result +++ b/mysql-test/main/information_schema.result @@ -101,6 +101,7 @@ TRIGGERS USERS USER_PRIVILEGES USER_STATISTICS +VECTOR_INDEXES VIEWS column_stats columns_priv @@ -1035,6 +1036,7 @@ TABLES TABLE_NAME select TABLE_CONSTRAINTS TABLE_NAME select TABLE_PRIVILEGES TABLE_NAME select TABLE_STATISTICS TABLE_NAME select +VECTOR_INDEXES TABLE_NAME select VIEWS TABLE_NAME select connection default; disconnect user10261; diff --git a/mysql-test/main/information_schema_all_engines.result b/mysql-test/main/information_schema_all_engines.result index 2d3c774c4cdca..f8421513e4a63 100644 --- a/mysql-test/main/information_schema_all_engines.result +++ b/mysql-test/main/information_schema_all_engines.result @@ -74,6 +74,7 @@ TRIGGERS USERS USER_PRIVILEGES USER_STATISTICS +VECTOR_INDEXES VIEWS SELECT t.table_name, c1.column_name FROM information_schema.tables t @@ -163,6 +164,7 @@ TRIGGERS TRIGGER_SCHEMA USERS USER USER_PRIVILEGES GRANTEE USER_STATISTICS USER +VECTOR_INDEXES TABLE_SCHEMA VIEWS TABLE_SCHEMA SELECT t.table_name, c1.column_name FROM information_schema.tables t @@ -252,6 +254,7 @@ TRIGGERS TRIGGER_SCHEMA USERS USER USER_PRIVILEGES GRANTEE USER_STATISTICS USER +VECTOR_INDEXES TABLE_SCHEMA VIEWS TABLE_SCHEMA select 1 as "must be 1" from information_schema.tables where "ACCOUNTS"= (select cast(table_name as char) from information_schema.tables @@ -339,6 +342,7 @@ TRIGGERS information_schema.TRIGGERS 1 USERS information_schema.USERS 1 USER_PRIVILEGES information_schema.USER_PRIVILEGES 1 USER_STATISTICS information_schema.USER_STATISTICS 1 +VECTOR_INDEXES information_schema.VECTOR_INDEXES 1 VIEWS information_schema.VIEWS 1 +---------------------------------------+ +---------------------------------------+ @@ -418,6 +422,7 @@ Database: information_schema | USERS | | USER_PRIVILEGES | | USER_STATISTICS | +| VECTOR_INDEXES | | VIEWS | +---------------------------------------+ +---------------------------------------+ @@ -497,6 +502,7 @@ Database: INFORMATION_SCHEMA | USERS | | USER_PRIVILEGES | | USER_STATISTICS | +| VECTOR_INDEXES | | VIEWS | +--------------------+ +--------------------+ @@ -506,5 +512,5 @@ Wildcard: inf_rmation_schema | information_schema | SELECT table_schema, count(*) FROM information_schema.TABLES WHERE table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test', 'mysqltest') GROUP BY TABLE_SCHEMA; table_schema count(*) -information_schema 74 +information_schema 75 mysql 31 diff --git a/mysql-test/main/vector,aria.rdiff b/mysql-test/main/vector,aria.rdiff index 521d226938478..14ba2716d3dd1 100644 --- a/mysql-test/main/vector,aria.rdiff +++ b/mysql-test/main/vector,aria.rdiff @@ -7,7 +7,7 @@ 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)); -@@ -12,7 +12,7 @@ t1 CREATE TABLE `t1` ( +@@ -12,7 +12,7 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -16,7 +16,7 @@ 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 -@@ -27,7 +27,7 @@ t1 CREATE TABLE `t1` ( +@@ -27,7 +27,7 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) `m`='7' @@ -25,7 +25,7 @@ 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 -@@ -42,7 +42,7 @@ t1 CREATE TABLE `t1` ( +@@ -42,7 +42,7 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) `m`='5' @@ -34,7 +34,7 @@ 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 -@@ -343,7 +343,7 @@ t2 CREATE TABLE `t2` ( +@@ -346,7 +346,7 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -43,7 +43,7 @@ drop table t1, t2; db.opt # Test insert ... select with vector index -@@ -388,8 +388,32 @@ db.opt +@@ -391,8 +391,32 @@ 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; @@ -76,7 +76,7 @@ insert t1 (id, v) values (1, x'e360d63ebe554f3fcdbc523f4522193f5236083d'); select id, hex(v) from t1; id hex(v) -@@ -401,33 +425,39 @@ t1 CREATE TABLE `t1` ( +@@ -404,33 +428,39 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -126,7 +126,7 @@ drop database test1; db.opt # -@@ -442,7 +472,7 @@ t1 CREATE TABLE `t1` ( +@@ -445,7 +475,7 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) `distance`='cosine' @@ -135,7 +135,7 @@ insert t1 (v) values (x'e360d63ebe554f3fcdbc523f4522193f5236083d'), (x'f511303f72224a3fdd05fe3eb22a133ffae86a3f'), (x'f09baa3ea172763f123def3e0c7fe53e288bf33e'), -@@ -504,9 +534,11 @@ insert t1 (v) values (x'e360d63ebe554f3fcdbc523f4522193f5236083d'), +@@ -507,9 +537,11 @@ # ADD/DROP COLUMN, ALGORITHM=COPY alter table t1 add column a int, algorithm=copy; db.opt @@ -149,7 +149,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -515,12 +547,14 @@ t1 CREATE TABLE `t1` ( +@@ -518,12 +550,14 @@ `a` int(11) DEFAULT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -167,7 +167,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -528,13 +562,15 @@ t1 CREATE TABLE `t1` ( +@@ -531,13 +565,15 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -186,7 +186,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -543,12 +579,14 @@ t1 CREATE TABLE `t1` ( +@@ -546,12 +582,14 @@ PRIMARY KEY (`id`), KEY `a` (`id`), VECTOR KEY `v` (`v`) @@ -204,7 +204,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -556,13 +594,15 @@ t1 CREATE TABLE `t1` ( +@@ -559,13 +597,15 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -223,7 +223,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -571,12 +611,14 @@ t1 CREATE TABLE `t1` ( +@@ -574,12 +614,14 @@ PRIMARY KEY (`id`), KEY `a` (`id`), VECTOR KEY `v` (`v`) @@ -241,7 +241,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -584,13 +626,15 @@ t1 CREATE TABLE `t1` ( +@@ -587,13 +629,15 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -260,7 +260,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -599,12 +643,14 @@ t1 CREATE TABLE `t1` ( +@@ -602,12 +646,14 @@ `a` int(11) DEFAULT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -278,7 +278,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -612,24 +658,27 @@ t1 CREATE TABLE `t1` ( +@@ -615,24 +661,27 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -311,7 +311,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -637,24 +686,27 @@ t1 CREATE TABLE `t1` ( +@@ -640,24 +689,27 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -344,7 +344,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -662,7 +714,7 @@ t1 CREATE TABLE `t1` ( +@@ -665,7 +717,7 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -353,7 +353,7 @@ # ADD/DROP INDEX, ALGORITHM=INPLACE (non-vector) alter table t1 add index a(id), algorithm=inplace; ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY -@@ -685,31 +737,15 @@ ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITH +@@ -688,31 +740,15 @@ alter table t1 modify column v vector(7) not null, algorithm=inplace; ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY # ADD/CHANGE/DROP/MODIFY COLUMN, ALGORITHM=INPLACE (non-vector) @@ -389,7 +389,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -717,13 +753,15 @@ t1 CREATE TABLE `t1` ( +@@ -720,13 +756,15 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -408,7 +408,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -731,14 +769,16 @@ t1 CREATE TABLE `t1` ( +@@ -734,14 +772,16 @@ `w` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`w`) @@ -428,7 +428,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -746,7 +786,7 @@ t1 CREATE TABLE `t1` ( +@@ -749,7 +789,7 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `w` (`v`) @@ -437,7 +437,7 @@ alter table t1 rename key w to v; # IF [NOT] EXISTS create vector index if not exists v on t1(v); -@@ -757,77 +797,22 @@ drop index if exists v on t1; +@@ -760,77 +800,22 @@ Warnings: Note 1091 Can't DROP INDEX `v`; check that it exists db.opt @@ -518,7 +518,7 @@ # CHANGE/MODIFY/DROP COLUMN (vector) alter table t1 modify column v int; ERROR HY000: Incorrect arguments to VECTOR INDEX -@@ -839,9 +824,11 @@ alter table t1 change column v v vector(6); +@@ -842,9 +827,11 @@ ERROR 42000: All parts of a VECTOR index must be NOT NULL alter table t1 modify column v vector(7) not null; db.opt @@ -532,7 +532,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -849,12 +836,14 @@ t1 CREATE TABLE `t1` ( +@@ -852,12 +839,14 @@ `v` vector(7) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -550,7 +550,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -862,17 +851,18 @@ t1 CREATE TABLE `t1` ( +@@ -865,17 +854,18 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -572,10 +572,47 @@ drop table t1; create table t1(v vector(5) not null, vector index(v)); alter table t1 add column a int; -@@ -889,5 +879,5 @@ Table Create Table +@@ -892,7 +882,7 @@ 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 +) ENGINE=Aria DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci PAGE_CHECKSUM=1 drop table t; + # + # MDEV-35821 - vector index sizes are not in INDEX_LENGTH +@@ -929,8 +919,8 @@ + TABLE_NAME t_vec + INDEX_NAME vi + VECTOR_DIMENSIONS 4 +-INDEX_SIZE 49152 +-TOTAL_NODES 1 ++INDEX_SIZE 16384 ++TOTAL_NODES 0 + CACHED_NODES 0 + DELETED_ROWS 0 + SUBDIST_ENABLED NO +@@ -949,11 +939,11 @@ + SUBDIST_ENABLED + FROM INFORMATION_SCHEMA.VECTOR_INDEXES + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_vec'; +-INDEX_SIZE 49152 ++INDEX_SIZE 40960 + TOTAL_NODES 3 +-CACHED_NODES 0 ++CACHED_NODES 3 + DELETED_ROWS 0 +-has_mem 0 ++has_mem 1 + SUBDIST_ENABLED NO + # After search + SELECT id FROM t_vec ORDER BY vec_distance_euclidean(v, VEC_FromText('[1,2,3,4]')) LIMIT 1; +@@ -990,7 +980,7 @@ + DELETED_ROWS + FROM INFORMATION_SCHEMA.VECTOR_INDEXES + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_vec'; +-INDEX_SIZE 49152 ++INDEX_SIZE 40960 + TOTAL_NODES 3 + CACHED_NODES 3 + has_mem 1 diff --git a/mysql-test/main/vector,myisam.rdiff b/mysql-test/main/vector,myisam.rdiff index 59a30dd1ee52c..e79d4c25bd409 100644 --- a/mysql-test/main/vector,myisam.rdiff +++ b/mysql-test/main/vector,myisam.rdiff @@ -1,6 +1,6 @@ ---- vector.result -+++ vector,myisam.reject -@@ -388,8 +388,30 @@ +--- a/mysql-test/main/vector.result ++++ b/mysql-test/main/vector.result +@@ -391,8 +391,30 @@ 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; @@ -31,7 +31,7 @@ insert t1 (id, v) values (1, x'e360d63ebe554f3fcdbc523f4522193f5236083d'); select id, hex(v) from t1; id hex(v) -@@ -407,27 +429,33 @@ +@@ -410,27 +432,33 @@ # 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 @@ -74,7 +74,7 @@ drop database test1; db.opt # -@@ -504,9 +532,11 @@ +@@ -507,9 +535,11 @@ # ADD/DROP COLUMN, ALGORITHM=COPY alter table t1 add column a int, algorithm=copy; db.opt @@ -88,7 +88,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -515,12 +545,14 @@ +@@ -518,12 +548,14 @@ `a` int(11) DEFAULT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -106,7 +106,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -528,13 +560,15 @@ +@@ -531,13 +563,15 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -125,7 +125,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -543,12 +577,14 @@ +@@ -546,12 +580,14 @@ PRIMARY KEY (`id`), KEY `a` (`id`), VECTOR KEY `v` (`v`) @@ -143,7 +143,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -556,13 +592,15 @@ +@@ -559,13 +595,15 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -162,7 +162,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -571,12 +609,14 @@ +@@ -574,12 +612,14 @@ PRIMARY KEY (`id`), KEY `a` (`id`), VECTOR KEY `v` (`v`) @@ -180,7 +180,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -584,13 +624,15 @@ +@@ -587,13 +627,15 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -199,7 +199,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -599,12 +641,14 @@ +@@ -602,12 +644,14 @@ `a` int(11) DEFAULT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -217,7 +217,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -612,24 +656,27 @@ +@@ -615,24 +659,27 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -250,7 +250,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -637,24 +684,27 @@ +@@ -640,24 +687,27 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -283,7 +283,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -662,7 +712,7 @@ +@@ -665,7 +715,7 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -292,7 +292,7 @@ # ADD/DROP INDEX, ALGORITHM=INPLACE (non-vector) alter table t1 add index a(id), algorithm=inplace; ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY -@@ -685,31 +735,15 @@ +@@ -688,31 +738,15 @@ alter table t1 modify column v vector(7) not null, algorithm=inplace; ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY # ADD/CHANGE/DROP/MODIFY COLUMN, ALGORITHM=INPLACE (non-vector) @@ -328,7 +328,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -717,13 +751,15 @@ +@@ -720,13 +754,15 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -347,7 +347,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -731,14 +767,16 @@ +@@ -734,14 +770,16 @@ `w` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`w`) @@ -367,7 +367,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -746,7 +784,7 @@ +@@ -749,7 +787,7 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `w` (`v`) @@ -376,7 +376,7 @@ alter table t1 rename key w to v; # IF [NOT] EXISTS create vector index if not exists v on t1(v); -@@ -757,77 +795,22 @@ +@@ -760,77 +798,22 @@ Warnings: Note 1091 Can't DROP INDEX `v`; check that it exists db.opt @@ -457,7 +457,7 @@ # CHANGE/MODIFY/DROP COLUMN (vector) alter table t1 modify column v int; ERROR HY000: Incorrect arguments to VECTOR INDEX -@@ -839,9 +822,11 @@ +@@ -842,9 +825,11 @@ ERROR 42000: All parts of a VECTOR index must be NOT NULL alter table t1 modify column v vector(7) not null; db.opt @@ -471,7 +471,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -849,12 +834,14 @@ +@@ -852,12 +837,14 @@ `v` vector(7) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -489,7 +489,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( -@@ -862,17 +849,18 @@ +@@ -865,17 +852,18 @@ `v` vector(5) NOT NULL, PRIMARY KEY (`id`), VECTOR KEY `v` (`v`) @@ -511,10 +511,47 @@ drop table t1; create table t1(v vector(5) not null, vector index(v)); alter table t1 add column a int; -@@ -889,5 +877,5 @@ +@@ -892,7 +880,7 @@ 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 +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci drop table t; + # + # MDEV-35821 - vector index sizes are not in INDEX_LENGTH +@@ -929,8 +917,8 @@ + TABLE_NAME t_vec + INDEX_NAME vi + VECTOR_DIMENSIONS 4 +-INDEX_SIZE 49152 +-TOTAL_NODES 1 ++INDEX_SIZE 1024 ++TOTAL_NODES 0 + CACHED_NODES 0 + DELETED_ROWS 0 + SUBDIST_ENABLED NO +@@ -949,11 +937,11 @@ + SUBDIST_ENABLED + FROM INFORMATION_SCHEMA.VECTOR_INDEXES + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_vec'; +-INDEX_SIZE 49152 ++INDEX_SIZE 3244 + TOTAL_NODES 3 +-CACHED_NODES 0 ++CACHED_NODES 3 + DELETED_ROWS 0 +-has_mem 0 ++has_mem 1 + SUBDIST_ENABLED NO + # After search + SELECT id FROM t_vec ORDER BY vec_distance_euclidean(v, VEC_FromText('[1,2,3,4]')) LIMIT 1; +@@ -990,7 +978,7 @@ + DELETED_ROWS + FROM INFORMATION_SCHEMA.VECTOR_INDEXES + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_vec'; +-INDEX_SIZE 49152 ++INDEX_SIZE 3244 + TOTAL_NODES 3 + CACHED_NODES 3 + has_mem 1 diff --git a/mysql-test/main/vector.result b/mysql-test/main/vector.result index 1c2542187e399..868388912e428 100644 --- a/mysql-test/main/vector.result +++ b/mysql-test/main/vector.result @@ -911,3 +911,156 @@ 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 MDEV-34805 tests diff --git a/mysql-test/main/vector.test b/mysql-test/main/vector.test index 161d26120737d..a76519bb615b2 100644 --- a/mysql-test/main/vector.test +++ b/mysql-test/main/vector.test @@ -459,3 +459,112 @@ from information_schema.tables where table_schema = database() and table_name = 't1'; drop table t1; + +--source include/have_innodb.inc + +--echo # +--echo # MDEV-34805 INFORMATION_SCHEMA.VECTOR_INDEXES +--echo # + +--echo # No vector tables yet in this schema +SELECT COUNT(*) FROM INFORMATION_SCHEMA.VECTOR_INDEXES + WHERE TABLE_SCHEMA = DATABASE(); + +--echo # On empty table +CREATE TABLE t_vec (id INT PRIMARY KEY, v VECTOR(4) NOT NULL, VECTOR INDEX vi(v)); +query_vertical SELECT * + FROM INFORMATION_SCHEMA.VECTOR_INDEXES + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_vec'; + +--echo # 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]')); + +query_vertical 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'; + +--echo # After search +SELECT id FROM t_vec ORDER BY vec_distance_euclidean(v, VEC_FromText('[1,2,3,4]')) LIMIT 1; + +query_vertical 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'; + +--echo # After FLUSH +FLUSH TABLES t_vec; + +query_vertical 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'; + +--echo # recover +SELECT id FROM t_vec ORDER BY vec_distance_euclidean(v, VEC_FromText('[1,2,3,4]')) LIMIT 1; + +query_vertical 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'; + +--echo # DELETED_ROWS approximation +DELETE FROM t_vec WHERE id = 1; +query_vertical SELECT TOTAL_NODES, CACHED_NODES, DELETED_ROWS + FROM INFORMATION_SCHEMA.VECTOR_INDEXES + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_vec'; + +--echo # 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'; + +--echo # 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'; + +--echo # 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]'))); +query_vertical SELECT SUBDIST_ENABLED FROM INFORMATION_SCHEMA.VECTOR_INDEXES + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_high'; + +--echo # 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; + +--echo # get_all_tables optimization +FLUSH TABLES; +FLUSH STATUS; +SHOW STATUS LIKE 'open_table%'; +SELECT TABLE_SCHEMA, TABLE_NAME, INDEX_NAME +FROM INFORMATION_SCHEMA.VECTOR_INDEXES + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_cos'; +SHOW STATUS LIKE 'open_table%'; +SELECT TABLE_SCHEMA, TABLE_NAME, INDEX_NAME, SUBDIST_ENABLED +FROM INFORMATION_SCHEMA.VECTOR_INDEXES + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 't_cos'; +SHOW STATUS LIKE 'open_table%'; + +--echo # Dropping tables +DROP TABLE t_vec, t_cos, t_high, t_dim; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.VECTOR_INDEXES + WHERE TABLE_SCHEMA = DATABASE(); + +--echo # End of MDEV-34805 tests diff --git a/mysql-test/suite/funcs_1/r/is_columns_is.result b/mysql-test/suite/funcs_1/r/is_columns_is.result index c9fa3052856e9..1c39af5d2a748 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_is.result +++ b/mysql-test/suite/funcs_1/r/is_columns_is.result @@ -620,6 +620,17 @@ def information_schema USER_STATISTICS TOTAL_CONNECTIONS 2 NULL NO int NULL NULL def information_schema USER_STATISTICS TOTAL_SSL_CONNECTIONS 26 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(21) unsigned select NEVER NULL NO NO def information_schema USER_STATISTICS UPDATE_COMMANDS 18 NULL NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select NEVER NULL NO NO def information_schema USER_STATISTICS USER 1 NULL NO varchar 128 384 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(128) select NEVER NULL NO NO +def information_schema VECTOR_INDEXES CACHED_NODES 8 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(19) unsigned select NEVER NULL NO NO +def information_schema VECTOR_INDEXES DELETED_ROWS 9 NULL YES bigint NULL NULL 20 0 NULL NULL NULL bigint(19) unsigned select NEVER NULL NO NO +def information_schema VECTOR_INDEXES INDEX_NAME 4 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select NEVER NULL NO NO +def information_schema VECTOR_INDEXES INDEX_SIZE 6 NULL YES bigint NULL NULL 20 0 NULL NULL NULL bigint(19) unsigned select NEVER NULL NO NO +def information_schema VECTOR_INDEXES MEMORY_SIZE 11 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(19) unsigned select NEVER NULL NO NO +def information_schema VECTOR_INDEXES SUBDIST_ENABLED 10 NULL YES varchar 3 9 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(3) select NEVER NULL NO NO +def information_schema VECTOR_INDEXES TABLE_CATALOG 1 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select NEVER NULL NO NO +def information_schema VECTOR_INDEXES TABLE_NAME 3 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select NEVER NULL NO NO +def information_schema VECTOR_INDEXES TABLE_SCHEMA 2 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) select NEVER NULL NO NO +def information_schema VECTOR_INDEXES TOTAL_NODES 7 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(19) unsigned select NEVER NULL NO NO +def information_schema VECTOR_INDEXES VECTOR_DIMENSIONS 5 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned select NEVER NULL NO NO def information_schema VIEWS ALGORITHM 11 NULL NO varchar 10 30 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(10) select NEVER NULL NO NO def information_schema VIEWS CHARACTER_SET_CLIENT 9 NULL NO varchar 32 96 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(32) select NEVER NULL NO NO def information_schema VIEWS CHECK_OPTION 5 NULL NO varchar 8 24 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(8) select NEVER NULL NO NO @@ -1315,6 +1326,17 @@ NULL information_schema USER_STATISTICS ACCESS_DENIED bigint NULL NULL NULL NULL NULL information_schema USER_STATISTICS EMPTY_QUERIES bigint NULL NULL NULL NULL bigint(21) NULL information_schema USER_STATISTICS TOTAL_SSL_CONNECTIONS bigint NULL NULL NULL NULL bigint(21) unsigned NULL information_schema USER_STATISTICS MAX_STATEMENT_TIME_EXCEEDED bigint NULL NULL NULL NULL bigint(21) +3.0000 information_schema VECTOR_INDEXES TABLE_CATALOG varchar 64 192 utf8mb3 utf8mb3_general_ci varchar(64) +3.0000 information_schema VECTOR_INDEXES TABLE_SCHEMA varchar 64 192 utf8mb3 utf8mb3_general_ci varchar(64) +3.0000 information_schema VECTOR_INDEXES TABLE_NAME varchar 64 192 utf8mb3 utf8mb3_general_ci varchar(64) +3.0000 information_schema VECTOR_INDEXES INDEX_NAME varchar 64 192 utf8mb3 utf8mb3_general_ci varchar(64) +NULL information_schema VECTOR_INDEXES VECTOR_DIMENSIONS int NULL NULL NULL NULL int(10) unsigned +NULL information_schema VECTOR_INDEXES INDEX_SIZE bigint NULL NULL NULL NULL bigint(19) unsigned +NULL information_schema VECTOR_INDEXES TOTAL_NODES bigint NULL NULL NULL NULL bigint(19) unsigned +NULL information_schema VECTOR_INDEXES CACHED_NODES bigint NULL NULL NULL NULL bigint(19) unsigned +NULL information_schema VECTOR_INDEXES DELETED_ROWS bigint NULL NULL NULL NULL bigint(19) unsigned +3.0000 information_schema VECTOR_INDEXES SUBDIST_ENABLED varchar 3 9 utf8mb3 utf8mb3_general_ci varchar(3) +NULL information_schema VECTOR_INDEXES MEMORY_SIZE bigint NULL NULL NULL NULL bigint(19) unsigned 3.0000 information_schema VIEWS TABLE_CATALOG varchar 512 1536 utf8mb3 utf8mb3_general_ci varchar(512) 3.0000 information_schema VIEWS TABLE_SCHEMA varchar 64 192 utf8mb3 utf8mb3_general_ci varchar(64) 3.0000 information_schema VIEWS TABLE_NAME varchar 64 192 utf8mb3 utf8mb3_general_ci varchar(64) diff --git a/mysql-test/suite/funcs_1/r/is_columns_is_embedded.result b/mysql-test/suite/funcs_1/r/is_columns_is_embedded.result index 771868a28ca92..8b00b8614d4a9 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_is_embedded.result +++ b/mysql-test/suite/funcs_1/r/is_columns_is_embedded.result @@ -553,6 +553,17 @@ def information_schema USER_STATISTICS TOTAL_CONNECTIONS 2 NULL NO int NULL NULL def information_schema USER_STATISTICS TOTAL_SSL_CONNECTIONS 26 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(21) unsigned NEVER NULL NO NO def information_schema USER_STATISTICS UPDATE_COMMANDS 18 NULL NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) NEVER NULL NO NO def information_schema USER_STATISTICS USER 1 NULL NO varchar 128 384 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(128) NEVER NULL NO NO +def information_schema VECTOR_INDEXES CACHED_NODES 8 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(19) unsigned NEVER NULL NO NO +def information_schema VECTOR_INDEXES DELETED_ROWS 9 NULL YES bigint NULL NULL 20 0 NULL NULL NULL bigint(19) unsigned NEVER NULL NO NO +def information_schema VECTOR_INDEXES INDEX_NAME 4 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) NEVER NULL NO NO +def information_schema VECTOR_INDEXES INDEX_SIZE 6 NULL YES bigint NULL NULL 20 0 NULL NULL NULL bigint(19) unsigned NEVER NULL NO NO +def information_schema VECTOR_INDEXES MEMORY_SIZE 11 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(19) unsigned NEVER NULL NO NO +def information_schema VECTOR_INDEXES SUBDIST_ENABLED 10 NULL YES varchar 3 9 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(3) NEVER NULL NO NO +def information_schema VECTOR_INDEXES TABLE_CATALOG 1 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) NEVER NULL NO NO +def information_schema VECTOR_INDEXES TABLE_NAME 3 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) NEVER NULL NO NO +def information_schema VECTOR_INDEXES TABLE_SCHEMA 2 NULL NO varchar 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(64) NEVER NULL NO NO +def information_schema VECTOR_INDEXES TOTAL_NODES 7 NULL NO bigint NULL NULL 20 0 NULL NULL NULL bigint(19) unsigned NEVER NULL NO NO +def information_schema VECTOR_INDEXES VECTOR_DIMENSIONS 5 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned NEVER NULL NO NO def information_schema VIEWS ALGORITHM 11 NULL NO varchar 10 30 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(10) NEVER NULL NO NO def information_schema VIEWS CHARACTER_SET_CLIENT 9 NULL NO varchar 32 96 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(32) NEVER NULL NO NO def information_schema VIEWS CHECK_OPTION 5 NULL NO varchar 8 24 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(8) NEVER NULL NO NO @@ -1180,6 +1191,17 @@ NULL information_schema USER_STATISTICS ACCESS_DENIED bigint NULL NULL NULL NULL NULL information_schema USER_STATISTICS EMPTY_QUERIES bigint NULL NULL NULL NULL bigint(21) NULL information_schema USER_STATISTICS TOTAL_SSL_CONNECTIONS bigint NULL NULL NULL NULL bigint(21) unsigned NULL information_schema USER_STATISTICS MAX_STATEMENT_TIME_EXCEEDED bigint NULL NULL NULL NULL bigint(21) +3.0000 information_schema VECTOR_INDEXES TABLE_CATALOG varchar 64 192 utf8mb3 utf8mb3_general_ci varchar(64) +3.0000 information_schema VECTOR_INDEXES TABLE_SCHEMA varchar 64 192 utf8mb3 utf8mb3_general_ci varchar(64) +3.0000 information_schema VECTOR_INDEXES TABLE_NAME varchar 64 192 utf8mb3 utf8mb3_general_ci varchar(64) +3.0000 information_schema VECTOR_INDEXES INDEX_NAME varchar 64 192 utf8mb3 utf8mb3_general_ci varchar(64) +NULL information_schema VECTOR_INDEXES VECTOR_DIMENSIONS int NULL NULL NULL NULL int(10) unsigned +NULL information_schema VECTOR_INDEXES INDEX_SIZE bigint NULL NULL NULL NULL bigint(19) unsigned +NULL information_schema VECTOR_INDEXES TOTAL_NODES bigint NULL NULL NULL NULL bigint(19) unsigned +NULL information_schema VECTOR_INDEXES CACHED_NODES bigint NULL NULL NULL NULL bigint(19) unsigned +NULL information_schema VECTOR_INDEXES DELETED_ROWS bigint NULL NULL NULL NULL bigint(19) unsigned +3.0000 information_schema VECTOR_INDEXES SUBDIST_ENABLED varchar 3 9 utf8mb3 utf8mb3_general_ci varchar(3) +NULL information_schema VECTOR_INDEXES MEMORY_SIZE bigint NULL NULL NULL NULL bigint(19) unsigned 3.0000 information_schema VIEWS TABLE_CATALOG varchar 512 1536 utf8mb3 utf8mb3_general_ci varchar(512) 3.0000 information_schema VIEWS TABLE_SCHEMA varchar 64 192 utf8mb3 utf8mb3_general_ci varchar(64) 3.0000 information_schema VIEWS TABLE_NAME varchar 64 192 utf8mb3 utf8mb3_general_ci varchar(64) diff --git a/mysql-test/suite/funcs_1/r/is_tables_is.result b/mysql-test/suite/funcs_1/r/is_tables_is.result index b8f15d43fdb6c..18000522544ae 100644 --- a/mysql-test/suite/funcs_1/r/is_tables_is.result +++ b/mysql-test/suite/funcs_1/r/is_tables_is.result @@ -1289,6 +1289,31 @@ user_comment Separator ----------------------------------------------------- TABLE_CATALOG def TABLE_SCHEMA information_schema +TABLE_NAME VECTOR_INDEXES +TABLE_TYPE SYSTEM VIEW +ENGINE MEMORY +VERSION 11 +ROW_FORMAT Fixed +TABLE_ROWS #TBLR# +AVG_ROW_LENGTH #ARL# +DATA_LENGTH #DL# +MAX_DATA_LENGTH #MDL# +INDEX_LENGTH #IL# +DATA_FREE #DF# +AUTO_INCREMENT NULL +CREATE_TIME #CRT# +UPDATE_TIME #UT# +CHECK_TIME #CT# +TABLE_COLLATION utf8mb3_general_ci +CHECKSUM NULL +CREATE_OPTIONS #CO# +TABLE_COMMENT #TC# +MAX_INDEX_LENGTH #MIL# +TEMPORARY Y +user_comment +Separator ----------------------------------------------------- +TABLE_CATALOG def +TABLE_SCHEMA information_schema TABLE_NAME VIEWS TABLE_TYPE SYSTEM VIEW ENGINE MYISAM_OR_MARIA @@ -2605,6 +2630,31 @@ user_comment Separator ----------------------------------------------------- TABLE_CATALOG def TABLE_SCHEMA information_schema +TABLE_NAME VECTOR_INDEXES +TABLE_TYPE SYSTEM VIEW +ENGINE MEMORY +VERSION 11 +ROW_FORMAT Fixed +TABLE_ROWS #TBLR# +AVG_ROW_LENGTH #ARL# +DATA_LENGTH #DL# +MAX_DATA_LENGTH #MDL# +INDEX_LENGTH #IL# +DATA_FREE #DF# +AUTO_INCREMENT NULL +CREATE_TIME #CRT# +UPDATE_TIME #UT# +CHECK_TIME #CT# +TABLE_COLLATION utf8mb3_general_ci +CHECKSUM NULL +CREATE_OPTIONS #CO# +TABLE_COMMENT #TC# +MAX_INDEX_LENGTH #MIL# +TEMPORARY Y +user_comment +Separator ----------------------------------------------------- +TABLE_CATALOG def +TABLE_SCHEMA information_schema TABLE_NAME VIEWS TABLE_TYPE SYSTEM VIEW ENGINE MYISAM_OR_MARIA diff --git a/mysql-test/suite/funcs_1/r/is_tables_is_embedded.result b/mysql-test/suite/funcs_1/r/is_tables_is_embedded.result index 4b43f74a53a63..46b022e9f70c7 100644 --- a/mysql-test/suite/funcs_1/r/is_tables_is_embedded.result +++ b/mysql-test/suite/funcs_1/r/is_tables_is_embedded.result @@ -1264,6 +1264,31 @@ user_comment Separator ----------------------------------------------------- TABLE_CATALOG def TABLE_SCHEMA information_schema +TABLE_NAME VECTOR_INDEXES +TABLE_TYPE SYSTEM VIEW +ENGINE MEMORY +VERSION 11 +ROW_FORMAT Fixed +TABLE_ROWS #TBLR# +AVG_ROW_LENGTH #ARL# +DATA_LENGTH #DL# +MAX_DATA_LENGTH #MDL# +INDEX_LENGTH #IL# +DATA_FREE #DF# +AUTO_INCREMENT NULL +CREATE_TIME #CRT# +UPDATE_TIME #UT# +CHECK_TIME #CT# +TABLE_COLLATION utf8mb3_general_ci +CHECKSUM NULL +CREATE_OPTIONS #CO# +TABLE_COMMENT #TC# +MAX_INDEX_LENGTH #MIL# +TEMPORARY Y +user_comment +Separator ----------------------------------------------------- +TABLE_CATALOG def +TABLE_SCHEMA information_schema TABLE_NAME VIEWS TABLE_TYPE SYSTEM VIEW ENGINE MYISAM_OR_MARIA @@ -2555,6 +2580,31 @@ user_comment Separator ----------------------------------------------------- TABLE_CATALOG def TABLE_SCHEMA information_schema +TABLE_NAME VECTOR_INDEXES +TABLE_TYPE SYSTEM VIEW +ENGINE MEMORY +VERSION 11 +ROW_FORMAT Fixed +TABLE_ROWS #TBLR# +AVG_ROW_LENGTH #ARL# +DATA_LENGTH #DL# +MAX_DATA_LENGTH #MDL# +INDEX_LENGTH #IL# +DATA_FREE #DF# +AUTO_INCREMENT NULL +CREATE_TIME #CRT# +UPDATE_TIME #UT# +CHECK_TIME #CT# +TABLE_COLLATION utf8mb3_general_ci +CHECKSUM NULL +CREATE_OPTIONS #CO# +TABLE_COMMENT #TC# +MAX_INDEX_LENGTH #MIL# +TEMPORARY Y +user_comment +Separator ----------------------------------------------------- +TABLE_CATALOG def +TABLE_SCHEMA information_schema TABLE_NAME VIEWS TABLE_TYPE SYSTEM VIEW ENGINE MYISAM_OR_MARIA diff --git a/sql/vector_mhnsw.cc b/sql/vector_mhnsw.cc index c480c36c7e7ad..c6248912093c3 100644 --- a/sql/vector_mhnsw.cc +++ b/sql/vector_mhnsw.cc @@ -23,6 +23,7 @@ #include #include #include "bloom_filters.h" +#include // distance can be a little bit < 0 because of fast math static constexpr float NEAREST = -1.0f; @@ -36,6 +37,8 @@ static constexpr float subdist_margin= 1.05f; static constexpr double subdist_stddev_threshold= 0.05; // 3σ, p>99.9% static constexpr ulonglong subdist_stddev_valid= 10000; // sufficient +static bool maybe_use_subdist(size_t dims) { return dims >= subdist_part * 2; } + /* The class below can assume normal distribution and only collect M1 and M2, or go beyond that and collect M3 and M4 to account @@ -502,6 +505,8 @@ class MHNSW_Share : public Sql_alloc public: ulonglong version= 0; // protected by commit_lock mysql_rwlock_t commit_lock; + Atomic_relaxed cache_overflow_count{0}; + size_t vec_len= 0; size_t byte_len= 0; FVectorNode *start= 0; @@ -555,7 +560,7 @@ class MHNSW_Share : public Sql_alloc { byte_len= len; vec_len= len / sizeof(float); - use_subdist= vec_len >= subdist_part * 2; + use_subdist= maybe_use_subdist(vec_len); } static int acquire(MHNSW_Share **ctx, TABLE *table, bool for_update); @@ -582,7 +587,10 @@ class MHNSW_Share : public Sql_alloc if (can_commit) mysql_rwlock_unlock(&commit_lock); if (root_size(&root) > mhnsw_max_cache_size) + { + cache_overflow_count.fetch_add(1); reset(share); + } if (--refcnt == 0) this->~MHNSW_Share(); // XXX reuse } @@ -643,11 +651,20 @@ class MHNSW_Share : public Sql_alloc return p; } - void read_stats(Stats *out) + dgt_mode read_stats(Stats *out) { mysql_mutex_lock(&cache_lock); *out= stats; mysql_mutex_unlock(&cache_lock); + if (use_subdist) + { + if (out->subdist.n > subdist_stddev_valid) + return out->subdist.stddev() < subdist_stddev_threshold + ? STAT_SUBDIST : NOSTAT_NOSUBDIST; + else + return STAT_NOSUBDIST; + } + return NOSTAT_NOSUBDIST; } void set_stats(size_t graph_size) @@ -666,6 +683,13 @@ class MHNSW_Share : public Sql_alloc stats.subdist.add(addend.subdist); mysql_mutex_unlock(&cache_lock); } + void get_cache_info(size_t *nodes, size_t *mem_size) + { + mysql_mutex_lock(&cache_lock); + *nodes= node_cache.size(); + *mem_size= root_size(&root); + mysql_mutex_unlock(&cache_lock); + } }; /* @@ -1072,20 +1096,10 @@ struct MHNSW_param : ctx(ctx), graph(graph), layer(layer) { Stats stats; - ctx->read_stats(&stats); + mode= ctx->read_stats(&stats); max_est_size= stats.graph_size/1.3; acc.diameter= stats.diameter; acc.ef_power= stats.ef_power; - if (ctx->use_subdist) - { - if (stats.subdist.n > subdist_stddev_valid) - mode= stats.subdist.stddev() < subdist_stddev_threshold - ? STAT_SUBDIST : NOSTAT_NOSUBDIST; - else - mode= STAT_NOSUBDIST; - } - else - mode= NOSTAT_NOSUBDIST; } }; @@ -1794,6 +1808,174 @@ static struct st_mysql_sys_var *mhnsw_sys_vars[]= NULL }; +//IS table + +namespace Show { + +static ST_FIELD_INFO vector_indexes_fields[] = +{ + Column("TABLE_CATALOG", Varchar(64), NOT_NULL), + Column("TABLE_SCHEMA", Varchar(64), NOT_NULL), + Column("TABLE_NAME", Varchar(64), NOT_NULL), + Column("INDEX_NAME", Varchar(64), NOT_NULL), + Column("VECTOR_DIMENSIONS", ULong(10), NOT_NULL), + Column("INDEX_SIZE", ULonglong(19), NULLABLE, OPEN_FULL_TABLE), + Column("TOTAL_NODES", ULonglong(19), NOT_NULL, OPEN_FULL_TABLE), + Column("CACHED_NODES", ULonglong(19), NOT_NULL, OPEN_FULL_TABLE), + Column("DELETED_ROWS", ULonglong(19), NULLABLE, OPEN_FULL_TABLE), + Column("SUBDIST_ENABLED", Varchar(3), NULLABLE, OPEN_FULL_TABLE), + Column("MEMORY_SIZE", ULonglong(19), NOT_NULL, OPEN_FULL_TABLE), + CEnd() +}; + +} //end namespace + +enum vector_indexes_fields_enum +{ + TABLE_CATALOG, + TABLE_SCHEMA, + TABLE_NAME, + INDEX_NAME, + VECTOR_DIMENSIONS, + INDEX_SIZE, + TOTAL_NODES, + CACHED_NODES, + DELETED_ROWS, + SUBDIST_ENABLED, + MEMORY_SIZE +}; + +static int get_schema_vector_indexes_record(THD *thd, TABLE_LIST *tables, + TABLE *out_table, bool res, const LEX_CSTRING *db_name, + const LEX_CSTRING *table_name) +{ + if (res) + return 0; + + TABLE *base_table= tables->table; + TABLE_SHARE *share= base_table->s; + + if (!share->hlindexes()) + return 0; + + /* + base_table->file == NULL means the table wasn't opened in the engine, + meaning none of the OPEN_FULL_TABLE fields were queried + */ + if (!base_table->hlindex && base_table->file && + base_table->hlindex_open(base_table->s->keys)) + return 0; + + KEY *key= &share->key_info[share->keys]; + if (key->algorithm != HA_KEY_ALG_VECTOR) + return 0; + + CHARSET_INFO *cs= system_charset_info; + restore_record(out_table, s->default_values); + + // TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, INDEX_NAME + out_table->field[TABLE_CATALOG]->store(STRING_WITH_LEN("def"), cs); + out_table->field[TABLE_SCHEMA]->store(db_name->str, db_name->length, cs); + out_table->field[TABLE_NAME]->store(table_name->str, table_name->length, cs); + out_table->field[INDEX_NAME]->store(key->name.str, key->name.length, cs); + + TABLE_SHARE *graph_share= share->hlindex; + auto ctx= graph_share + ? MHNSW_Share::get_from_share(share, nullptr) + : nullptr; + + // VECTOR_DIMENSIONS + Field *fld= key->key_part[0].field; + uint dims= fld ? fld->field_length / sizeof(float) : 0; + out_table->field[VECTOR_DIMENSIONS]->store(dims, true); + + // SUBDIST_ENABLED + dgt_mode subdist_mode= NOSTAT_NOSUBDIST; + if (ctx) + { + Stats stats; + subdist_mode= ctx->read_stats(&stats); + } + else if (maybe_use_subdist(dims)) + subdist_mode= STAT_NOSUBDIST; + + if (subdist_mode == STAT_NOSUBDIST) + out_table->field[SUBDIST_ENABLED]->set_null(); + else + { + out_table->field[SUBDIST_ENABLED]->set_notnull(); + out_table->field[SUBDIST_ENABLED]->store(Show::Yes_or_no::value(subdist_mode == STAT_SUBDIST), cs); + } + + handler *graph_file= base_table->hlindex ? base_table->hlindex->file : nullptr; + handler *base_file= base_table->file; + + ha_rows disk_nodes=0; + if (graph_file && !graph_file->info(HA_STATUS_VARIABLE)) + { + disk_nodes= graph_file->stats.records; + // INDEX_SIZE + out_table->field[INDEX_SIZE]->set_notnull(); + out_table->field[INDEX_SIZE]->store(graph_file->stats.data_file_length + + graph_file->stats.index_file_length, true); + + // DELETED_ROWS + if (base_file && !base_file->info(HA_STATUS_VARIABLE)) + { + ha_rows base_records= base_file->stats.records; + ha_rows deleted_estimate= disk_nodes > base_records + ? disk_nodes - base_records : 0; + out_table->field[DELETED_ROWS]->set_notnull(); + out_table->field[DELETED_ROWS]->store(deleted_estimate, true); + } + else + out_table->field[DELETED_ROWS]->set_null(); + } + else + { + out_table->field[INDEX_SIZE]->set_null(); + out_table->field[DELETED_ROWS]->set_null(); + } + + // TOTAL_NODES + out_table->field[TOTAL_NODES]->store(disk_nodes, true); + + // CACHED_NODES, MEMORY_SIZE + if (ctx) + { + size_t nodes, mem_size; + ctx->get_cache_info(&nodes, &mem_size); + out_table->field[CACHED_NODES]->store(nodes, true); + out_table->field[MEMORY_SIZE]->store(mem_size, true); + } + else + { + out_table->field[CACHED_NODES]->store(0ULL, true); + out_table->field[MEMORY_SIZE]->store(0ULL, true); + } + + if (ctx) + ctx->release(false, share); + + return schema_table_store_record(thd, out_table); +} + +static int vector_indexes_init(void *p) +{ + ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p; + schema->fields_info= Show::vector_indexes_fields; + schema->fill_table= get_all_tables; + schema->process_table= get_schema_vector_indexes_record; + schema->idx_field1= TABLE_SCHEMA; + schema->idx_field2= TABLE_NAME; + schema->i_s_requested_object= OPEN_TABLE_ONLY | OPTIMIZE_I_S_TABLE; + return 0; +} + + +static struct st_mysql_information_schema vi_descriptor = +{ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION }; + maria_declare_plugin(mhnsw) { MYSQL_DAEMON_PLUGIN, @@ -1801,5 +1983,18 @@ maria_declare_plugin(mhnsw) "A plugin for mhnsw vector index algorithm", PLUGIN_LICENSE_GPL, mhnsw_init, mhnsw_deinit, 0x0100, NULL, mhnsw_sys_vars, "1.0", MariaDB_PLUGIN_MATURITY_STABLE +}, +{ + MYSQL_INFORMATION_SCHEMA_PLUGIN, + &vi_descriptor, + "VECTOR_INDEXES", + "MariaDB plc", + "Information about vector indexes", + PLUGIN_LICENSE_GPL, + vector_indexes_init, + NULL, + 0x0100, + NULL, NULL, "1.0", + MariaDB_PLUGIN_MATURITY_BETA } maria_declare_plugin_end;