summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/my_global.h4
-rw-r--r--mysql-test/r/ctype_utf8.result2
-rw-r--r--mysql-test/r/myisam.result4
-rw-r--r--mysql-test/r/type_blob.result12
-rw-r--r--mysql-test/t/ctype_utf8.test2
-rw-r--r--mysql-test/t/type_blob.test6
-rw-r--r--sql/share/english/errmsg.txt4
-rw-r--r--sql/share/russian/errmsg.txt2
-rw-r--r--sql/share/ukrainian/errmsg.txt2
-rw-r--r--sql/sql_table.cc63
10 files changed, 66 insertions, 35 deletions
diff --git a/include/my_global.h b/include/my_global.h
index 41e3636116a..2652585d9e6 100644
--- a/include/my_global.h
+++ b/include/my_global.h
@@ -382,8 +382,8 @@ typedef unsigned short ushort;
#define sgn(a) (((a) < 0) ? -1 : ((a) > 0) ? 1 : 0)
#define swap(t,a,b) { register t dummy; dummy = a; a = b; b = dummy; }
#define test(a) ((a) ? 1 : 0)
-#define set_if_bigger(a,b) { if ((a) < (b)) (a)=(b); }
-#define set_if_smaller(a,b) { if ((a) > (b)) (a)=(b); }
+#define set_if_bigger(a,b) do { if ((a) < (b)) (a)=(b); } while(0)
+#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
#define test_all_bits(a,b) (((a) & (b)) == (b))
#define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
#define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0])))
diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result
index 8b7178993a7..0ea07baf42c 100644
--- a/mysql-test/r/ctype_utf8.result
+++ b/mysql-test/r/ctype_utf8.result
@@ -168,4 +168,4 @@ hex(s1)
41
drop table t1;
create table t1 (a char(160) character set utf8, primary key(a));
-ERROR HY000: Incorrect sub part key. The used key part isn't a string, the used length is longer than the key part or the storage engine doesn't support unique sub keys
+ERROR 42000: Specified key was too long; max key length is 255 bytes
diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result
index ec70cefc63f..377c45ac8ab 100644
--- a/mysql-test/r/myisam.result
+++ b/mysql-test/r/myisam.result
@@ -323,10 +323,10 @@ Table Op Msg_type Msg_text
test.t1 check status OK
drop table t1;
CREATE TABLE t1 (a varchar(255), b varchar(255), c varchar(255), KEY t1 (a, b, c));
-ERROR 42000: Specified key was too long. Max key length is 500
+ERROR 42000: Specified key was too long; max key length is 500 bytes
CREATE TABLE t1 (a varchar(255), b varchar(255), c varchar(255));
ALTER TABLE t1 ADD INDEX t1 (a, b, c);
-ERROR 42000: Specified key was too long. Max key length is 500
+ERROR 42000: Specified key was too long; max key length is 500 bytes
DROP TABLE t1;
CREATE TABLE t1 (a int not null, b int, c int, key(b), key(c), key(a,b), key(c,a));
INSERT into t1 values (0, null, 0), (0, null, 1), (0, null, 2), (0, null,3), (1,1,4);
diff --git a/mysql-test/r/type_blob.result b/mysql-test/r/type_blob.result
index 255b7f0d942..9c6d5b8fcf5 100644
--- a/mysql-test/r/type_blob.result
+++ b/mysql-test/r/type_blob.result
@@ -346,9 +346,17 @@ HELLO MY 1
a 1
hello 1
drop table t1;
+create table t1 (a text, unique (a(300)));
+ERROR 42000: Specified key was too long; max key length is 255 bytes
create table t1 (a text, key (a(300)));
-ERROR HY000: Incorrect sub part key. The used key part isn't a string, the used length is longer than the key part or the storage engine doesn't support unique sub keys
-create table t1 (a text, key (a(255)));
+Warnings:
+Warning 1071 Specified key was too long; max key length is 255 bytes
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` text,
+ KEY `a` (`a`(255))
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
CREATE TABLE t1 (
t1_id bigint(21) NOT NULL auto_increment,
diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test
index 49b1ed94757..6361f49fe55 100644
--- a/mysql-test/t/ctype_utf8.test
+++ b/mysql-test/t/ctype_utf8.test
@@ -103,5 +103,5 @@ drop table t1;
# Bug 2699
# UTF8 breaks primary keys for cols > 85 characters
#
---error 1089
+--error 1071
create table t1 (a char(160) character set utf8, primary key(a));
diff --git a/mysql-test/t/type_blob.test b/mysql-test/t/type_blob.test
index 70fa2f9b172..ca4762daf24 100644
--- a/mysql-test/t/type_blob.test
+++ b/mysql-test/t/type_blob.test
@@ -121,8 +121,10 @@ select c,count(*) from t1 group by c;
select d,count(*) from t1 group by d;
drop table t1;
-!$1089 create table t1 (a text, key (a(300))); # should give an error
-create table t1 (a text, key (a(255)));
+-- error 1071
+create table t1 (a text, unique (a(300))); # should give an error
+create table t1 (a text, key (a(300))); # key is auto-truncated
+show create table t1;
drop table t1;
#
diff --git a/sql/share/english/errmsg.txt b/sql/share/english/errmsg.txt
index 9632b4e1fd5..70cdf068587 100644
--- a/sql/share/english/errmsg.txt
+++ b/sql/share/english/errmsg.txt
@@ -72,9 +72,9 @@ character-set=latin1
"Not unique table/alias: '%-.64s'",
"Invalid default value for '%-.64s'",
"Multiple primary key defined",
-"Too many keys specified. Max %d keys allowed",
+"Too many keys specified; max %d keys allowed",
"Too many key parts specified. Max %d parts allowed",
-"Specified key was too long. Max key length is %d",
+"Specified key was too long; max key length is %d bytes",
"Key column '%-.64s' doesn't exist in table",
"BLOB column '%-.64s' can't be used in key specification with the used table type",
"Too big column length for column '%-.64s' (max = %d). Use BLOB instead",
diff --git a/sql/share/russian/errmsg.txt b/sql/share/russian/errmsg.txt
index 302f755f89f..8b33a147c59 100644
--- a/sql/share/russian/errmsg.txt
+++ b/sql/share/russian/errmsg.txt
@@ -76,7 +76,7 @@ character-set=koi8r
"Указано несколько первичных ключей",
"Указано слишком много ключей. Разрешается указывать не более %d ключей",
"Указано слишком много частей составного ключа. Разрешается указывать не более %d частей",
-"Указан слишком длинный ключ. Максимальная длина ключа составляет %d",
+"Указан слишком длинный ключ. Максимальная длина ключа составляет %d байт",
"Ключевой столбец '%-.64s' в таблице не существует",
"Столбец типа BLOB '%-.64s' не может быть использован как значение ключа в таблице такого типа",
"Слишком большая длина столбца '%-.64s' (максимум = %d). Используйте тип BLOB вместо текущего",
diff --git a/sql/share/ukrainian/errmsg.txt b/sql/share/ukrainian/errmsg.txt
index 77c6e437f5b..f4bc7fc5d19 100644
--- a/sql/share/ukrainian/errmsg.txt
+++ b/sql/share/ukrainian/errmsg.txt
@@ -79,7 +79,7 @@ character-set=koi8u
"Первинного ключа визначено неодноразово",
"Забагато ключ╕в зазначено. Дозволено не б╕льше %d ключ╕в",
"Забагато частин ключа зазначено. Дозволено не б╕льше %d частин",
-"Зазначений ключ задовгий. Найб╕льша довжина ключа %d",
+"Зазначений ключ задовгий. Найб╕льша довжина ключа %d байт╕в",
"Ключовий стовбець '%-.64s' не ╕сну╓ у таблиц╕",
"BLOB стовбець '%-.64s' не може бути використаний у визначенн╕ ключа в цьому тип╕ таблиц╕",
"Задовга довжина стовбця '%-.64s' (max = %d). Використайте тип BLOB",
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 9faabb265e1..1557cf042a1 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -850,26 +850,35 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
{
if ((length=column->length) > file->max_key_length() ||
length > file->max_key_part_length())
- {
- my_error(ER_WRONG_SUB_KEY,MYF(0));
- DBUG_RETURN(-1);
- }
- }
- /* TODO HF What's this for??? */
- else if (f_is_geom(sql_field->pack_flag))
- {
- }
- else if (column->length > length ||
- ((f_is_packed(sql_field->pack_flag) ||
- ((file->table_flags() & HA_NO_PREFIX_CHAR_KEYS) &&
- (key_info->flags & HA_NOSAME))) &&
- column->length != length))
- {
- my_error(ER_WRONG_SUB_KEY,MYF(0));
- DBUG_RETURN(-1);
+ {
+ length=min(file->max_key_length(), file->max_key_part_length());
+ if (key->type == Key::MULTIPLE)
+ {
+ /* not a critical problem */
+ char warn_buff[MYSQL_ERRMSG_SIZE];
+ sprintf(warn_buff,ER(ER_TOO_LONG_KEY),length);
+ push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ ER_TOO_LONG_KEY, warn_buff);
+ }
+ else
+ {
+ my_error(ER_TOO_LONG_KEY,MYF(0),length);
+ DBUG_RETURN(-1);
+ }
+ }
}
- if (!(file->table_flags() & HA_NO_PREFIX_CHAR_KEYS))
- length=column->length;
+ else if (!f_is_geom(sql_field->pack_flag) &&
+ (column->length > length ||
+ ((f_is_packed(sql_field->pack_flag) ||
+ ((file->table_flags() & HA_NO_PREFIX_CHAR_KEYS) &&
+ (key_info->flags & HA_NOSAME))) &&
+ column->length != length)))
+ {
+ my_error(ER_WRONG_SUB_KEY,MYF(0));
+ DBUG_RETURN(-1);
+ }
+ else if (!(file->table_flags() & HA_NO_PREFIX_CHAR_KEYS))
+ length=column->length;
}
else if (length == 0)
{
@@ -879,8 +888,20 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
}
if (length > file->max_key_part_length())
{
- my_error(ER_WRONG_SUB_KEY,MYF(0));
- DBUG_RETURN(-1);
+ length=file->max_key_part_length();
+ if (key->type == Key::MULTIPLE)
+ {
+ /* not a critical problem */
+ char warn_buff[MYSQL_ERRMSG_SIZE];
+ sprintf(warn_buff,ER(ER_TOO_LONG_KEY),length);
+ push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ ER_TOO_LONG_KEY, warn_buff);
+ }
+ else
+ {
+ my_error(ER_TOO_LONG_KEY,MYF(0),length);
+ DBUG_RETURN(-1);
+ }
}
key_part_info->length=(uint16) length;
/* Use packed keys for long strings on the first column */