mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Additional tweak to fix for bug #10543, to prevent a change in
behavior when extending fields that were fully part of a multi-part key. mysql-test/r/key.result: Update results mysql-test/t/key.test: Add test for behavior of extending fields in a multi-part key that were defined with a partial length the same as their field length. sql/sql_table.cc: Reset key_part_length when old field length was the same as the old key_part_length.
This commit is contained in:
@ -329,3 +329,28 @@ ERROR 42S21: Duplicate column name 'c1'
|
|||||||
alter table t1 add key (c1,c1,c2);
|
alter table t1 add key (c1,c1,c2);
|
||||||
ERROR 42S21: Duplicate column name 'c1'
|
ERROR 42S21: Duplicate column name 'c1'
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
create table t1 (a varchar(10), b varchar(10), key(a(10),b(10)));
|
||||||
|
show create table t1;
|
||||||
|
Table Create Table
|
||||||
|
t1 CREATE TABLE `t1` (
|
||||||
|
`a` varchar(10) default NULL,
|
||||||
|
`b` varchar(10) default NULL,
|
||||||
|
KEY `a` (`a`,`b`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||||
|
alter table t1 modify b varchar(20);
|
||||||
|
show create table t1;
|
||||||
|
Table Create Table
|
||||||
|
t1 CREATE TABLE `t1` (
|
||||||
|
`a` varchar(10) default NULL,
|
||||||
|
`b` varchar(20) default NULL,
|
||||||
|
KEY `a` (`a`,`b`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||||
|
alter table t1 modify a varchar(20);
|
||||||
|
show create table t1;
|
||||||
|
Table Create Table
|
||||||
|
t1 CREATE TABLE `t1` (
|
||||||
|
`a` varchar(20) default NULL,
|
||||||
|
`b` varchar(20) default NULL,
|
||||||
|
KEY `a` (`a`,`b`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||||
|
drop table t1;
|
||||||
|
@ -324,3 +324,16 @@ alter table t1 add key (c1,c2,c1);
|
|||||||
--error 1060
|
--error 1060
|
||||||
alter table t1 add key (c1,c1,c2);
|
alter table t1 add key (c1,c1,c2);
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
|
||||||
|
#
|
||||||
|
# If we use a partial field for a key that is actually the length of the
|
||||||
|
# field, and we extend the field, we end up with a key that includes the
|
||||||
|
# whole new length of the field.
|
||||||
|
#
|
||||||
|
create table t1 (a varchar(10), b varchar(10), key(a(10),b(10)));
|
||||||
|
show create table t1;
|
||||||
|
alter table t1 modify b varchar(20);
|
||||||
|
show create table t1;
|
||||||
|
alter table t1 modify a varchar(20);
|
||||||
|
show create table t1;
|
||||||
|
drop table t1;
|
||||||
|
@ -3341,11 +3341,15 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
|||||||
previous type, or the field length is less than the key part
|
previous type, or the field length is less than the key part
|
||||||
length, unset the key part length.
|
length, unset the key part length.
|
||||||
|
|
||||||
|
We also unset the key part length if it is the same as the
|
||||||
|
old field's length, so the whole new field will be used.
|
||||||
|
|
||||||
BLOBs may have cfield->length == 0, which is why we test it before
|
BLOBs may have cfield->length == 0, which is why we test it before
|
||||||
checking whether cfield->length < key_part_length (in chars).
|
checking whether cfield->length < key_part_length (in chars).
|
||||||
*/
|
*/
|
||||||
if (!Field::type_can_have_key_part(cfield->field->type()) ||
|
if (!Field::type_can_have_key_part(cfield->field->type()) ||
|
||||||
!Field::type_can_have_key_part(cfield->sql_type) ||
|
!Field::type_can_have_key_part(cfield->sql_type) ||
|
||||||
|
cfield->field->field_length == key_part_length ||
|
||||||
(cfield->length && (cfield->length < key_part_length /
|
(cfield->length && (cfield->length < key_part_length /
|
||||||
key_part->field->charset()->mbmaxlen)))
|
key_part->field->charset()->mbmaxlen)))
|
||||||
key_part_length= 0; // Use whole field
|
key_part_length= 0; // Use whole field
|
||||||
|
Reference in New Issue
Block a user