Commit b8e161be authored by serg@serg.mylan's avatar serg@serg.mylan

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

parent 90eb2d26
......@@ -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])))
......
......@@ -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
......@@ -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);
......
......@@ -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,
......
......@@ -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));
......@@ -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;
#
......
......@@ -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",
......
......@@ -76,7 +76,7 @@ character-set=koi8r
" ",
" . %d ",
" . %d ",
" . %d",
" . %d ",
" '%-.64s' ",
" BLOB '%-.64s' ",
" '%-.64s' ( = %d). BLOB ",
......
......@@ -79,7 +79,7 @@ character-set=koi8u
" ",
" ަ . ¦ %d ަ",
" . ¦ %d ",
" . ¦ %d",
" . ¦ %d Ԧ",
" '%-.64s' դ æ",
"BLOB '%-.64s' Φ Ц æ",
" '%-.64s' (max = %d). BLOB",
......
......@@ -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 */
......
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