Commit faf5df67 authored by unknown's avatar unknown

In CREATE syntax: KEY a (field_name(10))

10 now means "number of characters", not number of bytes.

parent e0c70de4
...@@ -19,3 +19,34 @@ SELECT * FROM t1; ...@@ -19,3 +19,34 @@ SELECT * FROM t1;
c1 c2 c3 c1 c2 c3
aaaabbbbcccc aaaabbbbcccc aaaabbbbcccc aaaabbbbcccc aaaabbbbcccc aaaabbbbcccc
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (a CHAR(4) CHARACTER SET utf8, KEY key_a(a(3)));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(4) character set utf8 default NULL,
KEY `key_a` (`a`(3))
) TYPE=MyISAM CHARSET=latin1
SHOW KEYS FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
t1 1 key_a 1 a A NULL 9 NULL YES BTREE
ALTER TABLE t1 CHANGE a a CHAR(4);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(4) default NULL,
KEY `key_a` (`a`(3))
) TYPE=MyISAM CHARSET=latin1
SHOW KEYS FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
t1 1 key_a 1 a A NULL 3 NULL YES BTREE
ALTER TABLE t1 CHANGE a a CHAR(4) CHARACTER SET utf8;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(4) character set utf8 default NULL,
KEY `key_a` (`a`(3))
) TYPE=MyISAM CHARSET=latin1
SHOW KEYS FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
t1 1 key_a 1 a A NULL 9 NULL YES BTREE
DROP TABLE t1;
...@@ -6,3 +6,14 @@ SHOW CREATE TABLE t1; ...@@ -6,3 +6,14 @@ SHOW CREATE TABLE t1;
INSERT INTO t1 VALUES ('aaaabbbbccccdddd','aaaabbbbccccdddd','aaaabbbbccccdddd'); INSERT INTO t1 VALUES ('aaaabbbbccccdddd','aaaabbbbccccdddd','aaaabbbbccccdddd');
SELECT * FROM t1; SELECT * FROM t1;
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (a CHAR(4) CHARACTER SET utf8, KEY key_a(a(3)));
SHOW CREATE TABLE t1;
SHOW KEYS FROM t1;
ALTER TABLE t1 CHANGE a a CHAR(4);
SHOW CREATE TABLE t1;
SHOW KEYS FROM t1;
ALTER TABLE t1 CHANGE a a CHAR(4) CHARACTER SET utf8;
SHOW CREATE TABLE t1;
SHOW KEYS FROM t1;
DROP TABLE t1;
...@@ -1214,7 +1214,9 @@ store_create_info(THD *thd, TABLE *table, String *packet) ...@@ -1214,7 +1214,9 @@ store_create_info(THD *thd, TABLE *table, String *packet)
!(key_info->flags & HA_FULLTEXT))) !(key_info->flags & HA_FULLTEXT)))
{ {
buff[0] = '('; buff[0] = '(';
char* end=int10_to_str((long) key_part->length, buff + 1,10); char* end=int10_to_str((long) key_part->length /
key_part->field->charset()->mbmaxlen,
buff + 1,10);
*end++ = ')'; *end++ = ')';
packet->append(buff,(uint) (end-buff)); packet->append(buff,(uint) (end-buff));
} }
......
...@@ -729,6 +729,9 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, ...@@ -729,6 +729,9 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
*/ */
if (key->type == Key::FULLTEXT) if (key->type == Key::FULLTEXT)
column->length=test(f_is_blob(sql_field->pack_flag)); column->length=test(f_is_blob(sql_field->pack_flag));
else
column->length*= sql_field->charset->mbmaxlen;
if (f_is_blob(sql_field->pack_flag)) if (f_is_blob(sql_field->pack_flag))
{ {
if (!(file->table_flags() & HA_BLOB_KEY)) if (!(file->table_flags() & HA_BLOB_KEY))
...@@ -2099,10 +2102,11 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -2099,10 +2102,11 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
{ // Check if sub key { // Check if sub key
if (cfield->field->type() != FIELD_TYPE_BLOB && if (cfield->field->type() != FIELD_TYPE_BLOB &&
(cfield->field->pack_length() == key_part_length || (cfield->field->pack_length() == key_part_length ||
cfield->length != cfield->pack_length || cfield->length <= key_part_length /
cfield->pack_length <= key_part_length)) key_part->field->charset()->mbmaxlen))
key_part_length=0; // Use whole field key_part_length=0; // Use whole field
} }
key_part_length /= key_part->field->charset()->mbmaxlen;
key_parts.push_back(new key_part_spec(cfield->field_name, key_parts.push_back(new key_part_spec(cfield->field_name,
key_part_length)); key_part_length));
} }
......
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