Skip to content

Commit e928bf1

Browse files
svojvuvova
authored andcommitted
MDEV-35292 - ALTER TABLE re-creating vector key is no-op with non-copying alter algorithms (default)
ALTER TABLE didn't recognize VECTOR index options change and kept table intact. VECTOR indexes have their own options_struct, let ALTER TABLE use it.
1 parent c453391 commit e928bf1

File tree

6 files changed

+41
-1
lines changed

6 files changed

+41
-1
lines changed

mysql-test/main/vector,aria.rdiff

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,3 +572,10 @@
572572
drop table t1;
573573
create table t1(v vector(5) not null, vector index(v));
574574
alter table t1 add column a int;
575+
@@ -889,5 +879,5 @@ Table Create Table
576+
t CREATE TABLE `t` (
577+
`v` vector(1) NOT NULL,
578+
VECTOR KEY `v` (`v`) `distance`=cosine
579+
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
580+
+) ENGINE=Aria DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci PAGE_CHECKSUM=1
581+
drop table t;

mysql-test/main/vector,myisam.rdiff

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,3 +509,10 @@
509509
-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
510510
+) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
511511
drop table t1;
512+
@@ -877,5 +877,5 @@
513+
t CREATE TABLE `t` (
514+
`v` vector(1) NOT NULL,
515+
VECTOR KEY `v` (`v`) `distance`=cosine
516+
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
517+
+) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
518+
drop table t;

mysql-test/main/vector.result

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,3 +877,17 @@ drop table t1;
877877
create table t1(v vector(5) not null, vector index(v));
878878
alter table t1 add column a int;
879879
drop table t1;
880+
#
881+
# MDEV-35292 - ALTER TABLE re-creating vector key is no-op with
882+
# non-copying alter algorithms (default)
883+
#
884+
create table t (v vector(1) not null, vector(v) distance=euclidean);
885+
insert into t values (0x31313131);
886+
alter table t drop index v, add vector(v) distance=cosine;
887+
show create table t;
888+
Table Create Table
889+
t CREATE TABLE `t` (
890+
`v` vector(1) NOT NULL,
891+
VECTOR KEY `v` (`v`) `distance`=cosine
892+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
893+
drop table t;

mysql-test/main/vector.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,3 +430,13 @@ drop table t1;
430430
create table t1(v vector(5) not null, vector index(v));
431431
alter table t1 add column a int;
432432
drop table t1;
433+
434+
--echo #
435+
--echo # MDEV-35292 - ALTER TABLE re-creating vector key is no-op with
436+
--echo # non-copying alter algorithms (default)
437+
--echo #
438+
create table t (v vector(1) not null, vector(v) distance=euclidean);
439+
insert into t values (0x31313131); # Optional, fails either way
440+
alter table t drop index v, add vector(v) distance=cosine;
441+
show create table t;
442+
drop table t;

mysql-test/main/vector2.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Table Create Table
143143
t CREATE TABLE `t` (
144144
`a` int(11) DEFAULT NULL,
145145
`v` vector(10) NOT NULL,
146-
VECTOR KEY `v` (`v`) `m`=10 `distance`='cosine'
146+
VECTOR KEY `v` (`v`) `distance`='cosine'
147147
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
148148
drop table t;
149149
set mhnsw_default_distance= default;

sql/sql_table.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6794,6 +6794,8 @@ Compare_keys compare_keys_but_name(const KEY *table_key, const KEY *new_key,
67946794
return Compare_keys::NotEqual;
67956795

67966796
if (engine_options_differ(table_key->option_struct, new_key->option_struct,
6797+
table_key->algorithm == HA_KEY_ALG_VECTOR ?
6798+
mhnsw_index_options :
67976799
table->file->ht->index_options))
67986800
return Compare_keys::NotEqual;
67996801

0 commit comments

Comments
 (0)