Skip to content

Commit a158bbb

Browse files
committed
MDEV-36777 create vector table failed with VECTOR INDEX when innodb_force_primary_key=on
mark creating an index as an SQLCOM_CREATE_INDEX operation. currently the only effect of this is to tell InnoDB that it's not a "CREATE TABLE" as such, so not affected by innodb_force_primary_key
1 parent 98f1623 commit a158bbb

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

mysql-test/main/vector_innodb.result

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,25 @@ set global innodb_force_primary_key=1;
270270
insert into t values (0x31313131);
271271
insert into t values (0x32323232);
272272
drop table t;
273-
create table t (v vector (1) not null,vector index (v)) engine=innodb;
274-
ERROR 42000: This table type requires a primary key
275273
set global innodb_force_primary_key=0;
276274
#
275+
# MDEV-36777 create vector table failed with VECTOR INDEX when innodb_force_primary_key=on
276+
#
277+
set global innodb_force_primary_key=on;
278+
create table t1 (v vector(5) not null, vector index (v)) engine=innodb;
279+
ERROR 42000: This table type requires a primary key
280+
create table t1 (id int primary key, v vector(5) not null, vector index (v)) engine=innodb;
281+
show create table t1;
282+
Table Create Table
283+
t1 CREATE TABLE `t1` (
284+
`id` int(11) NOT NULL,
285+
`v` vector(5) NOT NULL,
286+
PRIMARY KEY (`id`),
287+
VECTOR KEY `v` (`v`)
288+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
289+
drop table t1;
290+
set global innodb_force_primary_key=default;
291+
#
277292
# MDEV-35922 Server crashes in mhnsw_read_first upon using vector key with views
278293
#
279294
create table t (pk int primary key, v vector(1) not null, vector(v)) engine=innodb;

mysql-test/main/vector_innodb.test

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,18 @@ set global innodb_force_primary_key=1;
269269
insert into t values (0x31313131);
270270
insert into t values (0x32323232);
271271
drop table t;
272+
set global innodb_force_primary_key=0;
272273

273-
# vector index table has no PK, so cannot be created:
274+
--echo #
275+
--echo # MDEV-36777 create vector table failed with VECTOR INDEX when innodb_force_primary_key=on
276+
--echo #
277+
set global innodb_force_primary_key=on;
274278
--error ER_REQUIRES_PRIMARY_KEY
275-
create table t (v vector (1) not null,vector index (v)) engine=innodb;
276-
set global innodb_force_primary_key=0;
279+
create table t1 (v vector(5) not null, vector index (v)) engine=innodb;
280+
create table t1 (id int primary key, v vector(5) not null, vector index (v)) engine=innodb;
281+
show create table t1;
282+
drop table t1;
283+
set global innodb_force_primary_key=default;
277284

278285
--echo #
279286
--echo # MDEV-35922 Server crashes in mhnsw_read_first upon using vector key with views

sql/handler.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6523,8 +6523,10 @@ int ha_create_table(THD *thd, const char *path, const char *db,
65236523
if ((error= share.path.length > sizeof(file_name) - HLINDEX_BUF_LEN))
65246524
goto err;
65256525

6526+
enum_sql_command old_sql_command= thd->lex->sql_command;
65266527
for (uint i= share.keys; i < share.total_keys; i++)
65276528
{
6529+
thd->lex->sql_command= SQLCOM_CREATE_INDEX;
65286530
my_snprintf(path_end, HLINDEX_BUF_LEN, HLINDEX_TEMPLATE, i);
65296531
if (create_info->index_file_name)
65306532
my_snprintf(index_file_name_end, HLINDEX_BUF_LEN, HLINDEX_TEMPLATE, i);
@@ -6544,6 +6546,7 @@ int ha_create_table(THD *thd, const char *path, const char *db,
65446546
&unused)))
65456547
break;
65466548
}
6549+
thd->lex->sql_command= old_sql_command;
65476550
free_table_share(&index_share);
65486551
}
65496552

0 commit comments

Comments
 (0)