Commit 3307eaab authored by Jan Lindström's avatar Jan Lindström

MDEV-8582: innodb_force_primary_key option does not force PK or unique key

Analysis: Handler table flag HA_REQUIRE_PRIMARY_KEY alone is not enough
to force primary or unique key, if table has at least one NOT NULL
column and secondary key for that column.

Fix: Add additional check that table really has primary key or
unique key for InnoDB terms.
parent 05bcb088
...@@ -51,3 +51,15 @@ show warnings; ...@@ -51,3 +51,15 @@ show warnings;
Level Code Message Level Code Message
Error 1173 This table type requires a primary key Error 1173 This table type requires a primary key
drop table t1; drop table t1;
create table t1 (i int not null, key(i)) engine=innodb;
ERROR 42000: This table type requires a primary key
create table t1 (i int not null, unique key(i)) engine=innodb;
show warnings;
Level Code Message
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(11) NOT NULL,
UNIQUE KEY `i` (`i`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
drop table t1;
...@@ -33,6 +33,17 @@ create table t2(a integer) engine=innodb; ...@@ -33,6 +33,17 @@ create table t2(a integer) engine=innodb;
show warnings; show warnings;
drop table t1; drop table t1;
#
# MDEV-8582: innodb_force_primary_key option does not
# force PK or unique key
#
--error 1173
create table t1 (i int not null, key(i)) engine=innodb;
create table t1 (i int not null, unique key(i)) engine=innodb;
show warnings;
show create table t1;
drop table t1;
--disable_query_log --disable_query_log
eval set global innodb_force_primary_key=$force_pk; eval set global innodb_force_primary_key=$force_pk;
--enable_query_log --enable_query_log
...@@ -11134,6 +11134,11 @@ index_bad: ...@@ -11134,6 +11134,11 @@ index_bad:
} }
} }
if (srv_force_primary_key && form->s->primary_key >= MAX_KEY) {
my_error(ER_REQUIRES_PRIMARY_KEY, MYF(0));
DBUG_RETURN(false);
}
row_format = form->s->row_type; row_format = form->s->row_type;
if (create_info->key_block_size) { if (create_info->key_block_size) {
......
...@@ -11645,6 +11645,11 @@ index_bad: ...@@ -11645,6 +11645,11 @@ index_bad:
} }
} }
if (srv_force_primary_key && form->s->primary_key >= MAX_KEY) {
my_error(ER_REQUIRES_PRIMARY_KEY, MYF(0));
DBUG_RETURN(false);
}
row_format = form->s->row_type; row_format = form->s->row_type;
if (create_info->key_block_size) { if (create_info->key_block_size) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment