From 0e6a93ece30a2c5d145e51d5b8c3d0edb0066337 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 1 Jul 2005 15:07:06 +0500 Subject: [PATCH] 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 --- mysql-test/r/type_blob.result | 15 +++++++++++++++ mysql-test/t/type_blob.test | 9 ++++++++- sql/sql_table.cc | 3 ++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/type_blob.result b/mysql-test/r/type_blob.result index 67a011231be..193ed298339 100644 --- a/mysql-test/r/type_blob.result +++ b/mysql-test/r/type_blob.result @@ -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; diff --git a/mysql-test/t/type_blob.test b/mysql-test/t/type_blob.test index c33ea3f435d..80aabf6c5e0 100644 --- a/mysql-test/t/type_blob.test +++ b/mysql-test/t/type_blob.test @@ -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; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 553a853bede..5903576947d 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -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