Commit 0e6a93ec authored by unknown's avatar unknown

sql_table.cc:

  Bug#11657 Creation of secondary index fails:

  If TINYBLOB key part length is 255, it is equal
  to field length. For BLOB, unlike for CHAR/VARCHAR,
  we should keep a non-zero key part length, otherwise
  "BLOB/TEXT column used in key specification without a key length"
  error is produced afterwards.

type_blob.result, type_blob.test:
  fixing tests accordinly


sql/sql_table.cc:
  Bug#11657 Creation of secondary index fails
  For TINYBLOB key part length can be equal to field length.
  We should still keep a non-zero key part length,
mysql-test/t/type_blob.test:
  fixing tests accordinly
mysql-test/r/type_blob.result:
  fixing tests accordinly
parent 8e08a14b
......@@ -703,3 +703,18 @@ select max(i) from t1 where c = '';
max(i)
4
drop table t1;
create table t1 (a int, b int, c tinyblob, d int, e int);
alter table t1 add primary key (a,b,c(255),d);
alter table t1 add key (a,b,d,e);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL default '0',
`b` int(11) NOT NULL default '0',
`c` tinyblob NOT NULL,
`d` int(11) NOT NULL default '0',
`e` int(11) default NULL,
PRIMARY KEY (`a`,`b`,`c`(255),`d`),
KEY `a` (`a`,`b`,`d`,`e`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
......@@ -394,4 +394,11 @@ INSERT t1 (i, c) VALUES (1,''),(2,''),(3,'asdfh'),(4,'');
select max(i) from t1 where c = '';
drop table t1;
#
# Bug#11657: Creation of secondary index fails
#
create table t1 (a int, b int, c tinyblob, d int, e int);
alter table t1 add primary key (a,b,c(255),d);
alter table t1 add key (a,b,d,e);
show create table t1;
drop table t1;
......@@ -3400,7 +3400,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
*/
if (!Field::type_can_have_key_part(cfield->field->type()) ||
!Field::type_can_have_key_part(cfield->sql_type) ||
cfield->field->field_length == key_part_length ||
(cfield->field->field_length == key_part_length &&
!f_is_blob(key_part->key_type)) ||
(cfield->length && (cfield->length < key_part_length /
key_part->field->charset()->mbmaxlen)))
key_part_length= 0; // Use whole field
......
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