Commit 191ae582 authored by jan's avatar jan

Forward port r108 from from branches/5.0:

Fixed bug #15308: Problem of Order with Enum Column in 
Primary Key. Added a new test case for bug #14056.
parent f9425367
......@@ -2934,7 +2934,6 @@ ha_innobase::store_key_val_for_row(
continue;
}
cs = field->charset();
true_len = key_len;
lenlen = (ulint)
(((Field_varstring*)field)->length_bytes);
......@@ -2944,13 +2943,15 @@ ha_innobase::store_key_val_for_row(
+ (ulint)get_field_offset(table, field)),
lenlen);
true_len = len;
/* For multi byte character sets we need to calculate
the true length of the key */
if (key_len > 0 && cs->mbmaxlen > 1) {
if (len > 0 && cs->mbmaxlen > 1) {
true_len = (ulint) cs->cset->well_formed_len(cs,
(const char *) data,
(const char *) data + key_len,
(const char *) data + len,
key_len / cs->mbmaxlen,
&error);
}
......@@ -2958,17 +2959,17 @@ ha_innobase::store_key_val_for_row(
/* In a column prefix index, we may need to truncate
the stored value: */
if (len > true_len) {
len = true_len;
if (true_len > key_len) {
true_len = key_len;
}
/* The length in a key value is always stored in 2
bytes */
row_mysql_store_true_var_len((byte*)buff, len, 2);
row_mysql_store_true_var_len((byte*)buff, true_len, 2);
buff += 2;
memcpy(buff, data, len);
memcpy(buff, data, true_len);
/* Note that we always reserve the maximum possible
length of the true VARCHAR in the key value, though
......@@ -3002,24 +3003,25 @@ ha_innobase::store_key_val_for_row(
}
cs = field->charset();
true_len = key_len;
blob_data = row_mysql_read_blob_ref(&blob_len,
(byte*) (record
+ (ulint)get_field_offset(table, field)),
(ulint) field->pack_length());
true_len = blob_len;
ut_a(get_field_offset(table, field)
== key_part->offset);
/* For multi byte character sets we need to calculate
the true length of the key */
if (key_len > 0 && cs->mbmaxlen > 1) {
if (blob_len > 0 && cs->mbmaxlen > 1) {
true_len = (ulint) cs->cset->well_formed_len(cs,
(const char *) blob_data,
(const char *) blob_data
+ key_len,
+ blob_len,
key_len / cs->mbmaxlen,
&error);
}
......@@ -3028,18 +3030,18 @@ ha_innobase::store_key_val_for_row(
indexes, and we may need to truncate the data to be
stored in the key value: */
if (blob_len > true_len) {
blob_len = true_len;
if (true_len > key_len) {
true_len = key_len;
}
/* MySQL reserves 2 bytes for the length and the
storage of the number is little-endian */
innobase_write_to_2_little_endian(
(byte*)buff, (ulint)blob_len);
(byte*)buff, true_len);
buff += 2;
memcpy(buff, blob_data, blob_len);
memcpy(buff, blob_data, true_len);
/* Note that we always reserve the maximum possible
length of the BLOB prefix in the key value. */
......@@ -3071,7 +3073,7 @@ ha_innobase::store_key_val_for_row(
true_len = key_len;
/* Character set for the field is defined only
fields which type is string and real field
to fields whose type is string and real field
type is not enum or set. For these fields check
if character set is multi byte. */
......
This diff is collapsed.
......@@ -1679,6 +1679,10 @@ insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten');
insert into t2 values (4,_ucs2 0x05630563,_ucs2 0x05630563,'eleven');
insert into t2 values (4,_ucs2 0x0563001fc0563,_ucs2 0x0563001fc0563,'point');
insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken');
update t1 set filler = 'boo' where a = 1;
update t2 set filler ='email' where a = 4;
select a,hex(b),hex(c),filler from t1 order by filler;
select a,hex(b),hex(c),filler from t2 order by filler;
drop table t1;
drop table t2;
......@@ -1708,6 +1712,10 @@ insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten');
insert into t2 values (4,_ucs2 0x05630563,_ucs2 0x05630563,'eleven');
insert into t2 values (4,_ucs2 0x0563001fc0563,_ucs2 0x0563001fc0563,'point');
insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken');
update t1 set filler = 'boo' where a = 1;
update t2 set filler ='email' where a = 4;
select a,hex(b),hex(c),filler from t1 order by filler;
select a,hex(b),hex(c),filler from t2 order by filler;
drop table t1;
drop table t2;
......@@ -1737,6 +1745,10 @@ insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten');
insert into t2 values (4,_ucs2 0x05630563,_ucs2 0x05630563,'eleven');
insert into t2 values (4,_ucs2 0x0563001fc0563,_ucs2 0x0563001fc0563,'point');
insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken');
update t1 set filler = 'boo' where a = 1;
update t2 set filler ='email' where a = 4;
select a,hex(b),hex(c),filler from t1 order by filler;
select a,hex(b),hex(c),filler from t2 order by filler;
drop table t1;
drop table t2;
......@@ -1762,6 +1774,10 @@ insert into t2 values (4,_ucs2 0x01fc,_ucs2 0x01fc,'seven');
insert into t2 values (4,_ucs2 0x0120,_ucs2 0x0120,'eight');
insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten');
insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken');
update t1 set filler = 'boo' where a = 1;
update t2 set filler ='email' where a = 4;
select a,hex(b),hex(c),filler from t1 order by filler;
select a,hex(b),hex(c),filler from t2 order by filler;
drop table t1;
drop table t2;
commit;
......@@ -1943,3 +1959,91 @@ select a,hex(s1) from t1;
select hex(s1) from t2;
drop table t2,t1;
#
# Test cases for bug #15308 Problem of Order with Enum Column in Primary Key
#
CREATE TABLE t1 (
ind enum('0','1','2') NOT NULL default '0',
string1 varchar(250) NOT NULL,
PRIMARY KEY (ind)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE t2 (
ind enum('0','1','2') NOT NULL default '0',
string1 varchar(250) NOT NULL,
PRIMARY KEY (ind)
) ENGINE=InnoDB DEFAULT CHARSET=ucs2;
INSERT INTO t1 VALUES ('1', ''),('2', '');
INSERT INTO t2 VALUES ('1', ''),('2', '');
SELECT hex(ind),hex(string1) FROM t1 ORDER BY string1;
SELECT hex(ind),hex(string1) FROM t2 ORDER BY string1;
drop table t1,t2;
CREATE TABLE t1 (
ind set('0','1','2') NOT NULL default '0',
string1 varchar(250) NOT NULL,
PRIMARY KEY (ind)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE t2 (
ind set('0','1','2') NOT NULL default '0',
string1 varchar(250) NOT NULL,
PRIMARY KEY (ind)
) ENGINE=InnoDB DEFAULT CHARSET=ucs2;
INSERT INTO t1 VALUES ('1', ''),('2', '');
INSERT INTO t2 VALUES ('1', ''),('2', '');
SELECT hex(ind),hex(string1) FROM t1 ORDER BY string1;
SELECT hex(ind),hex(string1) FROM t2 ORDER BY string1;
drop table t1,t2;
CREATE TABLE t1 (
ind bit not null,
string1 varchar(250) NOT NULL,
PRIMARY KEY (ind)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE t2 (
ind bit not null,
string1 varchar(250) NOT NULL,
PRIMARY KEY (ind)
) ENGINE=InnoDB DEFAULT CHARSET=ucs2;
insert into t1 values(0,''),(1,'');
insert into t2 values(0,''),(1,'');
select hex(ind),hex(string1) from t1 order by string1;
select hex(ind),hex(string1) from t2 order by string1;
drop table t1,t2;
# tests for bug #14056 Column prefix index on UTF-8 primary key column causes 'Can't find record..'
create table t2 (
a int, b char(10), filler char(10), primary key(a, b(2))
) character set utf8 engine = innodb;
insert into t2 values (1,'abcdefg','one');
insert into t2 values (2,'ijkilmn','two');
insert into t2 values (3, 'qrstuvw','three');
update t2 set a=5, filler='booo' where a=1;
drop table t2;
create table t2 (
a int, b char(10), filler char(10), primary key(a, b(2))
) character set ucs2 engine = innodb;
insert into t2 values (1,'abcdefg','one');
insert into t2 values (2,'ijkilmn','two');
insert into t2 values (3, 'qrstuvw','three');
update t2 set a=5, filler='booo' where a=1;
drop table t2;
create table t1(a int not null, b char(110),primary key(a,b(100))) engine=innodb default charset=utf8;
insert into t1 values(1,'abcdefg'),(2,'defghijk');
insert into t1 values(6,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1);
insert into t1 values(7,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B2);
select a,hex(b) from t1 order by b;
update t1 set b = 'three' where a = 6;
drop table t1;
create table t1(a int not null, b text(110),primary key(a,b(100))) engine=innodb default charset=utf8;
insert into t1 values(1,'abcdefg'),(2,'defghijk');
insert into t1 values(6,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1);
insert into t1 values(7,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B2);
select a,hex(b) from t1 order by b;
update t1 set b = 'three' where a = 6;
drop table t1;
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