Skip to content

Commit 01b2e77

Browse files
committed
MDEV-15937 Assertion failure 'key->flags & 1' on ALTER TABLE
While the test case crashes a MariaDB 10.2 debug build only, let us apply the fix to the earliest applicable MariaDB series (10.0) to avoid any data corruption on a table-rebuilding ALTER TABLE using ALGORITHM=INPLACE. innobase_create_key_defs(): Use altered_table->s->primary_key when a new primary key is being created.
1 parent f2433b8 commit 01b2e77

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

mysql-test/suite/innodb/r/innodb-alter-nullable.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@ WHERE NAME='test/t';
5151
TABLE_ID NAME FLAG N_COLS SPACE FILE_FORMAT ROW_FORMAT ZIP_PAGE_SIZE
5252
# test/t 1 6 # Antelope Compact 0
5353
DROP TABLE t;
54+
CREATE TABLE t1(c1 INT) ENGINE=InnoDB;
55+
ALTER TABLE t1 ADD CONSTRAINT UNIQUE KEY i1(c1);
56+
ALTER TABLE t1 CHANGE c1 c1 INT NOT NULL,ADD KEY(c1);
57+
DROP TABLE t1;

mysql-test/suite/innodb/t/innodb-alter-nullable.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ WHERE NAME='test/t';
7171

7272
DROP TABLE t;
7373

74+
CREATE TABLE t1(c1 INT) ENGINE=InnoDB;
75+
ALTER TABLE t1 ADD CONSTRAINT UNIQUE KEY i1(c1);
76+
ALTER TABLE t1 CHANGE c1 c1 INT NOT NULL,ADD KEY(c1);
77+
DROP TABLE t1;
78+
7479
# Check that all connections opened by test cases in this file are really
7580
# gone so execution of other tests won't be affected by their presence.
7681
--source include/wait_until_count_sessions.inc

storage/innobase/handler/handler0alter.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,7 @@ innobase_create_index_def(
15941594

15951595
if (key_clustered) {
15961596
DBUG_ASSERT(!(key->flags & HA_FULLTEXT));
1597+
DBUG_ASSERT(key->flags & HA_NOSAME);
15971598
index->ind_type |= DICT_CLUSTERED;
15981599
} else if (key->flags & HA_FULLTEXT) {
15991600
DBUG_ASSERT(!(key->flags & HA_KEYFLAG_MASK
@@ -1909,14 +1910,9 @@ innobase_create_key_defs(
19091910
ulint primary_key_number;
19101911

19111912
if (new_primary) {
1912-
if (n_add == 0) {
1913-
DBUG_ASSERT(got_default_clust);
1914-
DBUG_ASSERT(altered_table->s->primary_key
1915-
== 0);
1916-
primary_key_number = 0;
1917-
} else {
1918-
primary_key_number = *add;
1919-
}
1913+
DBUG_ASSERT(n_add || got_default_clust);
1914+
DBUG_ASSERT(n_add || !altered_table->s->primary_key);
1915+
primary_key_number = altered_table->s->primary_key;
19201916
} else if (got_default_clust) {
19211917
/* Create the GEN_CLUST_INDEX */
19221918
index_def_t* index = indexdef++;

storage/xtradb/handler/handler0alter.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,7 @@ innobase_create_index_def(
15951595

15961596
if (key_clustered) {
15971597
DBUG_ASSERT(!(key->flags & HA_FULLTEXT));
1598+
DBUG_ASSERT(key->flags & HA_NOSAME);
15981599
index->ind_type |= DICT_CLUSTERED;
15991600
} else if (key->flags & HA_FULLTEXT) {
16001601
DBUG_ASSERT(!(key->flags & HA_KEYFLAG_MASK
@@ -1910,14 +1911,9 @@ innobase_create_key_defs(
19101911
ulint primary_key_number;
19111912

19121913
if (new_primary) {
1913-
if (n_add == 0) {
1914-
DBUG_ASSERT(got_default_clust);
1915-
DBUG_ASSERT(altered_table->s->primary_key
1916-
== 0);
1917-
primary_key_number = 0;
1918-
} else {
1919-
primary_key_number = *add;
1920-
}
1914+
DBUG_ASSERT(n_add || got_default_clust);
1915+
DBUG_ASSERT(n_add || !altered_table->s->primary_key);
1916+
primary_key_number = altered_table->s->primary_key;
19211917
} else if (got_default_clust) {
19221918
/* Create the GEN_CLUST_INDEX */
19231919
index_def_t* index = indexdef++;

0 commit comments

Comments
 (0)