Commit a0040b0b authored by unknown's avatar unknown

if a key length exceeds the supported maximum and it is safe to auto-decrease it, do it.


include/my_global.h:
  do macro correctly
mysql-test/r/ctype_utf8.result:
  updated
mysql-test/r/myisam.result:
  updated
mysql-test/r/type_blob.result:
  updated
mysql-test/t/ctype_utf8.test:
  updated
mysql-test/t/type_blob.test:
  new tests
sql/share/english/errmsg.txt:
  specify that max key length is in BYTES
sql/share/russian/errmsg.txt:
  specify that max key length is in BYTES
sql/share/ukrainian/errmsg.txt:
  specify that max key length is in BYTES
sql/sql_table.cc:
  if a key length exceeds the supported maximum and it is safe to auto-decrease it, do it.
  cleanup
parent 66a26620
...@@ -382,8 +382,8 @@ typedef unsigned short ushort; ...@@ -382,8 +382,8 @@ typedef unsigned short ushort;
#define sgn(a) (((a) < 0) ? -1 : ((a) > 0) ? 1 : 0) #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 swap(t,a,b) { register t dummy; dummy = a; a = b; b = dummy; }
#define test(a) ((a) ? 1 : 0) #define test(a) ((a) ? 1 : 0)
#define set_if_bigger(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) { if ((a) > (b)) (a)=(b); } #define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
#define test_all_bits(a,b) (((a) & (b)) == (b)) #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 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]))) #define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0])))
......
...@@ -168,4 +168,4 @@ hex(s1) ...@@ -168,4 +168,4 @@ hex(s1)
41 41
drop table t1; drop table t1;
create table t1 (a char(160) character set utf8, primary key(a)); 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
...@@ -323,10 +323,10 @@ Table Op Msg_type Msg_text ...@@ -323,10 +323,10 @@ Table Op Msg_type Msg_text
test.t1 check status OK test.t1 check status OK
drop table t1; drop table t1;
CREATE TABLE t1 (a varchar(255), b varchar(255), c varchar(255), KEY t1 (a, b, c)); 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)); CREATE TABLE t1 (a varchar(255), b varchar(255), c varchar(255));
ALTER TABLE t1 ADD INDEX t1 (a, b, c); 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; DROP TABLE t1;
CREATE TABLE t1 (a int not null, b int, c int, key(b), key(c), key(a,b), key(c,a)); 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); INSERT into t1 values (0, null, 0), (0, null, 1), (0, null, 2), (0, null,3), (1,1,4);
......
...@@ -346,9 +346,17 @@ HELLO MY 1 ...@@ -346,9 +346,17 @@ HELLO MY 1
a 1 a 1
hello 1 hello 1
drop table t1; 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))); 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 Warnings:
create table t1 (a text, key (a(255))); 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; drop table t1;
CREATE TABLE t1 ( CREATE TABLE t1 (
t1_id bigint(21) NOT NULL auto_increment, t1_id bigint(21) NOT NULL auto_increment,
......
...@@ -103,5 +103,5 @@ drop table t1; ...@@ -103,5 +103,5 @@ drop table t1;
# Bug 2699 # Bug 2699
# UTF8 breaks primary keys for cols > 85 characters # UTF8 breaks primary keys for cols > 85 characters
# #
--error 1089 --error 1071
create table t1 (a char(160) character set utf8, primary key(a)); create table t1 (a char(160) character set utf8, primary key(a));
...@@ -121,8 +121,10 @@ select c,count(*) from t1 group by c; ...@@ -121,8 +121,10 @@ select c,count(*) from t1 group by c;
select d,count(*) from t1 group by d; select d,count(*) from t1 group by d;
drop table t1; drop table t1;
!$1089 create table t1 (a text, key (a(300))); # should give an error -- error 1071
create table t1 (a text, key (a(255))); 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; drop table t1;
# #
......
...@@ -72,9 +72,9 @@ character-set=latin1 ...@@ -72,9 +72,9 @@ character-set=latin1
"Not unique table/alias: '%-.64s'", "Not unique table/alias: '%-.64s'",
"Invalid default value for '%-.64s'", "Invalid default value for '%-.64s'",
"Multiple primary key defined", "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", "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", "Key column '%-.64s' doesn't exist in table",
"BLOB column '%-.64s' can't be used in key specification with the used table type", "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", "Too big column length for column '%-.64s' (max = %d). Use BLOB instead",
......
...@@ -76,7 +76,7 @@ character-set=koi8r ...@@ -76,7 +76,7 @@ character-set=koi8r
" ", " ",
" . %d ", " . %d ",
" . %d ", " . %d ",
" . %d", " . %d ",
" '%-.64s' ", " '%-.64s' ",
" BLOB '%-.64s' ", " BLOB '%-.64s' ",
" '%-.64s' ( = %d). BLOB ", " '%-.64s' ( = %d). BLOB ",
......
...@@ -79,7 +79,7 @@ character-set=koi8u ...@@ -79,7 +79,7 @@ character-set=koi8u
" ", " ",
" ަ . ¦ %d ަ", " ަ . ¦ %d ަ",
" . ¦ %d ", " . ¦ %d ",
" . ¦ %d", " . ¦ %d Ԧ",
" '%-.64s' դ æ", " '%-.64s' դ æ",
"BLOB '%-.64s' Φ Ц æ", "BLOB '%-.64s' Φ Ц æ",
" '%-.64s' (max = %d). BLOB", " '%-.64s' (max = %d). BLOB",
......
...@@ -850,26 +850,35 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, ...@@ -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() || if ((length=column->length) > file->max_key_length() ||
length > file->max_key_part_length()) length > file->max_key_part_length())
{ {
my_error(ER_WRONG_SUB_KEY,MYF(0)); length=min(file->max_key_length(), file->max_key_part_length());
DBUG_RETURN(-1); if (key->type == Key::MULTIPLE)
} {
} /* not a critical problem */
/* TODO HF What's this for??? */ char warn_buff[MYSQL_ERRMSG_SIZE];
else if (f_is_geom(sql_field->pack_flag)) sprintf(warn_buff,ER(ER_TOO_LONG_KEY),length);
{ push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
} ER_TOO_LONG_KEY, warn_buff);
else if (column->length > length || }
((f_is_packed(sql_field->pack_flag) || else
((file->table_flags() & HA_NO_PREFIX_CHAR_KEYS) && {
(key_info->flags & HA_NOSAME))) && my_error(ER_TOO_LONG_KEY,MYF(0),length);
column->length != length)) DBUG_RETURN(-1);
{ }
my_error(ER_WRONG_SUB_KEY,MYF(0)); }
DBUG_RETURN(-1);
} }
if (!(file->table_flags() & HA_NO_PREFIX_CHAR_KEYS)) else if (!f_is_geom(sql_field->pack_flag) &&
length=column->length; (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) else if (length == 0)
{ {
...@@ -879,8 +888,20 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, ...@@ -879,8 +888,20 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
} }
if (length > file->max_key_part_length()) if (length > file->max_key_part_length())
{ {
my_error(ER_WRONG_SUB_KEY,MYF(0)); length=file->max_key_part_length();
DBUG_RETURN(-1); 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; key_part_info->length=(uint16) length;
/* Use packed keys for long strings on the first column */ /* Use packed keys for long strings on the first column */
......
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