mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 20:12:31 +01:00
Reapply a MySQL 5.6.23/5.7.10 Oracle Bug#20029625 fix that was inadvertently reverted in MariaDB 10.2.2
The fix716f97e271
was inadvertently reverted in commit2e814d4702
"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.
This commit is contained in:
parent
ac2ae901e8
commit
4de344a8d7
1 changed files with 53 additions and 8 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue