Skip to content

Commit 46ad86f

Browse files
author
Jan Lindström
committed
MDEV-8582: innodb_force_primary_key option does not force PK or unique key
Analysis: Handler used table flag HA_REQUIRE_PRIMARY_KEY but a bug on sql_table.cc function mysql_prepare_create_table internally marked secondary key with NOT NULL colums as unique key and did not then fail on requirement that table should have primary key or unique key.
1 parent 3307eaa commit 46ad86f

File tree

3 files changed

+1
-11
lines changed

3 files changed

+1
-11
lines changed

sql/sql_table.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4042,7 +4042,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
40424042
my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key_info->name);
40434043
DBUG_RETURN(TRUE);
40444044
}
4045-
if (!(key_info->flags & HA_NULL_PART_KEY))
4045+
if (key->type == Key::UNIQUE && !(key_info->flags & HA_NULL_PART_KEY))
40464046
unique_key=1;
40474047
key_info->key_length=(uint16) key_length;
40484048
if (key_length > max_key_length && key->type != Key::FULLTEXT)

storage/innobase/handler/ha_innodb.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11134,11 +11134,6 @@ innobase_table_flags(
1113411134
}
1113511135
}
1113611136

11137-
if (srv_force_primary_key && form->s->primary_key >= MAX_KEY) {
11138-
my_error(ER_REQUIRES_PRIMARY_KEY, MYF(0));
11139-
DBUG_RETURN(false);
11140-
}
11141-
1114211137
row_format = form->s->row_type;
1114311138

1114411139
if (create_info->key_block_size) {

storage/xtradb/handler/ha_innodb.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11645,11 +11645,6 @@ innobase_table_flags(
1164511645
}
1164611646
}
1164711647

11648-
if (srv_force_primary_key && form->s->primary_key >= MAX_KEY) {
11649-
my_error(ER_REQUIRES_PRIMARY_KEY, MYF(0));
11650-
DBUG_RETURN(false);
11651-
}
11652-
1165311648
row_format = form->s->row_type;
1165411649

1165511650
if (create_info->key_block_size) {

0 commit comments

Comments
 (0)