Skip to content

Commit d1667fb

Browse files
committed
MDEV-23852 alter table rename column to uppercase doesn't work
Case-sensitive compare to detect column name case change in inplace alter rename.
1 parent 5ca14da commit d1667fb

File tree

4 files changed

+52
-18
lines changed

4 files changed

+52
-18
lines changed

mysql-test/main/alter_table.result

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3322,5 +3322,28 @@ Note 1176 Key 'x' doesn't exist in table 't1'
33223322
unlock tables;
33233323
drop table t1;
33243324
#
3325+
# MDEV-23852 alter table rename column to uppercase doesn't work
3326+
#
3327+
create table t1 (abc int);
3328+
alter table t1 rename column abc to Abc, algorithm=copy;
3329+
show create table t1;
3330+
Table Create Table
3331+
t1 CREATE TABLE `t1` (
3332+
`Abc` int(11) DEFAULT NULL
3333+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
3334+
alter table t1 rename column abc to ABc, algorithm=inplace;
3335+
show create table t1;
3336+
Table Create Table
3337+
t1 CREATE TABLE `t1` (
3338+
`ABc` int(11) DEFAULT NULL
3339+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
3340+
alter table t1 rename column abc to ABC;
3341+
show create table t1;
3342+
Table Create Table
3343+
t1 CREATE TABLE `t1` (
3344+
`ABC` int(11) DEFAULT NULL
3345+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
3346+
drop table t1;
3347+
#
33253348
# End of 10.5 tests
33263349
#

mysql-test/main/alter_table.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,6 +2529,18 @@ alter table t1 rename key if exists x to xx;
25292529
unlock tables;
25302530
drop table t1;
25312531

2532+
--echo #
2533+
--echo # MDEV-23852 alter table rename column to uppercase doesn't work
2534+
--echo #
2535+
create table t1 (abc int);
2536+
alter table t1 rename column abc to Abc, algorithm=copy;
2537+
show create table t1;
2538+
alter table t1 rename column abc to ABc, algorithm=inplace;
2539+
show create table t1;
2540+
alter table t1 rename column abc to ABC;
2541+
show create table t1;
2542+
drop table t1;
2543+
25322544
--echo #
25332545
--echo # End of 10.5 tests
25342546
--echo #

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ Table Create Table
738738
t2 CREATE TABLE `t2` (
739739
`C2` int(11) DEFAULT NULL,
740740
KEY `c2` (`C2`),
741-
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`c2`) REFERENCES `t1` (`c1`)
741+
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`C2`) REFERENCES `t1` (`C1`)
742742
) ENGINE=InnoDB DEFAULT CHARSET=latin1
743743
ALTER TABLE t1 CHANGE COLUMN C1 c5 INT;
744744
ALTER TABLE t2 CHANGE COLUMN C2 c6 INT;
@@ -785,7 +785,7 @@ SELECT C.NAME FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS C INNER JOIN
785785
INFORMATION_SCHEMA.INNODB_SYS_TABLES T ON C.TABLE_ID=T.TABLE_ID
786786
WHERE T.NAME='test/t1';
787787
NAME
788-
a
788+
A
789789
b
790790
DROP TABLE t1;
791791
# different FOREIGN KEY cases
@@ -842,27 +842,27 @@ t2 CREATE TABLE `t2` (
842842
KEY `bb` (`BB`),
843843
KEY `CC` (`CC`),
844844
KEY `DD` (`DD`),
845-
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`aa`) REFERENCES `t1` (`a`),
846-
CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`bb`) REFERENCES `t1` (`b`),
847-
CONSTRAINT `t2_ibfk_3` FOREIGN KEY (`cc`) REFERENCES `t1` (`c`),
848-
CONSTRAINT `t2_ibfk_4` FOREIGN KEY (`dd`) REFERENCES `t1` (`d`)
845+
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`),
846+
CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`BB`) REFERENCES `t1` (`B`),
847+
CONSTRAINT `t2_ibfk_3` FOREIGN KEY (`CC`) REFERENCES `t1` (`C`),
848+
CONSTRAINT `t2_ibfk_4` FOREIGN KEY (`DD`) REFERENCES `t1` (`D`)
849849
) ENGINE=InnoDB DEFAULT CHARSET=latin1
850850
DELETE FROM t1 WHERE a=1;
851-
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`aa`) REFERENCES `t1` (`a`))
851+
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`))
852852
DELETE FROM t1 WHERE A=1;
853-
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`aa`) REFERENCES `t1` (`a`))
853+
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`))
854854
DELETE FROM t1 WHERE b=1;
855-
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`aa`) REFERENCES `t1` (`a`))
855+
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`))
856856
DELETE FROM t1 WHERE B=1;
857-
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`aa`) REFERENCES `t1` (`a`))
857+
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`))
858858
DELETE FROM t1 WHERE c=1;
859-
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`aa`) REFERENCES `t1` (`a`))
859+
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`))
860860
DELETE FROM t1 WHERE C=1;
861-
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`aa`) REFERENCES `t1` (`a`))
861+
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`))
862862
DELETE FROM t1 WHERE d=1;
863-
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`aa`) REFERENCES `t1` (`a`))
863+
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`))
864864
DELETE FROM t1 WHERE D=1;
865-
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`aa`) REFERENCES `t1` (`a`))
865+
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`))
866866
DROP TABLE t2, t1;
867867
# virtual columns case too
868868
CREATE TABLE t1 (a INT, b INT GENERATED ALWAYS AS (a) VIRTUAL) ENGINE = InnoDB;
@@ -877,7 +877,7 @@ SELECT C.NAME FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS C INNER JOIN
877877
INFORMATION_SCHEMA.INNODB_SYS_TABLES T ON C.TABLE_ID=T.TABLE_ID
878878
WHERE T.NAME='test/t1';
879879
NAME
880-
a
880+
A
881881
b
882882
DROP TABLE t1;
883883
# and an MDEV-18041 regression related to indexes prefixes

sql/sql_table.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7171,9 +7171,8 @@ static bool fill_alter_inplace_info(THD *thd, TABLE *table, bool varchar,
71717171
ha_alter_info->handler_flags|= ALTER_STORED_COLUMN_TYPE;
71727172
}
71737173

7174-
/* Check if field was renamed */
7175-
if (lex_string_cmp(system_charset_info, &field->field_name,
7176-
&new_field->field_name))
7174+
/* Check if field was renamed (case-sensitive for detecting case change) */
7175+
if (cmp(&field->field_name, &new_field->field_name))
71777176
{
71787177
field->flags|= FIELD_IS_RENAMED;
71797178
ha_alter_info->handler_flags|= ALTER_COLUMN_NAME;

0 commit comments

Comments
 (0)