From 9011fa1ace3c6a49afdf05c714844d938a8c6f99 Mon Sep 17 00:00:00 2001 From: sachin Date: Mon, 25 Feb 2019 00:46:48 +0530 Subject: Long Index is only allowed for unique keys not normal index. --- mysql-test/main/long_unique.result | 19 +++++++++++++++++++ mysql-test/main/long_unique.test | 13 +++++++++++++ sql/sql_table.cc | 6 +++--- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/mysql-test/main/long_unique.result b/mysql-test/main/long_unique.result index b9ba56b0cbe..87d121616ae 100644 --- a/mysql-test/main/long_unique.result +++ b/mysql-test/main/long_unique.result @@ -1405,4 +1405,23 @@ insert into t1 values( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, insert into t1 values( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63);; ERROR 23000: Duplicate entry '0' for key 'a63' drop table t1; +create table t1(a blob , key(a)); +ERROR 42000: BLOB/TEXT column 'a' used in key specification without a key length +create table t1(a blob); +alter table t1 add index(a); +ERROR 42000: BLOB/TEXT column 'a' used in key specification without a key length +drop table t1; +create table t1(a text , key(a)); +ERROR 42000: BLOB/TEXT column 'a' used in key specification without a key length +create table t1(a varchar(4000)); +alter table t1 add index(a); +Warnings: +Warning 1071 Specified key was too long; max key length is 1000 bytes +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(4000) DEFAULT NULL, + KEY `a` (`a`(1000)) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; set @@GLOBAL.max_allowed_packet= @allowed_packet; diff --git a/mysql-test/main/long_unique.test b/mysql-test/main/long_unique.test index 4d5ecba799f..9fee6d518f2 100644 --- a/mysql-test/main/long_unique.test +++ b/mysql-test/main/long_unique.test @@ -512,4 +512,17 @@ while ($count) --eval $insert_data_2 drop table t1; +--error ER_BLOB_KEY_WITHOUT_LENGTH +create table t1(a blob , key(a)); +create table t1(a blob); +--error ER_BLOB_KEY_WITHOUT_LENGTH +alter table t1 add index(a); +drop table t1; + +--error ER_BLOB_KEY_WITHOUT_LENGTH +create table t1(a text , key(a)); +create table t1(a varchar(4000)); +alter table t1 add index(a); +show create table t1; +drop table t1; set @@GLOBAL.max_allowed_packet= @allowed_packet; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index edd0b95fca0..5cb836f6bd0 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3941,13 +3941,13 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, column->length= MAX_LEN_GEOM_POINT_FIELD; if (!column->length) { - if (key->type == Key::PRIMARY) + if (key->type == Key::UNIQUE) + is_hash_field_needed= true; + else { my_error(ER_BLOB_KEY_WITHOUT_LENGTH, MYF(0), column->field_name.str); DBUG_RETURN(TRUE); } - else - is_hash_field_needed= true; } } #ifdef HAVE_SPATIAL -- cgit v1.2.1