Commit 6699cac0 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-18256 Duplicated call to dict_foreign_remove_from_cache()

ha_innobase::prepare_inplace_alter_table(): Filter out duplicates
from ha_alter_info->alter_info->drop_list.elements.
parent 5e06ee41
...@@ -61,3 +61,12 @@ ALTER TABLE t1 ADD pk INT NOT NULL AUTO_INCREMENT PRIMARY KEY; ...@@ -61,3 +61,12 @@ ALTER TABLE t1 ADD pk INT NOT NULL AUTO_INCREMENT PRIMARY KEY;
ALTER TABLE t1 CHANGE COLUMN a b TIME; ALTER TABLE t1 CHANGE COLUMN a b TIME;
SET SESSION FOREIGN_KEY_CHECKS = ON; SET SESSION FOREIGN_KEY_CHECKS = ON;
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-18256 InnoDB: Failing assertion: heap->magic_n == MEM_BLOCK_MAGIC_N
# upon DROP FOREIGN KEY
#
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
CREATE TABLE t2 (b INT PRIMARY KEY, FOREIGN KEY fk1 (b) REFERENCES t1 (a))
ENGINE=InnoDB;
ALTER TABLE t2 DROP FOREIGN KEY fk1, DROP FOREIGN KEY fk1;
DROP TABLE t2, t1;
...@@ -86,3 +86,13 @@ ALTER TABLE t1 ADD pk INT NOT NULL AUTO_INCREMENT PRIMARY KEY; ...@@ -86,3 +86,13 @@ ALTER TABLE t1 ADD pk INT NOT NULL AUTO_INCREMENT PRIMARY KEY;
ALTER TABLE t1 CHANGE COLUMN a b TIME; ALTER TABLE t1 CHANGE COLUMN a b TIME;
SET SESSION FOREIGN_KEY_CHECKS = ON; SET SESSION FOREIGN_KEY_CHECKS = ON;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # MDEV-18256 InnoDB: Failing assertion: heap->magic_n == MEM_BLOCK_MAGIC_N
--echo # upon DROP FOREIGN KEY
--echo #
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
CREATE TABLE t2 (b INT PRIMARY KEY, FOREIGN KEY fk1 (b) REFERENCES t1 (a))
ENGINE=InnoDB;
ALTER TABLE t2 DROP FOREIGN KEY fk1, DROP FOREIGN KEY fk1;
DROP TABLE t2, t1;
...@@ -3690,12 +3690,14 @@ ha_innobase::prepare_inplace_alter_table( ...@@ -3690,12 +3690,14 @@ ha_innobase::prepare_inplace_alter_table(
continue; continue;
} }
dict_foreign_t* foreign;
for (dict_foreign_set::iterator it for (dict_foreign_set::iterator it
= prebuilt->table->foreign_set.begin(); = prebuilt->table->foreign_set.begin();
it != prebuilt->table->foreign_set.end(); it != prebuilt->table->foreign_set.end();
++it) { ++it) {
dict_foreign_t* foreign = *it; foreign = *it;
const char* fid = strchr(foreign->id, '/'); const char* fid = strchr(foreign->id, '/');
DBUG_ASSERT(fid); DBUG_ASSERT(fid);
...@@ -3706,7 +3708,6 @@ ha_innobase::prepare_inplace_alter_table( ...@@ -3706,7 +3708,6 @@ ha_innobase::prepare_inplace_alter_table(
if (!my_strcasecmp(system_charset_info, if (!my_strcasecmp(system_charset_info,
fid, drop->name)) { fid, drop->name)) {
drop_fk[n_drop_fk++] = foreign;
goto found_fk; goto found_fk;
} }
} }
...@@ -3715,12 +3716,19 @@ ha_innobase::prepare_inplace_alter_table( ...@@ -3715,12 +3716,19 @@ ha_innobase::prepare_inplace_alter_table(
drop->name); drop->name);
goto err_exit; goto err_exit;
found_fk: found_fk:
for (ulint i = n_drop_fk; i--; ) {
if (drop_fk[i] == foreign) {
goto dup_fk;
}
}
drop_fk[n_drop_fk++] = foreign;
dup_fk:
continue; continue;
} }
DBUG_ASSERT(n_drop_fk > 0); DBUG_ASSERT(n_drop_fk > 0);
DBUG_ASSERT(n_drop_fk DBUG_ASSERT(n_drop_fk
== ha_alter_info->alter_info->drop_list.elements); <= ha_alter_info->alter_info->drop_list.elements);
} else { } else {
drop_fk = NULL; drop_fk = NULL;
} }
...@@ -5057,7 +5065,7 @@ commit_try_rebuild( ...@@ -5057,7 +5065,7 @@ commit_try_rebuild(
& Alter_inplace_info::DROP_FOREIGN_KEY) & Alter_inplace_info::DROP_FOREIGN_KEY)
|| ctx->num_to_drop_fk > 0); || ctx->num_to_drop_fk > 0);
DBUG_ASSERT(ctx->num_to_drop_fk DBUG_ASSERT(ctx->num_to_drop_fk
== ha_alter_info->alter_info->drop_list.elements); <= ha_alter_info->alter_info->drop_list.elements);
for (dict_index_t* index = dict_table_get_first_index(rebuilt_table); for (dict_index_t* index = dict_table_get_first_index(rebuilt_table);
index; index;
...@@ -5309,7 +5317,7 @@ commit_try_norebuild( ...@@ -5309,7 +5317,7 @@ commit_try_norebuild(
& Alter_inplace_info::DROP_FOREIGN_KEY) & Alter_inplace_info::DROP_FOREIGN_KEY)
|| ctx->num_to_drop_fk > 0); || ctx->num_to_drop_fk > 0);
DBUG_ASSERT(ctx->num_to_drop_fk DBUG_ASSERT(ctx->num_to_drop_fk
== ha_alter_info->alter_info->drop_list.elements); <= ha_alter_info->alter_info->drop_list.elements);
for (ulint i = 0; i < ctx->num_to_add_index; i++) { for (ulint i = 0; i < ctx->num_to_add_index; i++) {
dict_index_t* index = ctx->add_index[i]; dict_index_t* index = ctx->add_index[i];
......
...@@ -3704,12 +3704,14 @@ ha_innobase::prepare_inplace_alter_table( ...@@ -3704,12 +3704,14 @@ ha_innobase::prepare_inplace_alter_table(
continue; continue;
} }
dict_foreign_t* foreign;
for (dict_foreign_set::iterator it for (dict_foreign_set::iterator it
= prebuilt->table->foreign_set.begin(); = prebuilt->table->foreign_set.begin();
it != prebuilt->table->foreign_set.end(); it != prebuilt->table->foreign_set.end();
++it) { ++it) {
dict_foreign_t* foreign = *it; foreign = *it;
const char* fid = strchr(foreign->id, '/'); const char* fid = strchr(foreign->id, '/');
DBUG_ASSERT(fid); DBUG_ASSERT(fid);
...@@ -3720,7 +3722,6 @@ ha_innobase::prepare_inplace_alter_table( ...@@ -3720,7 +3722,6 @@ ha_innobase::prepare_inplace_alter_table(
if (!my_strcasecmp(system_charset_info, if (!my_strcasecmp(system_charset_info,
fid, drop->name)) { fid, drop->name)) {
drop_fk[n_drop_fk++] = foreign;
goto found_fk; goto found_fk;
} }
} }
...@@ -3729,12 +3730,19 @@ ha_innobase::prepare_inplace_alter_table( ...@@ -3729,12 +3730,19 @@ ha_innobase::prepare_inplace_alter_table(
drop->name); drop->name);
goto err_exit; goto err_exit;
found_fk: found_fk:
for (ulint i = n_drop_fk; i--; ) {
if (drop_fk[i] == foreign) {
goto dup_fk;
}
}
drop_fk[n_drop_fk++] = foreign;
dup_fk:
continue; continue;
} }
DBUG_ASSERT(n_drop_fk > 0); DBUG_ASSERT(n_drop_fk > 0);
DBUG_ASSERT(n_drop_fk DBUG_ASSERT(n_drop_fk
== ha_alter_info->alter_info->drop_list.elements); <= ha_alter_info->alter_info->drop_list.elements);
} else { } else {
drop_fk = NULL; drop_fk = NULL;
} }
...@@ -5071,7 +5079,7 @@ commit_try_rebuild( ...@@ -5071,7 +5079,7 @@ commit_try_rebuild(
& Alter_inplace_info::DROP_FOREIGN_KEY) & Alter_inplace_info::DROP_FOREIGN_KEY)
|| ctx->num_to_drop_fk > 0); || ctx->num_to_drop_fk > 0);
DBUG_ASSERT(ctx->num_to_drop_fk DBUG_ASSERT(ctx->num_to_drop_fk
== ha_alter_info->alter_info->drop_list.elements); <= ha_alter_info->alter_info->drop_list.elements);
for (dict_index_t* index = dict_table_get_first_index(rebuilt_table); for (dict_index_t* index = dict_table_get_first_index(rebuilt_table);
index; index;
...@@ -5325,7 +5333,7 @@ commit_try_norebuild( ...@@ -5325,7 +5333,7 @@ commit_try_norebuild(
& Alter_inplace_info::DROP_FOREIGN_KEY) & Alter_inplace_info::DROP_FOREIGN_KEY)
|| ctx->num_to_drop_fk > 0); || ctx->num_to_drop_fk > 0);
DBUG_ASSERT(ctx->num_to_drop_fk DBUG_ASSERT(ctx->num_to_drop_fk
== ha_alter_info->alter_info->drop_list.elements); <= ha_alter_info->alter_info->drop_list.elements);
for (ulint i = 0; i < ctx->num_to_add_index; i++) { for (ulint i = 0; i < ctx->num_to_add_index; i++) {
dict_index_t* index = ctx->add_index[i]; dict_index_t* index = ctx->add_index[i];
......
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