diff --git a/mysql-test/main/vector_innodb.result b/mysql-test/main/vector_innodb.result index f26bebb69aa..9952b5e1f69 100644 --- a/mysql-test/main/vector_innodb.result +++ b/mysql-test/main/vector_innodb.result @@ -103,3 +103,17 @@ select pk,hex(v) from t; pk hex(v) 1 B047263C9F87233FCFD27E3EAE493E3F0329F43E drop table t; +# +# MDEV-35039 Number of indexes inside InnoDB differs from that defined in MariaDB after altering table with vector key +# +create table t (v blob not null, vector index (v)) row_format=compressed engine=innodb; +alter table t add f int; +insert into t values (x'00000000',1); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `v` blob NOT NULL, + `f` int(11) DEFAULT NULL, + VECTOR KEY `v` (`v`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ROW_FORMAT=COMPRESSED +drop table t; diff --git a/mysql-test/main/vector_innodb.test b/mysql-test/main/vector_innodb.test index 5489627b152..9d77bde0d3c 100644 --- a/mysql-test/main/vector_innodb.test +++ b/mysql-test/main/vector_innodb.test @@ -87,3 +87,12 @@ create table t (pk int primary key, v varbinary(1024) not null, vector key(v)) e insert into t values (1, x'B047263C9F87233fcfd27e3eae493e3f0329f43e'); select pk,hex(v) from t; drop table t; + +--echo # +--echo # MDEV-35039 Number of indexes inside InnoDB differs from that defined in MariaDB after altering table with vector key +--echo # +create table t (v blob not null, vector index (v)) row_format=compressed engine=innodb; +alter table t add f int; +insert into t values (x'00000000',1); +show create table t; +drop table t; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index dec223a1813..2ffff612c45 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -7319,10 +7319,17 @@ static bool fill_alter_inplace_info(THD *thd, TABLE *table, Adding/dropping any indexes in a table that already has high-level indexes may shift high-level indexes numbers. And thus require high-level indexes rename, which algorithm=inplace (storage engines) shouldn't do. + + If we aren't adding/dropping indexes, ha_alter_info->key_count is + table->s->total_keys, but must be table->s->keys to not confuse the engine. */ - if (table->s->hlindexes() && - (ha_alter_info->index_drop_count || ha_alter_info->index_add_count)) - ha_alter_info->inplace_supported= HA_ALTER_INPLACE_NOT_SUPPORTED; + if (table->s->hlindexes()) + { + if (ha_alter_info->index_drop_count || ha_alter_info->index_add_count) + ha_alter_info->inplace_supported= HA_ALTER_INPLACE_NOT_SUPPORTED; + else + ha_alter_info->key_count= table->s->keys; + } DBUG_PRINT("exit", ("handler_flags: %llu", ha_alter_info->handler_flags)); DBUG_RETURN(false);