Commit 4de344a8 authored by Marko Mäkelä's avatar Marko Mäkelä

Reapply a MySQL 5.6.23/5.7.10 Oracle Bug#20029625 fix that was inadvertently...

Reapply a MySQL 5.6.23/5.7.10 Oracle Bug#20029625 fix that was inadvertently reverted in MariaDB 10.2.2

The fix https://github.com/mysql/mysql-server/commit/716f97e2714e70f35d2dc01f0125ed833c62b408
was inadvertently reverted in
commit 2e814d47
"Merge InnoDB 5.7 from mysql-5.7.9".

Reapply the fix, because the test of the bug would fail
after merging MDEV-13838, which replaced an earlier incorrect
bug fix with a correct one.
parent ac2ae901
......@@ -439,6 +439,9 @@ dict_mem_table_col_rename_low(
ut_ad(from_len <= NAME_LEN);
ut_ad(to_len <= NAME_LEN);
char from[NAME_LEN];
strncpy(from, s, NAME_LEN);
if (from_len == to_len) {
/* The easy case: simply replace the column name in
table->col_names. */
......@@ -523,14 +526,54 @@ dict_mem_table_col_rename_low(
foreign = *it;
for (unsigned f = 0; f < foreign->n_fields; f++) {
/* These can point straight to
table->col_names, because the foreign key
constraints will be freed at the same time
when the table object is freed. */
foreign->foreign_col_names[f]
= dict_index_get_nth_field(
foreign->foreign_index, f)->name;
if (foreign->foreign_index == NULL) {
/* We may go here when we set foreign_key_checks to 0,
and then try to rename a column and modify the
corresponding foreign key constraint. The index
would have been dropped, we have to find an equivalent
one */
for (unsigned f = 0; f < foreign->n_fields; f++) {
if (strcmp(foreign->foreign_col_names[f], from)
== 0) {
char** rc = const_cast<char**>(
foreign->foreign_col_names
+ f);
if (to_len <= strlen(*rc)) {
memcpy(*rc, to, to_len + 1);
} else {
*rc = static_cast<char*>(
mem_heap_dup(
foreign->heap,
to,
to_len + 1));
}
}
}
dict_index_t* new_index = dict_foreign_find_index(
foreign->foreign_table, NULL,
foreign->foreign_col_names,
foreign->n_fields, NULL, true, false,
NULL, NULL, NULL);
/* There must be an equivalent index in this case. */
ut_ad(new_index != NULL);
foreign->foreign_index = new_index;
} else {
for (unsigned f = 0; f < foreign->n_fields; f++) {
/* These can point straight to
table->col_names, because the foreign key
constraints will be freed at the same time
when the table object is freed. */
foreign->foreign_col_names[f]
= dict_index_get_nth_field(
foreign->foreign_index,
f)->name;
}
}
}
......@@ -540,6 +583,8 @@ dict_mem_table_col_rename_low(
foreign = *it;
ut_ad(foreign->referenced_index != NULL);
for (unsigned f = 0; f < foreign->n_fields; f++) {
/* foreign->referenced_col_names[] need to be
copies, because the constraint may become
......
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