Skip to content

Commit 0779e2c

Browse files
committed
MDEV-28576 RENAME COLUMN with NOCOPY algorithm leads to corrupt partitioned table
When f.ex. table is partitioned by HASH(a) and we rename column `a' to `b' partitioning filter stays unchanged: HASH(a). That's the wrong behavior. The patch updates partitioning filter in accordance to the new columns names. That includes partition/subpartition expression and partition/subpartition field list.
1 parent 4eb8c35 commit 0779e2c

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

mysql-test/main/partition_alter.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,15 @@ pk
200200
2
201201
delete from t1;
202202
drop table t1;
203+
#
204+
# MDEV-28576 RENAME COLUMN with NOCOPY algorithm leads to corrupt partitioned table
205+
#
206+
create table t (a int, b int) partition by list (b) (partition p1 values in (1, 2));
207+
insert into t values (0, 1), (2, 2);
208+
alter table t change b f int, change a b int, algorithm=nocopy;
209+
check table t;
210+
Table Op Msg_type Msg_text
211+
test.t check status OK
212+
delete from t order by b limit 1;
213+
drop table t;
203214
# End of 10.3 tests

mysql-test/main/partition_alter.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,15 @@ select * from t1 partition(p1);
185185
delete from t1;
186186
drop table t1;
187187

188+
--echo #
189+
--echo # MDEV-28576 RENAME COLUMN with NOCOPY algorithm leads to corrupt partitioned table
190+
--echo #
191+
create table t (a int, b int) partition by list (b) (partition p1 values in (1, 2));
192+
insert into t values (0, 1), (2, 2);
193+
alter table t change b f int, change a b int, algorithm=nocopy;
194+
check table t;
195+
delete from t order by b limit 1;
196+
# cleanup
197+
drop table t;
198+
188199
--echo # End of 10.3 tests

sql/sql_table.cc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7975,6 +7975,20 @@ void append_drop_column(THD *thd, String *str, Field *field)
79757975
}
79767976

79777977

7978+
static inline
7979+
void rename_field_in_list(Create_field *field, List<const char> *field_list)
7980+
{
7981+
DBUG_ASSERT(field->change.str);
7982+
List_iterator<const char> it(*field_list);
7983+
while (const char *name= it++)
7984+
{
7985+
if (my_strcasecmp(system_charset_info, name, field->change.str))
7986+
continue;
7987+
it.replace(field->field_name.str);
7988+
}
7989+
}
7990+
7991+
79787992
/**
79797993
Prepare column and key definitions for CREATE TABLE in ALTER TABLE.
79807994
@@ -8284,6 +8298,39 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
82848298
new_create_tail.push_back(def, thd->mem_root);
82858299
}
82868300
}
8301+
8302+
#ifdef WITH_PARTITION_STORAGE_ENGINE
8303+
if (alter_info->flags & ALTER_RENAME_COLUMN)
8304+
{
8305+
if (thd->work_part_info)
8306+
{
8307+
partition_info *part_info= thd->work_part_info;
8308+
List_iterator<Create_field> def_it(column_rename_param.fields);
8309+
const bool part_field_list= !part_info->part_field_list.is_empty();
8310+
const bool subpart_field_list= !part_info->subpart_field_list.is_empty();
8311+
if (part_info->part_expr)
8312+
part_info->part_expr->walk(&Item::rename_fields_processor, 1,
8313+
&column_rename_param);
8314+
if (part_info->subpart_expr)
8315+
part_info->subpart_expr->walk(&Item::rename_fields_processor, 1,
8316+
&column_rename_param);
8317+
if (part_field_list || subpart_field_list)
8318+
{
8319+
while (Create_field *def= def_it++)
8320+
{
8321+
if (def->change.str)
8322+
{
8323+
if (part_field_list)
8324+
rename_field_in_list(def, &part_info->part_field_list);
8325+
if (subpart_field_list)
8326+
rename_field_in_list(def, &part_info->subpart_field_list);
8327+
} /* if (def->change.str) */
8328+
} /* while (def) */
8329+
} /* if (part_field_list || subpart_field_list) */
8330+
} /* if (part_info) */
8331+
}
8332+
#endif
8333+
82878334
dropped_sys_vers_fields &= VERS_SYSTEM_FIELD;
82888335
if ((dropped_sys_vers_fields ||
82898336
alter_info->flags & ALTER_DROP_PERIOD) &&

0 commit comments

Comments
 (0)