From 600b5fea57b32ef60f32bec61a12f7290c42bae1 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 1 Sep 2005 19:31:08 +0500 Subject: [PATCH] Bug#12891: UNION doesn't return DISTINCT result for multi-byte characters hp_hash.c: This piece of code was pretty wrong, looks like no necessary changes were made after cut-and-paste from fixed length segment processing. Itroduced two new variables safe_length1 and safe_length2 to remember the original lengths. Fixing my_charpos and set_if_smaller calls to pass correct parameters. ctype_utf8.result, ctype_utf8.test: adding test case heap/hp_hash.c: Bug#12891: UNION doesn't return DISTINCT result for multi-byte characters This piece of code was pretty wrong. mysql-test/t/ctype_utf8.test: adding test case mysql-test/r/ctype_utf8.result: adding test case --- heap/hp_hash.c | 10 ++++++---- mysql-test/r/ctype_utf8.result | 12 ++++++++++++ mysql-test/t/ctype_utf8.test | 11 +++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/heap/hp_hash.c b/heap/hp_hash.c index d643f776731..77f3cf6d80b 100644 --- a/heap/hp_hash.c +++ b/heap/hp_hash.c @@ -551,11 +551,13 @@ int hp_rec_key_cmp(HP_KEYDEF *keydef, const byte *rec1, const byte *rec2, } if (cs->mbmaxlen > 1) { + uint safe_length1= char_length1; + uint safe_length2= char_length2; uint char_length= seg->length / cs->mbmaxlen; - char_length1= my_charpos(cs, pos1, pos1 + char_length1, char_length1); - set_if_smaller(char_length1, seg->length); - char_length2= my_charpos(cs, pos2, pos2 + char_length2, char_length2); - set_if_smaller(char_length2, seg->length); + char_length1= my_charpos(cs, pos1, pos1 + char_length1, char_length); + set_if_smaller(char_length1, safe_length1); + char_length2= my_charpos(cs, pos2, pos2 + char_length2, char_length); + set_if_smaller(char_length2, safe_length2); } if (cs->coll->strnncollsp(seg->charset, diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index 64c693a292a..ee109887dd3 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -1023,3 +1023,15 @@ aa xxx yyy DROP TABLE t1; +set names utf8; +create table t1 (a char(1)) default character set utf8; +create table t2 (a char(1)) default character set utf8; +insert into t1 values('a'),('a'),(0xE38182),(0xE38182); +insert into t1 values('i'),('i'),(0xE38184),(0xE38184); +select * from t1 union distinct select * from t2; +a +a +あ +i +い +drop table t1,t2; diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index ce259f465d9..eda64b82f38 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -857,3 +857,14 @@ SELECT DISTINCT id FROM t1; SELECT DISTINCT id FROM t1 ORDER BY id; DROP TABLE t1; + +# +# Bug#12891: UNION doesn't return DISTINCT result for multi-byte characters +# +set names utf8; +create table t1 (a char(1)) default character set utf8; +create table t2 (a char(1)) default character set utf8; +insert into t1 values('a'),('a'),(0xE38182),(0xE38182); +insert into t1 values('i'),('i'),(0xE38184),(0xE38184); +select * from t1 union distinct select * from t2; +drop table t1,t2;