summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mnogosearch.org>2013-10-23 20:25:52 +0400
committerAlexander Barkov <bar@mnogosearch.org>2013-10-23 20:25:52 +0400
commit426d246f5b8a4c598a913838b625e05e63ccb41f (patch)
tree16792dd3268c0ec0fb02837c761a535af1938b1f
parentde8e306b6921ab32aedde957594e570166a7fce1 (diff)
downloadmariadb-git-426d246f5b8a4c598a913838b625e05e63ccb41f.tar.gz
MDEV-5163 Merge WEIGHT_STRING function from MySQL-5.6
-rw-r--r--include/m_ctype.h31
-rw-r--r--mysql-test/include/ctype_german.inc14
-rw-r--r--mysql-test/include/ctype_pad_space.inc5
-rw-r--r--mysql-test/include/weight_string.inc31
-rw-r--r--mysql-test/include/weight_string_8140.inc36
-rw-r--r--mysql-test/include/weight_string_8EA1.inc36
-rw-r--r--mysql-test/include/weight_string_8FA2C3.inc36
-rw-r--r--mysql-test/include/weight_string_A1A1.inc36
-rw-r--r--mysql-test/include/weight_string_chde.inc59
-rw-r--r--mysql-test/include/weight_string_euro.inc30
-rw-r--r--mysql-test/include/weight_string_l1.inc10
-rw-r--r--mysql-test/include/weight_string_l12.inc5
-rw-r--r--mysql-test/include/weight_string_l14.inc37
-rw-r--r--mysql-test/include/weight_string_l2.inc7
-rw-r--r--mysql-test/include/weight_string_l3.inc10
-rw-r--r--mysql-test/include/weight_string_l4.inc10
-rw-r--r--mysql-test/r/ctype_big5.result395
-rw-r--r--mysql-test/r/ctype_cp1250_ch.result374
-rw-r--r--mysql-test/r/ctype_cp932_binlog_stm.result395
-rw-r--r--mysql-test/r/ctype_eucjpms.result743
-rw-r--r--mysql-test/r/ctype_euckr.result395
-rw-r--r--mysql-test/r/ctype_gb2312.result395
-rw-r--r--mysql-test/r/ctype_gbk.result743
-rw-r--r--mysql-test/r/ctype_latin1.result722
-rw-r--r--mysql-test/r/ctype_latin1_de.result264
-rw-r--r--mysql-test/r/ctype_latin2.result222
-rw-r--r--mysql-test/r/ctype_latin2_ch.result461
-rw-r--r--mysql-test/r/ctype_ldml.result964
-rw-r--r--mysql-test/r/ctype_sjis.result395
-rw-r--r--mysql-test/r/ctype_tis620.result234
-rw-r--r--mysql-test/r/ctype_uca.result725
-rw-r--r--mysql-test/r/ctype_ucs.result384
-rw-r--r--mysql-test/r/ctype_ujis.result743
-rw-r--r--mysql-test/r/ctype_utf16.result371
-rw-r--r--mysql-test/r/ctype_utf16_uca.result401
-rw-r--r--mysql-test/r/ctype_utf16le.result365
-rw-r--r--mysql-test/r/ctype_utf32.result371
-rw-r--r--mysql-test/r/ctype_utf32_uca.result401
-rw-r--r--mysql-test/r/ctype_utf8.result412
-rw-r--r--mysql-test/r/ctype_utf8mb4.result25
-rw-r--r--mysql-test/r/ctype_utf8mb4_heap.result25
-rw-r--r--mysql-test/r/ctype_utf8mb4_innodb.result25
-rw-r--r--mysql-test/r/ctype_utf8mb4_myisam.result25
-rw-r--r--mysql-test/r/func_weight_string.result92
-rw-r--r--mysql-test/std_data/Index.xml1
-rw-r--r--mysql-test/std_data/latin1.xml21
-rw-r--r--mysql-test/suite/innodb/r/innodb_ctype_ldml.result1078
-rw-r--r--mysql-test/suite/innodb/t/innodb_ctype_ldml-master.opt3
-rw-r--r--mysql-test/suite/innodb/t/innodb_ctype_ldml.test369
-rw-r--r--mysql-test/suite/perfschema/r/digest_table_full.result2
-rw-r--r--mysql-test/suite/perfschema/r/statement_digest.result60
-rw-r--r--mysql-test/suite/perfschema/r/statement_digest_consumers.result60
-rw-r--r--mysql-test/suite/perfschema/r/statement_digest_long_query.result4
-rw-r--r--mysql-test/t/ctype_big5.test23
-rw-r--r--mysql-test/t/ctype_cp1250_ch.test27
-rw-r--r--mysql-test/t/ctype_cp932_binlog_stm.test23
-rw-r--r--mysql-test/t/ctype_eucjpms.test26
-rw-r--r--mysql-test/t/ctype_euckr.test23
-rw-r--r--mysql-test/t/ctype_gb2312.test24
-rw-r--r--mysql-test/t/ctype_gbk.test27
-rw-r--r--mysql-test/t/ctype_latin1.test36
-rw-r--r--mysql-test/t/ctype_latin1_de.test37
-rw-r--r--mysql-test/t/ctype_latin2.test23
-rw-r--r--mysql-test/t/ctype_latin2_ch.test32
-rw-r--r--mysql-test/t/ctype_ldml.test16
-rw-r--r--mysql-test/t/ctype_sjis.test24
-rw-r--r--mysql-test/t/ctype_tis620.test26
-rw-r--r--mysql-test/t/ctype_uca.test37
-rw-r--r--mysql-test/t/ctype_ucs.test14
-rw-r--r--mysql-test/t/ctype_ujis.test27
-rw-r--r--mysql-test/t/ctype_utf16.test26
-rw-r--r--mysql-test/t/ctype_utf16_uca.test25
-rw-r--r--mysql-test/t/ctype_utf16le.test16
-rw-r--r--mysql-test/t/ctype_utf32.test27
-rw-r--r--mysql-test/t/ctype_utf32_uca.test24
-rw-r--r--mysql-test/t/ctype_utf8.test36
-rw-r--r--mysql-test/t/func_weight_string.test113
-rw-r--r--mysys/charset.c4
-rw-r--r--sql/field.cc25
-rw-r--r--sql/filesort.cc8
-rw-r--r--sql/item_strfunc.cc64
-rw-r--r--sql/item_strfunc.h20
-rw-r--r--sql/lex.h2
-rw-r--r--sql/sql_yacc.yy112
-rw-r--r--strings/ctype-big5.c48
-rw-r--r--strings/ctype-bin.c34
-rw-r--r--strings/ctype-cp932.c28
-rw-r--r--strings/ctype-czech.c40
-rw-r--r--strings/ctype-euc_kr.c4
-rw-r--r--strings/ctype-eucjpms.c4
-rw-r--r--strings/ctype-extra.c62
-rw-r--r--strings/ctype-gb2312.c4
-rw-r--r--strings/ctype-gbk.c46
-rw-r--r--strings/ctype-latin1.c32
-rw-r--r--strings/ctype-mb.c109
-rw-r--r--strings/ctype-simple.c164
-rw-r--r--strings/ctype-sjis.c27
-rw-r--r--strings/ctype-tis620.c32
-rw-r--r--strings/ctype-uca.c174
-rw-r--r--strings/ctype-ucs2.c9
-rw-r--r--strings/ctype-ujis.c4
-rw-r--r--strings/ctype-utf8.c205
-rw-r--r--strings/ctype-win1250ch.c33
103 files changed, 14243 insertions, 821 deletions
diff --git a/include/m_ctype.h b/include/m_ctype.h
index 4e05d65ca5f..826f0b98488 100644
--- a/include/m_ctype.h
+++ b/include/m_ctype.h
@@ -285,7 +285,8 @@ struct my_collation_handler_st
const uchar *, size_t, const uchar *, size_t,
my_bool diff_if_only_endspace_difference);
size_t (*strnxfrm)(CHARSET_INFO *,
- uchar *, size_t, const uchar *, size_t);
+ uchar *dst, size_t dstlen, uint nweights,
+ const uchar *src, size_t srclen, uint flags);
size_t (*strnxfrmlen)(CHARSET_INFO *, size_t);
my_bool (*like_range)(CHARSET_INFO *,
const char *s, size_t s_length,
@@ -428,6 +429,7 @@ struct charset_info_st
my_wc_t max_sort_char; /* For LIKE optimization */
uchar pad_char;
my_bool escape_with_backslash_is_dangerous;
+ uchar levels_for_order;
MY_CHARSET_HANDLER *cset;
MY_COLLATION_HANDLER *coll;
@@ -492,8 +494,9 @@ const uint16 *my_cs_contraction2_weight(CHARSET_INFO *cs, my_wc_t wc1,
my_wc_t wc2);
/* declarations for simple charsets */
-extern size_t my_strnxfrm_simple(CHARSET_INFO *, uchar *, size_t,
- const uchar *, size_t);
+extern size_t my_strnxfrm_simple(CHARSET_INFO *,
+ uchar *dst, size_t dstlen, uint nweights,
+ const uchar *src, size_t srclen, uint flags);
size_t my_strnxfrmlen_simple(CHARSET_INFO *, size_t);
extern int my_strnncoll_simple(CHARSET_INFO *, const uchar *, size_t,
const uchar *, size_t, my_bool);
@@ -662,13 +665,17 @@ int my_strcasecmp_mb_bin(CHARSET_INFO * cs __attribute__((unused)),
void my_hash_sort_mb_bin(CHARSET_INFO *cs __attribute__((unused)),
const uchar *key, size_t len,ulong *nr1, ulong *nr2);
+size_t my_strnxfrm_mb(CHARSET_INFO *,
+ uchar *dst, size_t dstlen, uint nweights,
+ const uchar *src, size_t srclen, uint flags);
+
size_t my_strnxfrm_unicode(CHARSET_INFO *,
- uchar *dst, size_t dstlen,
- const uchar *src, size_t srclen);
+ uchar *dst, size_t dstlen, uint nweights,
+ const uchar *src, size_t srclen, uint flags);
size_t my_strnxfrm_unicode_full_bin(CHARSET_INFO *,
- uchar *dst, size_t dstlen,
- const uchar *src, size_t srclen);
+ uchar *dst, size_t dstlen, uint nweights,
+ const uchar *src, size_t srclen, uint flags);
size_t my_strnxfrmlen_unicode_full_bin(CHARSET_INFO *, size_t);
int my_wildcmp_unicode(CHARSET_INFO *cs,
@@ -693,6 +700,13 @@ my_bool my_charset_is_ascii_based(CHARSET_INFO *cs);
my_bool my_charset_is_8bit_pure_ascii(CHARSET_INFO *cs);
uint my_charset_repertoire(CHARSET_INFO *cs);
+uint my_strxfrm_flag_normalize(uint flags, uint nlevels);
+void my_strxfrm_desc_and_reverse(uchar *str, uchar *strend,
+ uint flags, uint level);
+size_t my_strxfrm_pad_desc_and_reverse(CHARSET_INFO *cs,
+ uchar *str, uchar *frmend, uchar *strend,
+ uint nweights, uint flags, uint level);
+
my_bool my_charset_is_ascii_compatible(CHARSET_INFO *cs);
const MY_CONTRACTIONS *my_charset_get_contractions(const CHARSET_INFO *cs,
@@ -739,7 +753,8 @@ uint32 my_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs,
#define my_binary_compare(s) ((s)->state & MY_CS_BINSORT)
#define use_strnxfrm(s) ((s)->state & MY_CS_STRNXFRM)
-#define my_strnxfrm(s, a, b, c, d) ((s)->coll->strnxfrm((s), (a), (b), (c), (d)))
+#define my_strnxfrm(cs, d, dl, s, sl) \
+ ((cs)->coll->strnxfrm((cs), (d), (dl), (dl), (s), (sl), MY_STRXFRM_PAD_WITH_SPACE))
#define my_strnncoll(s, a, b, c, d) ((s)->coll->strnncoll((s), (a), (b), (c), (d), 0))
#define my_like_range(s, a, b, c, d, e, f, g, h, i, j) \
((s)->coll->like_range((s), (a), (b), (c), (d), (e), (f), (g), (h), (i), (j)))
diff --git a/mysql-test/include/ctype_german.inc b/mysql-test/include/ctype_german.inc
index 14d09358bea..b596e0437a2 100644
--- a/mysql-test/include/ctype_german.inc
+++ b/mysql-test/include/ctype_german.inc
@@ -38,3 +38,17 @@ insert into t1 values ('u'),('ue'),(_latin1 0xFC);
select s1, hex(s1) from t1 order by s1, binary s1;
select group_concat(s1 order by binary s1) from t1 group by s1;
drop table t1;
+
+
+#
+# Check filesort for 'S' and "U+00DF SHARP S",
+# for field and for item.
+#
+CREATE TABLE t1 AS SELECT REPEAT('a',1) AS a, 1 AS b LIMIT 0;
+SHOW CREATE TABLE t1;
+INSERT INTO t1 VALUES ('s',0),(_latin1 0xDF,1);
+SELECT * FROM t1 ORDER BY a, b;
+SELECT * FROM t1 ORDER BY a DESC, b;
+SELECT * FROM t1 ORDER BY CONCAT(a), b;
+SELECT * FROM t1 ORDER BY CONCAT(a) DESC, b;
+DROP TABLE t1;
diff --git a/mysql-test/include/ctype_pad_space.inc b/mysql-test/include/ctype_pad_space.inc
new file mode 100644
index 00000000000..667f97de710
--- /dev/null
+++ b/mysql-test/include/ctype_pad_space.inc
@@ -0,0 +1,5 @@
+SELECT strcmp('a','a ');
+SELECT strcmp('a\0','a' );
+SELECT strcmp('a\0','a ');
+SELECT strcmp('a\t','a' );
+SELECT strcmp('a\t','a ');
diff --git a/mysql-test/include/weight_string.inc b/mysql-test/include/weight_string.inc
new file mode 100644
index 00000000000..d8621a19687
--- /dev/null
+++ b/mysql-test/include/weight_string.inc
@@ -0,0 +1,31 @@
+select @@collation_connection;
+select hex(weight_string('a'));
+select hex(weight_string('A'));
+select hex(weight_string('abc'));
+select hex(weight_string('abc' as char(2)));
+select hex(weight_string('abc' as char(3)));
+select hex(weight_string('abc' as char(5)));
+
+# Read 2 characters from the source string (the last character is not used).
+select hex(weight_string('abc', 1, 2, 0xC0));
+select hex(weight_string('abc', 2, 2, 0xC0));
+select hex(weight_string('abc', 3, 2, 0xC0));
+select hex(weight_string('abc', 4, 2, 0xC0));
+select hex(weight_string('abc', 5, 2, 0xC0));
+select hex(weight_string('abc',25, 2, 0xC0));
+
+# Read 3 characters from the source string (the entire string is used).
+select hex(weight_string('abc', 1, 3, 0xC0));
+select hex(weight_string('abc', 2, 3, 0xC0));
+select hex(weight_string('abc', 3, 3, 0xC0));
+select hex(weight_string('abc', 4, 3, 0xC0));
+select hex(weight_string('abc', 5, 3, 0xC0));
+select hex(weight_string('abc',25, 3, 0xC0));
+
+# Read 4 characters from the source string (extra space is added)
+select hex(weight_string('abc', 1, 4, 0xC0));
+select hex(weight_string('abc', 2, 4, 0xC0));
+select hex(weight_string('abc', 3, 4, 0xC0));
+select hex(weight_string('abc', 4, 4, 0xC0));
+select hex(weight_string('abc', 5, 4, 0xC0));
+select hex(weight_string('abc',25, 4, 0xC0));
diff --git a/mysql-test/include/weight_string_8140.inc b/mysql-test/include/weight_string_8140.inc
new file mode 100644
index 00000000000..f91d40a1381
--- /dev/null
+++ b/mysql-test/include/weight_string_8140.inc
@@ -0,0 +1,36 @@
+select collation(cast(0x8140 as char));
+select hex(weight_string(cast(0x6141 as char)));
+select hex(weight_string(cast(0x8140 as char)));
+select hex(weight_string(cast(0x8140 as char) as char(1)));
+select hex(weight_string(cast(0x81408140 as char) as char(1)));
+select hex(weight_string(cast(0x8140 as char) as char(3)));
+select hex(weight_string(cast(0x81408140 as char) as char(3)));
+select hex(weight_string(cast(0x408140 as char) as char(3)));
+select hex(weight_string(cast(0x4081408140 as char) as char(3)));
+select hex(weight_string(cast(0x40814081408140 as char) as char(3)));
+select hex(weight_string(cast(0x4040814081408140 as char) as char(3)));
+
+# Read 2 characters from the source string (the last character is not used)
+select hex(weight_string(cast(0x814081408140 as char), 1, 2, 0xC0));
+select hex(weight_string(cast(0x814081408140 as char), 2, 2, 0xC0));
+select hex(weight_string(cast(0x814081408140 as char), 3, 2, 0xC0));
+select hex(weight_string(cast(0x814081408140 as char), 4, 2, 0xC0));
+select hex(weight_string(cast(0x814081408140 as char), 5, 2, 0xC0));
+select hex(weight_string(cast(0x814081408140 as char),25, 2, 0xC0));
+
+# Read 3 characters from the source string (the entire string is used)
+select hex(weight_string(cast(0x814081408140 as char), 1, 3, 0xC0));
+select hex(weight_string(cast(0x814081408140 as char), 2, 3, 0xC0));
+select hex(weight_string(cast(0x814081408140 as char), 3, 3, 0xC0));
+select hex(weight_string(cast(0x814081408140 as char), 4, 3, 0xC0));
+select hex(weight_string(cast(0x814081408140 as char), 5, 3, 0xC0));
+select hex(weight_string(cast(0x814081408140 as char),25, 3, 0xC0));
+
+# Read 4 characters from the source string (extra space is added)
+select hex(weight_string(cast(0x814081408140 as char), 1, 4, 0xC0));
+select hex(weight_string(cast(0x814081408140 as char), 2, 4, 0xC0));
+select hex(weight_string(cast(0x814081408140 as char), 3, 4, 0xC0));
+select hex(weight_string(cast(0x814081408140 as char), 4, 4, 0xC0));
+select hex(weight_string(cast(0x814081408140 as char), 5, 4, 0xC0));
+select hex(weight_string(cast(0x814081408140 as char),25, 4, 0xC0));
+
diff --git a/mysql-test/include/weight_string_8EA1.inc b/mysql-test/include/weight_string_8EA1.inc
new file mode 100644
index 00000000000..0396fc9d808
--- /dev/null
+++ b/mysql-test/include/weight_string_8EA1.inc
@@ -0,0 +1,36 @@
+select collation(cast(0xA1A1 as char));
+select hex(weight_string(cast(0x6141 as char)));
+select hex(weight_string(cast(0x8EA1 as char)));
+select hex(weight_string(cast(0x8EA1 as char) as char(1)));
+select hex(weight_string(cast(0x8EA18EA1 as char) as char(1)));
+select hex(weight_string(cast(0x8EA1 as char) as char(3)));
+select hex(weight_string(cast(0x8EA18EA1 as char) as char(3)));
+select hex(weight_string(cast(0x408EA1 as char) as char(3)));
+select hex(weight_string(cast(0x408EA18EA1 as char) as char(3)));
+select hex(weight_string(cast(0x408EA18EA18EA1 as char) as char(3)));
+select hex(weight_string(cast(0x40408EA18EA18EA1 as char) as char(3)));
+
+# Read 2 characters from the source string (the last character is not used)
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 2, 0xC0));
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 2, 0xC0));
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 2, 0xC0));
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 2, 0xC0));
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 2, 0xC0));
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 2, 0xC0));
+
+# Read 3 characters from the source string (the entire string is used)
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 3, 0xC0));
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 3, 0xC0));
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 3, 0xC0));
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 3, 0xC0));
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 3, 0xC0));
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 3, 0xC0));
+
+# Read 4 characters from the source string (extra space is added)
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 4, 0xC0));
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 4, 0xC0));
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 4, 0xC0));
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 4, 0xC0));
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 4, 0xC0));
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 4, 0xC0));
+
diff --git a/mysql-test/include/weight_string_8FA2C3.inc b/mysql-test/include/weight_string_8FA2C3.inc
new file mode 100644
index 00000000000..936b2e6c5e0
--- /dev/null
+++ b/mysql-test/include/weight_string_8FA2C3.inc
@@ -0,0 +1,36 @@
+select collation(cast(0x8FA2C3 as char));
+select hex(weight_string(cast(0x6141 as char)));
+select hex(weight_string(cast(0x8FA2C3 as char)));
+select hex(weight_string(cast(0x8FA2C3 as char) as char(1)));
+select hex(weight_string(cast(0x8FA2C38FA2C3 as char) as char(1)));
+select hex(weight_string(cast(0x8FA2C3 as char) as char(3)));
+select hex(weight_string(cast(0x8FA2C38FA2C3 as char) as char(3)));
+select hex(weight_string(cast(0x408FA2C3 as char) as char(3)));
+select hex(weight_string(cast(0x408FA2C38FA2C3 as char) as char(3)));
+select hex(weight_string(cast(0x408FA2C38FA2C38FA2C3 as char) as char(3)));
+select hex(weight_string(cast(0x40408FA2C38FA2C38FA2C3 as char) as char(3)));
+
+# Read 2 characters from the source string (the last character is not used)
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 2, 0xC0));
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 2, 0xC0));
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 2, 0xC0));
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 2, 0xC0));
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 2, 0xC0));
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 2, 0xC0));
+
+# Read 3 characters from the source string (the entire string is used)
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 3, 0xC0));
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 3, 0xC0));
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 3, 0xC0));
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 3, 0xC0));
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 3, 0xC0));
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 3, 0xC0));
+
+# Read 4 characters from the source string (extra space is added)
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 4, 0xC0));
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 4, 0xC0));
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 4, 0xC0));
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 4, 0xC0));
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 4, 0xC0));
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 4, 0xC0));
+
diff --git a/mysql-test/include/weight_string_A1A1.inc b/mysql-test/include/weight_string_A1A1.inc
new file mode 100644
index 00000000000..34ace06d203
--- /dev/null
+++ b/mysql-test/include/weight_string_A1A1.inc
@@ -0,0 +1,36 @@
+select collation(cast(0xA1A1 as char));
+select hex(weight_string(cast(0x6141 as char)));
+select hex(weight_string(cast(0xA1A1 as char)));
+select hex(weight_string(cast(0xA1A1 as char) as char(1)));
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)));
+select hex(weight_string(cast(0xA1A1 as char) as char(3)));
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)));
+select hex(weight_string(cast(0x40A1A1 as char) as char(3)));
+select hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)));
+select hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)));
+select hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)));
+
+# Read 2 characters from the source string (the last character is not used)
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0));
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0));
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0));
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0));
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0));
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0));
+
+# Read 3 characters from the source string (the entire string is used)
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0));
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0));
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0));
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0));
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0));
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0));
+
+# Read 4 characters from the source string (extra space is added)
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0));
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0));
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0));
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0));
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0));
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0));
+
diff --git a/mysql-test/include/weight_string_chde.inc b/mysql-test/include/weight_string_chde.inc
new file mode 100644
index 00000000000..97c929605f9
--- /dev/null
+++ b/mysql-test/include/weight_string_chde.inc
@@ -0,0 +1,59 @@
+select @@collation_connection;
+select collation(cast(_latin1 0xDF as char));
+select hex(weight_string('s'));
+select hex(weight_string(cast(_latin1 0xDF as char)));
+select hex(weight_string(cast(_latin1 0xDF as char) as char(1)));
+select hex(weight_string('c'));
+select hex(weight_string('h'));
+select hex(weight_string('ch'));
+select hex(weight_string('i'));
+# contraction 'ch' plus expansion 'sharp s'
+select hex(weight_string(cast(_latin1 0x6368DF as char)));
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(1)));
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(2)));
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(3)));
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(4)));
+# expansion 'sharp s' plus contraction 'ch'
+select hex(weight_string(cast(_latin1 0xDF6368 as char)));
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(1)));
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(2)));
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(3)));
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(4)));
+
+# contraction 'ch' plus expansion 'sharp s'
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 2, 0xC0));
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 2, 0xC0));
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 2, 0xC0));
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 2, 0xC0));
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 2, 0xC0));
+
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 3, 0xC0));
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 3, 0xC0));
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 3, 0xC0));
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 3, 0xC0));
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 3, 0xC0));
+
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 4, 0xC0));
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 4, 0xC0));
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 4, 0xC0));
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 4, 0xC0));
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 4, 0xC0));
+
+# expansion 'sharp s' plus contraction 'ch'
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 2,0xC0));
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 2,0xC0));
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 2,0xC0));
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 2,0xC0));
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 2,0xC0));
+
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 3,0xC0));
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 3,0xC0));
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 3,0xC0));
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 3,0xC0));
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 3,0xC0));
+
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 4,0xC0));
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 4,0xC0));
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 4,0xC0));
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 4,0xC0));
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 4,0xC0));
diff --git a/mysql-test/include/weight_string_euro.inc b/mysql-test/include/weight_string_euro.inc
new file mode 100644
index 00000000000..e888bdc3df0
--- /dev/null
+++ b/mysql-test/include/weight_string_euro.inc
@@ -0,0 +1,30 @@
+select @@collation_connection;
+select hex(weight_string(cast(_latin1 0x80 as char)));
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+
+# Read 2 characters from the source string (the last character is not used).
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+
+# Read 3 characters from the source string (the entire string is used).
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+
+# Read 4 characters from the source string (extra space is added)
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
diff --git a/mysql-test/include/weight_string_l1.inc b/mysql-test/include/weight_string_l1.inc
new file mode 100644
index 00000000000..f5ad279e563
--- /dev/null
+++ b/mysql-test/include/weight_string_l1.inc
@@ -0,0 +1,10 @@
+select @@collation_connection;
+select hex(weight_string('a' LEVEL 1));
+select hex(weight_string('A' LEVEL 1));
+select hex(weight_string('abc' LEVEL 1));
+select hex(weight_string('abc' as char(2) LEVEL 1));
+select hex(weight_string('abc' as char(3) LEVEL 1));
+select hex(weight_string('abc' as char(5) LEVEL 1));
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
diff --git a/mysql-test/include/weight_string_l12.inc b/mysql-test/include/weight_string_l12.inc
new file mode 100644
index 00000000000..4ecde8f5f5b
--- /dev/null
+++ b/mysql-test/include/weight_string_l12.inc
@@ -0,0 +1,5 @@
+select @@collation_connection;
+select hex(weight_string('a' LEVEL 1,2));
+select hex(weight_string('a' LEVEL 1-2));
+select hex(weight_string('A' LEVEL 1,2));
+select hex(weight_string('A' LEVEL 1-2));
diff --git a/mysql-test/include/weight_string_l14.inc b/mysql-test/include/weight_string_l14.inc
new file mode 100644
index 00000000000..2add64700c3
--- /dev/null
+++ b/mysql-test/include/weight_string_l14.inc
@@ -0,0 +1,37 @@
+select @@collation_connection;
+select hex(weight_string('a' LEVEL 1,3));
+select hex(weight_string('a' LEVEL 1-3));
+select hex(weight_string('A' LEVEL 1,3));
+select hex(weight_string('A' LEVEL 1-3));
+
+select hex(weight_string('a' LEVEL 1,4));
+select hex(weight_string('a' LEVEL 1-4));
+select hex(weight_string('A' LEVEL 1,4));
+select hex(weight_string('A' LEVEL 1-4));
+
+select hex(weight_string('a' LEVEL 2,3));
+select hex(weight_string('a' LEVEL 2-3));
+select hex(weight_string('A' LEVEL 2,3));
+select hex(weight_string('A' LEVEL 2-3));
+
+select hex(weight_string('a' LEVEL 2,4));
+select hex(weight_string('a' LEVEL 2-4));
+select hex(weight_string('A' LEVEL 2,4));
+select hex(weight_string('A' LEVEL 2-4));
+
+select hex(weight_string('a' LEVEL 3,4));
+select hex(weight_string('a' LEVEL 3-4));
+select hex(weight_string('A' LEVEL 3,4));
+select hex(weight_string('A' LEVEL 3-4));
+
+select hex(weight_string('a' LEVEL 1,2,3,4));
+select hex(weight_string('a' LEVEL 2,3,4));
+select hex(weight_string('a' LEVEL 1,3,4));
+select hex(weight_string('a' LEVEL 1,2,3));
+
+# If any number is less than 1, it is treated as 1.
+select hex(weight_string('a' LEVEL 0));
+
+#If any number is greater than the maximum, it is treated as the maximum.
+select hex(weight_string('a' LEVEL 8));
+select hex(weight_string('a' LEVEL 1,8));
diff --git a/mysql-test/include/weight_string_l2.inc b/mysql-test/include/weight_string_l2.inc
new file mode 100644
index 00000000000..1802fcc9c79
--- /dev/null
+++ b/mysql-test/include/weight_string_l2.inc
@@ -0,0 +1,7 @@
+select @@collation_connection;
+select hex(weight_string('a' LEVEL 2));
+select hex(weight_string('A' LEVEL 2));
+select hex(weight_string('abc' LEVEL 2));
+select hex(weight_string('abc' as char(2) LEVEL 2));
+select hex(weight_string('abc' as char(3) LEVEL 2));
+select hex(weight_string('abc' as char(5) LEVEL 2));
diff --git a/mysql-test/include/weight_string_l3.inc b/mysql-test/include/weight_string_l3.inc
new file mode 100644
index 00000000000..cae1dc3bf30
--- /dev/null
+++ b/mysql-test/include/weight_string_l3.inc
@@ -0,0 +1,10 @@
+select @@collation_connection;
+select hex(weight_string('a' LEVEL 3));
+select hex(weight_string('A' LEVEL 3));
+select hex(weight_string('abc' LEVEL 3));
+select hex(weight_string('abc' as char(2) LEVEL 3));
+select hex(weight_string('abc' as char(3) LEVEL 3));
+select hex(weight_string('Abc' as char(5) LEVEL 3));
+select hex(weight_string('Abc' as char(5) LEVEL 3 REVERSE));
+select hex(weight_string('Abc' as char(5) LEVEL 3 DESC));
+select hex(weight_string('Abc' as char(5) LEVEL 3 DESC REVERSE));
diff --git a/mysql-test/include/weight_string_l4.inc b/mysql-test/include/weight_string_l4.inc
new file mode 100644
index 00000000000..811632bfc30
--- /dev/null
+++ b/mysql-test/include/weight_string_l4.inc
@@ -0,0 +1,10 @@
+select @@collation_connection;
+select hex(weight_string('a' LEVEL 4));
+select hex(weight_string('A' LEVEL 4));
+select hex(weight_string('abc' LEVEL 4));
+select hex(weight_string('abc' as char(2) LEVEL 4));
+select hex(weight_string('abc' as char(3) LEVEL 4));
+select hex(weight_string('abc' as char(5) LEVEL 4));
+select hex(weight_string('abc' as char(5) LEVEL 4 REVERSE));
+select hex(weight_string('abc' as char(5) LEVEL 4 DESC));
+select hex(weight_string('abc' as char(5) LEVEL 4 DESC REVERSE));
diff --git a/mysql-test/r/ctype_big5.result b/mysql-test/r/ctype_big5.result
index d81534ac84e..18abda2a2d7 100644
--- a/mysql-test/r/ctype_big5.result
+++ b/mysql-test/r/ctype_big5.result
@@ -555,3 +555,398 @@ DROP TABLE t1;
#
# End of 5.5 tests
#
+#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+set names big5;
+select @@collation_connection;
+@@collation_connection
+big5_chinese_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+41
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+414243
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+4142
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+414243
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+4142432020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+41
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+4142
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+414220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+41422020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+4142202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+41422020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+41
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+4142
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+414243
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+41424320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+41
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+4142
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+414243
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+41424320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+big5_chinese_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+41
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+414243
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+4142
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+414243
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+4142432020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020434241
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+BEBDBCDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDFBCBDBE
+select collation(cast(0xA1A1 as char));
+collation(cast(0xA1A1 as char))
+big5_chinese_ci
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+4141
+select hex(weight_string(cast(0xA1A1 as char)));
+hex(weight_string(cast(0xA1A1 as char)))
+A140
+select hex(weight_string(cast(0xA1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1 as char) as char(1)))
+A140
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)))
+A140
+select hex(weight_string(cast(0xA1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1 as char) as char(3)))
+A1402020
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)))
+A140A14020
+select hex(weight_string(cast(0x40A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1 as char) as char(3)))
+40A14020
+select hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)))
+40A140A140
+select hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)))
+40A140A140
+select hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)))
+4040A140
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0))
+A140
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0))
+A140A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0))
+A140A140
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0))
+A140A14020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0))
+A140A140202020202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0))
+A140
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0))
+A140A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0))
+A140A140
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0))
+A140A140A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0))
+A140A140A14020202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0))
+A140
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0))
+A140A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0))
+A140A140
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0))
+A140A140A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0))
+A140A140A14020202020202020202020202020202020202020
+set collation_connection=big5_bin;
+select @@collation_connection;
+@@collation_connection
+big5_bin
+select hex(weight_string('a'));
+hex(weight_string('a'))
+61
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+616263
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+6162
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+616263
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+6162632020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+61
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+6162
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+616220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+61622020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+6162202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+61622020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+61
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+6162
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+616263
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+61626320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+61
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+6162
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+616263
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+61626320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+big5_bin
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+61
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+616263
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+6162
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+616263
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+6162632020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020636261
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+9E9D9CDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDF9C9D9E
+select collation(cast(0xA1A1 as char));
+collation(cast(0xA1A1 as char))
+big5_bin
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+6141
+select hex(weight_string(cast(0xA1A1 as char)));
+hex(weight_string(cast(0xA1A1 as char)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1 as char) as char(3)))
+A1A12020
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)))
+A1A1A1A120
+select hex(weight_string(cast(0x40A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1 as char) as char(3)))
+40A1A120
+select hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)))
+4040A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0))
+A1A1A1A120
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0))
+A1A1A1A1202020202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+#
+# End of 5.6 tests
+#
diff --git a/mysql-test/r/ctype_cp1250_ch.result b/mysql-test/r/ctype_cp1250_ch.result
index 231755a3f69..41cf6dca358 100644
--- a/mysql-test/r/ctype_cp1250_ch.result
+++ b/mysql-test/r/ctype_cp1250_ch.result
@@ -241,3 +241,377 @@ drop table t1;
set global LC_MESSAGES=convert((@@global.log_bin_trust_function_creators)
using cp1250);
ERROR HY000: Unknown locale: '1'
+#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+#
+# Note:
+# cp1250_czech_cs does not support WEIGHT_STRING in full extent
+#
+set names cp1250 collate cp1250_czech_cs;
+select @@collation_connection;
+@@collation_connection
+cp1250_czech_cs
+select hex(weight_string('a'));
+hex(weight_string('a'))
+A402
+select hex(weight_string('A'));
+hex(weight_string('A'))
+A401
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+A4A5A6020202
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+A4A5A6020202
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+A4A5A6020202
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+A4A5A6020202
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+A4A5
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+A4A5A6
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+A4A5A602
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+A4A5A60202
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+A4A5A6020202
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+A4A5A602020200000000000000000000000000000000000000
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+A4A5
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+A4A5A6
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+A4A5A602
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+A4A5A60202
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+A4A5A6020202
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+A4A5A602020200000000000000000000000000000000000000
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+A4A5
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+A4A5A6
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+A4A5A602
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+A4A5A60202
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+A4A5A6020202
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+A4A5A602020200000000000000000000000000000000000000
+select @@collation_connection;
+@@collation_connection
+cp1250_czech_cs
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+8123
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+818181232323
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+818181232323
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+818181232323
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+818181232323
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+8181
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+818181
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+81818123
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+8181812323
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+818181232323
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+81818123232300000000000000000000000000000000000000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+8181
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+818181
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+81818123
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+8181812323
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+818181232323
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+81818123232300000000000000000000000000000000000000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+8181
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+818181
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+81818123
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+8181812323
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+818181232323
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+81818123232300000000000000000000000000000000000000
+select @@collation_connection;
+@@collation_connection
+cp1250_czech_cs
+select collation(cast(_latin1 0xDF as char));
+collation(cast(_latin1 0xDF as char))
+cp1250_czech_cs
+select hex(weight_string('s'));
+hex(weight_string('s'))
+B902
+select hex(weight_string(cast(_latin1 0xDF as char)));
+hex(weight_string(cast(_latin1 0xDF as char)))
+BB01
+select hex(weight_string(cast(_latin1 0xDF as char) as char(1)));
+hex(weight_string(cast(_latin1 0xDF as char) as char(1)))
+BB01
+select hex(weight_string('c'));
+hex(weight_string('c'))
+A602
+select hex(weight_string('h'));
+hex(weight_string('h'))
+AC02
+select hex(weight_string('ch'));
+hex(weight_string('ch'))
+AD03
+select hex(weight_string('i'));
+hex(weight_string('i'))
+AE02
+select hex(weight_string(cast(_latin1 0x6368DF as char)));
+hex(weight_string(cast(_latin1 0x6368DF as char)))
+ADBB0301
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(1)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(1)))
+ADBB0301
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(2)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(2)))
+ADBB0301
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(3)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(3)))
+ADBB0301
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(4)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(4)))
+ADBB0301
+select hex(weight_string(cast(_latin1 0xDF6368 as char)));
+hex(weight_string(cast(_latin1 0xDF6368 as char)))
+BBAD0103
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(1)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(1)))
+BBAD0103
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(2)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(2)))
+BBAD0103
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(3)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(3)))
+BBAD0103
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(4)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(4)))
+BBAD0103
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 1, 2, 0xC0))
+ADBB
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 2, 2, 0xC0))
+ADBB03
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 3, 2, 0xC0))
+ADBB0301
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 4, 2, 0xC0))
+ADBB0301
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char),25, 2, 0xC0))
+ADBB0301000000000000000000000000000000000000000000
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 1, 3, 0xC0))
+ADBB
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 2, 3, 0xC0))
+ADBB03
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 3, 3, 0xC0))
+ADBB0301
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 4, 3, 0xC0))
+ADBB0301
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char),25, 3, 0xC0))
+ADBB0301000000000000000000000000000000000000000000
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 1, 4, 0xC0))
+ADBB
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 2, 4, 0xC0))
+ADBB03
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 3, 4, 0xC0))
+ADBB0301
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 4, 4, 0xC0))
+ADBB0301
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char),25, 4, 0xC0))
+ADBB0301000000000000000000000000000000000000000000
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 2,0xC0))
+BBAD
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 2,0xC0))
+BBAD01
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 2,0xC0))
+BBAD0103
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 2,0xC0))
+BBAD0103
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char),25, 2,0xC0))
+BBAD0103000000000000000000000000000000000000000000
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 3,0xC0))
+BBAD
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 3,0xC0))
+BBAD01
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 3,0xC0))
+BBAD0103
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 3,0xC0))
+BBAD0103
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char),25, 3,0xC0))
+BBAD0103000000000000000000000000000000000000000000
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 4,0xC0))
+BBAD
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 4,0xC0))
+BBAD01
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 4,0xC0))
+BBAD0103
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 4,0xC0))
+BBAD0103
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char),25, 4,0xC0))
+BBAD0103000000000000000000000000000000000000000000
+select @@collation_connection;
+@@collation_connection
+cp1250_czech_cs
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+A4
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+A4
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+A4A5A6
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+A4A5A6
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+A4A5A6
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+A4A5A6
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+A4A5A6
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+A4A5A6
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+A4A5A6
+select @@collation_connection;
+@@collation_connection
+cp1250_czech_cs
+select hex(weight_string('a' LEVEL 2));
+hex(weight_string('a' LEVEL 2))
+02
+select hex(weight_string('A' LEVEL 2));
+hex(weight_string('A' LEVEL 2))
+01
+select hex(weight_string('abc' LEVEL 2));
+hex(weight_string('abc' LEVEL 2))
+020202
+select hex(weight_string('abc' as char(2) LEVEL 2));
+hex(weight_string('abc' as char(2) LEVEL 2))
+020202
+select hex(weight_string('abc' as char(3) LEVEL 2));
+hex(weight_string('abc' as char(3) LEVEL 2))
+020202
+select hex(weight_string('abc' as char(5) LEVEL 2));
+hex(weight_string('abc' as char(5) LEVEL 2))
+020202
+select @@collation_connection;
+@@collation_connection
+cp1250_czech_cs
+select hex(weight_string('a' LEVEL 1,2));
+hex(weight_string('a' LEVEL 1,2))
+A402
+select hex(weight_string('a' LEVEL 1-2));
+hex(weight_string('a' LEVEL 1-2))
+A402
+select hex(weight_string('A' LEVEL 1,2));
+hex(weight_string('A' LEVEL 1,2))
+A401
+select hex(weight_string('A' LEVEL 1-2));
+hex(weight_string('A' LEVEL 1-2))
+A401
+#
+# End of 5.6 tests
+#
diff --git a/mysql-test/r/ctype_cp932_binlog_stm.result b/mysql-test/r/ctype_cp932_binlog_stm.result
index 413b96da16b..69d05b1c946 100644
--- a/mysql-test/r/ctype_cp932_binlog_stm.result
+++ b/mysql-test/r/ctype_cp932_binlog_stm.result
@@ -19533,3 +19533,398 @@ master-bin.000001 # Query # # use `test`; DROP TABLE `t1` /* generated by server
#
# End of 5.5 tests
#
+#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+set names cp932;
+select @@collation_connection;
+@@collation_connection
+cp932_japanese_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+41
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+414243
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+4142
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+414243
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+4142432020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+41
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+4142
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+414220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+41422020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+4142202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+41422020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+41
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+4142
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+414243
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+41424320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+41
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+4142
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+414243
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+41424320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+cp932_japanese_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+41
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+414243
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+4142
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+414243
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+4142432020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020434241
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+BEBDBCDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDFBCBDBE
+select collation(cast(0x8140 as char));
+collation(cast(0x8140 as char))
+cp932_japanese_ci
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+4141
+select hex(weight_string(cast(0x8140 as char)));
+hex(weight_string(cast(0x8140 as char)))
+8140
+select hex(weight_string(cast(0x8140 as char) as char(1)));
+hex(weight_string(cast(0x8140 as char) as char(1)))
+8140
+select hex(weight_string(cast(0x81408140 as char) as char(1)));
+hex(weight_string(cast(0x81408140 as char) as char(1)))
+8140
+select hex(weight_string(cast(0x8140 as char) as char(3)));
+hex(weight_string(cast(0x8140 as char) as char(3)))
+81402020
+select hex(weight_string(cast(0x81408140 as char) as char(3)));
+hex(weight_string(cast(0x81408140 as char) as char(3)))
+8140814020
+select hex(weight_string(cast(0x408140 as char) as char(3)));
+hex(weight_string(cast(0x408140 as char) as char(3)))
+40814020
+select hex(weight_string(cast(0x4081408140 as char) as char(3)));
+hex(weight_string(cast(0x4081408140 as char) as char(3)))
+4081408140
+select hex(weight_string(cast(0x40814081408140 as char) as char(3)));
+hex(weight_string(cast(0x40814081408140 as char) as char(3)))
+4081408140
+select hex(weight_string(cast(0x4040814081408140 as char) as char(3)));
+hex(weight_string(cast(0x4040814081408140 as char) as char(3)))
+40408140
+select hex(weight_string(cast(0x814081408140 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 1, 2, 0xC0))
+81
+select hex(weight_string(cast(0x814081408140 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 2, 2, 0xC0))
+8140
+select hex(weight_string(cast(0x814081408140 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 3, 2, 0xC0))
+814081
+select hex(weight_string(cast(0x814081408140 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 4, 2, 0xC0))
+81408140
+select hex(weight_string(cast(0x814081408140 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 5, 2, 0xC0))
+8140814020
+select hex(weight_string(cast(0x814081408140 as char),25, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char),25, 2, 0xC0))
+81408140202020202020202020202020202020202020202020
+select hex(weight_string(cast(0x814081408140 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 1, 3, 0xC0))
+81
+select hex(weight_string(cast(0x814081408140 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 2, 3, 0xC0))
+8140
+select hex(weight_string(cast(0x814081408140 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 3, 3, 0xC0))
+814081
+select hex(weight_string(cast(0x814081408140 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 4, 3, 0xC0))
+81408140
+select hex(weight_string(cast(0x814081408140 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 5, 3, 0xC0))
+8140814081
+select hex(weight_string(cast(0x814081408140 as char),25, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char),25, 3, 0xC0))
+81408140814020202020202020202020202020202020202020
+select hex(weight_string(cast(0x814081408140 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 1, 4, 0xC0))
+81
+select hex(weight_string(cast(0x814081408140 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 2, 4, 0xC0))
+8140
+select hex(weight_string(cast(0x814081408140 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 3, 4, 0xC0))
+814081
+select hex(weight_string(cast(0x814081408140 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 4, 4, 0xC0))
+81408140
+select hex(weight_string(cast(0x814081408140 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 5, 4, 0xC0))
+8140814081
+select hex(weight_string(cast(0x814081408140 as char),25, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char),25, 4, 0xC0))
+81408140814020202020202020202020202020202020202020
+set collation_connection=cp932_bin;
+select @@collation_connection;
+@@collation_connection
+cp932_bin
+select hex(weight_string('a'));
+hex(weight_string('a'))
+61
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+616263
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+6162
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+616263
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+6162632020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+61
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+6162
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+616220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+61622020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+6162202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+61622020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+61
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+6162
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+616263
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+61626320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+61
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+6162
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+616263
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+61626320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+cp932_bin
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+61
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+616263
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+6162
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+616263
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+6162632020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020636261
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+9E9D9CDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDF9C9D9E
+select collation(cast(0x8140 as char));
+collation(cast(0x8140 as char))
+cp932_bin
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+6141
+select hex(weight_string(cast(0x8140 as char)));
+hex(weight_string(cast(0x8140 as char)))
+8140
+select hex(weight_string(cast(0x8140 as char) as char(1)));
+hex(weight_string(cast(0x8140 as char) as char(1)))
+8140
+select hex(weight_string(cast(0x81408140 as char) as char(1)));
+hex(weight_string(cast(0x81408140 as char) as char(1)))
+8140
+select hex(weight_string(cast(0x8140 as char) as char(3)));
+hex(weight_string(cast(0x8140 as char) as char(3)))
+81402020
+select hex(weight_string(cast(0x81408140 as char) as char(3)));
+hex(weight_string(cast(0x81408140 as char) as char(3)))
+8140814020
+select hex(weight_string(cast(0x408140 as char) as char(3)));
+hex(weight_string(cast(0x408140 as char) as char(3)))
+40814020
+select hex(weight_string(cast(0x4081408140 as char) as char(3)));
+hex(weight_string(cast(0x4081408140 as char) as char(3)))
+4081408140
+select hex(weight_string(cast(0x40814081408140 as char) as char(3)));
+hex(weight_string(cast(0x40814081408140 as char) as char(3)))
+4081408140
+select hex(weight_string(cast(0x4040814081408140 as char) as char(3)));
+hex(weight_string(cast(0x4040814081408140 as char) as char(3)))
+40408140
+select hex(weight_string(cast(0x814081408140 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 1, 2, 0xC0))
+81
+select hex(weight_string(cast(0x814081408140 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 2, 2, 0xC0))
+8140
+select hex(weight_string(cast(0x814081408140 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 3, 2, 0xC0))
+814081
+select hex(weight_string(cast(0x814081408140 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 4, 2, 0xC0))
+81408140
+select hex(weight_string(cast(0x814081408140 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 5, 2, 0xC0))
+8140814020
+select hex(weight_string(cast(0x814081408140 as char),25, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char),25, 2, 0xC0))
+81408140202020202020202020202020202020202020202020
+select hex(weight_string(cast(0x814081408140 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 1, 3, 0xC0))
+81
+select hex(weight_string(cast(0x814081408140 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 2, 3, 0xC0))
+8140
+select hex(weight_string(cast(0x814081408140 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 3, 3, 0xC0))
+814081
+select hex(weight_string(cast(0x814081408140 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 4, 3, 0xC0))
+81408140
+select hex(weight_string(cast(0x814081408140 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 5, 3, 0xC0))
+8140814081
+select hex(weight_string(cast(0x814081408140 as char),25, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char),25, 3, 0xC0))
+81408140814020202020202020202020202020202020202020
+select hex(weight_string(cast(0x814081408140 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 1, 4, 0xC0))
+81
+select hex(weight_string(cast(0x814081408140 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 2, 4, 0xC0))
+8140
+select hex(weight_string(cast(0x814081408140 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 3, 4, 0xC0))
+814081
+select hex(weight_string(cast(0x814081408140 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 4, 4, 0xC0))
+81408140
+select hex(weight_string(cast(0x814081408140 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 5, 4, 0xC0))
+8140814081
+select hex(weight_string(cast(0x814081408140 as char),25, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char),25, 4, 0xC0))
+81408140814020202020202020202020202020202020202020
+#
+# End of 5.6 tests
+#
diff --git a/mysql-test/r/ctype_eucjpms.result b/mysql-test/r/ctype_eucjpms.result
index 5a402d57e65..e171e4a6352 100644
--- a/mysql-test/r/ctype_eucjpms.result
+++ b/mysql-test/r/ctype_eucjpms.result
@@ -32611,3 +32611,746 @@ DROP TABLE t1;
#
# End of 5.5 tests
#
+#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+set names eucjpms;
+select @@collation_connection;
+@@collation_connection
+eucjpms_japanese_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+41
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+414243
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+4142
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+414243
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+4142432020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+41
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+4142
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+414220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+41422020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+4142202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+41422020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+41
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+4142
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+414243
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+41424320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+41
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+4142
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+414243
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+41424320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+eucjpms_japanese_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+41
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+414243
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+4142
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+414243
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+4142432020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020434241
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+BEBDBCDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDFBCBDBE
+select collation(cast(0xA1A1 as char));
+collation(cast(0xA1A1 as char))
+eucjpms_japanese_ci
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+4141
+select hex(weight_string(cast(0xA1A1 as char)));
+hex(weight_string(cast(0xA1A1 as char)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1 as char) as char(3)))
+A1A12020
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)))
+A1A1A1A120
+select hex(weight_string(cast(0x40A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1 as char) as char(3)))
+40A1A120
+select hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)))
+4040A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0))
+A1A1A1A120
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0))
+A1A1A1A1202020202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+select collation(cast(0xA1A1 as char));
+collation(cast(0xA1A1 as char))
+eucjpms_japanese_ci
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+4141
+select hex(weight_string(cast(0x8EA1 as char)));
+hex(weight_string(cast(0x8EA1 as char)))
+8EA1
+select hex(weight_string(cast(0x8EA1 as char) as char(1)));
+hex(weight_string(cast(0x8EA1 as char) as char(1)))
+8EA1
+select hex(weight_string(cast(0x8EA18EA1 as char) as char(1)));
+hex(weight_string(cast(0x8EA18EA1 as char) as char(1)))
+8EA1
+select hex(weight_string(cast(0x8EA1 as char) as char(3)));
+hex(weight_string(cast(0x8EA1 as char) as char(3)))
+8EA12020
+select hex(weight_string(cast(0x8EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x8EA18EA1 as char) as char(3)))
+8EA18EA120
+select hex(weight_string(cast(0x408EA1 as char) as char(3)));
+hex(weight_string(cast(0x408EA1 as char) as char(3)))
+408EA120
+select hex(weight_string(cast(0x408EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x408EA18EA1 as char) as char(3)))
+408EA18EA1
+select hex(weight_string(cast(0x408EA18EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x408EA18EA18EA1 as char) as char(3)))
+408EA18EA1
+select hex(weight_string(cast(0x40408EA18EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x40408EA18EA18EA1 as char) as char(3)))
+40408EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 2, 0xC0))
+8E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 2, 0xC0))
+8EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 2, 0xC0))
+8EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 2, 0xC0))
+8EA18EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 2, 0xC0))
+8EA18EA120
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 2, 0xC0))
+8EA18EA1202020202020202020202020202020202020202020
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 3, 0xC0))
+8E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 3, 0xC0))
+8EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 3, 0xC0))
+8EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 3, 0xC0))
+8EA18EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 3, 0xC0))
+8EA18EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 3, 0xC0))
+8EA18EA18EA120202020202020202020202020202020202020
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 4, 0xC0))
+8E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 4, 0xC0))
+8EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 4, 0xC0))
+8EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 4, 0xC0))
+8EA18EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 4, 0xC0))
+8EA18EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 4, 0xC0))
+8EA18EA18EA120202020202020202020202020202020202020
+select collation(cast(0x8FA2C3 as char));
+collation(cast(0x8FA2C3 as char))
+eucjpms_japanese_ci
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+4141
+select hex(weight_string(cast(0x8FA2C3 as char)));
+hex(weight_string(cast(0x8FA2C3 as char)))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C3 as char) as char(1)));
+hex(weight_string(cast(0x8FA2C3 as char) as char(1)))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C3 as char) as char(1)));
+hex(weight_string(cast(0x8FA2C38FA2C3 as char) as char(1)))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x8FA2C3 as char) as char(3)))
+8FA2C32020
+select hex(weight_string(cast(0x8FA2C38FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x8FA2C38FA2C3 as char) as char(3)))
+8FA2C38FA2C320
+select hex(weight_string(cast(0x408FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x408FA2C3 as char) as char(3)))
+408FA2C320
+select hex(weight_string(cast(0x408FA2C38FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x408FA2C38FA2C3 as char) as char(3)))
+408FA2C38FA2C3
+select hex(weight_string(cast(0x408FA2C38FA2C38FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x408FA2C38FA2C38FA2C3 as char) as char(3)))
+408FA2C38FA2C3
+select hex(weight_string(cast(0x40408FA2C38FA2C38FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x40408FA2C38FA2C38FA2C3 as char) as char(3)))
+40408FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 2, 0xC0))
+8F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 2, 0xC0))
+8FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 2, 0xC0))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 2, 0xC0))
+8FA2C38F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 2, 0xC0))
+8FA2C38FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 2, 0xC0))
+8FA2C38FA2C320202020202020202020202020202020202020
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 3, 0xC0))
+8F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 3, 0xC0))
+8FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 3, 0xC0))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 3, 0xC0))
+8FA2C38F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 3, 0xC0))
+8FA2C38FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 3, 0xC0))
+8FA2C38FA2C38FA2C320202020202020202020202020202020
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 4, 0xC0))
+8F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 4, 0xC0))
+8FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 4, 0xC0))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 4, 0xC0))
+8FA2C38F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 4, 0xC0))
+8FA2C38FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 4, 0xC0))
+8FA2C38FA2C38FA2C320202020202020202020202020202020
+set collation_connection=eucjpms_bin;
+select @@collation_connection;
+@@collation_connection
+eucjpms_bin
+select hex(weight_string('a'));
+hex(weight_string('a'))
+61
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+616263
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+6162
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+616263
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+6162632020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+61
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+6162
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+616220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+61622020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+6162202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+61622020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+61
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+6162
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+616263
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+61626320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+61
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+6162
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+616263
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+61626320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+eucjpms_bin
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+61
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+616263
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+6162
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+616263
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+6162632020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020636261
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+9E9D9CDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDF9C9D9E
+select collation(cast(0xA1A1 as char));
+collation(cast(0xA1A1 as char))
+eucjpms_bin
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+6141
+select hex(weight_string(cast(0xA1A1 as char)));
+hex(weight_string(cast(0xA1A1 as char)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1 as char) as char(3)))
+A1A12020
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)))
+A1A1A1A120
+select hex(weight_string(cast(0x40A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1 as char) as char(3)))
+40A1A120
+select hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)))
+4040A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0))
+A1A1A1A120
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0))
+A1A1A1A1202020202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+select collation(cast(0xA1A1 as char));
+collation(cast(0xA1A1 as char))
+eucjpms_bin
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+6141
+select hex(weight_string(cast(0x8EA1 as char)));
+hex(weight_string(cast(0x8EA1 as char)))
+8EA1
+select hex(weight_string(cast(0x8EA1 as char) as char(1)));
+hex(weight_string(cast(0x8EA1 as char) as char(1)))
+8EA1
+select hex(weight_string(cast(0x8EA18EA1 as char) as char(1)));
+hex(weight_string(cast(0x8EA18EA1 as char) as char(1)))
+8EA1
+select hex(weight_string(cast(0x8EA1 as char) as char(3)));
+hex(weight_string(cast(0x8EA1 as char) as char(3)))
+8EA12020
+select hex(weight_string(cast(0x8EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x8EA18EA1 as char) as char(3)))
+8EA18EA120
+select hex(weight_string(cast(0x408EA1 as char) as char(3)));
+hex(weight_string(cast(0x408EA1 as char) as char(3)))
+408EA120
+select hex(weight_string(cast(0x408EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x408EA18EA1 as char) as char(3)))
+408EA18EA1
+select hex(weight_string(cast(0x408EA18EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x408EA18EA18EA1 as char) as char(3)))
+408EA18EA1
+select hex(weight_string(cast(0x40408EA18EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x40408EA18EA18EA1 as char) as char(3)))
+40408EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 2, 0xC0))
+8E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 2, 0xC0))
+8EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 2, 0xC0))
+8EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 2, 0xC0))
+8EA18EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 2, 0xC0))
+8EA18EA120
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 2, 0xC0))
+8EA18EA1202020202020202020202020202020202020202020
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 3, 0xC0))
+8E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 3, 0xC0))
+8EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 3, 0xC0))
+8EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 3, 0xC0))
+8EA18EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 3, 0xC0))
+8EA18EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 3, 0xC0))
+8EA18EA18EA120202020202020202020202020202020202020
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 4, 0xC0))
+8E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 4, 0xC0))
+8EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 4, 0xC0))
+8EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 4, 0xC0))
+8EA18EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 4, 0xC0))
+8EA18EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 4, 0xC0))
+8EA18EA18EA120202020202020202020202020202020202020
+select collation(cast(0x8FA2C3 as char));
+collation(cast(0x8FA2C3 as char))
+eucjpms_bin
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+6141
+select hex(weight_string(cast(0x8FA2C3 as char)));
+hex(weight_string(cast(0x8FA2C3 as char)))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C3 as char) as char(1)));
+hex(weight_string(cast(0x8FA2C3 as char) as char(1)))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C3 as char) as char(1)));
+hex(weight_string(cast(0x8FA2C38FA2C3 as char) as char(1)))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x8FA2C3 as char) as char(3)))
+8FA2C32020
+select hex(weight_string(cast(0x8FA2C38FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x8FA2C38FA2C3 as char) as char(3)))
+8FA2C38FA2C320
+select hex(weight_string(cast(0x408FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x408FA2C3 as char) as char(3)))
+408FA2C320
+select hex(weight_string(cast(0x408FA2C38FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x408FA2C38FA2C3 as char) as char(3)))
+408FA2C38FA2C3
+select hex(weight_string(cast(0x408FA2C38FA2C38FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x408FA2C38FA2C38FA2C3 as char) as char(3)))
+408FA2C38FA2C3
+select hex(weight_string(cast(0x40408FA2C38FA2C38FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x40408FA2C38FA2C38FA2C3 as char) as char(3)))
+40408FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 2, 0xC0))
+8F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 2, 0xC0))
+8FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 2, 0xC0))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 2, 0xC0))
+8FA2C38F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 2, 0xC0))
+8FA2C38FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 2, 0xC0))
+8FA2C38FA2C320202020202020202020202020202020202020
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 3, 0xC0))
+8F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 3, 0xC0))
+8FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 3, 0xC0))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 3, 0xC0))
+8FA2C38F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 3, 0xC0))
+8FA2C38FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 3, 0xC0))
+8FA2C38FA2C38FA2C320202020202020202020202020202020
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 4, 0xC0))
+8F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 4, 0xC0))
+8FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 4, 0xC0))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 4, 0xC0))
+8FA2C38F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 4, 0xC0))
+8FA2C38FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 4, 0xC0))
+8FA2C38FA2C38FA2C320202020202020202020202020202020
+#
+# End of 5.6 tests
+#
diff --git a/mysql-test/r/ctype_euckr.result b/mysql-test/r/ctype_euckr.result
index c20504e9ed7..6299b3e38fd 100644
--- a/mysql-test/r/ctype_euckr.result
+++ b/mysql-test/r/ctype_euckr.result
@@ -24602,3 +24602,398 @@ DROP TABLE t1;
#
# End of 5.5 tests
#
+#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+set names euckr;
+select @@collation_connection;
+@@collation_connection
+euckr_korean_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+41
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+414243
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+4142
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+414243
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+4142432020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+41
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+4142
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+414220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+41422020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+4142202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+41422020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+41
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+4142
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+414243
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+41424320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+41
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+4142
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+414243
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+41424320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+euckr_korean_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+41
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+414243
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+4142
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+414243
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+4142432020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020434241
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+BEBDBCDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDFBCBDBE
+select collation(cast(0xA1A1 as char));
+collation(cast(0xA1A1 as char))
+euckr_korean_ci
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+4141
+select hex(weight_string(cast(0xA1A1 as char)));
+hex(weight_string(cast(0xA1A1 as char)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1 as char) as char(3)))
+A1A12020
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)))
+A1A1A1A120
+select hex(weight_string(cast(0x40A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1 as char) as char(3)))
+40A1A120
+select hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)))
+4040A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0))
+A1A1A1A120
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0))
+A1A1A1A1202020202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+set collation_connection=euckr_bin;
+select @@collation_connection;
+@@collation_connection
+euckr_bin
+select hex(weight_string('a'));
+hex(weight_string('a'))
+61
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+616263
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+6162
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+616263
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+6162632020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+61
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+6162
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+616220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+61622020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+6162202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+61622020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+61
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+6162
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+616263
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+61626320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+61
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+6162
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+616263
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+61626320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+euckr_bin
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+61
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+616263
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+6162
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+616263
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+6162632020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020636261
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+9E9D9CDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDF9C9D9E
+select collation(cast(0xA1A1 as char));
+collation(cast(0xA1A1 as char))
+euckr_bin
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+6141
+select hex(weight_string(cast(0xA1A1 as char)));
+hex(weight_string(cast(0xA1A1 as char)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1 as char) as char(3)))
+A1A12020
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)))
+A1A1A1A120
+select hex(weight_string(cast(0x40A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1 as char) as char(3)))
+40A1A120
+select hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)))
+4040A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0))
+A1A1A1A120
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0))
+A1A1A1A1202020202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+#
+# End of 5.6 tests
+#
diff --git a/mysql-test/r/ctype_gb2312.result b/mysql-test/r/ctype_gb2312.result
index 9e9888aecd8..d947674909b 100644
--- a/mysql-test/r/ctype_gb2312.result
+++ b/mysql-test/r/ctype_gb2312.result
@@ -548,3 +548,398 @@ DROP TABLE t1;
#
# End of 5.5 tests
#
+#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+set names gb2312;
+select @@collation_connection;
+@@collation_connection
+gb2312_chinese_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+41
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+414243
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+4142
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+414243
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+4142432020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+41
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+4142
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+414220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+41422020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+4142202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+41422020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+41
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+4142
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+414243
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+41424320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+41
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+4142
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+414243
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+41424320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+gb2312_chinese_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+41
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+414243
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+4142
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+414243
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+4142432020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020434241
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+BEBDBCDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDFBCBDBE
+select collation(cast(0xA1A1 as char));
+collation(cast(0xA1A1 as char))
+gb2312_chinese_ci
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+4141
+select hex(weight_string(cast(0xA1A1 as char)));
+hex(weight_string(cast(0xA1A1 as char)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1 as char) as char(3)))
+A1A12020
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)))
+A1A1A1A120
+select hex(weight_string(cast(0x40A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1 as char) as char(3)))
+40A1A120
+select hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)))
+4040A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0))
+A1A1A1A120
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0))
+A1A1A1A1202020202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+set collation_connection=gb2312_bin;
+select @@collation_connection;
+@@collation_connection
+gb2312_bin
+select hex(weight_string('a'));
+hex(weight_string('a'))
+61
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+616263
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+6162
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+616263
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+6162632020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+61
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+6162
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+616220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+61622020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+6162202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+61622020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+61
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+6162
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+616263
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+61626320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+61
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+6162
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+616263
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+61626320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+gb2312_bin
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+61
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+616263
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+6162
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+616263
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+6162632020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020636261
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+9E9D9CDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDF9C9D9E
+select collation(cast(0xA1A1 as char));
+collation(cast(0xA1A1 as char))
+gb2312_bin
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+6141
+select hex(weight_string(cast(0xA1A1 as char)));
+hex(weight_string(cast(0xA1A1 as char)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1 as char) as char(3)))
+A1A12020
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)))
+A1A1A1A120
+select hex(weight_string(cast(0x40A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1 as char) as char(3)))
+40A1A120
+select hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)))
+4040A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0))
+A1A1A1A120
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0))
+A1A1A1A1202020202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+#
+# End of 5.6 tests
+#
diff --git a/mysql-test/r/ctype_gbk.result b/mysql-test/r/ctype_gbk.result
index 0abbbec1d7b..ec5fe0578cf 100644
--- a/mysql-test/r/ctype_gbk.result
+++ b/mysql-test/r/ctype_gbk.result
@@ -580,3 +580,746 @@ DROP TABLE t1;
#
# End of 5.5 tests
#
+#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+set names gbk;
+select @@collation_connection;
+@@collation_connection
+gbk_chinese_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+41
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+414243
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+4142
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+414243
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+4142432020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+41
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+4142
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+414220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+41422020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+4142202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+41422020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+41
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+4142
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+414243
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+41424320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+41
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+4142
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+414243
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+41424320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+gbk_chinese_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+41
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+414243
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+4142
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+414243
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+4142432020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020434241
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+BEBDBCDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDFBCBDBE
+select collation(cast(0xA1A1 as char));
+collation(cast(0xA1A1 as char))
+gbk_chinese_ci
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+4141
+select hex(weight_string(cast(0xA1A1 as char)));
+hex(weight_string(cast(0xA1A1 as char)))
+810B
+select hex(weight_string(cast(0xA1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1 as char) as char(1)))
+810B
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)))
+810B
+select hex(weight_string(cast(0xA1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1 as char) as char(3)))
+810B2020
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)))
+810B810B20
+select hex(weight_string(cast(0x40A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1 as char) as char(3)))
+40810B20
+select hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)))
+40810B810B
+select hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)))
+40810B810B
+select hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)))
+4040810B
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0))
+81
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0))
+810B
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0))
+810B81
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0))
+810B810B
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0))
+810B810B20
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0))
+810B810B202020202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0))
+81
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0))
+810B
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0))
+810B81
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0))
+810B810B
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0))
+810B810B81
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0))
+810B810B810B20202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0))
+81
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0))
+810B
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0))
+810B81
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0))
+810B810B
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0))
+810B810B81
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0))
+810B810B810B20202020202020202020202020202020202020
+select collation(cast(0x8140 as char));
+collation(cast(0x8140 as char))
+gbk_chinese_ci
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+4141
+select hex(weight_string(cast(0x8140 as char)));
+hex(weight_string(cast(0x8140 as char)))
+A2CD
+select hex(weight_string(cast(0x8140 as char) as char(1)));
+hex(weight_string(cast(0x8140 as char) as char(1)))
+A2CD
+select hex(weight_string(cast(0x81408140 as char) as char(1)));
+hex(weight_string(cast(0x81408140 as char) as char(1)))
+A2CD
+select hex(weight_string(cast(0x8140 as char) as char(3)));
+hex(weight_string(cast(0x8140 as char) as char(3)))
+A2CD2020
+select hex(weight_string(cast(0x81408140 as char) as char(3)));
+hex(weight_string(cast(0x81408140 as char) as char(3)))
+A2CDA2CD20
+select hex(weight_string(cast(0x408140 as char) as char(3)));
+hex(weight_string(cast(0x408140 as char) as char(3)))
+40A2CD20
+select hex(weight_string(cast(0x4081408140 as char) as char(3)));
+hex(weight_string(cast(0x4081408140 as char) as char(3)))
+40A2CDA2CD
+select hex(weight_string(cast(0x40814081408140 as char) as char(3)));
+hex(weight_string(cast(0x40814081408140 as char) as char(3)))
+40A2CDA2CD
+select hex(weight_string(cast(0x4040814081408140 as char) as char(3)));
+hex(weight_string(cast(0x4040814081408140 as char) as char(3)))
+4040A2CD
+select hex(weight_string(cast(0x814081408140 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 1, 2, 0xC0))
+A2
+select hex(weight_string(cast(0x814081408140 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 2, 2, 0xC0))
+A2CD
+select hex(weight_string(cast(0x814081408140 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 3, 2, 0xC0))
+A2CDA2
+select hex(weight_string(cast(0x814081408140 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 4, 2, 0xC0))
+A2CDA2CD
+select hex(weight_string(cast(0x814081408140 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 5, 2, 0xC0))
+A2CDA2CD20
+select hex(weight_string(cast(0x814081408140 as char),25, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char),25, 2, 0xC0))
+A2CDA2CD202020202020202020202020202020202020202020
+select hex(weight_string(cast(0x814081408140 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 1, 3, 0xC0))
+A2
+select hex(weight_string(cast(0x814081408140 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 2, 3, 0xC0))
+A2CD
+select hex(weight_string(cast(0x814081408140 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 3, 3, 0xC0))
+A2CDA2
+select hex(weight_string(cast(0x814081408140 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 4, 3, 0xC0))
+A2CDA2CD
+select hex(weight_string(cast(0x814081408140 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 5, 3, 0xC0))
+A2CDA2CDA2
+select hex(weight_string(cast(0x814081408140 as char),25, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char),25, 3, 0xC0))
+A2CDA2CDA2CD20202020202020202020202020202020202020
+select hex(weight_string(cast(0x814081408140 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 1, 4, 0xC0))
+A2
+select hex(weight_string(cast(0x814081408140 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 2, 4, 0xC0))
+A2CD
+select hex(weight_string(cast(0x814081408140 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 3, 4, 0xC0))
+A2CDA2
+select hex(weight_string(cast(0x814081408140 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 4, 4, 0xC0))
+A2CDA2CD
+select hex(weight_string(cast(0x814081408140 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 5, 4, 0xC0))
+A2CDA2CDA2
+select hex(weight_string(cast(0x814081408140 as char),25, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char),25, 4, 0xC0))
+A2CDA2CDA2CD20202020202020202020202020202020202020
+select collation(cast(0xA1A1 as char));
+collation(cast(0xA1A1 as char))
+gbk_chinese_ci
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+4141
+select hex(weight_string(cast(0x8EA1 as char)));
+hex(weight_string(cast(0x8EA1 as char)))
+8E08
+select hex(weight_string(cast(0x8EA1 as char) as char(1)));
+hex(weight_string(cast(0x8EA1 as char) as char(1)))
+8E08
+select hex(weight_string(cast(0x8EA18EA1 as char) as char(1)));
+hex(weight_string(cast(0x8EA18EA1 as char) as char(1)))
+8E08
+select hex(weight_string(cast(0x8EA1 as char) as char(3)));
+hex(weight_string(cast(0x8EA1 as char) as char(3)))
+8E082020
+select hex(weight_string(cast(0x8EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x8EA18EA1 as char) as char(3)))
+8E088E0820
+select hex(weight_string(cast(0x408EA1 as char) as char(3)));
+hex(weight_string(cast(0x408EA1 as char) as char(3)))
+408E0820
+select hex(weight_string(cast(0x408EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x408EA18EA1 as char) as char(3)))
+408E088E08
+select hex(weight_string(cast(0x408EA18EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x408EA18EA18EA1 as char) as char(3)))
+408E088E08
+select hex(weight_string(cast(0x40408EA18EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x40408EA18EA18EA1 as char) as char(3)))
+40408E08
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 2, 0xC0))
+8E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 2, 0xC0))
+8E08
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 2, 0xC0))
+8E088E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 2, 0xC0))
+8E088E08
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 2, 0xC0))
+8E088E0820
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 2, 0xC0))
+8E088E08202020202020202020202020202020202020202020
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 3, 0xC0))
+8E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 3, 0xC0))
+8E08
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 3, 0xC0))
+8E088E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 3, 0xC0))
+8E088E08
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 3, 0xC0))
+8E088E088E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 3, 0xC0))
+8E088E088E0820202020202020202020202020202020202020
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 4, 0xC0))
+8E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 4, 0xC0))
+8E08
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 4, 0xC0))
+8E088E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 4, 0xC0))
+8E088E08
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 4, 0xC0))
+8E088E088E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 4, 0xC0))
+8E088E088E0820202020202020202020202020202020202020
+set collation_connection=gbk_bin;
+select @@collation_connection;
+@@collation_connection
+gbk_bin
+select hex(weight_string('a'));
+hex(weight_string('a'))
+61
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+616263
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+6162
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+616263
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+6162632020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+61
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+6162
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+616220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+61622020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+6162202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+61622020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+61
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+6162
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+616263
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+61626320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+61
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+6162
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+616263
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+61626320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+gbk_bin
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+61
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+616263
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+6162
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+616263
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+6162632020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020636261
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+9E9D9CDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDF9C9D9E
+select collation(cast(0xA1A1 as char));
+collation(cast(0xA1A1 as char))
+gbk_bin
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+6141
+select hex(weight_string(cast(0xA1A1 as char)));
+hex(weight_string(cast(0xA1A1 as char)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1 as char) as char(3)))
+A1A12020
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)))
+A1A1A1A120
+select hex(weight_string(cast(0x40A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1 as char) as char(3)))
+40A1A120
+select hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)))
+4040A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0))
+A1A1A1A120
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0))
+A1A1A1A1202020202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+select collation(cast(0x8140 as char));
+collation(cast(0x8140 as char))
+gbk_bin
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+6141
+select hex(weight_string(cast(0x8140 as char)));
+hex(weight_string(cast(0x8140 as char)))
+8140
+select hex(weight_string(cast(0x8140 as char) as char(1)));
+hex(weight_string(cast(0x8140 as char) as char(1)))
+8140
+select hex(weight_string(cast(0x81408140 as char) as char(1)));
+hex(weight_string(cast(0x81408140 as char) as char(1)))
+8140
+select hex(weight_string(cast(0x8140 as char) as char(3)));
+hex(weight_string(cast(0x8140 as char) as char(3)))
+81402020
+select hex(weight_string(cast(0x81408140 as char) as char(3)));
+hex(weight_string(cast(0x81408140 as char) as char(3)))
+8140814020
+select hex(weight_string(cast(0x408140 as char) as char(3)));
+hex(weight_string(cast(0x408140 as char) as char(3)))
+40814020
+select hex(weight_string(cast(0x4081408140 as char) as char(3)));
+hex(weight_string(cast(0x4081408140 as char) as char(3)))
+4081408140
+select hex(weight_string(cast(0x40814081408140 as char) as char(3)));
+hex(weight_string(cast(0x40814081408140 as char) as char(3)))
+4081408140
+select hex(weight_string(cast(0x4040814081408140 as char) as char(3)));
+hex(weight_string(cast(0x4040814081408140 as char) as char(3)))
+40408140
+select hex(weight_string(cast(0x814081408140 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 1, 2, 0xC0))
+81
+select hex(weight_string(cast(0x814081408140 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 2, 2, 0xC0))
+8140
+select hex(weight_string(cast(0x814081408140 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 3, 2, 0xC0))
+814081
+select hex(weight_string(cast(0x814081408140 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 4, 2, 0xC0))
+81408140
+select hex(weight_string(cast(0x814081408140 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 5, 2, 0xC0))
+8140814020
+select hex(weight_string(cast(0x814081408140 as char),25, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char),25, 2, 0xC0))
+81408140202020202020202020202020202020202020202020
+select hex(weight_string(cast(0x814081408140 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 1, 3, 0xC0))
+81
+select hex(weight_string(cast(0x814081408140 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 2, 3, 0xC0))
+8140
+select hex(weight_string(cast(0x814081408140 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 3, 3, 0xC0))
+814081
+select hex(weight_string(cast(0x814081408140 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 4, 3, 0xC0))
+81408140
+select hex(weight_string(cast(0x814081408140 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 5, 3, 0xC0))
+8140814081
+select hex(weight_string(cast(0x814081408140 as char),25, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char),25, 3, 0xC0))
+81408140814020202020202020202020202020202020202020
+select hex(weight_string(cast(0x814081408140 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 1, 4, 0xC0))
+81
+select hex(weight_string(cast(0x814081408140 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 2, 4, 0xC0))
+8140
+select hex(weight_string(cast(0x814081408140 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 3, 4, 0xC0))
+814081
+select hex(weight_string(cast(0x814081408140 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 4, 4, 0xC0))
+81408140
+select hex(weight_string(cast(0x814081408140 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 5, 4, 0xC0))
+8140814081
+select hex(weight_string(cast(0x814081408140 as char),25, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char),25, 4, 0xC0))
+81408140814020202020202020202020202020202020202020
+select collation(cast(0xA1A1 as char));
+collation(cast(0xA1A1 as char))
+gbk_bin
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+6141
+select hex(weight_string(cast(0x8EA1 as char)));
+hex(weight_string(cast(0x8EA1 as char)))
+8EA1
+select hex(weight_string(cast(0x8EA1 as char) as char(1)));
+hex(weight_string(cast(0x8EA1 as char) as char(1)))
+8EA1
+select hex(weight_string(cast(0x8EA18EA1 as char) as char(1)));
+hex(weight_string(cast(0x8EA18EA1 as char) as char(1)))
+8EA1
+select hex(weight_string(cast(0x8EA1 as char) as char(3)));
+hex(weight_string(cast(0x8EA1 as char) as char(3)))
+8EA12020
+select hex(weight_string(cast(0x8EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x8EA18EA1 as char) as char(3)))
+8EA18EA120
+select hex(weight_string(cast(0x408EA1 as char) as char(3)));
+hex(weight_string(cast(0x408EA1 as char) as char(3)))
+408EA120
+select hex(weight_string(cast(0x408EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x408EA18EA1 as char) as char(3)))
+408EA18EA1
+select hex(weight_string(cast(0x408EA18EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x408EA18EA18EA1 as char) as char(3)))
+408EA18EA1
+select hex(weight_string(cast(0x40408EA18EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x40408EA18EA18EA1 as char) as char(3)))
+40408EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 2, 0xC0))
+8E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 2, 0xC0))
+8EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 2, 0xC0))
+8EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 2, 0xC0))
+8EA18EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 2, 0xC0))
+8EA18EA120
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 2, 0xC0))
+8EA18EA1202020202020202020202020202020202020202020
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 3, 0xC0))
+8E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 3, 0xC0))
+8EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 3, 0xC0))
+8EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 3, 0xC0))
+8EA18EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 3, 0xC0))
+8EA18EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 3, 0xC0))
+8EA18EA18EA120202020202020202020202020202020202020
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 4, 0xC0))
+8E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 4, 0xC0))
+8EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 4, 0xC0))
+8EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 4, 0xC0))
+8EA18EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 4, 0xC0))
+8EA18EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 4, 0xC0))
+8EA18EA18EA120202020202020202020202020202020202020
+#
+# End of 5.6 tests
+#
diff --git a/mysql-test/r/ctype_latin1.result b/mysql-test/r/ctype_latin1.result
index 6c11a68ea90..5cdce537241 100644
--- a/mysql-test/r/ctype_latin1.result
+++ b/mysql-test/r/ctype_latin1.result
@@ -3332,3 +3332,725 @@ Note 1003 select 'abcdó' AS `abcdó`,_latin1'abcd\xC3\xB3' AS `abcdó`,_utf8'ab
#
# End of 5.5 tests
#
+#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+set @@collation_connection=latin1_swedish_ci;
+select @@collation_connection;
+@@collation_connection
+latin1_swedish_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+41
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+414243
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+4142
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+414243
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+4142432020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+41
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+4142
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+414220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+41422020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+4142202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+41422020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+41
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+4142
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+414243
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+41424320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+41
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+4142
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+414243
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+41424320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+latin1_swedish_ci
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+80
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+808080
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+8080
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+808080
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+8080802020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+80
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+8080
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+808020
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+80802020
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+8080202020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+80802020202020202020202020202020202020202020202020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+80
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+8080
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+808080
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+80808020
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+8080802020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+80808020202020202020202020202020202020202020202020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+80
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+8080
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+808080
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+80808020
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+8080802020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+80808020202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+latin1_swedish_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+41
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+414243
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+4142
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+414243
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+4142432020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020434241
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+BEBDBCDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDFBCBDBE
+set @@collation_connection=latin1_bin;
+select @@collation_connection;
+@@collation_connection
+latin1_bin
+select hex(weight_string('a'));
+hex(weight_string('a'))
+61
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+616263
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+6162
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+616263
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+6162632020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+61
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+6162
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+616220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+61622020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+6162202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+61622020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+61
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+6162
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+616263
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+61626320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+61
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+6162
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+616263
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+61626320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+latin1_bin
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+80
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+808080
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+8080
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+808080
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+8080802020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+80
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+8080
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+808020
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+80802020
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+8080202020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+80802020202020202020202020202020202020202020202020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+80
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+8080
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+808080
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+80808020
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+8080802020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+80808020202020202020202020202020202020202020202020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+80
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+8080
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+808080
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+80808020
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+8080802020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+80808020202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+latin1_bin
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+61
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+616263
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+6162
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+616263
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+6162632020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020636261
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+9E9D9CDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDF9C9D9E
+set @@collation_connection=latin1_general_cs;
+select @@collation_connection;
+@@collation_connection
+latin1_general_cs
+select hex(weight_string('a'));
+hex(weight_string('a'))
+42
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+425254
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+4252
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+425254
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+4252542020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+42
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+4252
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+425220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+42522020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+4252202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+42522020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+42
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+4252
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+425254
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+42525420
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+4252542020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+42525420202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+42
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+4252
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+425254
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+42525420
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+4252542020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+42525420202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+latin1_general_cs
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+C0
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+C0C0C0
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+C0C0
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+C0C0C0
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+C0C0C02020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+C0
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+C0C0
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+C0C020
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+C0C02020
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+C0C0202020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+C0C02020202020202020202020202020202020202020202020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+C0
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+C0C0
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+C0C0C0
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+C0C0C020
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+C0C0C02020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+C0C0C020202020202020202020202020202020202020202020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+C0
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+C0C0
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+C0C0C0
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+C0C0C020
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+C0C0C02020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+C0C0C020202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+latin1_general_cs
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+42
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+425254
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+4252
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+425254
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+4252542020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020545242
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+BDADABDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDFABADBD
+set @@collation_connection=binary;
+select @@collation_connection;
+@@collation_connection
+binary
+select hex(weight_string('a'));
+hex(weight_string('a'))
+61
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+616263
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+6162
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+616263
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+6162630000
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+61
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+6162
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+616200
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+61620000
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+6162000000
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+61620000000000000000000000000000000000000000000000
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+61
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+6162
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+616263
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+61626300
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+6162630000
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+61626300000000000000000000000000000000000000000000
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+61
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+6162
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+616263
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+61626300
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+6162630000
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+61626300000000000000000000000000000000000000000000
+select @@collation_connection;
+@@collation_connection
+binary
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+80
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+808080
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+8080
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+808080
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+8080800000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+80
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+8080
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+808000
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+80800000
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+8080000000
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+80800000000000000000000000000000000000000000000000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+80
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+8080
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+808080
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+80808000
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+8080800000
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+80808000000000000000000000000000000000000000000000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+80
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+8080
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+808080
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+80808000
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+8080800000
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+80808000000000000000000000000000000000000000000000
+select @@collation_connection;
+@@collation_connection
+binary
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+61
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+616263
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+6162
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+616263
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+6162630000
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+0000636261
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+9E9D9CFFFF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+FFFF9C9D9E
+set names latin1;
+#
+# End of 5.6 tests
+#
diff --git a/mysql-test/r/ctype_latin1_de.result b/mysql-test/r/ctype_latin1_de.result
index f826199bb1f..d69102e76ff 100644
--- a/mysql-test/r/ctype_latin1_de.result
+++ b/mysql-test/r/ctype_latin1_de.result
@@ -361,6 +361,31 @@ ss,ß
u
ue,ü
drop table t1;
+CREATE TABLE t1 AS SELECT REPEAT('a',1) AS a, 1 AS b LIMIT 0;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1) COLLATE latin1_german2_ci NOT NULL DEFAULT '',
+ `b` int(1) NOT NULL DEFAULT '0'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci
+INSERT INTO t1 VALUES ('s',0),(_latin1 0xDF,1);
+SELECT * FROM t1 ORDER BY a, b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY a DESC, b;
+a b
+ß 1
+s 0
+SELECT * FROM t1 ORDER BY CONCAT(a), b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY CONCAT(a) DESC, b;
+a b
+ß 1
+s 0
+DROP TABLE t1;
SET NAMES latin1;
CREATE TABLE t1 (
col1 varchar(255) NOT NULL default ''
@@ -379,3 +404,242 @@ select * from t1 where length(s1)=1 and s1='oe';
s1
ö
drop table t1;
+End of 5.1 tests
+#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+set @@collation_connection=latin1_german2_ci;
+select @@collation_connection;
+@@collation_connection
+latin1_german2_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+41
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+414243
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+4142
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+414243
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+4142432020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+41
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+4142
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+414220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+41422020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+4142202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+41422020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+41
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+4142
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+414243
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+41424320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+41
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+4142
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+414243
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+41424320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+latin1_german2_ci
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+80
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+808080
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+8080
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+808080
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+8080802020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+80
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+8080
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+808020
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+80802020
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+8080202020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+80802020202020202020202020202020202020202020202020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+80
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+8080
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+808080
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+80808020
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+8080802020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+80808020202020202020202020202020202020202020202020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+80
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+8080
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+808080
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+80808020
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+8080802020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+80808020202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+latin1_german2_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+41
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+414243
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+4142
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+414243
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+4142432020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020434241
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+BEBDBCDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDFBCBDBE
+select hex(weight_string('Ä'));
+hex(weight_string('Ä'))
+4145
+select hex(weight_string('ä'));
+hex(weight_string('ä'))
+4145
+select hex(weight_string('Ö'));
+hex(weight_string('Ö'))
+4F45
+select hex(weight_string('ö'));
+hex(weight_string('ö'))
+4F45
+select hex(weight_string('Ü'));
+hex(weight_string('Ü'))
+5545
+select hex(weight_string('ü'));
+hex(weight_string('ü'))
+5545
+select hex(weight_string('S'));
+hex(weight_string('S'))
+53
+select hex(weight_string('s'));
+hex(weight_string('s'))
+53
+select hex(weight_string('ß'));
+hex(weight_string('ß'))
+5353
+select hex(weight_string('ä' as char(1)));
+hex(weight_string('ä' as char(1)))
+41
+select hex(weight_string('ö' as char(1)));
+hex(weight_string('ö' as char(1)))
+4F
+select hex(weight_string('ü' as char(1)));
+hex(weight_string('ü' as char(1)))
+55
+select hex(weight_string('ß' as char(1)));
+hex(weight_string('ß' as char(1)))
+53
+select hex(weight_string('xä' as char(2)));
+hex(weight_string('xä' as char(2)))
+5841
+select hex(weight_string('xö' as char(2)));
+hex(weight_string('xö' as char(2)))
+584F
+select hex(weight_string('xü' as char(2)));
+hex(weight_string('xü' as char(2)))
+5855
+select hex(weight_string('xß' as char(2)));
+hex(weight_string('xß' as char(2)))
+5853
+#
+# End of 5.6 tests
+#
diff --git a/mysql-test/r/ctype_latin2.result b/mysql-test/r/ctype_latin2.result
index c2c021b0760..2ddb78d5cc8 100644
--- a/mysql-test/r/ctype_latin2.result
+++ b/mysql-test/r/ctype_latin2.result
@@ -381,3 +381,225 @@ _
÷
ÿ
drop table t1;
+End of 5.1 tests
+#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+set names latin2;
+select @@collation_connection;
+@@collation_connection
+latin2_general_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+41
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+414445
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+4144
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+414445
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+4144452020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+41
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+4144
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+414420
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+41442020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+4144202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+41442020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+41
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+4144
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+414445
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+41444520
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+4144452020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+41444520202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+41
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+4144
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+414445
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+41444520
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+4144452020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+41444520202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+latin2_general_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+41
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+414445
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+4144
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+414445
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+4144452020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020454441
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+BEBBBADFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDFBABBBE
+set collation_connection=latin2_bin;
+select @@collation_connection;
+@@collation_connection
+latin2_bin
+select hex(weight_string('a'));
+hex(weight_string('a'))
+61
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+616263
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+6162
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+616263
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+6162632020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+61
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+6162
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+616220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+61622020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+6162202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+61622020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+61
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+6162
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+616263
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+61626320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+61
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+6162
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+616263
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+61626320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+latin2_bin
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+61
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+616263
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+6162
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+616263
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+6162632020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020636261
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+9E9D9CDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDF9C9D9E
+#
+# End of 5.6 tests
+#
diff --git a/mysql-test/r/ctype_latin2_ch.result b/mysql-test/r/ctype_latin2_ch.result
index 5b607872737..ebe01fdb747 100644
--- a/mysql-test/r/ctype_latin2_ch.result
+++ b/mysql-test/r/ctype_latin2_ch.result
@@ -29,3 +29,464 @@ id tt
select * from t1 where tt like '%AA%';
id tt
drop table t1;
+#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+set names latin2 collate latin2_czech_cs;
+SELECT strcmp('a','a ');
+strcmp('a','a ')
+0
+SELECT strcmp('a\0','a' );
+strcmp('a\0','a' )
+1
+SELECT strcmp('a\0','a ');
+strcmp('a\0','a ')
+1
+SELECT strcmp('a\t','a' );
+strcmp('a\t','a' )
+0
+SELECT strcmp('a\t','a ');
+strcmp('a\t','a ')
+0
+#
+# Note:
+# latin2_czech_cs does not support WEIGHT_STRING in full extent
+#
+select @@collation_connection;
+@@collation_connection
+latin2_czech_cs
+select hex(weight_string('a'));
+hex(weight_string('a'))
+0301030103010300
+select hex(weight_string('A'));
+hex(weight_string('A'))
+0301030104010400
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+0304050103090A01030F1101030F1100
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+0304050103090A01030F1101030F1100
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+0304050103090A01030F1101030F1100
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+0304050103090A01030F1101030F1100
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+03
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+0304
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+030405
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+03040501
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+0304050103
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+0304050103090A01030F1101030F1100202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+03
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+0304
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+030405
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+03040501
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+0304050103
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+0304050103090A01030F1101030F1100202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+03
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+0304
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+030405
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+03040501
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+0304050103
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+0304050103090A01030F1101030F1100202020202020202020
+select @@collation_connection;
+@@collation_connection
+latin2_czech_cs
+select collation(cast(_latin1 0xDF as char));
+collation(cast(_latin1 0xDF as char))
+latin2_czech_cs
+select hex(weight_string('s'));
+hex(weight_string('s'))
+1901310160016000
+select hex(weight_string(cast(_latin1 0xDF as char)));
+hex(weight_string(cast(_latin1 0xDF as char)))
+010101E200
+select hex(weight_string(cast(_latin1 0xDF as char) as char(1)));
+hex(weight_string(cast(_latin1 0xDF as char) as char(1)))
+010101E200
+select hex(weight_string('c'));
+hex(weight_string('c'))
+05010A0111011100
+select hex(weight_string('h'));
+hex(weight_string('h'))
+0B0118012D012D00
+select hex(weight_string('ch'));
+hex(weight_string('ch'))
+0C0119012F012F00
+select hex(weight_string('i'));
+hex(weight_string('i'))
+0D011A0132013200
+select hex(weight_string(cast(_latin1 0x6368DF as char)));
+hex(weight_string(cast(_latin1 0x6368DF as char)))
+0C0119012F012FE200
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(1)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(1)))
+0C0119012F012FE200
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(2)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(2)))
+0C0119012F012FE200
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(3)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(3)))
+0C0119012F012FE200
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(4)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(4)))
+0C0119012F012FE200
+select hex(weight_string(cast(_latin1 0xDF6368 as char)));
+hex(weight_string(cast(_latin1 0xDF6368 as char)))
+0C0119012F01E22F00
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(1)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(1)))
+0C0119012F01E22F00
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(2)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(2)))
+0C0119012F01E22F00
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(3)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(3)))
+0C0119012F01E22F00
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(4)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(4)))
+0C0119012F01E22F00
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 1, 2, 0xC0))
+0C
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 2, 2, 0xC0))
+0C01
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 3, 2, 0xC0))
+0C0119
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 4, 2, 0xC0))
+0C011901
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char),25, 2, 0xC0))
+0C0119012F012FE20020202020202020202020202020202020
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 1, 3, 0xC0))
+0C
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 2, 3, 0xC0))
+0C01
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 3, 3, 0xC0))
+0C0119
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 4, 3, 0xC0))
+0C011901
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char),25, 3, 0xC0))
+0C0119012F012FE20020202020202020202020202020202020
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 1, 4, 0xC0))
+0C
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 2, 4, 0xC0))
+0C01
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 3, 4, 0xC0))
+0C0119
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 4, 4, 0xC0))
+0C011901
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char),25, 4, 0xC0))
+0C0119012F012FE20020202020202020202020202020202020
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 2,0xC0))
+0C
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 2,0xC0))
+0C01
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 2,0xC0))
+0C0119
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 2,0xC0))
+0C011901
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char),25, 2,0xC0))
+0C0119012F01E22F0020202020202020202020202020202020
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 3,0xC0))
+0C
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 3,0xC0))
+0C01
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 3,0xC0))
+0C0119
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 3,0xC0))
+0C011901
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char),25, 3,0xC0))
+0C0119012F01E22F0020202020202020202020202020202020
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 4,0xC0))
+0C
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 4,0xC0))
+0C01
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 4,0xC0))
+0C0119
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 4,0xC0))
+0C011901
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char),25, 4,0xC0))
+0C0119012F01E22F0020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+latin2_czech_cs
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+0301
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+0301
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+03040501
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+03040501
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+03040501
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+03040501
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+03040501
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+03040501
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+03040501
+select @@collation_connection;
+@@collation_connection
+latin2_czech_cs
+select hex(weight_string('a' LEVEL 2));
+hex(weight_string('a' LEVEL 2))
+0301
+select hex(weight_string('A' LEVEL 2));
+hex(weight_string('A' LEVEL 2))
+0301
+select hex(weight_string('abc' LEVEL 2));
+hex(weight_string('abc' LEVEL 2))
+03090A01
+select hex(weight_string('abc' as char(2) LEVEL 2));
+hex(weight_string('abc' as char(2) LEVEL 2))
+03090A01
+select hex(weight_string('abc' as char(3) LEVEL 2));
+hex(weight_string('abc' as char(3) LEVEL 2))
+03090A01
+select hex(weight_string('abc' as char(5) LEVEL 2));
+hex(weight_string('abc' as char(5) LEVEL 2))
+03090A01
+select @@collation_connection;
+@@collation_connection
+latin2_czech_cs
+select hex(weight_string('a' LEVEL 3));
+hex(weight_string('a' LEVEL 3))
+0301
+select hex(weight_string('A' LEVEL 3));
+hex(weight_string('A' LEVEL 3))
+0401
+select hex(weight_string('abc' LEVEL 3));
+hex(weight_string('abc' LEVEL 3))
+030F1101
+select hex(weight_string('abc' as char(2) LEVEL 3));
+hex(weight_string('abc' as char(2) LEVEL 3))
+030F1101
+select hex(weight_string('abc' as char(3) LEVEL 3));
+hex(weight_string('abc' as char(3) LEVEL 3))
+030F1101
+select hex(weight_string('Abc' as char(5) LEVEL 3));
+hex(weight_string('Abc' as char(5) LEVEL 3))
+040F1101
+select hex(weight_string('Abc' as char(5) LEVEL 3 REVERSE));
+hex(weight_string('Abc' as char(5) LEVEL 3 REVERSE))
+040F1101
+select hex(weight_string('Abc' as char(5) LEVEL 3 DESC));
+hex(weight_string('Abc' as char(5) LEVEL 3 DESC))
+040F1101
+select hex(weight_string('Abc' as char(5) LEVEL 3 DESC REVERSE));
+hex(weight_string('Abc' as char(5) LEVEL 3 DESC REVERSE))
+040F1101
+select @@collation_connection;
+@@collation_connection
+latin2_czech_cs
+select hex(weight_string('a' LEVEL 4));
+hex(weight_string('a' LEVEL 4))
+0300
+select hex(weight_string('A' LEVEL 4));
+hex(weight_string('A' LEVEL 4))
+0400
+select hex(weight_string('abc' LEVEL 4));
+hex(weight_string('abc' LEVEL 4))
+030F1100
+select hex(weight_string('abc' as char(2) LEVEL 4));
+hex(weight_string('abc' as char(2) LEVEL 4))
+030F1100
+select hex(weight_string('abc' as char(3) LEVEL 4));
+hex(weight_string('abc' as char(3) LEVEL 4))
+030F1100
+select hex(weight_string('abc' as char(5) LEVEL 4));
+hex(weight_string('abc' as char(5) LEVEL 4))
+030F1100
+select hex(weight_string('abc' as char(5) LEVEL 4 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 4 REVERSE))
+030F1100
+select hex(weight_string('abc' as char(5) LEVEL 4 DESC));
+hex(weight_string('abc' as char(5) LEVEL 4 DESC))
+030F1100
+select hex(weight_string('abc' as char(5) LEVEL 4 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 4 DESC REVERSE))
+030F1100
+select @@collation_connection;
+@@collation_connection
+latin2_czech_cs
+select hex(weight_string('a' LEVEL 1,2));
+hex(weight_string('a' LEVEL 1,2))
+03010301
+select hex(weight_string('a' LEVEL 1-2));
+hex(weight_string('a' LEVEL 1-2))
+03010301
+select hex(weight_string('A' LEVEL 1,2));
+hex(weight_string('A' LEVEL 1,2))
+03010301
+select hex(weight_string('A' LEVEL 1-2));
+hex(weight_string('A' LEVEL 1-2))
+03010301
+select @@collation_connection;
+@@collation_connection
+latin2_czech_cs
+select hex(weight_string('a' LEVEL 1,3));
+hex(weight_string('a' LEVEL 1,3))
+03010301
+select hex(weight_string('a' LEVEL 1-3));
+hex(weight_string('a' LEVEL 1-3))
+030103010301
+select hex(weight_string('A' LEVEL 1,3));
+hex(weight_string('A' LEVEL 1,3))
+03010401
+select hex(weight_string('A' LEVEL 1-3));
+hex(weight_string('A' LEVEL 1-3))
+030103010401
+select hex(weight_string('a' LEVEL 1,4));
+hex(weight_string('a' LEVEL 1,4))
+03010300
+select hex(weight_string('a' LEVEL 1-4));
+hex(weight_string('a' LEVEL 1-4))
+0301030103010300
+select hex(weight_string('A' LEVEL 1,4));
+hex(weight_string('A' LEVEL 1,4))
+03010400
+select hex(weight_string('A' LEVEL 1-4));
+hex(weight_string('A' LEVEL 1-4))
+0301030104010400
+select hex(weight_string('a' LEVEL 2,3));
+hex(weight_string('a' LEVEL 2,3))
+03010301
+select hex(weight_string('a' LEVEL 2-3));
+hex(weight_string('a' LEVEL 2-3))
+03010301
+select hex(weight_string('A' LEVEL 2,3));
+hex(weight_string('A' LEVEL 2,3))
+03010401
+select hex(weight_string('A' LEVEL 2-3));
+hex(weight_string('A' LEVEL 2-3))
+03010401
+select hex(weight_string('a' LEVEL 2,4));
+hex(weight_string('a' LEVEL 2,4))
+03010300
+select hex(weight_string('a' LEVEL 2-4));
+hex(weight_string('a' LEVEL 2-4))
+030103010300
+select hex(weight_string('A' LEVEL 2,4));
+hex(weight_string('A' LEVEL 2,4))
+03010400
+select hex(weight_string('A' LEVEL 2-4));
+hex(weight_string('A' LEVEL 2-4))
+030104010400
+select hex(weight_string('a' LEVEL 3,4));
+hex(weight_string('a' LEVEL 3,4))
+03010300
+select hex(weight_string('a' LEVEL 3-4));
+hex(weight_string('a' LEVEL 3-4))
+03010300
+select hex(weight_string('A' LEVEL 3,4));
+hex(weight_string('A' LEVEL 3,4))
+04010400
+select hex(weight_string('A' LEVEL 3-4));
+hex(weight_string('A' LEVEL 3-4))
+04010400
+select hex(weight_string('a' LEVEL 1,2,3,4));
+hex(weight_string('a' LEVEL 1,2,3,4))
+0301030103010300
+select hex(weight_string('a' LEVEL 2,3,4));
+hex(weight_string('a' LEVEL 2,3,4))
+030103010300
+select hex(weight_string('a' LEVEL 1,3,4));
+hex(weight_string('a' LEVEL 1,3,4))
+030103010300
+select hex(weight_string('a' LEVEL 1,2,3));
+hex(weight_string('a' LEVEL 1,2,3))
+030103010301
+select hex(weight_string('a' LEVEL 0));
+hex(weight_string('a' LEVEL 0))
+0301
+select hex(weight_string('a' LEVEL 8));
+hex(weight_string('a' LEVEL 8))
+0300
+select hex(weight_string('a' LEVEL 1,8));
+hex(weight_string('a' LEVEL 1,8))
+03010300
+#
+# End of 5.6 tests
+#
diff --git a/mysql-test/r/ctype_ldml.result b/mysql-test/r/ctype_ldml.result
index 5eef6c38640..0373d74afb4 100644
--- a/mysql-test/r/ctype_ldml.result
+++ b/mysql-test/r/ctype_ldml.result
@@ -412,6 +412,7 @@ COLLATION_NAME CHARACTER_SET_NAME ID IS_DEFAULT IS_COMPILED SORTLEN
utf8mb4_test_ci utf8mb4 326 8
utf16_test_ci utf16 327 8
utf8mb4_test_400_ci utf8mb4 328 8
+latin1_test2 latin1 332 1
utf8_bengali_standard_ci utf8 336 8
utf8_bengali_traditional_ci utf8 337 8
utf8_phone_ci utf8 352 8
@@ -429,6 +430,7 @@ utf8_maxuserid_ci utf8 2047 8
show collation like '%test%';
Collation Charset Id Default Compiled Sortlen
latin1_test latin1 99 Yes 1
+latin1_test2 latin1 332 1
utf8_test_ci utf8 353 8
ucs2_test_ci ucs2 358 8
utf8mb4_test_ci utf8mb4 326 8
@@ -459,6 +461,12 @@ SHOW COLLATION LIKE 'utf8_phone_ci';
Collation Charset Id Default Compiled Sortlen
utf8_phone_ci utf8 352 8
SET NAMES utf8;
+SELECT hex(weight_string(_utf8mb4'a' collate utf8mb4_test_400_ci));
+hex(weight_string(_utf8mb4'a' collate utf8mb4_test_400_ci))
+0E33
+SELECT hex(weight_string(convert(_utf32 0x10002 using utf8mb4) collate utf8mb4_test_400_ci));
+hex(weight_string(convert(_utf32 0x10002 using utf8mb4) collate utf8mb4_test_400_ci))
+FFFD
SELECT hex(@a:=convert(_utf32 0x10400 using utf8mb4) collate utf8mb4_test_400_ci), hex(lower(@a));
hex(@a:=convert(_utf32 0x10400 using utf8mb4) collate utf8mb4_test_400_ci) hex(lower(@a))
F0909080 F0909080
@@ -507,258 +515,258 @@ INSERT INTO t1 VALUES ('lb-fv'),('lb-lv');
INSERT INTO t1 VALUES (_ucs2 0x3106),(_ucs2 0x3110), (_ucs2 0x3111), (_ucs2 0x3112);
INSERT INTO t1 VALUES (_ucs2 0x32A3), (_ucs2 0x3231);
INSERT INTO t1 VALUES (_ucs2 0x84D9), (_ucs2 0x98F5), (_ucs2 0x7CF3), (_ucs2 0x5497);
-SELECT a FROM t1 ORDER BY a, LENGTH(a), BINARY a;
-a
-lp-ft
-lp-lt
-lp-fpi
-lp-fsi
-lp-fti
-lp-lpi
-lp-lsi
-lp-lti
-lb-fv
-lb-fni
-lp-fv
-lp-fni
--
-=
-|
-lb-lv
-lp-lv
-1
-01
-001
-0001
-00001
-000001
-12
-012
-0012
-00012
-000012
-123
-0123
-00123
-000123
-1234
-01234
-001234
-12345
-012345
-9
-~
-!
-@
-#
-$
-%
-^
-(
-)
-+
-:
-;
-"
-'
-?
-a
-a
-aa-
-ab-
-ac-
-ad-
-ae-
-af-
-az-
-b
-À
-à
-á
-Ä€
-c
-k
-ch
-cs
-ccs
-cscs
-cz
-ÄŠ
-Ä‹
-d
-É
-Ê
-é
-ê
-Ä’
-Ä“
-Äš
-Ä›
-e
-f
-fz
-Ä 
-Ä¡
-g
-GĦ
-Għ
-gĦ
-għ
-h
-hz
-Ħ
-ħ
-i
-iz
-y
-yz
-Å»
-ż
-z
-ГÐИ
-ГИБДД
-lb-lni
-lp-lni
-ㄆ
-ã„
-ã„‘
-ã„’
-㊣
-㈱
-è“™
-飵
-ç³³
-å’—
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY a;
+a HEX(WEIGHT_STRING(a))
+lp-ft 0001
+lp-lt 0001
+lp-fpi 0001
+lp-fsi 0001
+lp-fti 0001
+lp-lpi 0001
+lp-lsi 0001
+lp-lti 0001
+lb-fv 0200233E
+lb-fni 0200233E
+lp-fv 0202
+lp-fni 0202
+- 0221
+= 042D
+| 0430
+lb-lv 0DD9233E
+lp-lv 0DDB
+1 0E2A
+01 0E2A
+001 0E2A
+0001 0E2A
+00001 0E2A
+000001 0E2A
+12 0E2A0E2B
+012 0E2A0E2B
+0012 0E2A0E2B
+00012 0E2A0E2B
+000012 0E2A0E2B
+123 0E2A0E2B0E2C
+0123 0E2A0E2B0E2C
+00123 0E2A0E2B0E2C
+000123 0E2A0E2B0E2C
+1234 0E2A0E2B0E2C0E2D
+01234 0E2A0E2B0E2C0E2D
+001234 0E2A0E2B0E2C0E2D
+12345 0E2A0E2B0E2C0E2D0E2E
+012345 0E2A0E2B0E2C0E2D0E2E
+9 0E32
+~ 0E32233E
+! 0E32233F
+@ 0E322340
+# 0E322341
+$ 0E322342
+% 0E322343
+^ 0E322344
+( 0E322346
+) 0E322347
++ 0E322348
+: 0E322349
+; 0E32234A
+" 0E32234B
+' 0E32234C
+? 0E32234D
+a 0E33
+a 0E33
+aa- 0E330E330221
+ab- 0E330E4A0E34
+ac- 0E330E600E60
+ad- 0E330E6D0E6D
+ae- 0E330E8B0E8B
+af- 0E330EB90EB9
+az- 0E33106A0221
+b 0E4A
+À 0E4A
+Ã 0E4A
+à 0E4A
+á 0E4A
+Ä€ 0E4A
+Ä 0E4A
+c 0E60
+k 0E600EE1
+ch 0E600EE1
+cs 0E600FEA
+ccs 0E600FEA0E600FEA
+cscs 0E600FEA0E600FEA
+cz 0E60106A
+ÄŠ 0E6C233E
+Ä‹ 0E6C233E
+d 0E6D
+É 0E6D
+Ê 0E6D
+é 0E6D
+ê 0E6D
+Ä’ 0E6D
+Ä“ 0E6D
+Äš 0E6D
+Ä› 0E6D
+e 0E8B
+f 0EB9
+fz 0EB9106A
+Ä  0EC0233E
+Ä¡ 0EC0233E
+g 0EC1
+GĦ 0EE0233E
+Għ 0EE0233E
+gĦ 0EE0233E
+għ 0EE0233E
+h 0EE1
+hz 0EE1106A
+Ħ 0EFA233E
+ħ 0EFA233E
+i 0EFB
+iz 0EFB106A
+y 105E
+yz 105E106A
+Å» 1069233E
+ż 1069233E
+z 106A
+ГÐИ 11341114117C
+ГИБДД 11341114117C
+lb-lni 233C233E
+lp-lni 233E
+ㄆ 233F
+ã„ 2349
+ã„‘ 234A
+ã„’ 234B
+㊣ 7147
+㈱ 72D5
+è“™ 753C
+飵 753D
+ç³³ 753E
+å’— 753F
#
# WL#5624, the same test with UCS2
#
ALTER TABLE t1 CONVERT TO CHARACTER SET ucs2 COLLATE ucs2_5624_1;
-SELECT a FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
-a
-lp-ft
-lp-lt
-lp-fpi
-lp-fsi
-lp-fti
-lp-lpi
-lp-lsi
-lp-lti
-lb-fv
-lb-fni
-lp-fv
-lp-fni
--
-=
-|
-lb-lv
-lp-lv
-1
-01
-001
-0001
-00001
-000001
-12
-012
-0012
-00012
-000012
-123
-0123
-00123
-000123
-1234
-01234
-001234
-12345
-012345
-9
-~
-!
-@
-#
-$
-%
-^
-(
-)
-+
-:
-;
-"
-'
-?
-a
-a
-aa-
-ab-
-ac-
-ad-
-ae-
-af-
-az-
-b
-À
-à
-á
-Ä€
-c
-k
-ch
-cs
-ccs
-cscs
-cz
-ÄŠ
-Ä‹
-d
-É
-Ê
-é
-ê
-Ä’
-Ä“
-Äš
-Ä›
-e
-f
-fz
-Ä 
-Ä¡
-g
-GĦ
-Għ
-gĦ
-għ
-h
-hz
-Ħ
-ħ
-i
-iz
-y
-yz
-Å»
-ż
-z
-ГÐИ
-ГИБДД
-lb-lni
-lp-lni
-ㄆ
-ã„
-ã„‘
-ã„’
-㊣
-㈱
-è“™
-飵
-ç³³
-å’—
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
+a HEX(WEIGHT_STRING(a))
+lp-ft 0001
+lp-lt 0001
+lp-fpi 0001
+lp-fsi 0001
+lp-fti 0001
+lp-lpi 0001
+lp-lsi 0001
+lp-lti 0001
+lb-fv 0200233E
+lb-fni 0200233E
+lp-fv 0202
+lp-fni 0202
+- 0221
+= 042D
+| 0430
+lb-lv 0DD9233E
+lp-lv 0DDB
+1 0E2A
+01 0E2A
+001 0E2A
+0001 0E2A
+00001 0E2A
+000001 0E2A
+12 0E2A0E2B
+012 0E2A0E2B
+0012 0E2A0E2B
+00012 0E2A0E2B
+000012 0E2A0E2B
+123 0E2A0E2B0E2C
+0123 0E2A0E2B0E2C
+00123 0E2A0E2B0E2C
+000123 0E2A0E2B0E2C
+1234 0E2A0E2B0E2C0E2D
+01234 0E2A0E2B0E2C0E2D
+001234 0E2A0E2B0E2C0E2D
+12345 0E2A0E2B0E2C0E2D0E2E
+012345 0E2A0E2B0E2C0E2D0E2E
+9 0E32
+~ 0E32233E
+! 0E32233F
+@ 0E322340
+# 0E322341
+$ 0E322342
+% 0E322343
+^ 0E322344
+( 0E322346
+) 0E322347
++ 0E322348
+: 0E322349
+; 0E32234A
+" 0E32234B
+' 0E32234C
+? 0E32234D
+a 0E33
+a 0E33
+aa- 0E330E330221
+ab- 0E330E4A0E34
+ac- 0E330E600E60
+ad- 0E330E6D0E6D
+ae- 0E330E8B0E8B
+af- 0E330EB90EB9
+az- 0E33106A0221
+b 0E4A
+À 0E4A
+Ã 0E4A
+à 0E4A
+á 0E4A
+Ä€ 0E4A
+Ä 0E4A
+c 0E60
+k 0E600EE1
+ch 0E600EE1
+cs 0E600FEA
+ccs 0E600FEA0E600FEA
+cscs 0E600FEA0E600FEA
+cz 0E60106A
+ÄŠ 0E6C233E
+Ä‹ 0E6C233E
+d 0E6D
+É 0E6D
+Ê 0E6D
+é 0E6D
+ê 0E6D
+Ä’ 0E6D
+Ä“ 0E6D
+Äš 0E6D
+Ä› 0E6D
+e 0E8B
+f 0EB9
+fz 0EB9106A
+Ä  0EC0233E
+Ä¡ 0EC0233E
+g 0EC1
+GĦ 0EE0233E
+Għ 0EE0233E
+gĦ 0EE0233E
+għ 0EE0233E
+h 0EE1
+hz 0EE1106A
+Ħ 0EFA233E
+ħ 0EFA233E
+i 0EFB
+iz 0EFB106A
+y 105E
+yz 105E106A
+Å» 1069233E
+ż 1069233E
+z 106A
+ГÐИ 11341114117C
+ГИБДД 11341114117C
+lb-lni 233C233E
+lp-lni 233E
+ㄆ 233F
+ã„ 2349
+ã„‘ 234A
+ã„’ 234B
+㊣ 7147
+㈱ 72D5
+è“™ 753C
+飵 753D
+ç³³ 753E
+å’— 753F
DROP TABLE t1;
#
# WL#5624, unsupported features
@@ -790,12 +798,12 @@ Warning 1273 Can't reset before a primary ignorable character U+A48C
SET NAMES utf8 COLLATE utf8_5624_4;
CREATE TABLE t1 AS SELECT REPEAT(' ', 10) AS a LIMIT 0;
INSERT INTO t1 VALUES ('\\'),('u'),('x'),('X');
-SELECT a FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
-a
-\
-x
-u
-X
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
+a HEX(WEIGHT_STRING(a))
+\ 02CE
+x 02CE101F
+u 101F
+X 105A
DROP TABLE t1;
#
# WL#5624, testing Bengali collations
@@ -806,19 +814,19 @@ INSERT INTO t1 VALUES (_ucs2 0x09FA), (_ucs2 0x09F8), (_ucs2 0x09F9), (_ucs2 0x0
INSERT INTO t1 VALUES (_ucs2 0x09DC), (_ucs2 0x09A109BC);
INSERT INTO t1 VALUES (_ucs2 0x09A2), (_ucs2 0x09DD), (_ucs2 0x09A209BC);
INSERT INTO t1 VALUES (_ucs2 0x09A3);
-SELECT HEX(CONVERT(a USING ucs2)), HEX(a)
+SELECT HEX(WEIGHT_STRING(a)), HEX(CONVERT(a USING ucs2)), HEX(a)
FROM t1 ORDER BY a, BINARY a;
-HEX(CONVERT(a USING ucs2)) HEX(a)
-09FA E0A7BA
-09F8 E0A7B8
-09F9 E0A7B9
-09F2 E0A7B2
-09A109BC E0A6A1E0A6BC
-09DC E0A79C
-09A2 E0A6A2
-09A209BC E0A6A2E0A6BC
-09DD E0A79D
-09A3 E0A6A3
+HEX(WEIGHT_STRING(a)) HEX(CONVERT(a USING ucs2)) HEX(a)
+0350 09FA E0A7BA
+0351 09F8 E0A7B8
+0352 09F9 E0A7B9
+0353 09F2 E0A7B2
+0374 09A109BC E0A6A1E0A6BC
+0374 09DC E0A79C
+0375 09A2 E0A6A2
+0376 09A209BC E0A6A2E0A6BC
+0376 09DD E0A79D
+0377 09A3 E0A6A3
DROP TABLE t1;
SET NAMES utf8, collation_connection=utf8_bengali_traditional_ci;
CREATE TABLE t1 AS SELECT REPEAT (' ', 10) AS a LIMIT 0;
@@ -854,159 +862,159 @@ INSERT INTO t1 VALUES
(_ucs2 0x099509CD0990),(_ucs2 0x099509C8),
(_ucs2 0x099509CD0993),(_ucs2 0x099509CB),
(_ucs2 0x099509CD0994),(_ucs2 0x099509CC);
-SELECT HEX(CONVERT(a USING ucs2)), HEX(a)
+SELECT HEX(WEIGHT_STRING(a)), HEX(CONVERT(a USING ucs2)), HEX(a)
FROM t1 ORDER BY a, BINARY(a);
-HEX(CONVERT(a USING ucs2)) HEX(a)
-0985 E0A685
-0986 E0A686
-0987 E0A687
-0988 E0A688
-0989 E0A689
-098A E0A68A
-098B E0A68B
-09E0 E0A7A0
-098C E0A68C
-09E1 E0A7A1
-098F E0A68F
-0990 E0A690
-0993 E0A693
-0994 E0A694
-0982 E0A682
-0983 E0A683
-0981 E0A681
-099509CD E0A695E0A78D
-0995 E0A695
-099509CD0985 E0A695E0A78DE0A685
-099509BE E0A695E0A6BE
-099509CD0986 E0A695E0A78DE0A686
-099509BF E0A695E0A6BF
-099509CD0987 E0A695E0A78DE0A687
-099509C0 E0A695E0A780
-099509CD0988 E0A695E0A78DE0A688
-099509C1 E0A695E0A781
-099509CD0989 E0A695E0A78DE0A689
-099509C2 E0A695E0A782
-099509CD098A E0A695E0A78DE0A68A
-099509C3 E0A695E0A783
-099509CD098B E0A695E0A78DE0A68B
-099509C4 E0A695E0A784
-099509CD09E0 E0A695E0A78DE0A7A0
-099509CD098C E0A695E0A78DE0A68C
-099509E2 E0A695E0A7A2
-099509CD09E1 E0A695E0A78DE0A7A1
-099509E3 E0A695E0A7A3
-099509C7 E0A695E0A787
-099509CD098F E0A695E0A78DE0A68F
-099509C8 E0A695E0A788
-099509CD0990 E0A695E0A78DE0A690
-099509CB E0A695E0A78B
-099509CD0993 E0A695E0A78DE0A693
-099509CC E0A695E0A78C
-099509CD0994 E0A695E0A78DE0A694
-099609CD E0A696E0A78D
-099709CD E0A697E0A78D
-099809CD E0A698E0A78D
-099909CD E0A699E0A78D
-099A09CD E0A69AE0A78D
-099B09CD E0A69BE0A78D
-099C09CD E0A69CE0A78D
-099D09CD E0A69DE0A78D
-099E09CD E0A69EE0A78D
-099F09CD E0A69FE0A78D
-09A009CD E0A6A0E0A78D
-09A109CD E0A6A1E0A78D
-09A209CD E0A6A2E0A78D
-09A309CD E0A6A3E0A78D
-09A409CD E0A6A4E0A78D
-09A409CD200D E0A6A4E0A78DE2808D
-09CE E0A78E
-09A509CD E0A6A5E0A78D
-09A609CD E0A6A6E0A78D
-09A709CD E0A6A7E0A78D
-09A809CD E0A6A8E0A78D
-09AA09CD E0A6AAE0A78D
-09AB09CD E0A6ABE0A78D
-09AC09CD E0A6ACE0A78D
-09AD09CD E0A6ADE0A78D
-09AE09CD E0A6AEE0A78D
-09AF09CD E0A6AFE0A78D
-09B009CD E0A6B0E0A78D
-09F009CD E0A7B0E0A78D
-09B209CD E0A6B2E0A78D
-09F109CD E0A7B1E0A78D
-09B609CD E0A6B6E0A78D
-09B709CD E0A6B7E0A78D
-09B809CD E0A6B8E0A78D
-09B909CD E0A6B9E0A78D
-SELECT
+HEX(WEIGHT_STRING(a)) HEX(CONVERT(a USING ucs2)) HEX(a)
+15A2 0985 E0A685
+15A3 0986 E0A686
+15A4 0987 E0A687
+15A5 0988 E0A688
+15A6 0989 E0A689
+15A7 098A E0A68A
+15A8 098B E0A68B
+15A9 09E0 E0A7A0
+15AA 098C E0A68C
+15AB 09E1 E0A7A1
+15AC 098F E0A68F
+15AD 0990 E0A690
+15AE 0993 E0A693
+15AF 0994 E0A694
+15B0 0982 E0A682
+15B1 0983 E0A683
+15B2 0981 E0A681
+15B3 099509CD E0A695E0A78D
+15B315A2 0995 E0A695
+15B315A2 099509CD0985 E0A695E0A78DE0A685
+15B315A3 099509BE E0A695E0A6BE
+15B315A3 099509CD0986 E0A695E0A78DE0A686
+15B315A4 099509BF E0A695E0A6BF
+15B315A4 099509CD0987 E0A695E0A78DE0A687
+15B315A5 099509C0 E0A695E0A780
+15B315A5 099509CD0988 E0A695E0A78DE0A688
+15B315A6 099509C1 E0A695E0A781
+15B315A6 099509CD0989 E0A695E0A78DE0A689
+15B315A7 099509C2 E0A695E0A782
+15B315A7 099509CD098A E0A695E0A78DE0A68A
+15B315A8 099509C3 E0A695E0A783
+15B315A8 099509CD098B E0A695E0A78DE0A68B
+15B315A9 099509C4 E0A695E0A784
+15B315A9 099509CD09E0 E0A695E0A78DE0A7A0
+15B315AA 099509CD098C E0A695E0A78DE0A68C
+15B315AA 099509E2 E0A695E0A7A2
+15B315AB 099509CD09E1 E0A695E0A78DE0A7A1
+15B315AB 099509E3 E0A695E0A7A3
+15B315AC 099509C7 E0A695E0A787
+15B315AC 099509CD098F E0A695E0A78DE0A68F
+15B315AD 099509C8 E0A695E0A788
+15B315AD 099509CD0990 E0A695E0A78DE0A690
+15B315AE 099509CB E0A695E0A78B
+15B315AE 099509CD0993 E0A695E0A78DE0A693
+15B315AF 099509CC E0A695E0A78C
+15B315AF 099509CD0994 E0A695E0A78DE0A694
+15B4 099609CD E0A696E0A78D
+15B5 099709CD E0A697E0A78D
+15B6 099809CD E0A698E0A78D
+15B7 099909CD E0A699E0A78D
+15B8 099A09CD E0A69AE0A78D
+15B9 099B09CD E0A69BE0A78D
+15BA 099C09CD E0A69CE0A78D
+15BB 099D09CD E0A69DE0A78D
+15BC 099E09CD E0A69EE0A78D
+15BD 099F09CD E0A69FE0A78D
+15BE 09A009CD E0A6A0E0A78D
+15BF 09A109CD E0A6A1E0A78D
+15C0 09A209CD E0A6A2E0A78D
+15C1 09A309CD E0A6A3E0A78D
+15C2 09A409CD E0A6A4E0A78D
+15C2 09A409CD200D E0A6A4E0A78DE2808D
+15C2 09CE E0A78E
+15C3 09A509CD E0A6A5E0A78D
+15C4 09A609CD E0A6A6E0A78D
+15C5 09A709CD E0A6A7E0A78D
+15C6 09A809CD E0A6A8E0A78D
+15C7 09AA09CD E0A6AAE0A78D
+15C8 09AB09CD E0A6ABE0A78D
+15C9 09AC09CD E0A6ACE0A78D
+15CA 09AD09CD E0A6ADE0A78D
+15CB 09AE09CD E0A6AEE0A78D
+15CC 09AF09CD E0A6AFE0A78D
+15CD 09B009CD E0A6B0E0A78D
+15CE 09F009CD E0A7B0E0A78D
+15CF 09B209CD E0A6B2E0A78D
+15D0 09F109CD E0A7B1E0A78D
+15D1 09B609CD E0A6B6E0A78D
+15D2 09B709CD E0A6B7E0A78D
+15D3 09B809CD E0A6B8E0A78D
+15D4 09B909CD E0A6B9E0A78D
+SELECT HEX(WEIGHT_STRING(a)) as wa,
GROUP_CONCAT(HEX(CONVERT(a USING ucs2)) ORDER BY LENGTH(a), BINARY a)
FROM t1 GROUP BY a ORDER BY a;
-GROUP_CONCAT(HEX(CONVERT(a USING ucs2)) ORDER BY LENGTH(a), BINARY a)
-0985
-0986
-0987
-0988
-0989
-098A
-098B
-09E0
-098C
-09E1
-098F
-0990
-0993
-0994
-0982
-0983
-0981
-099509CD
-0995,099509CD0985
-099509BE,099509CD0986
-099509BF,099509CD0987
-099509C0,099509CD0988
-099509C1,099509CD0989
-099509C2,099509CD098A
-099509C3,099509CD098B
-099509C4,099509CD09E0
-099509E2,099509CD098C
-099509E3,099509CD09E1
-099509C7,099509CD098F
-099509C8,099509CD0990
-099509CB,099509CD0993
-099509CC,099509CD0994
-099609CD
-099709CD
-099809CD
-099909CD
-099A09CD
-099B09CD
-099C09CD
-099D09CD
-099E09CD
-099F09CD
-09A009CD
-09A109CD
-09A209CD
-09A309CD
-09CE,09A409CD,09A409CD200D
-09A509CD
-09A609CD
-09A709CD
-09A809CD
-09AA09CD
-09AB09CD
-09AC09CD
-09AD09CD
-09AE09CD
-09AF09CD
-09B009CD
-09F009CD
-09B209CD
-09F109CD
-09B609CD
-09B709CD
-09B809CD
-09B909CD
+wa GROUP_CONCAT(HEX(CONVERT(a USING ucs2)) ORDER BY LENGTH(a), BINARY a)
+15A2 0985
+15A3 0986
+15A4 0987
+15A5 0988
+15A6 0989
+15A7 098A
+15A8 098B
+15A9 09E0
+15AA 098C
+15AB 09E1
+15AC 098F
+15AD 0990
+15AE 0993
+15AF 0994
+15B0 0982
+15B1 0983
+15B2 0981
+15B3 099509CD
+15B315A2 0995,099509CD0985
+15B315A3 099509BE,099509CD0986
+15B315A4 099509BF,099509CD0987
+15B315A5 099509C0,099509CD0988
+15B315A6 099509C1,099509CD0989
+15B315A7 099509C2,099509CD098A
+15B315A8 099509C3,099509CD098B
+15B315A9 099509C4,099509CD09E0
+15B315AA 099509E2,099509CD098C
+15B315AB 099509E3,099509CD09E1
+15B315AC 099509C7,099509CD098F
+15B315AD 099509C8,099509CD0990
+15B315AE 099509CB,099509CD0993
+15B315AF 099509CC,099509CD0994
+15B4 099609CD
+15B5 099709CD
+15B6 099809CD
+15B7 099909CD
+15B8 099A09CD
+15B9 099B09CD
+15BA 099C09CD
+15BB 099D09CD
+15BC 099E09CD
+15BD 099F09CD
+15BE 09A009CD
+15BF 09A109CD
+15C0 09A209CD
+15C1 09A309CD
+15C2 09CE,09A409CD,09A409CD200D
+15C3 09A509CD
+15C4 09A609CD
+15C5 09A709CD
+15C6 09A809CD
+15C7 09AA09CD
+15C8 09AB09CD
+15C9 09AC09CD
+15CA 09AD09CD
+15CB 09AE09CD
+15CC 09AF09CD
+15CD 09B009CD
+15CE 09F009CD
+15CF 09B209CD
+15D0 09F109CD
+15D1 09B609CD
+15D2 09B709CD
+15D3 09B809CD
+15D4 09B909CD
DROP TABLE t1;
#
# WL#5624, shift after, using expansion
@@ -1022,68 +1030,68 @@ INSERT INTO t1 VALUES ('A'),('B'),('C'),('D'),('E'),('F'),('G'),('H'),('I');
INSERT INTO t1 VALUES ('J'),('K'),('L'),('M'),('N'),('O'),('P'),('Q'),('R');
INSERT INTO t1 VALUES ('S'),('T'),('U'),('V'),('W'),('X'),('Y'),('Z');
INSERT INTO t1 VALUES ('AA'),('AAA');
-SELECT a FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
-a
-0
-0z
-0ï¾
-a
-b
-c
-d
-e
-f
-g
-h
-i
-j
-k
-l
-m
-n
-o
-p
-q
-r
-s
-t
-u
-v
-w
-x
-y
-z
-aa
-aaa
-A
-B
-C
-D
-E
-F
-G
-H
-I
-J
-K
-L
-M
-N
-O
-P
-Q
-R
-S
-T
-U
-V
-W
-X
-Y
-Z
-AA
-AAA
-1
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
+a HEX(WEIGHT_STRING(a))
+0 0E29
+0z 0E290E292357
+0ï¾ 0E291E81
+a 0E29233E
+b 0E29233F
+c 0E292340
+d 0E292341
+e 0E292342
+f 0E292343
+g 0E292344
+h 0E292345
+i 0E292346
+j 0E292347
+k 0E292348
+l 0E292349
+m 0E29234A
+n 0E29234B
+o 0E29234C
+p 0E29234D
+q 0E29234E
+r 0E29234F
+s 0E292350
+t 0E292351
+u 0E292352
+v 0E292353
+w 0E292354
+x 0E292355
+y 0E292356
+z 0E292357
+aa 0E292358
+aaa 0E292359
+A 0E29333E
+B 0E29333F
+C 0E293340
+D 0E293341
+E 0E293342
+F 0E293343
+G 0E293344
+H 0E293345
+I 0E293346
+J 0E293347
+K 0E293348
+L 0E293349
+M 0E29334A
+N 0E29334B
+O 0E29334C
+P 0E29334D
+Q 0E29334E
+R 0E29334F
+S 0E293350
+T 0E293351
+U 0E293352
+V 0E293353
+W 0E293354
+X 0E293355
+Y 0E293356
+Z 0E293357
+AA 0E293358
+AAA 0E293359
+1 0E2A
DROP TABLE t1;
#
# End of WL#5624
diff --git a/mysql-test/r/ctype_sjis.result b/mysql-test/r/ctype_sjis.result
index abeb19c0c8f..110d81491f9 100644
--- a/mysql-test/r/ctype_sjis.result
+++ b/mysql-test/r/ctype_sjis.result
@@ -14562,3 +14562,398 @@ DROP TABLE t1;
#
# End of 5.5 tests
#
+#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+set names sjis;
+select @@collation_connection;
+@@collation_connection
+sjis_japanese_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+41
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+414243
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+4142
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+414243
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+4142432020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+41
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+4142
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+414220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+41422020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+4142202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+41422020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+41
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+4142
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+414243
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+41424320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+41
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+4142
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+414243
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+41424320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+sjis_japanese_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+41
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+414243
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+4142
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+414243
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+4142432020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020434241
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+BEBDBCDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDFBCBDBE
+select collation(cast(0x8140 as char));
+collation(cast(0x8140 as char))
+sjis_japanese_ci
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+4141
+select hex(weight_string(cast(0x8140 as char)));
+hex(weight_string(cast(0x8140 as char)))
+8140
+select hex(weight_string(cast(0x8140 as char) as char(1)));
+hex(weight_string(cast(0x8140 as char) as char(1)))
+8140
+select hex(weight_string(cast(0x81408140 as char) as char(1)));
+hex(weight_string(cast(0x81408140 as char) as char(1)))
+8140
+select hex(weight_string(cast(0x8140 as char) as char(3)));
+hex(weight_string(cast(0x8140 as char) as char(3)))
+81402020
+select hex(weight_string(cast(0x81408140 as char) as char(3)));
+hex(weight_string(cast(0x81408140 as char) as char(3)))
+8140814020
+select hex(weight_string(cast(0x408140 as char) as char(3)));
+hex(weight_string(cast(0x408140 as char) as char(3)))
+40814020
+select hex(weight_string(cast(0x4081408140 as char) as char(3)));
+hex(weight_string(cast(0x4081408140 as char) as char(3)))
+4081408140
+select hex(weight_string(cast(0x40814081408140 as char) as char(3)));
+hex(weight_string(cast(0x40814081408140 as char) as char(3)))
+4081408140
+select hex(weight_string(cast(0x4040814081408140 as char) as char(3)));
+hex(weight_string(cast(0x4040814081408140 as char) as char(3)))
+40408140
+select hex(weight_string(cast(0x814081408140 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 1, 2, 0xC0))
+81
+select hex(weight_string(cast(0x814081408140 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 2, 2, 0xC0))
+8140
+select hex(weight_string(cast(0x814081408140 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 3, 2, 0xC0))
+814081
+select hex(weight_string(cast(0x814081408140 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 4, 2, 0xC0))
+81408140
+select hex(weight_string(cast(0x814081408140 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 5, 2, 0xC0))
+8140814020
+select hex(weight_string(cast(0x814081408140 as char),25, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char),25, 2, 0xC0))
+81408140202020202020202020202020202020202020202020
+select hex(weight_string(cast(0x814081408140 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 1, 3, 0xC0))
+81
+select hex(weight_string(cast(0x814081408140 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 2, 3, 0xC0))
+8140
+select hex(weight_string(cast(0x814081408140 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 3, 3, 0xC0))
+814081
+select hex(weight_string(cast(0x814081408140 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 4, 3, 0xC0))
+81408140
+select hex(weight_string(cast(0x814081408140 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 5, 3, 0xC0))
+8140814081
+select hex(weight_string(cast(0x814081408140 as char),25, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char),25, 3, 0xC0))
+81408140814020202020202020202020202020202020202020
+select hex(weight_string(cast(0x814081408140 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 1, 4, 0xC0))
+81
+select hex(weight_string(cast(0x814081408140 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 2, 4, 0xC0))
+8140
+select hex(weight_string(cast(0x814081408140 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 3, 4, 0xC0))
+814081
+select hex(weight_string(cast(0x814081408140 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 4, 4, 0xC0))
+81408140
+select hex(weight_string(cast(0x814081408140 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 5, 4, 0xC0))
+8140814081
+select hex(weight_string(cast(0x814081408140 as char),25, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char),25, 4, 0xC0))
+81408140814020202020202020202020202020202020202020
+set collation_connection=sjis_bin;
+select @@collation_connection;
+@@collation_connection
+sjis_bin
+select hex(weight_string('a'));
+hex(weight_string('a'))
+61
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+616263
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+6162
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+616263
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+6162632020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+61
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+6162
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+616220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+61622020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+6162202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+61622020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+61
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+6162
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+616263
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+61626320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+61
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+6162
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+616263
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+61626320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+sjis_bin
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+61
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+616263
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+6162
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+616263
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+6162632020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020636261
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+9E9D9CDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDF9C9D9E
+select collation(cast(0x8140 as char));
+collation(cast(0x8140 as char))
+sjis_bin
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+6141
+select hex(weight_string(cast(0x8140 as char)));
+hex(weight_string(cast(0x8140 as char)))
+8140
+select hex(weight_string(cast(0x8140 as char) as char(1)));
+hex(weight_string(cast(0x8140 as char) as char(1)))
+8140
+select hex(weight_string(cast(0x81408140 as char) as char(1)));
+hex(weight_string(cast(0x81408140 as char) as char(1)))
+8140
+select hex(weight_string(cast(0x8140 as char) as char(3)));
+hex(weight_string(cast(0x8140 as char) as char(3)))
+81402020
+select hex(weight_string(cast(0x81408140 as char) as char(3)));
+hex(weight_string(cast(0x81408140 as char) as char(3)))
+8140814020
+select hex(weight_string(cast(0x408140 as char) as char(3)));
+hex(weight_string(cast(0x408140 as char) as char(3)))
+40814020
+select hex(weight_string(cast(0x4081408140 as char) as char(3)));
+hex(weight_string(cast(0x4081408140 as char) as char(3)))
+4081408140
+select hex(weight_string(cast(0x40814081408140 as char) as char(3)));
+hex(weight_string(cast(0x40814081408140 as char) as char(3)))
+4081408140
+select hex(weight_string(cast(0x4040814081408140 as char) as char(3)));
+hex(weight_string(cast(0x4040814081408140 as char) as char(3)))
+40408140
+select hex(weight_string(cast(0x814081408140 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 1, 2, 0xC0))
+81
+select hex(weight_string(cast(0x814081408140 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 2, 2, 0xC0))
+8140
+select hex(weight_string(cast(0x814081408140 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 3, 2, 0xC0))
+814081
+select hex(weight_string(cast(0x814081408140 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 4, 2, 0xC0))
+81408140
+select hex(weight_string(cast(0x814081408140 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 5, 2, 0xC0))
+8140814020
+select hex(weight_string(cast(0x814081408140 as char),25, 2, 0xC0));
+hex(weight_string(cast(0x814081408140 as char),25, 2, 0xC0))
+81408140202020202020202020202020202020202020202020
+select hex(weight_string(cast(0x814081408140 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 1, 3, 0xC0))
+81
+select hex(weight_string(cast(0x814081408140 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 2, 3, 0xC0))
+8140
+select hex(weight_string(cast(0x814081408140 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 3, 3, 0xC0))
+814081
+select hex(weight_string(cast(0x814081408140 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 4, 3, 0xC0))
+81408140
+select hex(weight_string(cast(0x814081408140 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 5, 3, 0xC0))
+8140814081
+select hex(weight_string(cast(0x814081408140 as char),25, 3, 0xC0));
+hex(weight_string(cast(0x814081408140 as char),25, 3, 0xC0))
+81408140814020202020202020202020202020202020202020
+select hex(weight_string(cast(0x814081408140 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 1, 4, 0xC0))
+81
+select hex(weight_string(cast(0x814081408140 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 2, 4, 0xC0))
+8140
+select hex(weight_string(cast(0x814081408140 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 3, 4, 0xC0))
+814081
+select hex(weight_string(cast(0x814081408140 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 4, 4, 0xC0))
+81408140
+select hex(weight_string(cast(0x814081408140 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char), 5, 4, 0xC0))
+8140814081
+select hex(weight_string(cast(0x814081408140 as char),25, 4, 0xC0));
+hex(weight_string(cast(0x814081408140 as char),25, 4, 0xC0))
+81408140814020202020202020202020202020202020202020
+#
+# End of 5.6 tests
+#
diff --git a/mysql-test/r/ctype_tis620.result b/mysql-test/r/ctype_tis620.result
index c86b8392b32..a338d05a8e8 100644
--- a/mysql-test/r/ctype_tis620.result
+++ b/mysql-test/r/ctype_tis620.result
@@ -2993,3 +2993,237 @@ select c1 as c2h from t1 where c1 like 'ab#_def' escape '#';
c2h
ab_def
drop table t1;
+#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+set names tis620;
+set collation_connection=tis620_thai_ci;
+select @@collation_connection;
+@@collation_connection
+tis620_thai_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+61
+select hex(weight_string('A'));
+hex(weight_string('A'))
+61
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+616263
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+6162
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+616263
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+6162632020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+61
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+6162
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+616220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+61622020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+6162202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+61622020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+61
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+6162
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+616263
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+61626320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+61
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+6162
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+616263
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+61626320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+tis620_thai_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+61
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+61
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+616263
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+6162
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+616263
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+6162632020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020636261
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+9E9D9CDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDF9C9D9E
+select hex(weight_string(cast(0xE0A1 as char)));
+hex(weight_string(cast(0xE0A1 as char)))
+A1E0
+select hex(weight_string(cast(0xE0A1 as char) as char(1)));
+hex(weight_string(cast(0xE0A1 as char) as char(1)))
+A1
+set collation_connection=tis620_bin;
+select @@collation_connection;
+@@collation_connection
+tis620_bin
+select hex(weight_string('a'));
+hex(weight_string('a'))
+61
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+616263
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+6162
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+616263
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+6162632020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+61
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+6162
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+616220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+61622020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+6162202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+61622020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+61
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+6162
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+616263
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+61626320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+61
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+6162
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+616263
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+61626320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+tis620_bin
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+61
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+616263
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+6162
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+616263
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+6162632020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020636261
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+9E9D9CDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDF9C9D9E
+select hex(weight_string(cast(0xE0A1 as char)));
+hex(weight_string(cast(0xE0A1 as char)))
+E0A1
+select hex(weight_string(cast(0xE0A1 as char) as char(1)));
+hex(weight_string(cast(0xE0A1 as char) as char(1)))
+E0
+#
+# End of 5.6 tests
+#
diff --git a/mysql-test/r/ctype_uca.result b/mysql-test/r/ctype_uca.result
index de090d1680b..afcf87d62e8 100644
--- a/mysql-test/r/ctype_uca.result
+++ b/mysql-test/r/ctype_uca.result
@@ -2926,6 +2926,31 @@ ss,ß
u,ü
ue
drop table t1;
+CREATE TABLE t1 AS SELECT REPEAT('a',1) AS a, 1 AS b LIMIT 0;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
+ `b` int(1) NOT NULL DEFAULT '0'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 VALUES ('s',0),(_latin1 0xDF,1);
+SELECT * FROM t1 ORDER BY a, b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY a DESC, b;
+a b
+ß 1
+s 0
+SELECT * FROM t1 ORDER BY CONCAT(a), b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY CONCAT(a) DESC, b;
+a b
+ß 1
+s 0
+DROP TABLE t1;
CREATE TABLE t1 (id int, a varchar(30) character set utf8);
INSERT INTO t1 VALUES (1, _ucs2 0x01310069), (2, _ucs2 0x01310131);
INSERT INTO t1 VALUES (3, _ucs2 0x00690069), (4, _ucs2 0x01300049);
@@ -3299,6 +3324,681 @@ drop table t1;
# End of 5.5 tests
#
#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+set collation_connection=ucs2_unicode_ci;
+select @@collation_connection;
+@@collation_connection
+ucs2_unicode_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+0E33
+select hex(weight_string('A'));
+hex(weight_string('A'))
+0E33
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+0E330E4A0E60
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+0E330E4A
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+0E330E4A0E60
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+0E330E4A0E6002090209
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+0E
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+0E33
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+0E330E
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+0E330E4A
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+0E330E4A02
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+0E330E4A020902090209020902090209020902090209020902
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+0E
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+0E33
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+0E330E
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+0E330E4A
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+0E330E4A0E
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+0E330E4A0E6002090209020902090209020902090209020902
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+0E
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+0E33
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+0E330E
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+0E330E4A
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+0E330E4A0E
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+0E330E4A0E6002090209020902090209020902090209020902
+select @@collation_connection;
+@@collation_connection
+ucs2_unicode_ci
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+0E23
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+0E230E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+0E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+0E230E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+0E230E230E2302090209
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+0E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+0E230E
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+0E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+0E230E2302
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+0E230E23020902090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+0E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+0E230E
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+0E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+0E230E230E
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+0E230E230E2302090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+0E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+0E230E
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+0E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+0E230E230E
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+0E230E230E2302090209020902090209020902090209020902
+select @@collation_connection;
+@@collation_connection
+ucs2_unicode_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+0E33
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+0E33
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+0E330E4A0E60
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+0E330E4A
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+0E330E4A0E60
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+0E330E4A0E6002090209
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+09020902600E4A0E330E
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+F1CCF1B5F19FFDF6FDF6
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+F6FDF6FD9FF1B5F1CCF1
+set @@collation_connection=utf8_unicode_ci;
+select @@collation_connection;
+@@collation_connection
+utf8_unicode_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+0E33
+select hex(weight_string('A'));
+hex(weight_string('A'))
+0E33
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+0E330E4A0E60
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+0E330E4A
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+0E330E4A0E60
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+0E330E4A0E6002090209
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+0E
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+0E33
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+0E330E
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+0E330E4A
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+0E330E4A02
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+0E330E4A020902090209020902090209020902090209020902
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+0E
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+0E33
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+0E330E
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+0E330E4A
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+0E330E4A0E
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+0E330E4A0E6002090209020902090209020902090209020902
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+0E
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+0E33
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+0E330E
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+0E330E4A
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+0E330E4A0E
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+0E330E4A0E6002090209020902090209020902090209020902
+select @@collation_connection;
+@@collation_connection
+utf8_unicode_ci
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+0E23
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+0E230E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+0E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+0E230E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+0E230E230E2302090209
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+0E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+0E230E
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+0E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+0E230E2302
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+0E230E23020902090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+0E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+0E230E
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+0E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+0E230E230E
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+0E230E230E2302090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+0E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+0E230E
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+0E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+0E230E230E
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+0E230E230E2302090209020902090209020902090209020902
+select @@collation_connection;
+@@collation_connection
+utf8_unicode_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+0E33
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+0E33
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+0E330E4A0E60
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+0E330E4A
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+0E330E4A0E60
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+0E330E4A0E6002090209
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+09020902600E4A0E330E
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+F1CCF1B5F19FFDF6FDF6
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+F6FDF6FD9FF1B5F1CCF1
+set @@collation_connection=utf8_czech_ci;
+select @@collation_connection;
+@@collation_connection
+utf8_czech_ci
+select collation(cast(_latin1 0xDF as char));
+collation(cast(_latin1 0xDF as char))
+utf8_czech_ci
+select hex(weight_string('s'));
+hex(weight_string('s'))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF as char)));
+hex(weight_string(cast(_latin1 0xDF as char)))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF as char) as char(1)));
+hex(weight_string(cast(_latin1 0xDF as char) as char(1)))
+0FEA
+select hex(weight_string('c'));
+hex(weight_string('c'))
+0E60
+select hex(weight_string('h'));
+hex(weight_string('h'))
+0EE1
+select hex(weight_string('ch'));
+hex(weight_string('ch'))
+0EE2
+select hex(weight_string('i'));
+hex(weight_string('i'))
+0EFB
+select hex(weight_string(cast(_latin1 0x6368DF as char)));
+hex(weight_string(cast(_latin1 0x6368DF as char)))
+0EE20FEA0FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(1)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(1)))
+0EE2
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(2)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(2)))
+0EE20FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(3)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(3)))
+0EE20FEA0FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(4)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(4)))
+0EE20FEA0FEA0209
+select hex(weight_string(cast(_latin1 0xDF6368 as char)));
+hex(weight_string(cast(_latin1 0xDF6368 as char)))
+0FEA0FEA0EE2
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(1)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(1)))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(2)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(2)))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(3)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(3)))
+0FEA0FEA0EE2
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(4)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(4)))
+0FEA0FEA0EE20209
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 1, 2, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 2, 2, 0xC0))
+0EE2
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 3, 2, 0xC0))
+0EE20F
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 4, 2, 0xC0))
+0EE20FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char),25, 2, 0xC0))
+0EE20FEA020902090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 1, 3, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 2, 3, 0xC0))
+0EE2
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 3, 3, 0xC0))
+0EE20F
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 4, 3, 0xC0))
+0EE20FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char),25, 3, 0xC0))
+0EE20FEA0FEA02090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 1, 4, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 2, 4, 0xC0))
+0EE2
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 3, 4, 0xC0))
+0EE20F
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 4, 4, 0xC0))
+0EE20FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char),25, 4, 0xC0))
+0EE20FEA0FEA02090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 2,0xC0))
+0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 2,0xC0))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 2,0xC0))
+0FEA0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 2,0xC0))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char),25, 2,0xC0))
+0FEA0FEA020902090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 3,0xC0))
+0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 3,0xC0))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 3,0xC0))
+0FEA0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 3,0xC0))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char),25, 3,0xC0))
+0FEA0FEA0EE202090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 4,0xC0))
+0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 4,0xC0))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 4,0xC0))
+0FEA0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 4,0xC0))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char),25, 4,0xC0))
+0FEA0FEA0EE202090209020902090209020902090209020902
+set @@collation_connection=ucs2_czech_ci;
+select @@collation_connection;
+@@collation_connection
+ucs2_czech_ci
+select collation(cast(_latin1 0xDF as char));
+collation(cast(_latin1 0xDF as char))
+ucs2_czech_ci
+select hex(weight_string('s'));
+hex(weight_string('s'))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF as char)));
+hex(weight_string(cast(_latin1 0xDF as char)))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF as char) as char(1)));
+hex(weight_string(cast(_latin1 0xDF as char) as char(1)))
+0FEA
+select hex(weight_string('c'));
+hex(weight_string('c'))
+0E60
+select hex(weight_string('h'));
+hex(weight_string('h'))
+0EE1
+select hex(weight_string('ch'));
+hex(weight_string('ch'))
+0EE2
+select hex(weight_string('i'));
+hex(weight_string('i'))
+0EFB
+select hex(weight_string(cast(_latin1 0x6368DF as char)));
+hex(weight_string(cast(_latin1 0x6368DF as char)))
+0EE20FEA0FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(1)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(1)))
+0EE2
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(2)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(2)))
+0EE20FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(3)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(3)))
+0EE20FEA0FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(4)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(4)))
+0EE20FEA0FEA0209
+select hex(weight_string(cast(_latin1 0xDF6368 as char)));
+hex(weight_string(cast(_latin1 0xDF6368 as char)))
+0FEA0FEA0EE2
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(1)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(1)))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(2)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(2)))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(3)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(3)))
+0FEA0FEA0EE2
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(4)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(4)))
+0FEA0FEA0EE20209
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 1, 2, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 2, 2, 0xC0))
+0EE2
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 3, 2, 0xC0))
+0EE20F
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 4, 2, 0xC0))
+0EE20FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char),25, 2, 0xC0))
+0EE20FEA020902090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 1, 3, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 2, 3, 0xC0))
+0EE2
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 3, 3, 0xC0))
+0EE20F
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 4, 3, 0xC0))
+0EE20FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char),25, 3, 0xC0))
+0EE20FEA0FEA02090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 1, 4, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 2, 4, 0xC0))
+0EE2
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 3, 4, 0xC0))
+0EE20F
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 4, 4, 0xC0))
+0EE20FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char),25, 4, 0xC0))
+0EE20FEA0FEA02090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 2,0xC0))
+0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 2,0xC0))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 2,0xC0))
+0FEA0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 2,0xC0))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char),25, 2,0xC0))
+0FEA0FEA020902090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 3,0xC0))
+0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 3,0xC0))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 3,0xC0))
+0FEA0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 3,0xC0))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char),25, 3,0xC0))
+0FEA0FEA0EE202090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 4,0xC0))
+0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 4,0xC0))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 4,0xC0))
+0FEA0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 4,0xC0))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char),25, 4,0xC0))
+0FEA0FEA0EE202090209020902090209020902090209020902
+#
+# Bug#33077 weight of supplementary characters is not 0xfffd
+#
+select hex(weight_string(_utf8mb4 0xF0908080 /* U+10000 */ collate utf8mb4_unicode_ci));
+hex(weight_string(_utf8mb4 0xF0908080 /* U+10000 */ collate utf8mb4_unicode_ci))
+FFFD
+#
+# Bug#53064 garbled data when using utf8_german2_ci collation
+#
+CREATE TABLE t1 (s1 VARCHAR(10) COLLATE utf8_german2_ci);
+INSERT INTO t1 VALUES ('a'),('ae'),('af');
+SELECT s1,hex(s1),hex(weight_string(s1)) FROM t1 ORDER BY s1;
+s1 hex(s1) hex(weight_string(s1))
+a 61 0E33
+ae 6165 0E330E8B
+af 6166 0E330EB9
+DROP TABLE t1;
+#
# WL#4013 Unicode german2 collation
#
SET collation_connection=utf8_german2_ci;
@@ -3337,6 +4037,31 @@ ss,ß
u
ue,ü
drop table t1;
+CREATE TABLE t1 AS SELECT REPEAT('a',1) AS a, 1 AS b LIMIT 0;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1) CHARACTER SET utf8 COLLATE utf8_german2_ci NOT NULL DEFAULT '',
+ `b` int(1) NOT NULL DEFAULT '0'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 VALUES ('s',0),(_latin1 0xDF,1);
+SELECT * FROM t1 ORDER BY a, b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY a DESC, b;
+a b
+ß 1
+s 0
+SELECT * FROM t1 ORDER BY CONCAT(a), b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY CONCAT(a) DESC, b;
+a b
+ß 1
+s 0
+DROP TABLE t1;
#
# End of 5.6 tests
#
diff --git a/mysql-test/r/ctype_ucs.result b/mysql-test/r/ctype_ucs.result
index c6303f9e4de..85b3ae6c8dd 100644
--- a/mysql-test/r/ctype_ucs.result
+++ b/mysql-test/r/ctype_ucs.result
@@ -787,6 +787,31 @@ ss
u,ü
ue
drop table t1;
+CREATE TABLE t1 AS SELECT REPEAT('a',1) AS a, 1 AS b LIMIT 0;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1) CHARACTER SET ucs2 NOT NULL DEFAULT '',
+ `b` int(1) NOT NULL DEFAULT '0'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 VALUES ('s',0),(_latin1 0xDF,1);
+SELECT * FROM t1 ORDER BY a, b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY a DESC, b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY CONCAT(a), b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY CONCAT(a) DESC, b;
+a b
+s 0
+ß 1
+DROP TABLE t1;
CREATE TABLE t1 AS
SELECT 10 AS a, REPEAT('a',20) AS b, REPEAT('a',8) AS c, REPEAT('a',8) AS d;
ALTER TABLE t1 ADD PRIMARY KEY(a), ADD KEY(b);
@@ -4242,6 +4267,365 @@ DROP TABLE t1;
# Start of 5.6 tests
#
#
+# WL#3664 WEIGHT_STRING
+#
+set collation_connection=ucs2_general_ci;
+select @@collation_connection;
+@@collation_connection
+ucs2_general_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+0041
+select hex(weight_string('A'));
+hex(weight_string('A'))
+0041
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+004100420043
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+00410042
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+004100420043
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+00410042004300200020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+00
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+0041
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+004100
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+00410042
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+0041004200
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+00410042002000200020002000200020002000200020002000
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+00
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+0041
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+004100
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+00410042
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+0041004200
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+00410042004300200020002000200020002000200020002000
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+00
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+0041
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+004100
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+00410042
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+0041004200
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+00410042004300200020002000200020002000200020002000
+select @@collation_connection;
+@@collation_connection
+ucs2_general_ci
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+20AC20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+20AC20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+20AC20AC20AC00200020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+20AC20AC00
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+20AC20AC002000200020002000200020002000200020002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+20AC20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+20AC20AC20AC00200020002000200020002000200020002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+20AC20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+20AC20AC20AC00200020002000200020002000200020002000
+select @@collation_connection;
+@@collation_connection
+ucs2_general_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+0041
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+0041
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+004100420043
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+00410042
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+004100420043
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+00410042004300200020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+20002000430042004100
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+FFBEFFBDFFBCFFDFFFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFFFDFFFBCFFBDFFBEFF
+set collation_connection=ucs2_bin;
+select @@collation_connection;
+@@collation_connection
+ucs2_bin
+select hex(weight_string('a'));
+hex(weight_string('a'))
+0061
+select hex(weight_string('A'));
+hex(weight_string('A'))
+0041
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+006100620063
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+00610062
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+006100620063
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+00610062006300200020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+00
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+0061
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+006100
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+00610062
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+0061006200
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+00610062002000200020002000200020002000200020002000
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+00
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+0061
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+006100
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+00610062
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+0061006200
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+00610062006300200020002000200020002000200020002000
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+00
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+0061
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+006100
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+00610062
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+0061006200
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+00610062006300200020002000200020002000200020002000
+select @@collation_connection;
+@@collation_connection
+ucs2_bin
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+20AC20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+20AC20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+20AC20AC20AC00200020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+20AC20AC00
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+20AC20AC002000200020002000200020002000200020002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+20AC20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+20AC20AC20AC00200020002000200020002000200020002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+20AC20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+20AC20AC20AC00200020002000200020002000200020002000
+select @@collation_connection;
+@@collation_connection
+ucs2_bin
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+0061
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+0041
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+006100620063
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+00610062
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+006100620063
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+00610062006300200020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+20002000630062006100
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+FF9EFF9DFF9CFFDFFFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFFFDFFF9CFF9DFF9EFF
+#
# Bug#59145 valgrind warnings for uninitialized values in my_strtoll10_mb2
#
SET NAMES latin1;
diff --git a/mysql-test/r/ctype_ujis.result b/mysql-test/r/ctype_ujis.result
index 3db6aee37cc..f167f5d1446 100644
--- a/mysql-test/r/ctype_ujis.result
+++ b/mysql-test/r/ctype_ujis.result
@@ -24916,3 +24916,746 @@ DROP TABLE t1;
#
# End of 5.5 tests
#
+#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+set names ujis;
+select @@collation_connection;
+@@collation_connection
+ujis_japanese_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+41
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+414243
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+4142
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+414243
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+4142432020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+41
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+4142
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+414220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+41422020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+4142202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+41422020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+41
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+4142
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+414243
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+41424320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+41
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+4142
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+414243
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+41424320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+4142432020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+41424320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+ujis_japanese_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+41
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+414243
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+4142
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+414243
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+4142432020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020434241
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+BEBDBCDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDFBCBDBE
+select collation(cast(0xA1A1 as char));
+collation(cast(0xA1A1 as char))
+ujis_japanese_ci
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+4141
+select hex(weight_string(cast(0xA1A1 as char)));
+hex(weight_string(cast(0xA1A1 as char)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1 as char) as char(3)))
+A1A12020
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)))
+A1A1A1A120
+select hex(weight_string(cast(0x40A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1 as char) as char(3)))
+40A1A120
+select hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)))
+4040A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0))
+A1A1A1A120
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0))
+A1A1A1A1202020202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+select collation(cast(0xA1A1 as char));
+collation(cast(0xA1A1 as char))
+ujis_japanese_ci
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+4141
+select hex(weight_string(cast(0x8EA1 as char)));
+hex(weight_string(cast(0x8EA1 as char)))
+8EA1
+select hex(weight_string(cast(0x8EA1 as char) as char(1)));
+hex(weight_string(cast(0x8EA1 as char) as char(1)))
+8EA1
+select hex(weight_string(cast(0x8EA18EA1 as char) as char(1)));
+hex(weight_string(cast(0x8EA18EA1 as char) as char(1)))
+8EA1
+select hex(weight_string(cast(0x8EA1 as char) as char(3)));
+hex(weight_string(cast(0x8EA1 as char) as char(3)))
+8EA12020
+select hex(weight_string(cast(0x8EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x8EA18EA1 as char) as char(3)))
+8EA18EA120
+select hex(weight_string(cast(0x408EA1 as char) as char(3)));
+hex(weight_string(cast(0x408EA1 as char) as char(3)))
+408EA120
+select hex(weight_string(cast(0x408EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x408EA18EA1 as char) as char(3)))
+408EA18EA1
+select hex(weight_string(cast(0x408EA18EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x408EA18EA18EA1 as char) as char(3)))
+408EA18EA1
+select hex(weight_string(cast(0x40408EA18EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x40408EA18EA18EA1 as char) as char(3)))
+40408EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 2, 0xC0))
+8E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 2, 0xC0))
+8EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 2, 0xC0))
+8EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 2, 0xC0))
+8EA18EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 2, 0xC0))
+8EA18EA120
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 2, 0xC0))
+8EA18EA1202020202020202020202020202020202020202020
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 3, 0xC0))
+8E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 3, 0xC0))
+8EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 3, 0xC0))
+8EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 3, 0xC0))
+8EA18EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 3, 0xC0))
+8EA18EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 3, 0xC0))
+8EA18EA18EA120202020202020202020202020202020202020
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 4, 0xC0))
+8E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 4, 0xC0))
+8EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 4, 0xC0))
+8EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 4, 0xC0))
+8EA18EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 4, 0xC0))
+8EA18EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 4, 0xC0))
+8EA18EA18EA120202020202020202020202020202020202020
+select collation(cast(0x8FA2C3 as char));
+collation(cast(0x8FA2C3 as char))
+ujis_japanese_ci
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+4141
+select hex(weight_string(cast(0x8FA2C3 as char)));
+hex(weight_string(cast(0x8FA2C3 as char)))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C3 as char) as char(1)));
+hex(weight_string(cast(0x8FA2C3 as char) as char(1)))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C3 as char) as char(1)));
+hex(weight_string(cast(0x8FA2C38FA2C3 as char) as char(1)))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x8FA2C3 as char) as char(3)))
+8FA2C32020
+select hex(weight_string(cast(0x8FA2C38FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x8FA2C38FA2C3 as char) as char(3)))
+8FA2C38FA2C320
+select hex(weight_string(cast(0x408FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x408FA2C3 as char) as char(3)))
+408FA2C320
+select hex(weight_string(cast(0x408FA2C38FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x408FA2C38FA2C3 as char) as char(3)))
+408FA2C38FA2C3
+select hex(weight_string(cast(0x408FA2C38FA2C38FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x408FA2C38FA2C38FA2C3 as char) as char(3)))
+408FA2C38FA2C3
+select hex(weight_string(cast(0x40408FA2C38FA2C38FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x40408FA2C38FA2C38FA2C3 as char) as char(3)))
+40408FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 2, 0xC0))
+8F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 2, 0xC0))
+8FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 2, 0xC0))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 2, 0xC0))
+8FA2C38F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 2, 0xC0))
+8FA2C38FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 2, 0xC0))
+8FA2C38FA2C320202020202020202020202020202020202020
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 3, 0xC0))
+8F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 3, 0xC0))
+8FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 3, 0xC0))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 3, 0xC0))
+8FA2C38F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 3, 0xC0))
+8FA2C38FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 3, 0xC0))
+8FA2C38FA2C38FA2C320202020202020202020202020202020
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 4, 0xC0))
+8F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 4, 0xC0))
+8FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 4, 0xC0))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 4, 0xC0))
+8FA2C38F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 4, 0xC0))
+8FA2C38FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 4, 0xC0))
+8FA2C38FA2C38FA2C320202020202020202020202020202020
+set collation_connection=ujis_bin;
+select @@collation_connection;
+@@collation_connection
+ujis_bin
+select hex(weight_string('a'));
+hex(weight_string('a'))
+61
+select hex(weight_string('A'));
+hex(weight_string('A'))
+41
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+616263
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+6162
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+616263
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+6162632020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+61
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+6162
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+616220
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+61622020
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+6162202020
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+61622020202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+61
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+6162
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+616263
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+61626320202020202020202020202020202020202020202020
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+61
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+6162
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+616263
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+61626320
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+6162632020
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+61626320202020202020202020202020202020202020202020
+select @@collation_connection;
+@@collation_connection
+ujis_bin
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+61
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+41
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+616263
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+6162
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+616263
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+6162632020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+2020636261
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+9E9D9CDFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFDF9C9D9E
+select collation(cast(0xA1A1 as char));
+collation(cast(0xA1A1 as char))
+ujis_bin
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+6141
+select hex(weight_string(cast(0xA1A1 as char)));
+hex(weight_string(cast(0xA1A1 as char)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(1)))
+A1A1
+select hex(weight_string(cast(0xA1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1 as char) as char(3)))
+A1A12020
+select hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0xA1A1A1A1 as char) as char(3)))
+A1A1A1A120
+select hex(weight_string(cast(0x40A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1 as char) as char(3)))
+40A1A120
+select hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x40A1A1A1A1A1A1 as char) as char(3)))
+40A1A1A1A1
+select hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)));
+hex(weight_string(cast(0x4040A1A1A1A1A1A1 as char) as char(3)))
+4040A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 2, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 2, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 2, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 2, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 2, 0xC0))
+A1A1A1A120
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 2, 0xC0))
+A1A1A1A1202020202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 3, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 3, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 3, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 3, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 3, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 3, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 1, 4, 0xC0))
+A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 2, 4, 0xC0))
+A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 3, 4, 0xC0))
+A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 4, 4, 0xC0))
+A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char), 5, 4, 0xC0))
+A1A1A1A1A1
+select hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0));
+hex(weight_string(cast(0xA1A1A1A1A1A1 as char),25, 4, 0xC0))
+A1A1A1A1A1A120202020202020202020202020202020202020
+select collation(cast(0xA1A1 as char));
+collation(cast(0xA1A1 as char))
+ujis_bin
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+6141
+select hex(weight_string(cast(0x8EA1 as char)));
+hex(weight_string(cast(0x8EA1 as char)))
+8EA1
+select hex(weight_string(cast(0x8EA1 as char) as char(1)));
+hex(weight_string(cast(0x8EA1 as char) as char(1)))
+8EA1
+select hex(weight_string(cast(0x8EA18EA1 as char) as char(1)));
+hex(weight_string(cast(0x8EA18EA1 as char) as char(1)))
+8EA1
+select hex(weight_string(cast(0x8EA1 as char) as char(3)));
+hex(weight_string(cast(0x8EA1 as char) as char(3)))
+8EA12020
+select hex(weight_string(cast(0x8EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x8EA18EA1 as char) as char(3)))
+8EA18EA120
+select hex(weight_string(cast(0x408EA1 as char) as char(3)));
+hex(weight_string(cast(0x408EA1 as char) as char(3)))
+408EA120
+select hex(weight_string(cast(0x408EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x408EA18EA1 as char) as char(3)))
+408EA18EA1
+select hex(weight_string(cast(0x408EA18EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x408EA18EA18EA1 as char) as char(3)))
+408EA18EA1
+select hex(weight_string(cast(0x40408EA18EA18EA1 as char) as char(3)));
+hex(weight_string(cast(0x40408EA18EA18EA1 as char) as char(3)))
+40408EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 2, 0xC0))
+8E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 2, 0xC0))
+8EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 2, 0xC0))
+8EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 2, 0xC0))
+8EA18EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 2, 0xC0))
+8EA18EA120
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 2, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 2, 0xC0))
+8EA18EA1202020202020202020202020202020202020202020
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 3, 0xC0))
+8E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 3, 0xC0))
+8EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 3, 0xC0))
+8EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 3, 0xC0))
+8EA18EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 3, 0xC0))
+8EA18EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 3, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 3, 0xC0))
+8EA18EA18EA120202020202020202020202020202020202020
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 1, 4, 0xC0))
+8E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 2, 4, 0xC0))
+8EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 3, 4, 0xC0))
+8EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 4, 4, 0xC0))
+8EA18EA1
+select hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char), 5, 4, 0xC0))
+8EA18EA18E
+select hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 4, 0xC0));
+hex(weight_string(cast(0x8EA18EA18EA1 as char),25, 4, 0xC0))
+8EA18EA18EA120202020202020202020202020202020202020
+select collation(cast(0x8FA2C3 as char));
+collation(cast(0x8FA2C3 as char))
+ujis_bin
+select hex(weight_string(cast(0x6141 as char)));
+hex(weight_string(cast(0x6141 as char)))
+6141
+select hex(weight_string(cast(0x8FA2C3 as char)));
+hex(weight_string(cast(0x8FA2C3 as char)))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C3 as char) as char(1)));
+hex(weight_string(cast(0x8FA2C3 as char) as char(1)))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C3 as char) as char(1)));
+hex(weight_string(cast(0x8FA2C38FA2C3 as char) as char(1)))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x8FA2C3 as char) as char(3)))
+8FA2C32020
+select hex(weight_string(cast(0x8FA2C38FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x8FA2C38FA2C3 as char) as char(3)))
+8FA2C38FA2C320
+select hex(weight_string(cast(0x408FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x408FA2C3 as char) as char(3)))
+408FA2C320
+select hex(weight_string(cast(0x408FA2C38FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x408FA2C38FA2C3 as char) as char(3)))
+408FA2C38FA2C3
+select hex(weight_string(cast(0x408FA2C38FA2C38FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x408FA2C38FA2C38FA2C3 as char) as char(3)))
+408FA2C38FA2C3
+select hex(weight_string(cast(0x40408FA2C38FA2C38FA2C3 as char) as char(3)));
+hex(weight_string(cast(0x40408FA2C38FA2C38FA2C3 as char) as char(3)))
+40408FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 2, 0xC0))
+8F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 2, 0xC0))
+8FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 2, 0xC0))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 2, 0xC0))
+8FA2C38F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 2, 0xC0))
+8FA2C38FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 2, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 2, 0xC0))
+8FA2C38FA2C320202020202020202020202020202020202020
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 3, 0xC0))
+8F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 3, 0xC0))
+8FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 3, 0xC0))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 3, 0xC0))
+8FA2C38F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 3, 0xC0))
+8FA2C38FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 3, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 3, 0xC0))
+8FA2C38FA2C38FA2C320202020202020202020202020202020
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 1, 4, 0xC0))
+8F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 2, 4, 0xC0))
+8FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 3, 4, 0xC0))
+8FA2C3
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 4, 4, 0xC0))
+8FA2C38F
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char), 5, 4, 0xC0))
+8FA2C38FA2
+select hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 4, 0xC0));
+hex(weight_string(cast(0x8FA2C38FA2C38FA2C3 as char),25, 4, 0xC0))
+8FA2C38FA2C38FA2C320202020202020202020202020202020
+#
+# End of 5.6 tests
+#
diff --git a/mysql-test/r/ctype_utf16.result b/mysql-test/r/ctype_utf16.result
index 34b25ab4f4f..1b2bd4b62cf 100644
--- a/mysql-test/r/ctype_utf16.result
+++ b/mysql-test/r/ctype_utf16.result
@@ -1327,3 +1327,374 @@ Warning 1260 Row 1 was cut by GROUP_CONCAT()
#
# End of 5.5 tests
#
+#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+set collation_connection=utf16_general_ci;
+select @@collation_connection;
+@@collation_connection
+utf16_general_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+0041
+select hex(weight_string('A'));
+hex(weight_string('A'))
+0041
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+004100420043
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+00410042
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+004100420043
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+00410042004300200020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+00
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+0041
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+004100
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+00410042
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+0041004200
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+00410042002000200020002000200020002000200020002000
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+00
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+0041
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+004100
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+00410042
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+0041004200
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+00410042004300200020002000200020002000200020002000
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+00
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+0041
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+004100
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+00410042
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+0041004200
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+00410042004300200020002000200020002000200020002000
+select @@collation_connection;
+@@collation_connection
+utf16_general_ci
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+20AC20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+20AC20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+20AC20AC20AC00200020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+20AC20AC00
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+20AC20AC002000200020002000200020002000200020002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+20AC20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+20AC20AC20AC00200020002000200020002000200020002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+20AC20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+20AC20AC20AC00200020002000200020002000200020002000
+select hex(weight_string(_utf16 0xD800DC00));
+hex(weight_string(_utf16 0xD800DC00))
+FFFD
+select hex(weight_string(_utf16 0xD800DC01));
+hex(weight_string(_utf16 0xD800DC01))
+FFFD
+select @@collation_connection;
+@@collation_connection
+utf16_general_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+0041
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+0041
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+004100420043
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+00410042
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+004100420043
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+00410042004300200020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+20002000430042004100
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+FFBEFFBDFFBCFFDFFFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFFFDFFFBCFFBDFFBEFF
+set collation_connection=utf16_bin;
+select @@collation_connection;
+@@collation_connection
+utf16_bin
+select hex(weight_string('a'));
+hex(weight_string('a'))
+000061
+select hex(weight_string('A'));
+hex(weight_string('A'))
+000041
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+000061000062000063
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+000061000062
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+000061000062000063
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+000061000062000063000020000020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+00
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+0000
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+000061
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+00006100
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+0000610000
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+00006100006200002000002000002000002000002000002000
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+00
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+0000
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+000061
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+00006100
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+0000610000
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+00006100006200006300002000002000002000002000002000
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+00
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+0000
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+000061
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+00006100
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+0000610000
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+00006100006200006300002000002000002000002000002000
+select @@collation_connection;
+@@collation_connection
+utf16_bin
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+0020AC0020AC0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+0020AC0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+0020AC0020AC0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+0020AC0020AC0020AC000020000020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+00
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+0020
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+0020AC00
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+0020AC0020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+0020AC0020AC00002000002000002000002000002000002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+00
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+0020
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+0020AC00
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+0020AC0020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+0020AC0020AC0020AC00002000002000002000002000002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+00
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+0020
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+0020AC00
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+0020AC0020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+0020AC0020AC0020AC00002000002000002000002000002000
+select @@collation_connection;
+@@collation_connection
+utf16_bin
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+000061
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+000041
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+000061000062000063
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+000061000062
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+000061000062000063
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+000061000062000063000020000020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+200000200000630000620000610000
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+FFFF9EFFFF9DFFFF9CFFFFDFFFFFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFFFFFDFFFFF9CFFFF9DFFFF9EFFFF
+#
+# End of 5.6 tests
+#
diff --git a/mysql-test/r/ctype_utf16_uca.result b/mysql-test/r/ctype_utf16_uca.result
index fe715ba1438..c33b27d5317 100644
--- a/mysql-test/r/ctype_utf16_uca.result
+++ b/mysql-test/r/ctype_utf16_uca.result
@@ -2290,6 +2290,66 @@ select c1 as c2h from t1 where c1 like 'ab#_def' escape '#';
c2h
ab_def
drop table t1;
+drop table if exists t1;
+create table t1 as select repeat(' ', 64) as s1;
+select collation(s1) from t1;
+collation(s1)
+utf16_unicode_ci
+delete from t1;
+insert into t1 values ('a'),('ae'),(_latin1 0xE4);
+insert into t1 values ('o'),('oe'),(_latin1 0xF6);
+insert into t1 values ('s'),('ss'),(_latin1 0xDF);
+insert into t1 values ('u'),('ue'),(_latin1 0xFC);
+select s1, hex(s1) from t1 order by s1, binary s1;
+s1 hex(s1)
+a 0061
+ä 00E4
+ae 00610065
+o 006F
+ö 00F6
+oe 006F0065
+s 0073
+ss 00730073
+ß 00DF
+u 0075
+ü 00FC
+ue 00750065
+select group_concat(s1 order by binary s1) from t1 group by s1;
+group_concat(s1 order by binary s1)
+a,ä
+ae
+o,ö
+oe
+s
+ss,ß
+u,ü
+ue
+drop table t1;
+CREATE TABLE t1 AS SELECT REPEAT('a',1) AS a, 1 AS b LIMIT 0;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1) CHARACTER SET utf16 COLLATE utf16_unicode_ci NOT NULL DEFAULT '',
+ `b` int(1) NOT NULL DEFAULT '0'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 VALUES ('s',0),(_latin1 0xDF,1);
+SELECT * FROM t1 ORDER BY a, b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY a DESC, b;
+a b
+ß 1
+s 0
+SELECT * FROM t1 ORDER BY CONCAT(a), b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY CONCAT(a) DESC, b;
+a b
+ß 1
+s 0
+DROP TABLE t1;
End of 4.1 tests
CREATE TABLE t1 (id int, a varchar(30) character set utf16);
INSERT INTO t1 VALUES (1, 0x01310069), (2, 0x01310131);
@@ -2417,3 +2477,344 @@ DROP TABLE t1;
#
# End of 5.5 tests
#
+#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+set collation_connection=utf16_unicode_ci;
+select @@collation_connection;
+@@collation_connection
+utf16_unicode_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+0E33
+select hex(weight_string('A'));
+hex(weight_string('A'))
+0E33
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+0E330E4A0E60
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+0E330E4A
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+0E330E4A0E60
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+0E330E4A0E6002090209
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+0E
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+0E33
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+0E330E
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+0E330E4A
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+0E330E4A02
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+0E330E4A020902090209020902090209020902090209020902
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+0E
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+0E33
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+0E330E
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+0E330E4A
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+0E330E4A0E
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+0E330E4A0E6002090209020902090209020902090209020902
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+0E
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+0E33
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+0E330E
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+0E330E4A
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+0E330E4A0E
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+0E330E4A0E6002090209020902090209020902090209020902
+select @@collation_connection;
+@@collation_connection
+utf16_unicode_ci
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+0E23
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+0E230E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+0E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+0E230E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+0E230E230E2302090209
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+0E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+0E230E
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+0E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+0E230E2302
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+0E230E23020902090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+0E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+0E230E
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+0E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+0E230E230E
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+0E230E230E2302090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+0E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+0E230E
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+0E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+0E230E230E
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+0E230E230E2302090209020902090209020902090209020902
+select hex(weight_string(_utf16 0xD800DC00 collate utf16_unicode_ci));
+hex(weight_string(_utf16 0xD800DC00 collate utf16_unicode_ci))
+FFFD
+select hex(weight_string(_utf16 0xD800DC01 collate utf16_unicode_ci));
+hex(weight_string(_utf16 0xD800DC01 collate utf16_unicode_ci))
+FFFD
+select @@collation_connection;
+@@collation_connection
+utf16_unicode_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+0E33
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+0E33
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+0E330E4A0E60
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+0E330E4A
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+0E330E4A0E60
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+0E330E4A0E6002090209
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+09020902600E4A0E330E
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+F1CCF1B5F19FFDF6FDF6
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+F6FDF6FD9FF1B5F1CCF1
+set @@collation_connection=utf16_czech_ci;
+select @@collation_connection;
+@@collation_connection
+utf16_czech_ci
+select collation(cast(_latin1 0xDF as char));
+collation(cast(_latin1 0xDF as char))
+utf16_czech_ci
+select hex(weight_string('s'));
+hex(weight_string('s'))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF as char)));
+hex(weight_string(cast(_latin1 0xDF as char)))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF as char) as char(1)));
+hex(weight_string(cast(_latin1 0xDF as char) as char(1)))
+0FEA
+select hex(weight_string('c'));
+hex(weight_string('c'))
+0E60
+select hex(weight_string('h'));
+hex(weight_string('h'))
+0EE1
+select hex(weight_string('ch'));
+hex(weight_string('ch'))
+0EE2
+select hex(weight_string('i'));
+hex(weight_string('i'))
+0EFB
+select hex(weight_string(cast(_latin1 0x6368DF as char)));
+hex(weight_string(cast(_latin1 0x6368DF as char)))
+0EE20FEA0FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(1)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(1)))
+0EE2
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(2)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(2)))
+0EE20FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(3)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(3)))
+0EE20FEA0FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(4)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(4)))
+0EE20FEA0FEA0209
+select hex(weight_string(cast(_latin1 0xDF6368 as char)));
+hex(weight_string(cast(_latin1 0xDF6368 as char)))
+0FEA0FEA0EE2
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(1)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(1)))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(2)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(2)))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(3)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(3)))
+0FEA0FEA0EE2
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(4)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(4)))
+0FEA0FEA0EE20209
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 1, 2, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 2, 2, 0xC0))
+0EE2
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 3, 2, 0xC0))
+0EE20F
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 4, 2, 0xC0))
+0EE20FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char),25, 2, 0xC0))
+0EE20FEA020902090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 1, 3, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 2, 3, 0xC0))
+0EE2
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 3, 3, 0xC0))
+0EE20F
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 4, 3, 0xC0))
+0EE20FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char),25, 3, 0xC0))
+0EE20FEA0FEA02090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 1, 4, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 2, 4, 0xC0))
+0EE2
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 3, 4, 0xC0))
+0EE20F
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 4, 4, 0xC0))
+0EE20FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char),25, 4, 0xC0))
+0EE20FEA0FEA02090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 2,0xC0))
+0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 2,0xC0))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 2,0xC0))
+0FEA0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 2,0xC0))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char),25, 2,0xC0))
+0FEA0FEA020902090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 3,0xC0))
+0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 3,0xC0))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 3,0xC0))
+0FEA0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 3,0xC0))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char),25, 3,0xC0))
+0FEA0FEA0EE202090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 4,0xC0))
+0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 4,0xC0))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 4,0xC0))
+0FEA0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 4,0xC0))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char),25, 4,0xC0))
+0FEA0FEA0EE202090209020902090209020902090209020902
+#
+# End of 5.6 tests
+#
diff --git a/mysql-test/r/ctype_utf16le.result b/mysql-test/r/ctype_utf16le.result
index ae36dd5abfd..a8407001ce2 100644
--- a/mysql-test/r/ctype_utf16le.result
+++ b/mysql-test/r/ctype_utf16le.result
@@ -1572,5 +1572,370 @@ ACB
ABC
DROP TABLE t1;
#
+# WL#3664 WEIGHT_STRING
+#
+SET NAMES utf8, collation_connection=utf16le_general_ci;
+select @@collation_connection;
+@@collation_connection
+utf16le_general_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+0041
+select hex(weight_string('A'));
+hex(weight_string('A'))
+0041
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+004100420043
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+00410042
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+004100420043
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+00410042004300200020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+00
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+0041
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+004100
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+00410042
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+0041004200
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+00410042002000200020002000200020002000200020002000
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+00
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+0041
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+004100
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+00410042
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+0041004200
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+00410042004300200020002000200020002000200020002000
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+00
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+0041
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+004100
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+00410042
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+0041004200
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+00410042004300200020002000200020002000200020002000
+select @@collation_connection;
+@@collation_connection
+utf16le_general_ci
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+20AC20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+20AC20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+20AC20AC20AC00200020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+20AC20AC00
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+20AC20AC002000200020002000200020002000200020002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+20AC20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+20AC20AC20AC00200020002000200020002000200020002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+20AC20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+20AC20AC20AC00200020002000200020002000200020002000
+SELECT HEX(WEIGHT_STRING(_utf16le 0x00D800DC));
+HEX(WEIGHT_STRING(_utf16le 0x00D800DC))
+FFFD
+SELECT HEX(WEIGHT_STRING(_utf16le 0x00D801DC));
+HEX(WEIGHT_STRING(_utf16le 0x00D801DC))
+FFFD
+select @@collation_connection;
+@@collation_connection
+utf16le_general_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+0041
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+0041
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+004100420043
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+00410042
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+004100420043
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+00410042004300200020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+20002000430042004100
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+FFBEFFBDFFBCFFDFFFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFFFDFFFBCFFBDFFBEFF
+SET NAMES utf8, collation_connection=utf16le_bin;
+select @@collation_connection;
+@@collation_connection
+utf16le_bin
+select hex(weight_string('a'));
+hex(weight_string('a'))
+000061
+select hex(weight_string('A'));
+hex(weight_string('A'))
+000041
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+000061000062000063
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+000061000062
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+000061000062000063
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+000061000062000063000020000020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+00
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+0000
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+000061
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+00006100
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+0000610000
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+00006100006200002000002000002000002000002000002000
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+00
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+0000
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+000061
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+00006100
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+0000610000
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+00006100006200006300002000002000002000002000002000
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+00
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+0000
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+000061
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+00006100
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+0000610000
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+00006100006200006300002000002000002000002000002000
+select @@collation_connection;
+@@collation_connection
+utf16le_bin
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+0020AC0020AC0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+0020AC0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+0020AC0020AC0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+0020AC0020AC0020AC000020000020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+00
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+0020
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+0020AC00
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+0020AC0020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+0020AC0020AC00002000002000002000002000002000002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+00
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+0020
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+0020AC00
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+0020AC0020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+0020AC0020AC0020AC00002000002000002000002000002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+00
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+0020
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+0020AC00
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+0020AC0020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+0020AC0020AC0020AC00002000002000002000002000002000
+select @@collation_connection;
+@@collation_connection
+utf16le_bin
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+000061
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+000041
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+000061000062000063
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+000061000062
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+000061000062000063
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+000061000062000063000020000020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+200000200000630000620000610000
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+FFFF9EFFFF9DFFFF9CFFFFDFFFFFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFFFFFDFFFFF9CFFFF9DFFFF9EFFFF
+#
# End of 5.6 tests
#
diff --git a/mysql-test/r/ctype_utf32.result b/mysql-test/r/ctype_utf32.result
index 8a16e5cca71..4cdbdea1fc3 100644
--- a/mysql-test/r/ctype_utf32.result
+++ b/mysql-test/r/ctype_utf32.result
@@ -1380,3 +1380,374 @@ SELECT '2010-10-10 10:10:10' + INTERVAL GeometryType(GeomFromText('POINT(1 1)'))
#
# End of 5.5 tests
#
+#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+set collation_connection=utf32_general_ci;
+select @@collation_connection;
+@@collation_connection
+utf32_general_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+0041
+select hex(weight_string('A'));
+hex(weight_string('A'))
+0041
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+004100420043
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+00410042
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+004100420043
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+00410042004300200020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+00
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+0041
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+004100
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+00410042
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+0041004200
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+00410042002000200020002000200020002000200020002000
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+00
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+0041
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+004100
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+00410042
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+0041004200
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+00410042004300200020002000200020002000200020002000
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+00
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+0041
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+004100
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+00410042
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+0041004200
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+00410042004300200020002000200020002000200020002000
+select @@collation_connection;
+@@collation_connection
+utf32_general_ci
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+20AC20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+20AC20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+20AC20AC20AC00200020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+20AC20AC00
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+20AC20AC002000200020002000200020002000200020002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+20AC20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+20AC20AC20AC00200020002000200020002000200020002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+20AC20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+20AC20AC20AC00200020002000200020002000200020002000
+select hex(weight_string(_utf32 0x10000));
+hex(weight_string(_utf32 0x10000))
+FFFD
+select hex(weight_string(_utf32 0x10001));
+hex(weight_string(_utf32 0x10001))
+FFFD
+select @@collation_connection;
+@@collation_connection
+utf32_general_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+0041
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+0041
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+004100420043
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+00410042
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+004100420043
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+00410042004300200020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+20002000430042004100
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+FFBEFFBDFFBCFFDFFFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFFFDFFFBCFFBDFFBEFF
+set collation_connection=utf32_bin;
+select @@collation_connection;
+@@collation_connection
+utf32_bin
+select hex(weight_string('a'));
+hex(weight_string('a'))
+000061
+select hex(weight_string('A'));
+hex(weight_string('A'))
+000041
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+000061000062000063
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+000061000062
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+000061000062000063
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+000061000062000063000020000020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+00
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+0000
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+000061
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+00006100
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+0000610000
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+00006100006200002000002000002000002000002000002000
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+00
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+0000
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+000061
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+00006100
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+0000610000
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+00006100006200006300002000002000002000002000002000
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+00
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+0000
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+000061
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+00006100
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+0000610000
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+00006100006200006300002000002000002000002000002000
+select @@collation_connection;
+@@collation_connection
+utf32_bin
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+0020AC0020AC0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+0020AC0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+0020AC0020AC0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+0020AC0020AC0020AC000020000020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+00
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+0020
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+0020AC00
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+0020AC0020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+0020AC0020AC00002000002000002000002000002000002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+00
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+0020
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+0020AC00
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+0020AC0020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+0020AC0020AC0020AC00002000002000002000002000002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+00
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+0020
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+0020AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+0020AC00
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+0020AC0020
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+0020AC0020AC0020AC00002000002000002000002000002000
+select @@collation_connection;
+@@collation_connection
+utf32_bin
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+000061
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+000041
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+000061000062000063
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+000061000062
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+000061000062000063
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+000061000062000063000020000020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+200000200000630000620000610000
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+FFFF9EFFFF9DFFFF9CFFFFDFFFFFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFFFFFDFFFFF9CFFFF9DFFFF9EFFFF
+#
+# End of 5.6 tests
+#
diff --git a/mysql-test/r/ctype_utf32_uca.result b/mysql-test/r/ctype_utf32_uca.result
index 695e250f4a8..1c8b683f4fa 100644
--- a/mysql-test/r/ctype_utf32_uca.result
+++ b/mysql-test/r/ctype_utf32_uca.result
@@ -2290,6 +2290,66 @@ select c1 as c2h from t1 where c1 like 'ab#_def' escape '#';
c2h
ab_def
drop table t1;
+drop table if exists t1;
+create table t1 as select repeat(' ', 64) as s1;
+select collation(s1) from t1;
+collation(s1)
+utf32_unicode_ci
+delete from t1;
+insert into t1 values ('a'),('ae'),(_latin1 0xE4);
+insert into t1 values ('o'),('oe'),(_latin1 0xF6);
+insert into t1 values ('s'),('ss'),(_latin1 0xDF);
+insert into t1 values ('u'),('ue'),(_latin1 0xFC);
+select s1, hex(s1) from t1 order by s1, binary s1;
+s1 hex(s1)
+a 00000061
+ä 000000E4
+ae 0000006100000065
+o 0000006F
+ö 000000F6
+oe 0000006F00000065
+s 00000073
+ss 0000007300000073
+ß 000000DF
+u 00000075
+ü 000000FC
+ue 0000007500000065
+select group_concat(s1 order by binary s1) from t1 group by s1;
+group_concat(s1 order by binary s1)
+a,ä
+ae
+o,ö
+oe
+s
+ss,ß
+u,ü
+ue
+drop table t1;
+CREATE TABLE t1 AS SELECT REPEAT('a',1) AS a, 1 AS b LIMIT 0;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1) CHARACTER SET utf32 COLLATE utf32_unicode_ci NOT NULL DEFAULT '',
+ `b` int(1) NOT NULL DEFAULT '0'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 VALUES ('s',0),(_latin1 0xDF,1);
+SELECT * FROM t1 ORDER BY a, b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY a DESC, b;
+a b
+ß 1
+s 0
+SELECT * FROM t1 ORDER BY CONCAT(a), b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY CONCAT(a) DESC, b;
+a b
+ß 1
+s 0
+DROP TABLE t1;
End of 4.1 tests
CREATE TABLE t1 (id int, a varchar(30) character set utf32);
INSERT INTO t1 VALUES (1, _ucs2 0x01310069), (2, _ucs2 0x01310131);
@@ -2437,3 +2497,344 @@ DROP TABLE t1,t2;
#
# End of 5.5 tests
#
+#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+set collation_connection=utf32_unicode_ci;
+select @@collation_connection;
+@@collation_connection
+utf32_unicode_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+0E33
+select hex(weight_string('A'));
+hex(weight_string('A'))
+0E33
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+0E330E4A0E60
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+0E330E4A
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+0E330E4A0E60
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+0E330E4A0E6002090209
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+0E
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+0E33
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+0E330E
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+0E330E4A
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+0E330E4A02
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+0E330E4A020902090209020902090209020902090209020902
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+0E
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+0E33
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+0E330E
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+0E330E4A
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+0E330E4A0E
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+0E330E4A0E6002090209020902090209020902090209020902
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+0E
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+0E33
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+0E330E
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+0E330E4A
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+0E330E4A0E
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+0E330E4A0E6002090209020902090209020902090209020902
+select @@collation_connection;
+@@collation_connection
+utf32_unicode_ci
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+0E23
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+0E230E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+0E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+0E230E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+0E230E230E2302090209
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+0E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+0E230E
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+0E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+0E230E2302
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+0E230E23020902090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+0E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+0E230E
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+0E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+0E230E230E
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+0E230E230E2302090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+0E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+0E230E
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+0E230E23
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+0E230E230E
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+0E230E230E2302090209020902090209020902090209020902
+select hex(weight_string(_utf32 0x10000 collate utf32_unicode_ci));
+hex(weight_string(_utf32 0x10000 collate utf32_unicode_ci))
+FFFD
+select hex(weight_string(_utf32 0x10001 collate utf32_unicode_ci));
+hex(weight_string(_utf32 0x10001 collate utf32_unicode_ci))
+FFFD
+select @@collation_connection;
+@@collation_connection
+utf32_unicode_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+0E33
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+0E33
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+0E330E4A0E60
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+0E330E4A
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+0E330E4A0E60
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+0E330E4A0E6002090209
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+09020902600E4A0E330E
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+F1CCF1B5F19FFDF6FDF6
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+F6FDF6FD9FF1B5F1CCF1
+set @@collation_connection=utf32_czech_ci;
+select @@collation_connection;
+@@collation_connection
+utf32_czech_ci
+select collation(cast(_latin1 0xDF as char));
+collation(cast(_latin1 0xDF as char))
+utf32_czech_ci
+select hex(weight_string('s'));
+hex(weight_string('s'))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF as char)));
+hex(weight_string(cast(_latin1 0xDF as char)))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF as char) as char(1)));
+hex(weight_string(cast(_latin1 0xDF as char) as char(1)))
+0FEA
+select hex(weight_string('c'));
+hex(weight_string('c'))
+0E60
+select hex(weight_string('h'));
+hex(weight_string('h'))
+0EE1
+select hex(weight_string('ch'));
+hex(weight_string('ch'))
+0EE2
+select hex(weight_string('i'));
+hex(weight_string('i'))
+0EFB
+select hex(weight_string(cast(_latin1 0x6368DF as char)));
+hex(weight_string(cast(_latin1 0x6368DF as char)))
+0EE20FEA0FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(1)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(1)))
+0EE2
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(2)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(2)))
+0EE20FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(3)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(3)))
+0EE20FEA0FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char) as char(4)));
+hex(weight_string(cast(_latin1 0x6368DF as char) as char(4)))
+0EE20FEA0FEA0209
+select hex(weight_string(cast(_latin1 0xDF6368 as char)));
+hex(weight_string(cast(_latin1 0xDF6368 as char)))
+0FEA0FEA0EE2
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(1)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(1)))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(2)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(2)))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(3)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(3)))
+0FEA0FEA0EE2
+select hex(weight_string(cast(_latin1 0xDF6368 as char) as char(4)));
+hex(weight_string(cast(_latin1 0xDF6368 as char) as char(4)))
+0FEA0FEA0EE20209
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 1, 2, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 2, 2, 0xC0))
+0EE2
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 3, 2, 0xC0))
+0EE20F
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 4, 2, 0xC0))
+0EE20FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char),25, 2, 0xC0))
+0EE20FEA020902090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 1, 3, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 2, 3, 0xC0))
+0EE2
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 3, 3, 0xC0))
+0EE20F
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 4, 3, 0xC0))
+0EE20FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char),25, 3, 0xC0))
+0EE20FEA0FEA02090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0x6368DF as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 1, 4, 0xC0))
+0E
+select hex(weight_string(cast(_latin1 0x6368DF as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 2, 4, 0xC0))
+0EE2
+select hex(weight_string(cast(_latin1 0x6368DF as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 3, 4, 0xC0))
+0EE20F
+select hex(weight_string(cast(_latin1 0x6368DF as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char), 4, 4, 0xC0))
+0EE20FEA
+select hex(weight_string(cast(_latin1 0x6368DF as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x6368DF as char),25, 4, 0xC0))
+0EE20FEA0FEA02090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 2,0xC0))
+0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 2,0xC0))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 2,0xC0))
+0FEA0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 2,0xC0))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 2,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char),25, 2,0xC0))
+0FEA0FEA020902090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 3,0xC0))
+0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 3,0xC0))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 3,0xC0))
+0FEA0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 3,0xC0))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 3,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char),25, 3,0xC0))
+0FEA0FEA0EE202090209020902090209020902090209020902
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 1, 4,0xC0))
+0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 2, 4,0xC0))
+0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 3, 4,0xC0))
+0FEA0F
+select hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char), 4, 4,0xC0))
+0FEA0FEA
+select hex(weight_string(cast(_latin1 0xDF6368 as char),25, 4,0xC0));
+hex(weight_string(cast(_latin1 0xDF6368 as char),25, 4,0xC0))
+0FEA0FEA0EE202090209020902090209020902090209020902
+#
+# End of 5.6 tests
+#
diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result
index 42d10ddeef5..ccc379b1864 100644
--- a/mysql-test/r/ctype_utf8.result
+++ b/mysql-test/r/ctype_utf8.result
@@ -977,6 +977,31 @@ ss
u,ü
ue
drop table t1;
+CREATE TABLE t1 AS SELECT REPEAT('a',1) AS a, 1 AS b LIMIT 0;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1) CHARACTER SET utf8 NOT NULL DEFAULT '',
+ `b` int(1) NOT NULL DEFAULT '0'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 VALUES ('s',0),(_latin1 0xDF,1);
+SELECT * FROM t1 ORDER BY a, b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY a DESC, b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY CONCAT(a), b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY CONCAT(a) DESC, b;
+a b
+s 0
+ß 1
+DROP TABLE t1;
SET collation_connection='utf8_bin';
create table t1 select repeat('a',4000) a;
delete from t1;
@@ -5104,3 +5129,390 @@ Warning 1260 Row 2 was cut by GROUP_CONCAT()
#
# End of 5.5 tests
#
+#
+# Start of 5.6 tests
+#
+#
+# WL#3664 WEIGHT_STRING
+#
+set names utf8;
+select @@collation_connection;
+@@collation_connection
+utf8_general_ci
+select hex(weight_string('a'));
+hex(weight_string('a'))
+0041
+select hex(weight_string('A'));
+hex(weight_string('A'))
+0041
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+004100420043
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+00410042
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+004100420043
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+00410042004300200020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+00
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+0041
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+004100
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+00410042
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+0041004200
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+00410042002000200020002000200020002000200020002000
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+00
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+0041
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+004100
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+00410042
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+0041004200
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+00410042004300200020002000200020002000200020002000
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+00
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+0041
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+004100
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+00410042
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+0041004200
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+00410042004300200020002000200020002000200020002000
+select @@collation_connection;
+@@collation_connection
+utf8_general_ci
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+20AC20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+20AC20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+20AC20AC20AC00200020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+20AC20AC00
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+20AC20AC002000200020002000200020002000200020002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+20AC20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+20AC20AC20AC00200020002000200020002000200020002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+20AC20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+20AC20AC20AC00200020002000200020002000200020002000
+select @@collation_connection;
+@@collation_connection
+utf8_general_ci
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+0041
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+0041
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+004100420043
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+00410042
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+004100420043
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+00410042004300200020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+20002000430042004100
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+FFBEFFBDFFBCFFDFFFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFFFDFFFBCFFBDFFBEFF
+set @@collation_connection=utf8_bin;
+select @@collation_connection;
+@@collation_connection
+utf8_bin
+select hex(weight_string('a'));
+hex(weight_string('a'))
+0061
+select hex(weight_string('A'));
+hex(weight_string('A'))
+0041
+select hex(weight_string('abc'));
+hex(weight_string('abc'))
+006100620063
+select hex(weight_string('abc' as char(2)));
+hex(weight_string('abc' as char(2)))
+00610062
+select hex(weight_string('abc' as char(3)));
+hex(weight_string('abc' as char(3)))
+006100620063
+select hex(weight_string('abc' as char(5)));
+hex(weight_string('abc' as char(5)))
+00610062006300200020
+select hex(weight_string('abc', 1, 2, 0xC0));
+hex(weight_string('abc', 1, 2, 0xC0))
+00
+select hex(weight_string('abc', 2, 2, 0xC0));
+hex(weight_string('abc', 2, 2, 0xC0))
+0061
+select hex(weight_string('abc', 3, 2, 0xC0));
+hex(weight_string('abc', 3, 2, 0xC0))
+006100
+select hex(weight_string('abc', 4, 2, 0xC0));
+hex(weight_string('abc', 4, 2, 0xC0))
+00610062
+select hex(weight_string('abc', 5, 2, 0xC0));
+hex(weight_string('abc', 5, 2, 0xC0))
+0061006200
+select hex(weight_string('abc',25, 2, 0xC0));
+hex(weight_string('abc',25, 2, 0xC0))
+00610062002000200020002000200020002000200020002000
+select hex(weight_string('abc', 1, 3, 0xC0));
+hex(weight_string('abc', 1, 3, 0xC0))
+00
+select hex(weight_string('abc', 2, 3, 0xC0));
+hex(weight_string('abc', 2, 3, 0xC0))
+0061
+select hex(weight_string('abc', 3, 3, 0xC0));
+hex(weight_string('abc', 3, 3, 0xC0))
+006100
+select hex(weight_string('abc', 4, 3, 0xC0));
+hex(weight_string('abc', 4, 3, 0xC0))
+00610062
+select hex(weight_string('abc', 5, 3, 0xC0));
+hex(weight_string('abc', 5, 3, 0xC0))
+0061006200
+select hex(weight_string('abc',25, 3, 0xC0));
+hex(weight_string('abc',25, 3, 0xC0))
+00610062006300200020002000200020002000200020002000
+select hex(weight_string('abc', 1, 4, 0xC0));
+hex(weight_string('abc', 1, 4, 0xC0))
+00
+select hex(weight_string('abc', 2, 4, 0xC0));
+hex(weight_string('abc', 2, 4, 0xC0))
+0061
+select hex(weight_string('abc', 3, 4, 0xC0));
+hex(weight_string('abc', 3, 4, 0xC0))
+006100
+select hex(weight_string('abc', 4, 4, 0xC0));
+hex(weight_string('abc', 4, 4, 0xC0))
+00610062
+select hex(weight_string('abc', 5, 4, 0xC0));
+hex(weight_string('abc', 5, 4, 0xC0))
+0061006200
+select hex(weight_string('abc',25, 4, 0xC0));
+hex(weight_string('abc',25, 4, 0xC0))
+00610062006300200020002000200020002000200020002000
+select @@collation_connection;
+@@collation_connection
+utf8_bin
+select hex(weight_string(cast(_latin1 0x80 as char)));
+hex(weight_string(cast(_latin1 0x80 as char)))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char)));
+hex(weight_string(cast(_latin1 0x808080 as char)))
+20AC20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(2)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(2)))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(3)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(3)))
+20AC20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char) as char(5)));
+hex(weight_string(cast(_latin1 0x808080 as char) as char(5)))
+20AC20AC20AC00200020
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 2, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 2, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 2, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 2, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 2, 0xC0))
+20AC20AC00
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 2, 0xC0))
+20AC20AC002000200020002000200020002000200020002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 3, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 3, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 3, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 3, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 3, 0xC0))
+20AC20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 3, 0xC0))
+20AC20AC20AC00200020002000200020002000200020002000
+select hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 1, 4, 0xC0))
+20
+select hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 2, 4, 0xC0))
+20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 3, 4, 0xC0))
+20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 4, 4, 0xC0))
+20AC20AC
+select hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char), 5, 4, 0xC0))
+20AC20AC20
+select hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0));
+hex(weight_string(cast(_latin1 0x808080 as char),25, 4, 0xC0))
+20AC20AC20AC00200020002000200020002000200020002000
+select @@collation_connection;
+@@collation_connection
+utf8_bin
+select hex(weight_string('a' LEVEL 1));
+hex(weight_string('a' LEVEL 1))
+0061
+select hex(weight_string('A' LEVEL 1));
+hex(weight_string('A' LEVEL 1))
+0041
+select hex(weight_string('abc' LEVEL 1));
+hex(weight_string('abc' LEVEL 1))
+006100620063
+select hex(weight_string('abc' as char(2) LEVEL 1));
+hex(weight_string('abc' as char(2) LEVEL 1))
+00610062
+select hex(weight_string('abc' as char(3) LEVEL 1));
+hex(weight_string('abc' as char(3) LEVEL 1))
+006100620063
+select hex(weight_string('abc' as char(5) LEVEL 1));
+hex(weight_string('abc' as char(5) LEVEL 1))
+00610062006300200020
+select hex(weight_string('abc' as char(5) LEVEL 1 REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 REVERSE))
+20002000630062006100
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC))
+FF9EFF9DFF9CFFDFFFDF
+select hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE));
+hex(weight_string('abc' as char(5) LEVEL 1 DESC REVERSE))
+DFFFDFFF9CFF9DFF9EFF
+#
+# Checking strnxfrm() with odd length
+#
+set max_sort_length=5;
+select @@max_sort_length;
+@@max_sort_length
+5
+create table t1 (a varchar(128) character set utf8 collate utf8_general_ci);
+insert into t1 values ('a'),('b'),('c');
+select * from t1 order by a;
+a
+a
+b
+c
+alter table t1 modify a varchar(128) character set utf8 collate utf8_bin;
+select * from t1 order by a;
+a
+a
+b
+c
+drop table t1;
+set max_sort_length=default;
+#
+# End of 5.6 tests
+#
diff --git a/mysql-test/r/ctype_utf8mb4.result b/mysql-test/r/ctype_utf8mb4.result
index c713ce39e41..ecd4b8bcef5 100644
--- a/mysql-test/r/ctype_utf8mb4.result
+++ b/mysql-test/r/ctype_utf8mb4.result
@@ -977,6 +977,31 @@ ss
u,ü
ue
drop table t1;
+CREATE TABLE t1 AS SELECT REPEAT('a',1) AS a, 1 AS b LIMIT 0;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1) CHARACTER SET utf8mb4 NOT NULL DEFAULT '',
+ `b` int(1) NOT NULL DEFAULT '0'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 VALUES ('s',0),(_latin1 0xDF,1);
+SELECT * FROM t1 ORDER BY a, b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY a DESC, b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY CONCAT(a), b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY CONCAT(a) DESC, b;
+a b
+s 0
+ß 1
+DROP TABLE t1;
SET collation_connection='utf8mb4_bin';
create table t1 select repeat('a',4000) a;
delete from t1;
diff --git a/mysql-test/r/ctype_utf8mb4_heap.result b/mysql-test/r/ctype_utf8mb4_heap.result
index 1649e7afeaf..0323a13cdb6 100644
--- a/mysql-test/r/ctype_utf8mb4_heap.result
+++ b/mysql-test/r/ctype_utf8mb4_heap.result
@@ -916,6 +916,31 @@ ss
u,ü
ue
drop table t1;
+CREATE TABLE t1 AS SELECT REPEAT('a',1) AS a, 1 AS b LIMIT 0;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1) CHARACTER SET utf8mb4 NOT NULL DEFAULT '',
+ `b` int(1) NOT NULL DEFAULT '0'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 VALUES ('s',0),(_latin1 0xDF,1);
+SELECT * FROM t1 ORDER BY a, b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY a DESC, b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY CONCAT(a), b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY CONCAT(a) DESC, b;
+a b
+s 0
+ß 1
+DROP TABLE t1;
SET collation_connection='utf8mb4_bin';
create table t1 select repeat('a',4000) a;
delete from t1;
diff --git a/mysql-test/r/ctype_utf8mb4_innodb.result b/mysql-test/r/ctype_utf8mb4_innodb.result
index a0c334834ba..1b7f8425968 100644
--- a/mysql-test/r/ctype_utf8mb4_innodb.result
+++ b/mysql-test/r/ctype_utf8mb4_innodb.result
@@ -977,6 +977,31 @@ ss
u,ü
ue
drop table t1;
+CREATE TABLE t1 AS SELECT REPEAT('a',1) AS a, 1 AS b LIMIT 0;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1) CHARACTER SET utf8mb4 NOT NULL DEFAULT '',
+ `b` int(1) NOT NULL DEFAULT '0'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 VALUES ('s',0),(_latin1 0xDF,1);
+SELECT * FROM t1 ORDER BY a, b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY a DESC, b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY CONCAT(a), b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY CONCAT(a) DESC, b;
+a b
+s 0
+ß 1
+DROP TABLE t1;
SET collation_connection='utf8mb4_bin';
create table t1 select repeat('a',4000) a;
delete from t1;
diff --git a/mysql-test/r/ctype_utf8mb4_myisam.result b/mysql-test/r/ctype_utf8mb4_myisam.result
index 3b40d646b61..b2d8c9dbc20 100644
--- a/mysql-test/r/ctype_utf8mb4_myisam.result
+++ b/mysql-test/r/ctype_utf8mb4_myisam.result
@@ -977,6 +977,31 @@ ss
u,ü
ue
drop table t1;
+CREATE TABLE t1 AS SELECT REPEAT('a',1) AS a, 1 AS b LIMIT 0;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1) CHARACTER SET utf8mb4 NOT NULL DEFAULT '',
+ `b` int(1) NOT NULL DEFAULT '0'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO t1 VALUES ('s',0),(_latin1 0xDF,1);
+SELECT * FROM t1 ORDER BY a, b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY a DESC, b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY CONCAT(a), b;
+a b
+s 0
+ß 1
+SELECT * FROM t1 ORDER BY CONCAT(a) DESC, b;
+a b
+s 0
+ß 1
+DROP TABLE t1;
SET collation_connection='utf8mb4_bin';
create table t1 select repeat('a',4000) a;
delete from t1;
diff --git a/mysql-test/r/func_weight_string.result b/mysql-test/r/func_weight_string.result
new file mode 100644
index 00000000000..91ca9f68076
--- /dev/null
+++ b/mysql-test/r/func_weight_string.result
@@ -0,0 +1,92 @@
+drop table if exists t1;
+set names latin1;
+select hex(weight_string(0x010203));
+hex(weight_string(0x010203))
+010203
+select hex(weight_string('aa' as char(3)));
+hex(weight_string('aa' as char(3)))
+414120
+select hex(weight_string('a' as char(-1)));
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-1)))' at line 1
+select hex(weight_string('a' as char(0)));
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '0)))' at line 1
+select hex(weight_string('a' as char(1)));
+hex(weight_string('a' as char(1)))
+41
+select hex(weight_string('ab' as char(1)));
+hex(weight_string('ab' as char(1)))
+41
+select hex(weight_string('ab'));
+hex(weight_string('ab'))
+4142
+select hex(weight_string('aa' as binary(3)));
+hex(weight_string('aa' as binary(3)))
+616100
+select hex(weight_string(cast('aa' as binary(3))));
+hex(weight_string(cast('aa' as binary(3))))
+616100
+select hex(weight_string('ab' level 1-1 ASC));
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ASC))' at line 1
+select hex(weight_string('ab' level 1-1 DESC));
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DESC))' at line 1
+select hex(weight_string('ab' level 1-1 REVERSE));
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'REVERSE))' at line 1
+select hex(weight_string('ab' level 1 ASC));
+hex(weight_string('ab' level 1 ASC))
+4142
+select hex(weight_string('ab' level 1 DESC));
+hex(weight_string('ab' level 1 DESC))
+BEBD
+select hex(weight_string('ab' level 1 REVERSE));
+hex(weight_string('ab' level 1 REVERSE))
+4241
+select hex(weight_string('ab' level 1 DESC REVERSE));
+hex(weight_string('ab' level 1 DESC REVERSE))
+BDBE
+create table t1 select weight_string('test') as w;
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `w` varbinary(4) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+drop table t1;
+create table t1 select weight_string(repeat('t',66000)) as w;
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `w` longblob
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+drop table t1;
+select weight_string(NULL);
+weight_string(NULL)
+NULL
+select 1 as weight_string, 2 as reverse;
+weight_string reverse
+1 2
+select coercibility(weight_string('test'));
+coercibility(weight_string('test'))
+4
+select coercibility(weight_string('test' collate latin1_swedish_ci));
+coercibility(weight_string('test' collate latin1_swedish_ci))
+0
+create table t1 (s1 varchar(5));
+insert into t1 values ('a'),(null);
+select hex(weight_string(s1)) from t1 order by s1;
+hex(weight_string(s1))
+NULL
+41
+drop table t1;
+#
+# BUG#11898467 - SERVER CRASHES ON SELECT HEX(WEIGHT_STRING(STR AS [CHAR|BINARY](N))) IF N IS BIG
+#
+SELECT HEX(WEIGHT_STRING('ab' AS CHAR(1000000000000000000)));
+HEX(WEIGHT_STRING('ab' AS CHAR(1000000000000000000)))
+NULL
+Warnings:
+Warning 1301 Result of weight_string() was larger than max_allowed_packet (1048576) - truncated
+SELECT HEX(WEIGHT_STRING('ab' AS BINARY(1000000000000000000)));
+HEX(WEIGHT_STRING('ab' AS BINARY(1000000000000000000)))
+NULL
+Warnings:
+Warning 1301 Result of cast_as_binary() was larger than max_allowed_packet (1048576) - truncated
+Warning 1301 Result of weight_string() was larger than max_allowed_packet (1048576) - truncated
diff --git a/mysql-test/std_data/Index.xml b/mysql-test/std_data/Index.xml
index 66a9091a3a2..25c32099203 100644
--- a/mysql-test/std_data/Index.xml
+++ b/mysql-test/std_data/Index.xml
@@ -307,6 +307,7 @@
<alias>l1</alias>
<alias>latin1</alias>
<collation name="latin1_test" id="99" order="test"/>
+ <collation name="latin1_test2" id="332" order="test"/>
</charset>
<charset name="utf8">
diff --git a/mysql-test/std_data/latin1.xml b/mysql-test/std_data/latin1.xml
index 5884416c30e..fd5197254e2 100644
--- a/mysql-test/std_data/latin1.xml
+++ b/mysql-test/std_data/latin1.xml
@@ -131,6 +131,27 @@
</map>
</collation>
+<collation name="latin1_test2">
+<map>
+ 00 01 02 03 37 2D 2E 2F 16 05 25 0B 0C 0D 0E 0F
+ 10 11 12 13 3C 3D 32 26 18 19 3F 27 1C 1D 1E 1F
+ 40 4F 7F 7B 5B 6C 50 7D 4D 5D 5C 4E 6B 60 4B 61
+ F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 7A 5E 4C 7E 6E 6F
+ 7C C1 C2 C3 C4 C5 C6 C7 C8 C9 D1 D2 D3 D4 D5 D6
+ D7 D8 D9 E2 E3 E4 E5 E6 E7 E8 E9 4A E0 5A 5F 6D
+ 79 81 82 83 84 85 86 87 88 89 91 92 93 94 95 96
+ 97 98 99 A2 A3 A4 A5 A6 A7 A8 A9 C0 6A D0 A1 07
+ 20 21 22 23 24 15 06 17 28 29 2A 2B 2C 09 0A 1B
+ 30 31 1A 33 34 35 36 08 38 39 3A 3B 04 14 3E E1
+ 41 42 43 44 45 46 47 48 49 51 52 53 54 55 56 57
+ 58 59 62 63 64 65 66 67 68 69 70 71 72 73 74 75
+ 76 77 78 80 8A 8B 8C 8D 8E 8F 90 9A 9B 9C 9D 9E
+ 9F A0 AA AB AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7
+ B8 B9 BA BB BC BD BE BF CA CB CC CD CE CF DA DB
+ DC DD DE DF EA EB EC ED EE EF FA FB FC FD FE FF
+</map>
+</collation>
+
</charset>
</charsets>
diff --git a/mysql-test/suite/innodb/r/innodb_ctype_ldml.result b/mysql-test/suite/innodb/r/innodb_ctype_ldml.result
new file mode 100644
index 00000000000..02dd8be66d2
--- /dev/null
+++ b/mysql-test/suite/innodb/r/innodb_ctype_ldml.result
@@ -0,0 +1,1078 @@
+drop table if exists t1;
+In the following tests we change the order of letter "b"
+making it equal to letter "a", and check that it works
+with all Unicode character sets
+set names utf8;
+show variables like 'character_sets_dir%';
+Variable_name Value
+character_sets_dir MYSQL_TEST_DIR/std_data/
+show collation like 'utf8_phone_ci';
+Collation Charset Id Default Compiled Sortlen
+utf8_phone_ci utf8 352 8
+CREATE TABLE t1 (
+name VARCHAR(64),
+phone VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_phone_ci
+);
+INSERT INTO t1 VALUES ('Svoj','+7 912 800 80 02');
+INSERT INTO t1 VALUES ('Hf','+7 (912) 800 80 04');
+INSERT INTO t1 VALUES ('Bar','+7-912-800-80-01');
+INSERT INTO t1 VALUES ('Ramil','(7912) 800 80 03');
+INSERT INTO t1 VALUES ('Sanja','+380 (912) 8008005');
+SELECT * FROM t1 ORDER BY phone;
+name phone
+Sanja +380 (912) 8008005
+Bar +7-912-800-80-01
+Svoj +7 912 800 80 02
+Ramil (7912) 800 80 03
+Hf +7 (912) 800 80 04
+SELECT * FROM t1 WHERE phone='+7(912)800-80-01';
+name phone
+Bar +7-912-800-80-01
+SELECT * FROM t1 WHERE phone='79128008001';
+name phone
+Bar +7-912-800-80-01
+SELECT * FROM t1 WHERE phone='7 9 1 2 8 0 0 8 0 0 1';
+name phone
+Bar +7-912-800-80-01
+DROP TABLE t1;
+show collation like 'utf8_test_ci';
+Collation Charset Id Default Compiled Sortlen
+utf8_test_ci utf8 353 8
+create table t1 (c1 char(1) character set utf8 collate utf8_test_ci);
+insert into t1 values ('a');
+select * from t1 where c1='b';
+c1
+a
+drop table t1;
+show collation like 'ucs2_test_ci';
+Collation Charset Id Default Compiled Sortlen
+ucs2_test_ci ucs2 358 8
+create table t1 (c1 char(1) character set ucs2 collate ucs2_test_ci);
+insert into t1 values ('a');
+select * from t1 where c1='b';
+c1
+a
+drop table t1;
+show collation like 'utf8mb4_test_ci';
+Collation Charset Id Default Compiled Sortlen
+utf8mb4_test_ci utf8mb4 326 8
+create table t1 (c1 char(1) character set utf8mb4 collate utf8mb4_test_ci);
+insert into t1 values ('a');
+select * from t1 where c1='b';
+c1
+a
+drop table t1;
+show collation like 'utf16_test_ci';
+Collation Charset Id Default Compiled Sortlen
+utf16_test_ci utf16 327 8
+create table t1 (c1 char(1) character set utf16 collate utf16_test_ci);
+insert into t1 values ('a');
+select * from t1 where c1='b';
+c1
+a
+drop table t1;
+show collation like 'utf32_test_ci';
+Collation Charset Id Default Compiled Sortlen
+utf32_test_ci utf32 391 8
+create table t1 (c1 char(1) character set utf32 collate utf32_test_ci);
+insert into t1 values ('a');
+select * from t1 where c1='b';
+c1
+a
+drop table t1;
+#
+# Bug#45645 Mysql server close all connection and restart using lower function
+#
+CREATE TABLE t1 (a VARCHAR(10)) CHARACTER SET utf8 COLLATE utf8_test_ci;
+INSERT INTO t1 (a) VALUES ('hello!');
+SELECT * FROM t1 WHERE LOWER(a)=LOWER('N');
+a
+DROP TABLE t1;
+#
+# Bug#51976 LDML collations issue (cyrillic example)
+#
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_test_ci);
+INSERT INTO t1 (a) VALUES ('Hello');
+SELECT a, UPPER(a), LOWER(a) FROM t1;
+a UPPER(a) LOWER(a)
+Hello HELLO hello
+DROP TABLE t1;
+#
+# Bug#43827 Server closes connections and restarts
+#
+CREATE TABLE t1 (c1 VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_test_ci);
+INSERT INTO t1 SELECT REPEAT('a',11);
+Warnings:
+Warning 1265 Data truncated for column 'c1' at row 1
+DROP TABLE t1;
+Vietnamese experimental collation
+show collation like 'ucs2_vn_ci';
+Collation Charset Id Default Compiled Sortlen
+ucs2_vn_ci ucs2 359 8
+create table t1 (c1 char(1) character set ucs2 collate ucs2_vn_ci);
+insert into t1 values (0x0061),(0x0041),(0x00E0),(0x00C0),(0x1EA3),(0x1EA2),
+(0x00E3),(0x00C3),(0x00E1),(0x00C1),(0x1EA1),(0x1EA0);
+insert into t1 values (0x0103),(0x0102),(0x1EB1),(0x1EB0),(0x1EB3),(0x1EB2),
+(0x1EB5),(0x1EB4),(0x1EAF),(0x1EAE),(0x1EB7),(0x1EB6);
+insert into t1 values (0x00E2),(0x00C2),(0x1EA7),(0x1EA6),(0x1EA9),(0x1EA8),
+(0x1EAB),(0x1EAA),(0x1EA5),(0x1EA4),(0x1EAD),(0x1EAC);
+insert into t1 values ('b'),('B'),('c'),('C');
+insert into t1 values ('d'),('D'),(0x0111),(0x0110);
+insert into t1 values (0x0065),(0x0045),(0x00E8),(0x00C8),(0x1EBB),(0x1EBA),
+(0x1EBD),(0x1EBC),(0x00E9),(0x00C9),(0x1EB9),(0x1EB8);
+insert into t1 values (0x00EA),(0x00CA),(0x1EC1),(0x1EC0),(0x1EC3),(0x1EC2),
+(0x1EC5),(0x1EC4),(0x1EBF),(0x1EBE),(0x1EC7),(0x1EC6);
+insert into t1 values ('g'),('G'),('h'),('H');
+insert into t1 values (0x0069),(0x0049),(0x00EC),(0x00CC),(0x1EC9),(0x1EC8),
+(0x0129),(0x0128),(0x00ED),(0x00CD),(0x1ECB),(0x1ECA);
+insert into t1 values ('k'),('K'),('l'),('L'),('m'),('M');
+insert into t1 values (0x006F),(0x004F),(0x00F2),(0x00D2),(0x1ECF),(0x1ECE),
+(0x00F5),(0x00D5),(0x00F3),(0x00D3),(0x1ECD),(0x1ECC);
+insert into t1 values (0x00F4),(0x00D4),(0x1ED3),(0x1ED2),(0x1ED5),(0x1ED4),
+(0x1ED7),(0x1ED6),(0x1ED1),(0x1ED0),(0x1ED9),(0x1ED8);
+insert into t1 values (0x01A1),(0x01A0),(0x1EDD),(0x1EDC),(0x1EDF),(0x1EDE),
+(0x1EE1),(0x1EE0),(0x1EDB),(0x1EDA),(0x1EE3),(0x1EE2);
+insert into t1 values ('p'),('P'),('q'),('Q'),('r'),('R'),('s'),('S'),('t'),('T');
+insert into t1 values (0x0075),(0x0055),(0x00F9),(0x00D9),(0x1EE7),(0x1EE6),
+(0x0169),(0x0168),(0x00FA),(0x00DA),(0x1EE5),(0x1EE4);
+insert into t1 values (0x01B0),(0x01AF),(0x1EEB),(0x1EEA),(0x1EED),(0x1EEC),
+(0x1EEF),(0x1EEE),(0x1EE9),(0x1EE8),(0x1EF1),(0x1EF0);
+insert into t1 values ('v'),('V'),('x'),('X');
+insert into t1 values (0x0079),(0x0059),(0x1EF3),(0x1EF2),(0x1EF7),(0x1EF6),
+(0x1EF9),(0x1EF8),(0x00FD),(0x00DD),(0x1EF5),(0x1EF4);
+select hex(c1) as h, c1 from t1 order by c1, h;
+h c1
+0041 A
+0061 a
+00C0 À
+00C1 Ã
+00C3 Ã
+00E0 à
+00E1 á
+00E3 ã
+1EA0 Ạ
+1EA1 ạ
+1EA2 Ả
+1EA3 ả
+0102 Ä‚
+0103 ă
+1EAE Ắ
+1EAF ắ
+1EB0 Ằ
+1EB1 ằ
+1EB2 Ẳ
+1EB3 ẳ
+1EB4 Ẵ
+1EB5 ẵ
+1EB6 Ặ
+1EB7 ặ
+00C2 Â
+00E2 â
+1EA4 Ấ
+1EA5 ấ
+1EA6 Ầ
+1EA7 ầ
+1EA8 Ẩ
+1EA9 ẩ
+1EAA Ẫ
+1EAB ẫ
+1EAC Ậ
+1EAD ậ
+0042 B
+0062 b
+0043 C
+0063 c
+0044 D
+0064 d
+0110 Ä
+0111 Ä‘
+0045 E
+0065 e
+00C8 È
+00C9 É
+00E8 è
+00E9 é
+1EB8 Ẹ
+1EB9 ẹ
+1EBA Ẻ
+1EBB ẻ
+1EBC Ẽ
+1EBD ẽ
+00CA Ê
+00EA ê
+1EBE Ế
+1EBF ế
+1EC0 Ề
+1EC1 á»
+1EC2 Ể
+1EC3 ể
+1EC4 Ễ
+1EC5 á»…
+1EC6 Ệ
+1EC7 ệ
+0047 G
+0067 g
+0048 H
+0068 h
+0049 I
+0069 i
+00CC Ì
+00CD Ã
+00EC ì
+00ED í
+0128 Ĩ
+0129 Ä©
+1EC8 Ỉ
+1EC9 ỉ
+1ECA Ị
+1ECB ị
+004B K
+006B k
+004C L
+006C l
+004D M
+006D m
+004F O
+006F o
+00D2 Ã’
+00D3 Ó
+00D5 Õ
+00F2 ò
+00F3 ó
+00F5 õ
+1ECC Ọ
+1ECD á»
+1ECE Ỏ
+1ECF á»
+00D4 Ô
+00F4 ô
+1ED0 á»
+1ED1 ố
+1ED2 á»’
+1ED3 ồ
+1ED4 á»”
+1ED5 ổ
+1ED6 á»–
+1ED7 á»—
+1ED8 Ộ
+1ED9 á»™
+01A0 Æ 
+01A1 Æ¡
+1EDA Ớ
+1EDB á»›
+1EDC Ờ
+1EDD á»
+1EDE Ở
+1EDF ở
+1EE0 á» 
+1EE1 ỡ
+1EE2 Ợ
+1EE3 ợ
+0050 P
+0070 p
+0051 Q
+0071 q
+0052 R
+0072 r
+0053 S
+0073 s
+0054 T
+0074 t
+0055 U
+0075 u
+00D9 Ù
+00DA Ú
+00F9 ù
+00FA ú
+0168 Ũ
+0169 Å©
+1EE4 Ụ
+1EE5 ụ
+1EE6 Ủ
+1EE7 ủ
+01AF Ư
+01B0 Æ°
+1EE8 Ứ
+1EE9 ứ
+1EEA Ừ
+1EEB ừ
+1EEC Ử
+1EED á»­
+1EEE á»®
+1EEF ữ
+1EF0 á»°
+1EF1 á»±
+0056 V
+0076 v
+0058 X
+0078 x
+0059 Y
+0079 y
+00DD Ã
+00FD ý
+1EF2 Ỳ
+1EF3 ỳ
+1EF4 á»´
+1EF5 ỵ
+1EF6 Ỷ
+1EF7 á»·
+1EF8 Ỹ
+1EF9 ỹ
+select group_concat(hex(c1) order by hex(c1)) from t1 group by c1;
+group_concat(hex(c1) order by hex(c1))
+0041,0061,00C0,00C1,00C3,00E0,00E1,00E3,1EA0,1EA1,1EA2,1EA3
+0102,0103,1EAE,1EAF,1EB0,1EB1,1EB2,1EB3,1EB4,1EB5,1EB6,1EB7
+00C2,00E2,1EA4,1EA5,1EA6,1EA7,1EA8,1EA9,1EAA,1EAB,1EAC,1EAD
+0042,0062
+0043,0063
+0044,0064
+0110,0111
+0045,0065,00C8,00C9,00E8,00E9,1EB8,1EB9,1EBA,1EBB,1EBC,1EBD
+00CA,00EA,1EBE,1EBF,1EC0,1EC1,1EC2,1EC3,1EC4,1EC5,1EC6,1EC7
+0047,0067
+0048,0068
+0049,0069,00CC,00CD,00EC,00ED,0128,0129,1EC8,1EC9,1ECA,1ECB
+004B,006B
+004C,006C
+004D,006D
+004F,006F,00D2,00D3,00D5,00F2,00F3,00F5,1ECC,1ECD,1ECE,1ECF
+00D4,00F4,1ED0,1ED1,1ED2,1ED3,1ED4,1ED5,1ED6,1ED7,1ED8,1ED9
+01A0,01A1,1EDA,1EDB,1EDC,1EDD,1EDE,1EDF,1EE0,1EE1,1EE2,1EE3
+0050,0070
+0051,0071
+0052,0072
+0053,0073
+0054,0074
+0055,0075,00D9,00DA,00F9,00FA,0168,0169,1EE4,1EE5,1EE6,1EE7
+01AF,01B0,1EE8,1EE9,1EEA,1EEB,1EEC,1EED,1EEE,1EEF,1EF0,1EF1
+0056,0076
+0058,0078
+0059,0079,00DD,00FD,1EF2,1EF3,1EF4,1EF5,1EF6,1EF7,1EF8,1EF9
+select group_concat(c1 order by hex(c1) SEPARATOR '') from t1 group by c1;
+group_concat(c1 order by hex(c1) SEPARATOR '')
+AaÀÃÃàáãẠạẢả
+ĂăẮắẰằẲẳẴẵẶặ
+ÂâẤấẦầẨẩẪẫẬậ
+Bb
+Cc
+Dd
+ÄÄ‘
+EeÈÉèéẸẹẺẻẼẽ
+ÊêẾếỀá»á»‚ểỄễỆệ
+Gg
+Hh
+IiÃŒÃìíĨĩỈỉỊị
+Kk
+Ll
+Mm
+OoÒÓÕòóõỌá»á»Žá»
+Ôôá»á»‘ỒồỔổỖỗỘộ
+ƠơỚớỜá»á»žá»Ÿá» á»¡á»¢á»£
+Pp
+Qq
+Rr
+Ss
+Tt
+UuÙÚùúŨũỤụỦủ
+ƯưỨứỪừỬửỮữỰự
+Vv
+Xx
+YyÃýỲỳỴỵỶỷỸỹ
+drop table t1;
+Bug#46448 trailing spaces are not ignored when user collation maps space != 0x20
+set names latin1;
+show collation like 'latin1_test';
+Collation Charset Id Default Compiled Sortlen
+latin1_test latin1 99 Yes 1
+select "foo" = "foo " collate latin1_test;
+"foo" = "foo " collate latin1_test
+1
+The following tests check that two-byte collation IDs work
+select * from information_schema.collations where id>256 order by id;
+COLLATION_NAME CHARACTER_SET_NAME ID IS_DEFAULT IS_COMPILED SORTLEN
+utf8mb4_test_ci utf8mb4 326 8
+utf16_test_ci utf16 327 8
+utf8mb4_test_400_ci utf8mb4 328 8
+latin1_test2 latin1 332 1
+utf8_bengali_standard_ci utf8 336 8
+utf8_bengali_traditional_ci utf8 337 8
+utf8_phone_ci utf8 352 8
+utf8_test_ci utf8 353 8
+utf8_5624_1 utf8 354 8
+utf8_5624_2 utf8 355 8
+utf8_5624_3 utf8 356 8
+utf8_5624_4 utf8 357 8
+ucs2_test_ci ucs2 358 8
+ucs2_vn_ci ucs2 359 8
+ucs2_5624_1 ucs2 360 8
+utf8_5624_5 utf8 368 8
+utf32_test_ci utf32 391 8
+utf8_maxuserid_ci utf8 2047 8
+show collation like '%test%';
+Collation Charset Id Default Compiled Sortlen
+latin1_test latin1 99 Yes 1
+latin1_test2 latin1 332 1
+utf8_test_ci utf8 353 8
+ucs2_test_ci ucs2 358 8
+utf8mb4_test_ci utf8mb4 326 8
+utf8mb4_test_400_ci utf8mb4 328 8
+utf16_test_ci utf16 327 8
+utf32_test_ci utf32 391 8
+show collation like 'ucs2_vn_ci';
+Collation Charset Id Default Compiled Sortlen
+ucs2_vn_ci ucs2 359 8
+create table t1 (c1 char(1) character set ucs2 collate ucs2_vn_ci);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `c1` char(1) CHARACTER SET ucs2 COLLATE ucs2_vn_ci DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+insert into t1 values (0x0061);
+set @@character_set_results=NULL;
+select * from t1;
+Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
+def test t1 t1 c1 c1 254 2 2 Y 0 0 359
+c1
+
+drop table t1;
+CREATE TABLE t1 (s1 char(10) character set utf8 collate utf8_maxuserid_ci);
+INSERT INTO t1 VALUES ('a'),('b');
+SELECT * FROM t1 WHERE s1='a' ORDER BY BINARY s1;
+s1
+a
+b
+DROP TABLE t1;
+SET NAMES utf8 COLLATE utf8_phone_ci;
+SHOW COLLATION LIKE 'utf8_phone_ci';
+Collation Charset Id Default Compiled Sortlen
+utf8_phone_ci utf8 352 8
+SET NAMES utf8;
+SELECT hex(weight_string(_utf8mb4'a' collate utf8mb4_test_400_ci));
+hex(weight_string(_utf8mb4'a' collate utf8mb4_test_400_ci))
+0E33
+SELECT hex(weight_string(convert(_utf32 0x10002 using utf8mb4) collate utf8mb4_test_400_ci));
+hex(weight_string(convert(_utf32 0x10002 using utf8mb4) collate utf8mb4_test_400_ci))
+FFFD
+SELECT hex(@a:=convert(_utf32 0x10400 using utf8mb4) collate utf8mb4_test_400_ci), hex(lower(@a));
+hex(@a:=convert(_utf32 0x10400 using utf8mb4) collate utf8mb4_test_400_ci) hex(lower(@a))
+F0909080 F0909080
+SELECT hex(@a:=convert(_utf32 0x10428 using utf8mb4) collate utf8mb4_test_400_ci), hex(upper(@a));
+hex(@a:=convert(_utf32 0x10428 using utf8mb4) collate utf8mb4_test_400_ci) hex(upper(@a))
+F09090A8 F09090A8
+SELECT hex(@a:=convert(_utf32 0x2C00 using utf8mb4) collate utf8mb4_test_400_ci), hex(lower(@a));
+hex(@a:=convert(_utf32 0x2C00 using utf8mb4) collate utf8mb4_test_400_ci) hex(lower(@a))
+E2B080 E2B080
+SELECT hex(@a:=convert(_utf32 0x2C30 using utf8mb4) collate utf8mb4_test_400_ci), hex(upper(@a));
+hex(@a:=convert(_utf32 0x2C30 using utf8mb4) collate utf8mb4_test_400_ci) hex(upper(@a))
+E2B0B0 E2B0B0
+#
+# WL#5624 Collation customization improvements
+#
+SET NAMES utf8 COLLATE utf8_5624_1;
+CREATE TABLE t1 AS SELECT REPEAT(' ', 16) AS a LIMIT 0;
+INSERT INTO t1 VALUES ('012345'),('001234'),('000123'),('000012'),('000001');
+INSERT INTO t1 VALUES ('12345'),('01234'),('00123'),('00012'),('00001');
+INSERT INTO t1 VALUES ('1234'),('0123'),('0012'),('0001');
+INSERT INTO t1 VALUES ('123'),('012'),('001');
+INSERT INTO t1 VALUES ('12'),('01');
+INSERT INTO t1 VALUES ('1'),('9');
+INSERT INTO t1 VALUES ('ГÐИ'),('ГИБДД');
+INSERT INTO t1 VALUES ('a'),('b'),('c'),('d'),('e');
+INSERT INTO t1 VALUES ('cz'),('ÄŠ'),('Ä‹');
+INSERT INTO t1 VALUES ('f'),('fz'),('g'),('Ä '),('Ä¡');
+INSERT INTO t1 VALUES ('h'),('hz'),('GĦ'),('Għ'),('gĦ'),('għ');
+INSERT INTO t1 VALUES ('i'),('iz'),('Ħ'),('ħ');
+INSERT INTO t1 VALUES ('y'),('yz'),('z'),('Ż'),('ż');
+INSERT INTO t1 VALUES ('Ä'),('Ä€'),('á'),('Ã'),('à'),('À');
+INSERT INTO t1 VALUES ('ē'),('é'),('ě'),('ê'),('Ē'),('É'),('Ě'),('Ê');
+INSERT INTO t1 VALUES ('a'),('~'),('!'),('@'),('#'),('$'),('%'),('^');
+INSERT INTO t1 VALUES ('('),(')'),('-'),('+'),('|'),('='),(':'),(';');
+INSERT INTO t1 VALUES ('"'),('\''),('?');
+INSERT INTO t1 VALUES ('ch'),('k'),('cs'),('ccs'),('cscs');
+INSERT INTO t1 VALUES ('aa-'),('ab-'),('ac-'),('ad-'),('ae-'),('af-'),('az-');
+INSERT INTO t1 VALUES ('lp-fni'),('lp-lni');
+INSERT INTO t1 VALUES ('lp-fpi'),('lp-lpi');
+INSERT INTO t1 VALUES ('lp-fsi'),('lp-lsi');
+INSERT INTO t1 VALUES ('lp-fti'),('lp-lti');
+INSERT INTO t1 VALUES ('lp-ft'),('lp-lt');
+INSERT INTO t1 VALUES ('lp-fv'),('lp-lv');
+INSERT INTO t1 VALUES ('lb-fni'),('lb-lni');
+INSERT INTO t1 VALUES ('lb-fv'),('lb-lv');
+INSERT INTO t1 VALUES (_ucs2 0x3106),(_ucs2 0x3110), (_ucs2 0x3111), (_ucs2 0x3112);
+INSERT INTO t1 VALUES (_ucs2 0x32A3), (_ucs2 0x3231);
+INSERT INTO t1 VALUES (_ucs2 0x84D9), (_ucs2 0x98F5), (_ucs2 0x7CF3), (_ucs2 0x5497);
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY a;
+a HEX(WEIGHT_STRING(a))
+lp-ft 0001
+lp-lt 0001
+lp-fpi 0001
+lp-fsi 0001
+lp-fti 0001
+lp-lpi 0001
+lp-lsi 0001
+lp-lti 0001
+lb-fv 0200233E
+lb-fni 0200233E
+lp-fv 0202
+lp-fni 0202
+- 0221
+= 042D
+| 0430
+lb-lv 0DD9233E
+lp-lv 0DDB
+1 0E2A
+01 0E2A
+001 0E2A
+0001 0E2A
+00001 0E2A
+000001 0E2A
+12 0E2A0E2B
+012 0E2A0E2B
+0012 0E2A0E2B
+00012 0E2A0E2B
+000012 0E2A0E2B
+123 0E2A0E2B0E2C
+0123 0E2A0E2B0E2C
+00123 0E2A0E2B0E2C
+000123 0E2A0E2B0E2C
+1234 0E2A0E2B0E2C0E2D
+01234 0E2A0E2B0E2C0E2D
+001234 0E2A0E2B0E2C0E2D
+12345 0E2A0E2B0E2C0E2D0E2E
+012345 0E2A0E2B0E2C0E2D0E2E
+9 0E32
+~ 0E32233E
+! 0E32233F
+@ 0E322340
+# 0E322341
+$ 0E322342
+% 0E322343
+^ 0E322344
+( 0E322346
+) 0E322347
++ 0E322348
+: 0E322349
+; 0E32234A
+" 0E32234B
+' 0E32234C
+? 0E32234D
+a 0E33
+a 0E33
+aa- 0E330E330221
+ab- 0E330E4A0E34
+ac- 0E330E600E60
+ad- 0E330E6D0E6D
+ae- 0E330E8B0E8B
+af- 0E330EB90EB9
+az- 0E33106A0221
+b 0E4A
+À 0E4A
+Ã 0E4A
+à 0E4A
+á 0E4A
+Ä€ 0E4A
+Ä 0E4A
+c 0E60
+k 0E600EE1
+ch 0E600EE1
+cs 0E600FEA
+ccs 0E600FEA0E600FEA
+cscs 0E600FEA0E600FEA
+cz 0E60106A
+ÄŠ 0E6C233E
+Ä‹ 0E6C233E
+d 0E6D
+É 0E6D
+Ê 0E6D
+é 0E6D
+ê 0E6D
+Ä’ 0E6D
+Ä“ 0E6D
+Äš 0E6D
+Ä› 0E6D
+e 0E8B
+f 0EB9
+fz 0EB9106A
+Ä  0EC0233E
+Ä¡ 0EC0233E
+g 0EC1
+GĦ 0EE0233E
+Għ 0EE0233E
+gĦ 0EE0233E
+għ 0EE0233E
+h 0EE1
+hz 0EE1106A
+Ħ 0EFA233E
+ħ 0EFA233E
+i 0EFB
+iz 0EFB106A
+y 105E
+yz 105E106A
+Å» 1069233E
+ż 1069233E
+z 106A
+ГÐИ 11341114117C
+ГИБДД 11341114117C
+lb-lni 233C233E
+lp-lni 233E
+ㄆ 233F
+ã„ 2349
+ã„‘ 234A
+ã„’ 234B
+㊣ 7147
+㈱ 72D5
+è“™ 753C
+飵 753D
+ç³³ 753E
+å’— 753F
+#
+# WL#5624, the same test with UCS2
+#
+ALTER TABLE t1 CONVERT TO CHARACTER SET ucs2 COLLATE ucs2_5624_1;
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
+a HEX(WEIGHT_STRING(a))
+lp-ft 0001
+lp-lt 0001
+lp-fpi 0001
+lp-fsi 0001
+lp-fti 0001
+lp-lpi 0001
+lp-lsi 0001
+lp-lti 0001
+lb-fv 0200233E
+lb-fni 0200233E
+lp-fv 0202
+lp-fni 0202
+- 0221
+= 042D
+| 0430
+lb-lv 0DD9233E
+lp-lv 0DDB
+1 0E2A
+01 0E2A
+001 0E2A
+0001 0E2A
+00001 0E2A
+000001 0E2A
+12 0E2A0E2B
+012 0E2A0E2B
+0012 0E2A0E2B
+00012 0E2A0E2B
+000012 0E2A0E2B
+123 0E2A0E2B0E2C
+0123 0E2A0E2B0E2C
+00123 0E2A0E2B0E2C
+000123 0E2A0E2B0E2C
+1234 0E2A0E2B0E2C0E2D
+01234 0E2A0E2B0E2C0E2D
+001234 0E2A0E2B0E2C0E2D
+12345 0E2A0E2B0E2C0E2D0E2E
+012345 0E2A0E2B0E2C0E2D0E2E
+9 0E32
+~ 0E32233E
+! 0E32233F
+@ 0E322340
+# 0E322341
+$ 0E322342
+% 0E322343
+^ 0E322344
+( 0E322346
+) 0E322347
++ 0E322348
+: 0E322349
+; 0E32234A
+" 0E32234B
+' 0E32234C
+? 0E32234D
+a 0E33
+a 0E33
+aa- 0E330E330221
+ab- 0E330E4A0E34
+ac- 0E330E600E60
+ad- 0E330E6D0E6D
+ae- 0E330E8B0E8B
+af- 0E330EB90EB9
+az- 0E33106A0221
+b 0E4A
+À 0E4A
+Ã 0E4A
+à 0E4A
+á 0E4A
+Ä€ 0E4A
+Ä 0E4A
+c 0E60
+k 0E600EE1
+ch 0E600EE1
+cs 0E600FEA
+ccs 0E600FEA0E600FEA
+cscs 0E600FEA0E600FEA
+cz 0E60106A
+ÄŠ 0E6C233E
+Ä‹ 0E6C233E
+d 0E6D
+É 0E6D
+Ê 0E6D
+é 0E6D
+ê 0E6D
+Ä’ 0E6D
+Ä“ 0E6D
+Äš 0E6D
+Ä› 0E6D
+e 0E8B
+f 0EB9
+fz 0EB9106A
+Ä  0EC0233E
+Ä¡ 0EC0233E
+g 0EC1
+GĦ 0EE0233E
+Għ 0EE0233E
+gĦ 0EE0233E
+għ 0EE0233E
+h 0EE1
+hz 0EE1106A
+Ħ 0EFA233E
+ħ 0EFA233E
+i 0EFB
+iz 0EFB106A
+y 105E
+yz 105E106A
+Å» 1069233E
+ż 1069233E
+z 106A
+ГÐИ 11341114117C
+ГИБДД 11341114117C
+lb-lni 233C233E
+lp-lni 233E
+ㄆ 233F
+ã„ 2349
+ã„‘ 234A
+ã„’ 234B
+㊣ 7147
+㈱ 72D5
+è“™ 753C
+飵 753D
+ç³³ 753E
+å’— 753F
+DROP TABLE t1;
+#
+# WL#5624, unsupported features
+#
+SET NAMES utf8 COLLATE utf8_5624_2;
+ERROR HY000: Unknown collation: 'utf8_5624_2'
+SHOW WARNINGS;
+Level Code Message
+Error 1273 Unknown collation: 'utf8_5624_2'
+Warning 1273 Syntax error at '[strength tertiary]'
+#
+# WL#5624, reset before primary ignorable
+#
+SET NAMES utf8 COLLATE utf8_5624_3;
+ERROR HY000: Unknown collation: 'utf8_5624_3'
+SHOW WARNINGS;
+Level Code Message
+Error 1273 Unknown collation: 'utf8_5624_3'
+Warning 1273 Can't reset before a primary ignorable character U+A48C
+#
+# WL#5624, \u without hex digits is equal to {'\', 'u'}
+#
+SET NAMES utf8 COLLATE utf8_5624_4;
+CREATE TABLE t1 AS SELECT REPEAT(' ', 10) AS a LIMIT 0;
+INSERT INTO t1 VALUES ('\\'),('u'),('x'),('X');
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
+a HEX(WEIGHT_STRING(a))
+\ 02CE
+x 02CE101F
+u 101F
+X 105A
+DROP TABLE t1;
+#
+# WL#5624, testing Bengali collations
+#
+SET NAMES utf8, collation_connection=utf8_bengali_standard_ci;
+CREATE TABLE t1 AS SELECT REPEAT (' ', 10) AS a LIMIT 0;
+INSERT INTO t1 VALUES (_ucs2 0x09FA), (_ucs2 0x09F8), (_ucs2 0x09F9), (_ucs2 0x09F2);
+INSERT INTO t1 VALUES (_ucs2 0x09DC), (_ucs2 0x09A109BC);
+INSERT INTO t1 VALUES (_ucs2 0x09A2), (_ucs2 0x09DD), (_ucs2 0x09A209BC);
+INSERT INTO t1 VALUES (_ucs2 0x09A3);
+SELECT HEX(WEIGHT_STRING(a)), HEX(CONVERT(a USING ucs2)), HEX(a)
+FROM t1 ORDER BY a, BINARY a;
+HEX(WEIGHT_STRING(a)) HEX(CONVERT(a USING ucs2)) HEX(a)
+0350 09FA E0A7BA
+0351 09F8 E0A7B8
+0352 09F9 E0A7B9
+0353 09F2 E0A7B2
+0374 09A109BC E0A6A1E0A6BC
+0374 09DC E0A79C
+0375 09A2 E0A6A2
+0376 09A209BC E0A6A2E0A6BC
+0376 09DD E0A79D
+0377 09A3 E0A6A3
+DROP TABLE t1;
+SET NAMES utf8, collation_connection=utf8_bengali_traditional_ci;
+CREATE TABLE t1 AS SELECT REPEAT (' ', 10) AS a LIMIT 0;
+INSERT INTO t1 VALUES
+(_ucs2 0x0985),(_ucs2 0x0986),(_ucs2 0x0987),(_ucs2 0x0988),
+(_ucs2 0x0989),(_ucs2 0x098A),(_ucs2 0x098B),(_ucs2 0x09E0),
+(_ucs2 0x098C),(_ucs2 0x09E1),(_ucs2 0x098F),(_ucs2 0x0990),
+(_ucs2 0x0993);
+INSERT INTO t1 VALUES
+(_ucs2 0x0994),(_ucs2 0x0982),(_ucs2 0x0983),(_ucs2 0x0981),
+(_ucs2 0x099509CD), (_ucs2 0x099609CD), (_ucs2 0x099709CD), (_ucs2 0x099809CD),
+(_ucs2 0x099909CD), (_ucs2 0x099A09CD), (_ucs2 0x099B09CD), (_ucs2 0x099C09CD),
+(_ucs2 0x099D09CD), (_ucs2 0x099E09CD), (_ucs2 0x099F09CD), (_ucs2 0x09A009CD),
+(_ucs2 0x09A109CD), (_ucs2 0x09A209CD), (_ucs2 0x09A309CD),
+(_ucs2 0x09CE), (_ucs2 0x09A409CD200D), (_ucs2 0x09A409CD),
+(_ucs2 0x09A509CD),(_ucs2 0x09A609CD),
+(_ucs2 0x09A709CD), (_ucs2 0x09A809CD), (_ucs2 0x09AA09CD), (_ucs2 0x09AB09CD),
+(_ucs2 0x09AC09CD), (_ucs2 0x09AD09CD), (_ucs2 0x09AE09CD), (_ucs2 0x09AF09CD),
+(_ucs2 0x09B009CD), (_ucs2 0x09F009CD), (_ucs2 0x09B209CD), (_ucs2 0x09F109CD),
+(_ucs2 0x09B609CD), (_ucs2 0x09B709CD), (_ucs2 0x09B809CD), (_ucs2 0x09B909CD);
+INSERT INTO t1 VALUES
+(_ucs2 0x099509CD0985),(_ucs2 0x0995),
+(_ucs2 0x099509CD0986),(_ucs2 0x099509BE),
+(_ucs2 0x099509CD0987),(_ucs2 0x099509BF),
+(_ucs2 0x099509CD0988),(_ucs2 0x099509C0),
+(_ucs2 0x099509CD0989),(_ucs2 0x099509C1),
+(_ucs2 0x099509CD098A),(_ucs2 0x099509C2),
+(_ucs2 0x099509CD098B),(_ucs2 0x099509C3),
+(_ucs2 0x099509CD09E0),(_ucs2 0x099509C4),
+(_ucs2 0x099509CD098C),(_ucs2 0x099509E2),
+(_ucs2 0x099509CD09E1),(_ucs2 0x099509E3),
+(_ucs2 0x099509CD098F),(_ucs2 0x099509C7),
+(_ucs2 0x099509CD0990),(_ucs2 0x099509C8),
+(_ucs2 0x099509CD0993),(_ucs2 0x099509CB),
+(_ucs2 0x099509CD0994),(_ucs2 0x099509CC);
+SELECT HEX(WEIGHT_STRING(a)), HEX(CONVERT(a USING ucs2)), HEX(a)
+FROM t1 ORDER BY a, BINARY(a);
+HEX(WEIGHT_STRING(a)) HEX(CONVERT(a USING ucs2)) HEX(a)
+15A2 0985 E0A685
+15A3 0986 E0A686
+15A4 0987 E0A687
+15A5 0988 E0A688
+15A6 0989 E0A689
+15A7 098A E0A68A
+15A8 098B E0A68B
+15A9 09E0 E0A7A0
+15AA 098C E0A68C
+15AB 09E1 E0A7A1
+15AC 098F E0A68F
+15AD 0990 E0A690
+15AE 0993 E0A693
+15AF 0994 E0A694
+15B0 0982 E0A682
+15B1 0983 E0A683
+15B2 0981 E0A681
+15B3 099509CD E0A695E0A78D
+15B315A2 0995 E0A695
+15B315A2 099509CD0985 E0A695E0A78DE0A685
+15B315A3 099509BE E0A695E0A6BE
+15B315A3 099509CD0986 E0A695E0A78DE0A686
+15B315A4 099509BF E0A695E0A6BF
+15B315A4 099509CD0987 E0A695E0A78DE0A687
+15B315A5 099509C0 E0A695E0A780
+15B315A5 099509CD0988 E0A695E0A78DE0A688
+15B315A6 099509C1 E0A695E0A781
+15B315A6 099509CD0989 E0A695E0A78DE0A689
+15B315A7 099509C2 E0A695E0A782
+15B315A7 099509CD098A E0A695E0A78DE0A68A
+15B315A8 099509C3 E0A695E0A783
+15B315A8 099509CD098B E0A695E0A78DE0A68B
+15B315A9 099509C4 E0A695E0A784
+15B315A9 099509CD09E0 E0A695E0A78DE0A7A0
+15B315AA 099509CD098C E0A695E0A78DE0A68C
+15B315AA 099509E2 E0A695E0A7A2
+15B315AB 099509CD09E1 E0A695E0A78DE0A7A1
+15B315AB 099509E3 E0A695E0A7A3
+15B315AC 099509C7 E0A695E0A787
+15B315AC 099509CD098F E0A695E0A78DE0A68F
+15B315AD 099509C8 E0A695E0A788
+15B315AD 099509CD0990 E0A695E0A78DE0A690
+15B315AE 099509CB E0A695E0A78B
+15B315AE 099509CD0993 E0A695E0A78DE0A693
+15B315AF 099509CC E0A695E0A78C
+15B315AF 099509CD0994 E0A695E0A78DE0A694
+15B4 099609CD E0A696E0A78D
+15B5 099709CD E0A697E0A78D
+15B6 099809CD E0A698E0A78D
+15B7 099909CD E0A699E0A78D
+15B8 099A09CD E0A69AE0A78D
+15B9 099B09CD E0A69BE0A78D
+15BA 099C09CD E0A69CE0A78D
+15BB 099D09CD E0A69DE0A78D
+15BC 099E09CD E0A69EE0A78D
+15BD 099F09CD E0A69FE0A78D
+15BE 09A009CD E0A6A0E0A78D
+15BF 09A109CD E0A6A1E0A78D
+15C0 09A209CD E0A6A2E0A78D
+15C1 09A309CD E0A6A3E0A78D
+15C2 09A409CD E0A6A4E0A78D
+15C2 09A409CD200D E0A6A4E0A78DE2808D
+15C2 09CE E0A78E
+15C3 09A509CD E0A6A5E0A78D
+15C4 09A609CD E0A6A6E0A78D
+15C5 09A709CD E0A6A7E0A78D
+15C6 09A809CD E0A6A8E0A78D
+15C7 09AA09CD E0A6AAE0A78D
+15C8 09AB09CD E0A6ABE0A78D
+15C9 09AC09CD E0A6ACE0A78D
+15CA 09AD09CD E0A6ADE0A78D
+15CB 09AE09CD E0A6AEE0A78D
+15CC 09AF09CD E0A6AFE0A78D
+15CD 09B009CD E0A6B0E0A78D
+15CE 09F009CD E0A7B0E0A78D
+15CF 09B209CD E0A6B2E0A78D
+15D0 09F109CD E0A7B1E0A78D
+15D1 09B609CD E0A6B6E0A78D
+15D2 09B709CD E0A6B7E0A78D
+15D3 09B809CD E0A6B8E0A78D
+15D4 09B909CD E0A6B9E0A78D
+SELECT HEX(WEIGHT_STRING(a)) as wa,
+GROUP_CONCAT(HEX(CONVERT(a USING ucs2)) ORDER BY LENGTH(a), BINARY a)
+FROM t1 GROUP BY a ORDER BY a;
+wa GROUP_CONCAT(HEX(CONVERT(a USING ucs2)) ORDER BY LENGTH(a), BINARY a)
+15A2 0985
+15A3 0986
+15A4 0987
+15A5 0988
+15A6 0989
+15A7 098A
+15A8 098B
+15A9 09E0
+15AA 098C
+15AB 09E1
+15AC 098F
+15AD 0990
+15AE 0993
+15AF 0994
+15B0 0982
+15B1 0983
+15B2 0981
+15B3 099509CD
+15B315A2 0995,099509CD0985
+15B315A3 099509BE,099509CD0986
+15B315A4 099509BF,099509CD0987
+15B315A5 099509C0,099509CD0988
+15B315A6 099509C1,099509CD0989
+15B315A7 099509C2,099509CD098A
+15B315A8 099509C3,099509CD098B
+15B315A9 099509C4,099509CD09E0
+15B315AA 099509E2,099509CD098C
+15B315AB 099509E3,099509CD09E1
+15B315AC 099509C7,099509CD098F
+15B315AD 099509C8,099509CD0990
+15B315AE 099509CB,099509CD0993
+15B315AF 099509CC,099509CD0994
+15B4 099609CD
+15B5 099709CD
+15B6 099809CD
+15B7 099909CD
+15B8 099A09CD
+15B9 099B09CD
+15BA 099C09CD
+15BB 099D09CD
+15BC 099E09CD
+15BD 099F09CD
+15BE 09A009CD
+15BF 09A109CD
+15C0 09A209CD
+15C1 09A309CD
+15C2 09CE,09A409CD,09A409CD200D
+15C3 09A509CD
+15C4 09A609CD
+15C5 09A709CD
+15C6 09A809CD
+15C7 09AA09CD
+15C8 09AB09CD
+15C9 09AC09CD
+15CA 09AD09CD
+15CB 09AE09CD
+15CC 09AF09CD
+15CD 09B009CD
+15CE 09F009CD
+15CF 09B209CD
+15D0 09F109CD
+15D1 09B609CD
+15D2 09B709CD
+15D3 09B809CD
+15D4 09B909CD
+DROP TABLE t1;
+#
+# WL#5624, shift after, using expansion
+#
+SET NAMES utf8 COLLATE utf8_5624_5;
+CREATE TABLE t1 AS SELECT REPEAT(' ', 10) AS a LIMIT 0;
+INSERT INTO t1 VALUES ('0'),('1'),('0z'),(_ucs2 0x0030FF9D);
+INSERT INTO t1 VALUES ('a'),('b'),('c'),('d'),('e'),('f'),('g'),('h'),('i');
+INSERT INTO t1 VALUES ('j'),('k'),('l'),('m'),('n'),('o'),('p'),('q'),('r');
+INSERT INTO t1 VALUES ('s'),('t'),('u'),('v'),('w'),('x'),('y'),('z');
+INSERT INTO t1 VALUES ('aa'),('aaa');
+INSERT INTO t1 VALUES ('A'),('B'),('C'),('D'),('E'),('F'),('G'),('H'),('I');
+INSERT INTO t1 VALUES ('J'),('K'),('L'),('M'),('N'),('O'),('P'),('Q'),('R');
+INSERT INTO t1 VALUES ('S'),('T'),('U'),('V'),('W'),('X'),('Y'),('Z');
+INSERT INTO t1 VALUES ('AA'),('AAA');
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
+a HEX(WEIGHT_STRING(a))
+0 0E29
+0z 0E290E292357
+0ï¾ 0E291E81
+a 0E29233E
+b 0E29233F
+c 0E292340
+d 0E292341
+e 0E292342
+f 0E292343
+g 0E292344
+h 0E292345
+i 0E292346
+j 0E292347
+k 0E292348
+l 0E292349
+m 0E29234A
+n 0E29234B
+o 0E29234C
+p 0E29234D
+q 0E29234E
+r 0E29234F
+s 0E292350
+t 0E292351
+u 0E292352
+v 0E292353
+w 0E292354
+x 0E292355
+y 0E292356
+z 0E292357
+aa 0E292358
+aaa 0E292359
+A 0E29333E
+B 0E29333F
+C 0E293340
+D 0E293341
+E 0E293342
+F 0E293343
+G 0E293344
+H 0E293345
+I 0E293346
+J 0E293347
+K 0E293348
+L 0E293349
+M 0E29334A
+N 0E29334B
+O 0E29334C
+P 0E29334D
+Q 0E29334E
+R 0E29334F
+S 0E293350
+T 0E293351
+U 0E293352
+V 0E293353
+W 0E293354
+X 0E293355
+Y 0E293356
+Z 0E293357
+AA 0E293358
+AAA 0E293359
+1 0E2A
+DROP TABLE t1;
+#
+# End of WL#5624
+#
diff --git a/mysql-test/suite/innodb/t/innodb_ctype_ldml-master.opt b/mysql-test/suite/innodb/t/innodb_ctype_ldml-master.opt
new file mode 100644
index 00000000000..cddf744de98
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_ctype_ldml-master.opt
@@ -0,0 +1,3 @@
+--character-sets-dir=$MYSQL_TEST_DIR/std_data/
+--default-storage-engine=InnoDB
+
diff --git a/mysql-test/suite/innodb/t/innodb_ctype_ldml.test b/mysql-test/suite/innodb/t/innodb_ctype_ldml.test
new file mode 100644
index 00000000000..ddc3bac36c7
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_ctype_ldml.test
@@ -0,0 +1,369 @@
+--source include/have_innodb.inc
+--source include/have_ucs2.inc
+--source include/have_utf8mb4.inc
+--source include/have_utf16.inc
+--source include/have_utf32.inc
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+# Index.xml has some intentional errors in collation definitions.
+# They are reported to the server error log. Let's suppress them.
+--disable_query_log
+call mtr.add_suppression("Syntax error at '\\[strength tertiary\\]'");
+call mtr.add_suppression("Can't reset before a primary ignorable character U\\+A48C");
+--enable_query_log
+
+--echo In the following tests we change the order of letter "b"
+--echo making it equal to letter "a", and check that it works
+--echo with all Unicode character sets
+set names utf8;
+
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+show variables like 'character_sets_dir%';
+
+show collation like 'utf8_phone_ci';
+CREATE TABLE t1 (
+ name VARCHAR(64),
+ phone VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_phone_ci
+);
+INSERT INTO t1 VALUES ('Svoj','+7 912 800 80 02');
+INSERT INTO t1 VALUES ('Hf','+7 (912) 800 80 04');
+INSERT INTO t1 VALUES ('Bar','+7-912-800-80-01');
+INSERT INTO t1 VALUES ('Ramil','(7912) 800 80 03');
+INSERT INTO t1 VALUES ('Sanja','+380 (912) 8008005');
+SELECT * FROM t1 ORDER BY phone;
+SELECT * FROM t1 WHERE phone='+7(912)800-80-01';
+SELECT * FROM t1 WHERE phone='79128008001';
+SELECT * FROM t1 WHERE phone='7 9 1 2 8 0 0 8 0 0 1';
+DROP TABLE t1;
+
+show collation like 'utf8_test_ci';
+create table t1 (c1 char(1) character set utf8 collate utf8_test_ci);
+insert into t1 values ('a');
+select * from t1 where c1='b';
+drop table t1;
+
+show collation like 'ucs2_test_ci';
+create table t1 (c1 char(1) character set ucs2 collate ucs2_test_ci);
+insert into t1 values ('a');
+select * from t1 where c1='b';
+drop table t1;
+
+show collation like 'utf8mb4_test_ci';
+create table t1 (c1 char(1) character set utf8mb4 collate utf8mb4_test_ci);
+insert into t1 values ('a');
+select * from t1 where c1='b';
+drop table t1;
+
+show collation like 'utf16_test_ci';
+create table t1 (c1 char(1) character set utf16 collate utf16_test_ci);
+insert into t1 values ('a');
+select * from t1 where c1='b';
+drop table t1;
+
+show collation like 'utf32_test_ci';
+create table t1 (c1 char(1) character set utf32 collate utf32_test_ci);
+insert into t1 values ('a');
+select * from t1 where c1='b';
+drop table t1;
+
+###
+### TODO: activate this when utf8_unicode_520_ci is merged
+###
+### make sure utf8_test_ci is Unicode-5.0.0
+##SELECT hex(weight_string(_utf8mb4'a' collate utf8mb4_test_ci));
+##SELECT hex(weight_string(convert(_utf32 0x10002 using utf8mb4) collate utf8mb4_test_ci));
+##SELECT hex(@a:=convert(_utf32 0x10400 using utf8mb4) collate utf8mb4_test_ci), hex(lower(@a));
+##SELECT hex(@a:=convert(_utf32 0x10428 using utf8mb4) collate utf8mb4_test_ci), hex(upper(@a));
+##SELECT hex(@a:=convert(_utf32 0x2C00 using utf8mb4) collate utf8mb4_test_ci), hex(lower(@a));
+##SELECT hex(@a:=convert(_utf32 0x2C30 using utf8mb4) collate utf8mb4_test_ci), hex(upper(@a));
+
+### check that it works with supplementary characters
+##SELECT hex(weight_string(convert(_utf32 0x61 using utf8mb4) collate utf8mb4_test_ci));
+##SELECT hex(weight_string(convert(_utf32 0x62 using utf8mb4) collate utf8mb4_test_ci));
+##SELECT hex(weight_string(convert(_utf32 0x10062 using utf8mb4) collate utf8mb4_test_ci));
+##SELECT hex(weight_string(convert(_utf32 0x10400 using utf8mb4) collate utf8mb4_test_ci));
+##SELECT hex(weight_string(convert(_utf32 0x100400 using utf8mb4) collate utf8mb4_test_ci));
+
+### check contractions with non-ascii characters
+##SELECT hex(weight_string(_utf8mb4 0x64 collate utf8mb4_test_ci));
+##SELECT hex(weight_string(convert(_ucs2 0x0064017e using utf8mb4) collate utf8mb4_test_ci));
+##SELECT hex(weight_string(convert(_ucs2 0x0044017e using utf8mb4) collate utf8mb4_test_ci));
+##SELECT hex(weight_string(convert(_ucs2 0x0044017d using utf8mb4) collate utf8mb4_test_ci));
+
+
+--echo #
+--echo # Bug#45645 Mysql server close all connection and restart using lower function
+--echo #
+CREATE TABLE t1 (a VARCHAR(10)) CHARACTER SET utf8 COLLATE utf8_test_ci;
+INSERT INTO t1 (a) VALUES ('hello!');
+SELECT * FROM t1 WHERE LOWER(a)=LOWER('N');
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#51976 LDML collations issue (cyrillic example)
+--echo #
+CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_test_ci);
+INSERT INTO t1 (a) VALUES ('Hello');
+SELECT a, UPPER(a), LOWER(a) FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#43827 Server closes connections and restarts
+--echo #
+# Crash happened with a user-defined utf8 collation,
+# on attempt to insert a string longer than the column can store.
+CREATE TABLE t1 (c1 VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_test_ci);
+INSERT INTO t1 SELECT REPEAT('a',11);
+DROP TABLE t1;
+
+#
+# Vietnamese experimental collation
+#
+--echo Vietnamese experimental collation
+
+show collation like 'ucs2_vn_ci';
+create table t1 (c1 char(1) character set ucs2 collate ucs2_vn_ci);
+insert into t1 values (0x0061),(0x0041),(0x00E0),(0x00C0),(0x1EA3),(0x1EA2),
+ (0x00E3),(0x00C3),(0x00E1),(0x00C1),(0x1EA1),(0x1EA0);
+insert into t1 values (0x0103),(0x0102),(0x1EB1),(0x1EB0),(0x1EB3),(0x1EB2),
+ (0x1EB5),(0x1EB4),(0x1EAF),(0x1EAE),(0x1EB7),(0x1EB6);
+insert into t1 values (0x00E2),(0x00C2),(0x1EA7),(0x1EA6),(0x1EA9),(0x1EA8),
+ (0x1EAB),(0x1EAA),(0x1EA5),(0x1EA4),(0x1EAD),(0x1EAC);
+insert into t1 values ('b'),('B'),('c'),('C');
+insert into t1 values ('d'),('D'),(0x0111),(0x0110);
+insert into t1 values (0x0065),(0x0045),(0x00E8),(0x00C8),(0x1EBB),(0x1EBA),
+ (0x1EBD),(0x1EBC),(0x00E9),(0x00C9),(0x1EB9),(0x1EB8);
+insert into t1 values (0x00EA),(0x00CA),(0x1EC1),(0x1EC0),(0x1EC3),(0x1EC2),
+ (0x1EC5),(0x1EC4),(0x1EBF),(0x1EBE),(0x1EC7),(0x1EC6);
+insert into t1 values ('g'),('G'),('h'),('H');
+insert into t1 values (0x0069),(0x0049),(0x00EC),(0x00CC),(0x1EC9),(0x1EC8),
+ (0x0129),(0x0128),(0x00ED),(0x00CD),(0x1ECB),(0x1ECA);
+insert into t1 values ('k'),('K'),('l'),('L'),('m'),('M');
+insert into t1 values (0x006F),(0x004F),(0x00F2),(0x00D2),(0x1ECF),(0x1ECE),
+ (0x00F5),(0x00D5),(0x00F3),(0x00D3),(0x1ECD),(0x1ECC);
+insert into t1 values (0x00F4),(0x00D4),(0x1ED3),(0x1ED2),(0x1ED5),(0x1ED4),
+ (0x1ED7),(0x1ED6),(0x1ED1),(0x1ED0),(0x1ED9),(0x1ED8);
+insert into t1 values (0x01A1),(0x01A0),(0x1EDD),(0x1EDC),(0x1EDF),(0x1EDE),
+ (0x1EE1),(0x1EE0),(0x1EDB),(0x1EDA),(0x1EE3),(0x1EE2);
+insert into t1 values ('p'),('P'),('q'),('Q'),('r'),('R'),('s'),('S'),('t'),('T');
+insert into t1 values (0x0075),(0x0055),(0x00F9),(0x00D9),(0x1EE7),(0x1EE6),
+ (0x0169),(0x0168),(0x00FA),(0x00DA),(0x1EE5),(0x1EE4);
+insert into t1 values (0x01B0),(0x01AF),(0x1EEB),(0x1EEA),(0x1EED),(0x1EEC),
+ (0x1EEF),(0x1EEE),(0x1EE9),(0x1EE8),(0x1EF1),(0x1EF0);
+insert into t1 values ('v'),('V'),('x'),('X');
+insert into t1 values (0x0079),(0x0059),(0x1EF3),(0x1EF2),(0x1EF7),(0x1EF6),
+ (0x1EF9),(0x1EF8),(0x00FD),(0x00DD),(0x1EF5),(0x1EF4);
+select hex(c1) as h, c1 from t1 order by c1, h;
+select group_concat(hex(c1) order by hex(c1)) from t1 group by c1;
+select group_concat(c1 order by hex(c1) SEPARATOR '') from t1 group by c1;
+drop table t1;
+
+--echo Bug#46448 trailing spaces are not ignored when user collation maps space != 0x20
+set names latin1;
+show collation like 'latin1_test';
+select "foo" = "foo " collate latin1_test;
+
+-- echo The following tests check that two-byte collation IDs work
+# The file ../std-data/Index.xml has a number of collations with high IDs.
+
+# Test that the "ID" column in I_S and SHOW queries can handle two bytes
+select * from information_schema.collations where id>256 order by id;
+show collation like '%test%';
+
+# Test that two-byte collation ID is correctly transfered to the client side.
+show collation like 'ucs2_vn_ci';
+create table t1 (c1 char(1) character set ucs2 collate ucs2_vn_ci);
+
+show create table t1;
+
+insert into t1 values (0x0061);
+--enable_metadata
+set @@character_set_results=NULL;
+select * from t1;
+--disable_metadata
+drop table t1;
+
+#
+# Check maximum collation ID (2047 as of MySQL-6.0.9)
+#
+CREATE TABLE t1 (s1 char(10) character set utf8 collate utf8_maxuserid_ci);
+INSERT INTO t1 VALUES ('a'),('b');
+SELECT * FROM t1 WHERE s1='a' ORDER BY BINARY s1;
+DROP TABLE t1;
+
+
+#
+# Bug#47756 Setting 2byte collation ID with 'set names' crashes the server
+#
+SET NAMES utf8 COLLATE utf8_phone_ci;
+SHOW COLLATION LIKE 'utf8_phone_ci';
+SET NAMES utf8;
+
+# make sure utf8mb4_test_400_ci is Unicode-4.0.0 based
+SELECT hex(weight_string(_utf8mb4'a' collate utf8mb4_test_400_ci));
+SELECT hex(weight_string(convert(_utf32 0x10002 using utf8mb4) collate utf8mb4_test_400_ci));
+SELECT hex(@a:=convert(_utf32 0x10400 using utf8mb4) collate utf8mb4_test_400_ci), hex(lower(@a));
+SELECT hex(@a:=convert(_utf32 0x10428 using utf8mb4) collate utf8mb4_test_400_ci), hex(upper(@a));
+SELECT hex(@a:=convert(_utf32 0x2C00 using utf8mb4) collate utf8mb4_test_400_ci), hex(lower(@a));
+SELECT hex(@a:=convert(_utf32 0x2C30 using utf8mb4) collate utf8mb4_test_400_ci), hex(upper(@a));
+
+--echo #
+--echo # WL#5624 Collation customization improvements
+--echo #
+SET NAMES utf8 COLLATE utf8_5624_1;
+CREATE TABLE t1 AS SELECT REPEAT(' ', 16) AS a LIMIT 0;
+# Part 1,2,3: long contractions and expansions
+# Part 7: Quarternary difference
+INSERT INTO t1 VALUES ('012345'),('001234'),('000123'),('000012'),('000001');
+INSERT INTO t1 VALUES ('12345'),('01234'),('00123'),('00012'),('00001');
+INSERT INTO t1 VALUES ('1234'),('0123'),('0012'),('0001');
+INSERT INTO t1 VALUES ('123'),('012'),('001');
+INSERT INTO t1 VALUES ('12'),('01');
+INSERT INTO t1 VALUES ('1'),('9');
+INSERT INTO t1 VALUES ('ГÐИ'),('ГИБДД');
+# Part 4: reset before
+# Part 6: characters rather than escape sequences
+INSERT INTO t1 VALUES ('a'),('b'),('c'),('d'),('e');
+INSERT INTO t1 VALUES ('cz'),('ÄŠ'),('Ä‹');
+INSERT INTO t1 VALUES ('f'),('fz'),('g'),('Ä '),('Ä¡');
+INSERT INTO t1 VALUES ('h'),('hz'),('GĦ'),('Għ'),('gĦ'),('għ');
+INSERT INTO t1 VALUES ('i'),('iz'),('Ħ'),('ħ');
+INSERT INTO t1 VALUES ('y'),('yz'),('z'),('Ż'),('ż');
+INSERT INTO t1 VALUES ('Ä'),('Ä€'),('á'),('Ã'),('à'),('À');
+INSERT INTO t1 VALUES ('ē'),('é'),('ě'),('ê'),('Ē'),('É'),('Ě'),('Ê');
+# Part 8: Abbreviated shift syntax
+INSERT INTO t1 VALUES ('a'),('~'),('!'),('@'),('#'),('$'),('%'),('^');
+INSERT INTO t1 VALUES ('('),(')'),('-'),('+'),('|'),('='),(':'),(';');
+INSERT INTO t1 VALUES ('"'),('\''),('?');
+# Part 9: Normal expansion syntax
+INSERT INTO t1 VALUES ('ch'),('k'),('cs'),('ccs'),('cscs');
+# Part 10: Previous context
+INSERT INTO t1 VALUES ('aa-'),('ab-'),('ac-'),('ad-'),('ae-'),('af-'),('az-');
+# Part 12: Logical reset positions
+INSERT INTO t1 VALUES ('lp-fni'),('lp-lni');
+INSERT INTO t1 VALUES ('lp-fpi'),('lp-lpi');
+INSERT INTO t1 VALUES ('lp-fsi'),('lp-lsi');
+INSERT INTO t1 VALUES ('lp-fti'),('lp-lti');
+INSERT INTO t1 VALUES ('lp-ft'),('lp-lt');
+INSERT INTO t1 VALUES ('lp-fv'),('lp-lv');
+# Logical positions with reset before
+INSERT INTO t1 VALUES ('lb-fni'),('lb-lni');
+INSERT INTO t1 VALUES ('lb-fv'),('lb-lv');
+# Part 5: Long tailoring
+INSERT INTO t1 VALUES (_ucs2 0x3106),(_ucs2 0x3110), (_ucs2 0x3111), (_ucs2 0x3112);
+INSERT INTO t1 VALUES (_ucs2 0x32A3), (_ucs2 0x3231);
+INSERT INTO t1 VALUES (_ucs2 0x84D9), (_ucs2 0x98F5), (_ucs2 0x7CF3), (_ucs2 0x5497);
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY a;
+--echo #
+--echo # WL#5624, the same test with UCS2
+--echo #
+ALTER TABLE t1 CONVERT TO CHARACTER SET ucs2 COLLATE ucs2_5624_1;
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
+DROP TABLE t1;
+
+--echo #
+--echo # WL#5624, unsupported features
+--echo #
+# Part 13: More verbosity
+--error ER_UNKNOWN_COLLATION
+SET NAMES utf8 COLLATE utf8_5624_2;
+SHOW WARNINGS;
+
+--echo #
+--echo # WL#5624, reset before primary ignorable
+--echo #
+--error ER_UNKNOWN_COLLATION
+SET NAMES utf8 COLLATE utf8_5624_3;
+SHOW WARNINGS;
+
+--echo #
+--echo # WL#5624, \u without hex digits is equal to {'\\', 'u'}
+--echo #
+SET NAMES utf8 COLLATE utf8_5624_4;
+CREATE TABLE t1 AS SELECT REPEAT(' ', 10) AS a LIMIT 0;
+INSERT INTO t1 VALUES ('\\'),('u'),('x'),('X');
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
+DROP TABLE t1;
+
+--echo #
+--echo # WL#5624, testing Bengali collations
+--echo #
+SET NAMES utf8, collation_connection=utf8_bengali_standard_ci;
+CREATE TABLE t1 AS SELECT REPEAT (' ', 10) AS a LIMIT 0;
+INSERT INTO t1 VALUES (_ucs2 0x09FA), (_ucs2 0x09F8), (_ucs2 0x09F9), (_ucs2 0x09F2);
+INSERT INTO t1 VALUES (_ucs2 0x09DC), (_ucs2 0x09A109BC);
+INSERT INTO t1 VALUES (_ucs2 0x09A2), (_ucs2 0x09DD), (_ucs2 0x09A209BC);
+INSERT INTO t1 VALUES (_ucs2 0x09A3);
+SELECT HEX(WEIGHT_STRING(a)), HEX(CONVERT(a USING ucs2)), HEX(a)
+FROM t1 ORDER BY a, BINARY a;
+DROP TABLE t1;
+
+SET NAMES utf8, collation_connection=utf8_bengali_traditional_ci;
+CREATE TABLE t1 AS SELECT REPEAT (' ', 10) AS a LIMIT 0;
+INSERT INTO t1 VALUES
+(_ucs2 0x0985),(_ucs2 0x0986),(_ucs2 0x0987),(_ucs2 0x0988),
+(_ucs2 0x0989),(_ucs2 0x098A),(_ucs2 0x098B),(_ucs2 0x09E0),
+(_ucs2 0x098C),(_ucs2 0x09E1),(_ucs2 0x098F),(_ucs2 0x0990),
+(_ucs2 0x0993);
+
+INSERT INTO t1 VALUES
+(_ucs2 0x0994),(_ucs2 0x0982),(_ucs2 0x0983),(_ucs2 0x0981),
+(_ucs2 0x099509CD), (_ucs2 0x099609CD), (_ucs2 0x099709CD), (_ucs2 0x099809CD),
+(_ucs2 0x099909CD), (_ucs2 0x099A09CD), (_ucs2 0x099B09CD), (_ucs2 0x099C09CD),
+(_ucs2 0x099D09CD), (_ucs2 0x099E09CD), (_ucs2 0x099F09CD), (_ucs2 0x09A009CD),
+(_ucs2 0x09A109CD), (_ucs2 0x09A209CD), (_ucs2 0x09A309CD),
+(_ucs2 0x09CE), (_ucs2 0x09A409CD200D), (_ucs2 0x09A409CD),
+(_ucs2 0x09A509CD),(_ucs2 0x09A609CD),
+(_ucs2 0x09A709CD), (_ucs2 0x09A809CD), (_ucs2 0x09AA09CD), (_ucs2 0x09AB09CD),
+(_ucs2 0x09AC09CD), (_ucs2 0x09AD09CD), (_ucs2 0x09AE09CD), (_ucs2 0x09AF09CD),
+(_ucs2 0x09B009CD), (_ucs2 0x09F009CD), (_ucs2 0x09B209CD), (_ucs2 0x09F109CD),
+(_ucs2 0x09B609CD), (_ucs2 0x09B709CD), (_ucs2 0x09B809CD), (_ucs2 0x09B909CD);
+
+INSERT INTO t1 VALUES
+ (_ucs2 0x099509CD0985),(_ucs2 0x0995),
+ (_ucs2 0x099509CD0986),(_ucs2 0x099509BE),
+ (_ucs2 0x099509CD0987),(_ucs2 0x099509BF),
+ (_ucs2 0x099509CD0988),(_ucs2 0x099509C0),
+ (_ucs2 0x099509CD0989),(_ucs2 0x099509C1),
+ (_ucs2 0x099509CD098A),(_ucs2 0x099509C2),
+ (_ucs2 0x099509CD098B),(_ucs2 0x099509C3),
+ (_ucs2 0x099509CD09E0),(_ucs2 0x099509C4),
+ (_ucs2 0x099509CD098C),(_ucs2 0x099509E2),
+ (_ucs2 0x099509CD09E1),(_ucs2 0x099509E3),
+ (_ucs2 0x099509CD098F),(_ucs2 0x099509C7),
+ (_ucs2 0x099509CD0990),(_ucs2 0x099509C8),
+ (_ucs2 0x099509CD0993),(_ucs2 0x099509CB),
+ (_ucs2 0x099509CD0994),(_ucs2 0x099509CC);
+
+SELECT HEX(WEIGHT_STRING(a)), HEX(CONVERT(a USING ucs2)), HEX(a)
+FROM t1 ORDER BY a, BINARY(a);
+SELECT HEX(WEIGHT_STRING(a)) as wa,
+GROUP_CONCAT(HEX(CONVERT(a USING ucs2)) ORDER BY LENGTH(a), BINARY a)
+FROM t1 GROUP BY a ORDER BY a;
+DROP TABLE t1;
+
+--echo #
+--echo # WL#5624, shift after, using expansion
+--echo #
+SET NAMES utf8 COLLATE utf8_5624_5;
+CREATE TABLE t1 AS SELECT REPEAT(' ', 10) AS a LIMIT 0;
+INSERT INTO t1 VALUES ('0'),('1'),('0z'),(_ucs2 0x0030FF9D);
+INSERT INTO t1 VALUES ('a'),('b'),('c'),('d'),('e'),('f'),('g'),('h'),('i');
+INSERT INTO t1 VALUES ('j'),('k'),('l'),('m'),('n'),('o'),('p'),('q'),('r');
+INSERT INTO t1 VALUES ('s'),('t'),('u'),('v'),('w'),('x'),('y'),('z');
+INSERT INTO t1 VALUES ('aa'),('aaa');
+INSERT INTO t1 VALUES ('A'),('B'),('C'),('D'),('E'),('F'),('G'),('H'),('I');
+INSERT INTO t1 VALUES ('J'),('K'),('L'),('M'),('N'),('O'),('P'),('Q'),('R');
+INSERT INTO t1 VALUES ('S'),('T'),('U'),('V'),('W'),('X'),('Y'),('Z');
+INSERT INTO t1 VALUES ('AA'),('AAA');
+
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
+DROP TABLE t1;
+
+
+--echo #
+--echo # End of WL#5624
+--echo #
diff --git a/mysql-test/suite/perfschema/r/digest_table_full.result b/mysql-test/suite/perfschema/r/digest_table_full.result
index 263c92033df..51c6404e332 100644
--- a/mysql-test/suite/perfschema/r/digest_table_full.result
+++ b/mysql-test/suite/perfschema/r/digest_table_full.result
@@ -113,7 +113,7 @@ SELECT SCHEMA_NAME, DIGEST, DIGEST_TEXT, COUNT_STAR, SUM_ROWS_AFFECTED, SUM_WARN
SUM_ERRORS FROM performance_schema.events_statements_summary_by_digest;
SCHEMA_NAME DIGEST DIGEST_TEXT COUNT_STAR SUM_ROWS_AFFECTED SUM_WARNINGS SUM_ERRORS
NULL NULL NULL 55 32 1 2
-statements_digest 058e261e03a3429e9dde588ee7852ca9 TRUNCATE TABLE performance_schema . events_statements_summary_by_digest 1 0 0 0
+statements_digest 9dc10607f0c5f847fdec5021ec55454c TRUNCATE TABLE performance_schema . events_statements_summary_by_digest 1 0 0 0
SHOW VARIABLES LIKE "performance_schema_digests_size";
Variable_name Value
performance_schema_digests_size 2
diff --git a/mysql-test/suite/perfschema/r/statement_digest.result b/mysql-test/suite/perfschema/r/statement_digest.result
index 21f201c8b34..862239b015c 100644
--- a/mysql-test/suite/perfschema/r/statement_digest.result
+++ b/mysql-test/suite/perfschema/r/statement_digest.result
@@ -112,43 +112,43 @@ DROP TRIGGER trg;
SELECT SCHEMA_NAME, DIGEST, DIGEST_TEXT, COUNT_STAR, SUM_ROWS_AFFECTED, SUM_WARNINGS,
SUM_ERRORS FROM performance_schema.events_statements_summary_by_digest;
SCHEMA_NAME DIGEST DIGEST_TEXT COUNT_STAR SUM_ROWS_AFFECTED SUM_WARNINGS SUM_ERRORS
-statements_digest 058e261e03a3429e9dde588ee7852ca9 TRUNCATE TABLE performance_schema . events_statements_summary_by_digest 1 0 0 0
-statements_digest f06e1e6dfc4bf7cfd4dba5c51f13c627 SELECT ? FROM t1 1 0 0 0
-statements_digest 1aa077e01aca3d45b15ce527a070b870 SELECT ? FROM `t1` 1 0 0 0
-statements_digest e8a62a4be5eebe5da537dca976a46369 SELECT ?, ... FROM t1 2 0 0 0
-statements_digest 55954e653faa536a8d04cb581ff2c3dd SELECT ? FROM t2 1 0 0 0
-statements_digest dfba57e13cf9a61e71d382e5e8f507dc SELECT ?, ... FROM t2 2 0 0 0
-statements_digest 07fd34fc3ad88826c4680e5517df8b56 INSERT INTO t1 VALUES (?) 1 1 0 0
-statements_digest f9bbb87739bb3e674e1b4d888f4d852d INSERT INTO t2 VALUES (?) 1 1 0 0
-statements_digest fd3d685c4ffea28c372da82013927fe9 INSERT INTO t3 VALUES (...) 4 4 0 0
-statements_digest a40fcf6ddcce2b12549af18a460f34cc INSERT INTO t4 VALUES (...) 1 1 0 0
-statements_digest bd9efa806d48703d9e0c04f42ef248be INSERT INTO t5 VALUES (...) 1 1 0 0
-statements_digest e0a648ba1f7102ad97159137f51d03e2 INSERT INTO t1 VALUES (?) /* , ... */ 2 7 0 0
-statements_digest bf47d74b741aa74e219661e51cc7bd5a INSERT INTO t3 VALUES (...) /* , ... */ 1 3 0 0
-statements_digest 770e2aa80fd5c31b698f372846b60a26 INSERT INTO t5 VALUES (...) /* , ... */ 1 3 0 0
-statements_digest a201d75ec8bbedb67d81bf34d8e72d11 INSERT INTO t1 VALUES ( NULL ) 1 1 0 0
-statements_digest 570ad676b68ac8372387855d3a49ad3b INSERT INTO t6 VALUES (...) 5 5 0 0
-statements_digest 2070052b03b2d75f23d12feb7cf14db8 SELECT ? + ? 3 0 0 0
-statements_digest ac19ca62acbdacd2f797f8656936cc46 SELECT ? 1 0 0 0
+statements_digest 9dc10607f0c5f847fdec5021ec55454c TRUNCATE TABLE performance_schema . events_statements_summary_by_digest 1 0 0 0
+statements_digest 70dfef34974722c072dfde594161c53f SELECT ? FROM t1 1 0 0 0
+statements_digest 92afc5f0de28802cf90bac0d2ecc28ea SELECT ? FROM `t1` 1 0 0 0
+statements_digest a3c82be9beb57590c35da4ffdde342f4 SELECT ?, ... FROM t1 2 0 0 0
+statements_digest 4aa210c131d9f75ee7acfea2b4f84f8e SELECT ? FROM t2 1 0 0 0
+statements_digest 4160fd3e7a59e6a4fab0d5188e306d8f SELECT ?, ... FROM t2 2 0 0 0
+statements_digest 033964070b3cfe70ea0e6edf21ab5595 INSERT INTO t1 VALUES (?) 1 1 0 0
+statements_digest cd2843f72a1484fb137664855d268a23 INSERT INTO t2 VALUES (?) 1 1 0 0
+statements_digest 51de047a21efe42b07e3af030330af0e INSERT INTO t3 VALUES (...) 4 4 0 0
+statements_digest 159f7021cd6b766d3f8f98d6f49c26c7 INSERT INTO t4 VALUES (...) 1 1 0 0
+statements_digest 0d298ad85eb763cfed01450d45ed311f INSERT INTO t5 VALUES (...) 1 1 0 0
+statements_digest 2872669f092c0878080b93d8d55a9efa INSERT INTO t1 VALUES (?) /* , ... */ 2 7 0 0
+statements_digest f8b8ffcea0840f0b796c04be7c4586a7 INSERT INTO t3 VALUES (...) /* , ... */ 1 3 0 0
+statements_digest ba4e21efb9e3704e86b2036505d76608 INSERT INTO t5 VALUES (...) /* , ... */ 1 3 0 0
+statements_digest 7b81bc3a5cc54098b68df4297456ca42 INSERT INTO t1 VALUES ( NULL ) 1 1 0 0
+statements_digest dc50d0a03e9f4c25493bbb660614a979 INSERT INTO t6 VALUES (...) 5 5 0 0
+statements_digest 772f22c3ca1b998449570d41d677b739 SELECT ? + ? 3 0 0 0
+statements_digest 4077abb1c6924eb2e61a4e6b5832e610 SELECT ? 1 0 0 0
statements_digest dec987af5d13596c58a0b3382bf4be0a CREATE SCHEMA statements_digest_temp 2 2 0 0
statements_digest 310050e7e30e166116fd9b04b9a39cec DROP SCHEMA statements_digest_temp 2 0 0 0
-statements_digest 9e0ac69ff040710432c714809211455b SELECT ? FROM no_such_table 1 0 0 1
-statements_digest a1ca1ae73bcb5f885f599ed928b63d4f CREATE TABLE dup_table ( c CHARACTER (?) ) 2 0 0 1
-statements_digest b27c620e7d1bef3db8935413b4d76902 DROP TABLE dup_table 1 0 0 0
-statements_digest d822ef0a683e0cf695ae25fb22a3888b INSERT INTO t11 VALUES (?) 1 1 1 0
-statements_digest 5fc311802f8a481642977bff3fc89e7f SHOW WARNINGS 1 0 0 0
-statements_digest 0f36f46585cc5004c9c9690a390f1849 PREPARE stmt FROM ? 1 0 0 0
+statements_digest 1de70c587e0cc8f72f18f5532ea9ce41 SELECT ? FROM no_such_table 1 0 0 1
+statements_digest a0fcbd276415d695cbbd0ff9ea988fd1 CREATE TABLE dup_table ( c CHARACTER (?) ) 2 0 0 1
+statements_digest 47eff8114ef3ff7156ea1f894792a780 DROP TABLE dup_table 1 0 0 0
+statements_digest ca7b7a57283e104af725938959e04acc INSERT INTO t11 VALUES (?) 1 1 1 0
+statements_digest 09d296fc41f9a0a8e3badbfb548e69d9 SHOW WARNINGS 1 0 0 0
+statements_digest daef8b2773ba22b629205ac8d37275ba PREPARE stmt FROM ? 1 0 0 0
statements_digest 933bf6630b020a5215edb27059bd68cc EXECUTE stmt 2 0 0 0
statements_digest 45459d112476cdf389c4c43b25fe1751 DEALLOCATE PREPARE stmt 1 0 0 0
-statements_digest fb7cce5ec6c4793335b102e006bde9f0 CREATE PROCEDURE p1 ( ) BEGIN SELECT * FROM t12 ; END 1 0 0 0
+statements_digest 317d254d2506653e151e8ca097fc8f18 CREATE PROCEDURE p1 ( ) BEGIN SELECT * FROM t12 ; END 1 0 0 0
statements_digest 554e43a1cba81ed9076c04f39721c94b CALL p1 ( ) 2 0 0 0
statements_digest aa9d2a149756e50d528de565a14d1d18 DROP PROCEDURE p1 1 0 0 0
-statements_digest 67c2e7a9c61879240dac40286cfd97f9 CREATE FUNCTION `func` ( a INTEGER , b INTEGER ) RETURNS INTEGER (?) RETURN a + b 1 0 0 0
-statements_digest 208d842bca1bfdcfa6267c5cf90014a5 SELECT func (...) 2 0 0 0
+statements_digest e5674b0df28911bcb4fb4a1902b6e30a CREATE FUNCTION `func` ( a INTEGER , b INTEGER ) RETURNS INTEGER (?) RETURN a + b 1 0 0 0
+statements_digest a70c0561b972d4e50638d5ecdeef2ff1 SELECT func (...) 2 0 0 0
statements_digest eba7f0de7c0682908b1810e99b3194e8 DROP FUNCTION func 1 0 0 0
-statements_digest 51c49c31b51f43b83a4933782addee0a CREATE TRIGGER trg BEFORE INSERT ON t12 FOR EACH ROW SET @ ? := ? 1 0 0 0
-statements_digest 3d8c6af34b1cc5c04dddfa8cc81b6a9a INSERT INTO t12 VALUES (?) 2 2 0 0
-statements_digest 78eb3e982b2f4887f2e8c7b5a49ce982 DROP TRIGGER trg 1 0 0 0
+statements_digest 3f4217b75adb295c507c21edda9a7880 CREATE TRIGGER trg BEFORE INSERT ON t12 FOR EACH ROW SET @ ? := ? 1 0 0 0
+statements_digest 9628bd16a7f019ca3046a449ec9e4e30 INSERT INTO t12 VALUES (?) 2 2 0 0
+statements_digest d62fc8c82ef777e9c3af4f47743e0c46 DROP TRIGGER trg 1 0 0 0
####################################
# CLEANUP
####################################
diff --git a/mysql-test/suite/perfschema/r/statement_digest_consumers.result b/mysql-test/suite/perfschema/r/statement_digest_consumers.result
index fc5696af326..48f13c1ed01 100644
--- a/mysql-test/suite/perfschema/r/statement_digest_consumers.result
+++ b/mysql-test/suite/perfschema/r/statement_digest_consumers.result
@@ -125,43 +125,43 @@ DROP TRIGGER trg;
####################################
SELECT schema_name, digest, digest_text, count_star FROM performance_schema.events_statements_summary_by_digest;
schema_name digest digest_text count_star
-statements_digest 058e261e03a3429e9dde588ee7852ca9 TRUNCATE TABLE performance_schema . events_statements_summary_by_digest 1
-statements_digest f06e1e6dfc4bf7cfd4dba5c51f13c627 SELECT ? FROM t1 1
-statements_digest 1aa077e01aca3d45b15ce527a070b870 SELECT ? FROM `t1` 1
-statements_digest e8a62a4be5eebe5da537dca976a46369 SELECT ?, ... FROM t1 2
-statements_digest 55954e653faa536a8d04cb581ff2c3dd SELECT ? FROM t2 1
-statements_digest dfba57e13cf9a61e71d382e5e8f507dc SELECT ?, ... FROM t2 2
-statements_digest 07fd34fc3ad88826c4680e5517df8b56 INSERT INTO t1 VALUES (?) 1
-statements_digest f9bbb87739bb3e674e1b4d888f4d852d INSERT INTO t2 VALUES (?) 1
-statements_digest fd3d685c4ffea28c372da82013927fe9 INSERT INTO t3 VALUES (...) 4
-statements_digest a40fcf6ddcce2b12549af18a460f34cc INSERT INTO t4 VALUES (...) 1
-statements_digest bd9efa806d48703d9e0c04f42ef248be INSERT INTO t5 VALUES (...) 1
-statements_digest e0a648ba1f7102ad97159137f51d03e2 INSERT INTO t1 VALUES (?) /* , ... */ 2
-statements_digest bf47d74b741aa74e219661e51cc7bd5a INSERT INTO t3 VALUES (...) /* , ... */ 1
-statements_digest 770e2aa80fd5c31b698f372846b60a26 INSERT INTO t5 VALUES (...) /* , ... */ 1
-statements_digest a201d75ec8bbedb67d81bf34d8e72d11 INSERT INTO t1 VALUES ( NULL ) 1
-statements_digest 570ad676b68ac8372387855d3a49ad3b INSERT INTO t6 VALUES (...) 5
-statements_digest 2070052b03b2d75f23d12feb7cf14db8 SELECT ? + ? 3
-statements_digest ac19ca62acbdacd2f797f8656936cc46 SELECT ? 1
+statements_digest 9dc10607f0c5f847fdec5021ec55454c TRUNCATE TABLE performance_schema . events_statements_summary_by_digest 1
+statements_digest 70dfef34974722c072dfde594161c53f SELECT ? FROM t1 1
+statements_digest 92afc5f0de28802cf90bac0d2ecc28ea SELECT ? FROM `t1` 1
+statements_digest a3c82be9beb57590c35da4ffdde342f4 SELECT ?, ... FROM t1 2
+statements_digest 4aa210c131d9f75ee7acfea2b4f84f8e SELECT ? FROM t2 1
+statements_digest 4160fd3e7a59e6a4fab0d5188e306d8f SELECT ?, ... FROM t2 2
+statements_digest 033964070b3cfe70ea0e6edf21ab5595 INSERT INTO t1 VALUES (?) 1
+statements_digest cd2843f72a1484fb137664855d268a23 INSERT INTO t2 VALUES (?) 1
+statements_digest 51de047a21efe42b07e3af030330af0e INSERT INTO t3 VALUES (...) 4
+statements_digest 159f7021cd6b766d3f8f98d6f49c26c7 INSERT INTO t4 VALUES (...) 1
+statements_digest 0d298ad85eb763cfed01450d45ed311f INSERT INTO t5 VALUES (...) 1
+statements_digest 2872669f092c0878080b93d8d55a9efa INSERT INTO t1 VALUES (?) /* , ... */ 2
+statements_digest f8b8ffcea0840f0b796c04be7c4586a7 INSERT INTO t3 VALUES (...) /* , ... */ 1
+statements_digest ba4e21efb9e3704e86b2036505d76608 INSERT INTO t5 VALUES (...) /* , ... */ 1
+statements_digest 7b81bc3a5cc54098b68df4297456ca42 INSERT INTO t1 VALUES ( NULL ) 1
+statements_digest dc50d0a03e9f4c25493bbb660614a979 INSERT INTO t6 VALUES (...) 5
+statements_digest 772f22c3ca1b998449570d41d677b739 SELECT ? + ? 3
+statements_digest 4077abb1c6924eb2e61a4e6b5832e610 SELECT ? 1
statements_digest dec987af5d13596c58a0b3382bf4be0a CREATE SCHEMA statements_digest_temp 2
statements_digest 310050e7e30e166116fd9b04b9a39cec DROP SCHEMA statements_digest_temp 2
-statements_digest 9e0ac69ff040710432c714809211455b SELECT ? FROM no_such_table 1
-statements_digest a1ca1ae73bcb5f885f599ed928b63d4f CREATE TABLE dup_table ( c CHARACTER (?) ) 2
-statements_digest b27c620e7d1bef3db8935413b4d76902 DROP TABLE dup_table 1
-statements_digest d822ef0a683e0cf695ae25fb22a3888b INSERT INTO t11 VALUES (?) 1
-statements_digest 5fc311802f8a481642977bff3fc89e7f SHOW WARNINGS 1
-statements_digest 0f36f46585cc5004c9c9690a390f1849 PREPARE stmt FROM ? 1
+statements_digest 1de70c587e0cc8f72f18f5532ea9ce41 SELECT ? FROM no_such_table 1
+statements_digest a0fcbd276415d695cbbd0ff9ea988fd1 CREATE TABLE dup_table ( c CHARACTER (?) ) 2
+statements_digest 47eff8114ef3ff7156ea1f894792a780 DROP TABLE dup_table 1
+statements_digest ca7b7a57283e104af725938959e04acc INSERT INTO t11 VALUES (?) 1
+statements_digest 09d296fc41f9a0a8e3badbfb548e69d9 SHOW WARNINGS 1
+statements_digest daef8b2773ba22b629205ac8d37275ba PREPARE stmt FROM ? 1
statements_digest 933bf6630b020a5215edb27059bd68cc EXECUTE stmt 2
statements_digest 45459d112476cdf389c4c43b25fe1751 DEALLOCATE PREPARE stmt 1
-statements_digest fb7cce5ec6c4793335b102e006bde9f0 CREATE PROCEDURE p1 ( ) BEGIN SELECT * FROM t12 ; END 1
+statements_digest 317d254d2506653e151e8ca097fc8f18 CREATE PROCEDURE p1 ( ) BEGIN SELECT * FROM t12 ; END 1
statements_digest 554e43a1cba81ed9076c04f39721c94b CALL p1 ( ) 2
statements_digest aa9d2a149756e50d528de565a14d1d18 DROP PROCEDURE p1 1
-statements_digest 67c2e7a9c61879240dac40286cfd97f9 CREATE FUNCTION `func` ( a INTEGER , b INTEGER ) RETURNS INTEGER (?) RETURN a + b 1
-statements_digest 208d842bca1bfdcfa6267c5cf90014a5 SELECT func (...) 2
+statements_digest e5674b0df28911bcb4fb4a1902b6e30a CREATE FUNCTION `func` ( a INTEGER , b INTEGER ) RETURNS INTEGER (?) RETURN a + b 1
+statements_digest a70c0561b972d4e50638d5ecdeef2ff1 SELECT func (...) 2
statements_digest eba7f0de7c0682908b1810e99b3194e8 DROP FUNCTION func 1
-statements_digest 51c49c31b51f43b83a4933782addee0a CREATE TRIGGER trg BEFORE INSERT ON t12 FOR EACH ROW SET @ ? := ? 1
-statements_digest 3d8c6af34b1cc5c04dddfa8cc81b6a9a INSERT INTO t12 VALUES (?) 2
-statements_digest 78eb3e982b2f4887f2e8c7b5a49ce982 DROP TRIGGER trg 1
+statements_digest 3f4217b75adb295c507c21edda9a7880 CREATE TRIGGER trg BEFORE INSERT ON t12 FOR EACH ROW SET @ ? := ? 1
+statements_digest 9628bd16a7f019ca3046a449ec9e4e30 INSERT INTO t12 VALUES (?) 2
+statements_digest d62fc8c82ef777e9c3af4f47743e0c46 DROP TRIGGER trg 1
SELECT digest, digest_text FROM performance_schema.events_statements_current;
digest digest_text
####################################
diff --git a/mysql-test/suite/perfschema/r/statement_digest_long_query.result b/mysql-test/suite/perfschema/r/statement_digest_long_query.result
index 8fda5a25531..f304b0108de 100644
--- a/mysql-test/suite/perfschema/r/statement_digest_long_query.result
+++ b/mysql-test/suite/perfschema/r/statement_digest_long_query.result
@@ -8,5 +8,5 @@ SELECT 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
####################################
SELECT schema_name, digest, digest_text, count_star FROM events_statements_summary_by_digest;
schema_name digest digest_text count_star
-performance_schema 9e06e018ca7b7970092dc19fdd8ed04f TRUNCATE TABLE events_statements_summary_by_digest 1
-performance_schema c7ab01a5f5014d6c8f90f88c9545a611 SELECT ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ... 1
+performance_schema f7e1956f59eac75d9274653d492191ad TRUNCATE TABLE events_statements_summary_by_digest 1
+performance_schema aa750e240d5b31fa3ca6ef4375863e28 SELECT ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ... 1
diff --git a/mysql-test/t/ctype_big5.test b/mysql-test/t/ctype_big5.test
index b024420dee3..afac3e4a435 100644
--- a/mysql-test/t/ctype_big5.test
+++ b/mysql-test/t/ctype_big5.test
@@ -145,3 +145,26 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names big5;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+
+set collation_connection=big5_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/ctype_cp1250_ch.test b/mysql-test/t/ctype_cp1250_ch.test
index a4c59f494a7..c4efae13c39 100644
--- a/mysql-test/t/ctype_cp1250_ch.test
+++ b/mysql-test/t/ctype_cp1250_ch.test
@@ -82,3 +82,30 @@ drop table t1;
--error 1649
set global LC_MESSAGES=convert((@@global.log_bin_trust_function_creators)
using cp1250);
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+--echo #
+--echo # Note:
+--echo # cp1250_czech_cs does not support WEIGHT_STRING in full extent
+--echo #
+
+set names cp1250 collate cp1250_czech_cs;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_chde.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_l2.inc
+--source include/weight_string_l12.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
diff --git a/mysql-test/t/ctype_cp932_binlog_stm.test b/mysql-test/t/ctype_cp932_binlog_stm.test
index a83f48b1439..ca8853b9ea1 100644
--- a/mysql-test/t/ctype_cp932_binlog_stm.test
+++ b/mysql-test/t/ctype_cp932_binlog_stm.test
@@ -162,3 +162,26 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names cp932;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_8140.inc
+
+set collation_connection=cp932_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_8140.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/ctype_eucjpms.test b/mysql-test/t/ctype_eucjpms.test
index fea48061c69..264d9156a0c 100644
--- a/mysql-test/t/ctype_eucjpms.test
+++ b/mysql-test/t/ctype_eucjpms.test
@@ -494,3 +494,29 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names eucjpms;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+--source include/weight_string_8EA1.inc
+--source include/weight_string_8FA2C3.inc
+
+set collation_connection=eucjpms_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+--source include/weight_string_8EA1.inc
+--source include/weight_string_8FA2C3.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/ctype_euckr.test b/mysql-test/t/ctype_euckr.test
index 3a88e8ac715..155b8ebed00 100644
--- a/mysql-test/t/ctype_euckr.test
+++ b/mysql-test/t/ctype_euckr.test
@@ -174,3 +174,26 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+set names euckr;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+
+set collation_connection=euckr_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
diff --git a/mysql-test/t/ctype_gb2312.test b/mysql-test/t/ctype_gb2312.test
index f092a0a501f..eab79adfe08 100644
--- a/mysql-test/t/ctype_gb2312.test
+++ b/mysql-test/t/ctype_gb2312.test
@@ -124,3 +124,27 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names gb2312;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+
+set collation_connection=gb2312_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/ctype_gbk.test b/mysql-test/t/ctype_gbk.test
index b9e25e97a3c..3b61f16a178 100644
--- a/mysql-test/t/ctype_gbk.test
+++ b/mysql-test/t/ctype_gbk.test
@@ -159,3 +159,30 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names gbk;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+--source include/weight_string_8140.inc
+--source include/weight_string_8EA1.inc
+
+set collation_connection=gbk_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+--source include/weight_string_8140.inc
+--source include/weight_string_8EA1.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/ctype_latin1.test b/mysql-test/t/ctype_latin1.test
index 5d1acf107d7..390325529e7 100644
--- a/mysql-test/t/ctype_latin1.test
+++ b/mysql-test/t/ctype_latin1.test
@@ -161,3 +161,39 @@ EXPLAIN EXTENDED SELECT 'abcdó', _latin1'abcdó', _utf8'abcdó';
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set @@collation_connection=latin1_swedish_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+set @@collation_connection=latin1_bin;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+set @@collation_connection=latin1_general_cs;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+set @@collation_connection=binary;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+set names latin1;
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/ctype_latin1_de.test b/mysql-test/t/ctype_latin1_de.test
index 1efbfa4a3ae..29a52c36db6 100644
--- a/mysql-test/t/ctype_latin1_de.test
+++ b/mysql-test/t/ctype_latin1_de.test
@@ -143,3 +143,40 @@ create table t1 (s1 char(5) character set latin1 collate latin1_german2_ci);
insert into t1 values (0xf6) /* this is o-umlaut */;
select * from t1 where length(s1)=1 and s1='oe';
drop table t1;
+
+--echo End of 5.1 tests
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set @@collation_connection=latin1_german2_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+select hex(weight_string('Ä'));
+select hex(weight_string('ä'));
+select hex(weight_string('Ö'));
+select hex(weight_string('ö'));
+select hex(weight_string('Ü'));
+select hex(weight_string('ü'));
+select hex(weight_string('S'));
+select hex(weight_string('s'));
+select hex(weight_string('ß'));
+select hex(weight_string('ä' as char(1)));
+select hex(weight_string('ö' as char(1)));
+select hex(weight_string('ü' as char(1)));
+select hex(weight_string('ß' as char(1)));
+select hex(weight_string('xä' as char(2)));
+select hex(weight_string('xö' as char(2)));
+select hex(weight_string('xü' as char(2)));
+select hex(weight_string('xß' as char(2)));
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/ctype_latin2.test b/mysql-test/t/ctype_latin2.test
index 676b472e7b8..91def43eb03 100644
--- a/mysql-test/t/ctype_latin2.test
+++ b/mysql-test/t/ctype_latin2.test
@@ -50,3 +50,26 @@ SELECT group_concat(a collate latin2_croatian_ci order by binary a) from t1 grou
drop table t1;
# End of 4.1 tests
+
+--echo End of 5.1 tests
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names latin2;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+
+set collation_connection=latin2_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/ctype_latin2_ch.test b/mysql-test/t/ctype_latin2_ch.test
index 3925d02659d..94d8fde5ec8 100644
--- a/mysql-test/t/ctype_latin2_ch.test
+++ b/mysql-test/t/ctype_latin2_ch.test
@@ -30,3 +30,35 @@ select * from t1 where tt like '%AA%';
# End of 4.1 tests
drop table t1;
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names latin2 collate latin2_czech_cs;
+--source include/ctype_pad_space.inc
+# We can not use ctype_filesort.inc because
+# order of SPACE and TAB is not strict
+#--source include/ctype_filesort.inc
+
+--echo #
+--echo # Note:
+--echo # latin2_czech_cs does not support WEIGHT_STRING in full extent
+--echo #
+--source include/weight_string.inc
+--source include/weight_string_chde.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_l2.inc
+--source include/weight_string_l3.inc
+--source include/weight_string_l4.inc
+--source include/weight_string_l12.inc
+--source include/weight_string_l14.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/ctype_ldml.test b/mysql-test/t/ctype_ldml.test
index bcb16334df4..4442cf9b35a 100644
--- a/mysql-test/t/ctype_ldml.test
+++ b/mysql-test/t/ctype_ldml.test
@@ -182,6 +182,8 @@ SHOW COLLATION LIKE 'utf8_phone_ci';
SET NAMES utf8;
# make sure utf8mb4_test_400_ci is Unicode-4.0.0 based
+SELECT hex(weight_string(_utf8mb4'a' collate utf8mb4_test_400_ci));
+SELECT hex(weight_string(convert(_utf32 0x10002 using utf8mb4) collate utf8mb4_test_400_ci));
SELECT hex(@a:=convert(_utf32 0x10400 using utf8mb4) collate utf8mb4_test_400_ci), hex(lower(@a));
SELECT hex(@a:=convert(_utf32 0x10428 using utf8mb4) collate utf8mb4_test_400_ci), hex(upper(@a));
SELECT hex(@a:=convert(_utf32 0x2C00 using utf8mb4) collate utf8mb4_test_400_ci), hex(lower(@a));
@@ -233,12 +235,12 @@ INSERT INTO t1 VALUES ('lb-fv'),('lb-lv');
INSERT INTO t1 VALUES (_ucs2 0x3106),(_ucs2 0x3110), (_ucs2 0x3111), (_ucs2 0x3112);
INSERT INTO t1 VALUES (_ucs2 0x32A3), (_ucs2 0x3231);
INSERT INTO t1 VALUES (_ucs2 0x84D9), (_ucs2 0x98F5), (_ucs2 0x7CF3), (_ucs2 0x5497);
-SELECT a FROM t1 ORDER BY a, LENGTH(a), BINARY a;
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY a;
--echo #
--echo # WL#5624, the same test with UCS2
--echo #
ALTER TABLE t1 CONVERT TO CHARACTER SET ucs2 COLLATE ucs2_5624_1;
-SELECT a FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
DROP TABLE t1;
--echo #
@@ -266,7 +268,7 @@ SHOW WARNINGS;
SET NAMES utf8 COLLATE utf8_5624_4;
CREATE TABLE t1 AS SELECT REPEAT(' ', 10) AS a LIMIT 0;
INSERT INTO t1 VALUES ('\\'),('u'),('x'),('X');
-SELECT a FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
DROP TABLE t1;
--echo #
@@ -278,7 +280,7 @@ INSERT INTO t1 VALUES (_ucs2 0x09FA), (_ucs2 0x09F8), (_ucs2 0x09F9), (_ucs2 0x0
INSERT INTO t1 VALUES (_ucs2 0x09DC), (_ucs2 0x09A109BC);
INSERT INTO t1 VALUES (_ucs2 0x09A2), (_ucs2 0x09DD), (_ucs2 0x09A209BC);
INSERT INTO t1 VALUES (_ucs2 0x09A3);
-SELECT HEX(CONVERT(a USING ucs2)), HEX(a)
+SELECT HEX(WEIGHT_STRING(a)), HEX(CONVERT(a USING ucs2)), HEX(a)
FROM t1 ORDER BY a, BINARY a;
DROP TABLE t1;
@@ -319,9 +321,9 @@ INSERT INTO t1 VALUES
(_ucs2 0x099509CD0993),(_ucs2 0x099509CB),
(_ucs2 0x099509CD0994),(_ucs2 0x099509CC);
-SELECT HEX(CONVERT(a USING ucs2)), HEX(a)
+SELECT HEX(WEIGHT_STRING(a)), HEX(CONVERT(a USING ucs2)), HEX(a)
FROM t1 ORDER BY a, BINARY(a);
-SELECT
+SELECT HEX(WEIGHT_STRING(a)) as wa,
GROUP_CONCAT(HEX(CONVERT(a USING ucs2)) ORDER BY LENGTH(a), BINARY a)
FROM t1 GROUP BY a ORDER BY a;
DROP TABLE t1;
@@ -341,7 +343,7 @@ INSERT INTO t1 VALUES ('J'),('K'),('L'),('M'),('N'),('O'),('P'),('Q'),('R');
INSERT INTO t1 VALUES ('S'),('T'),('U'),('V'),('W'),('X'),('Y'),('Z');
INSERT INTO t1 VALUES ('AA'),('AAA');
-SELECT a FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
+SELECT a, HEX(WEIGHT_STRING(a)) FROM t1 ORDER BY a, LENGTH(a), BINARY(a);
DROP TABLE t1;
diff --git a/mysql-test/t/ctype_sjis.test b/mysql-test/t/ctype_sjis.test
index f45e6ab9b54..4041af4d6ad 100644
--- a/mysql-test/t/ctype_sjis.test
+++ b/mysql-test/t/ctype_sjis.test
@@ -190,3 +190,27 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names sjis;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_8140.inc
+
+
+set collation_connection=sjis_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_8140.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/ctype_tis620.test b/mysql-test/t/ctype_tis620.test
index c49540de24b..8b373b2a03b 100644
--- a/mysql-test/t/ctype_tis620.test
+++ b/mysql-test/t/ctype_tis620.test
@@ -161,3 +161,29 @@ SET collation_connection='tis620_bin';
-- source include/ctype_like_escape.inc
# End of 4.1 tests
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names tis620;
+set collation_connection=tis620_thai_ci;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+select hex(weight_string(cast(0xE0A1 as char)));
+select hex(weight_string(cast(0xE0A1 as char) as char(1)));
+
+set collation_connection=tis620_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+select hex(weight_string(cast(0xE0A1 as char)));
+select hex(weight_string(cast(0xE0A1 as char) as char(1)));
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/ctype_uca.test b/mysql-test/t/ctype_uca.test
index bded2489f56..04a8abe6350 100644
--- a/mysql-test/t/ctype_uca.test
+++ b/mysql-test/t/ctype_uca.test
@@ -583,6 +583,43 @@ drop table t1;
--echo #
--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set collation_connection=ucs2_unicode_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+set @@collation_connection=utf8_unicode_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+set @@collation_connection=utf8_czech_ci;
+--source include/weight_string_chde.inc
+
+set @@collation_connection=ucs2_czech_ci;
+--source include/weight_string_chde.inc
+
+--echo #
+--echo # Bug#33077 weight of supplementary characters is not 0xfffd
+--echo #
+select hex(weight_string(_utf8mb4 0xF0908080 /* U+10000 */ collate utf8mb4_unicode_ci));
+
+--echo #
+--echo # Bug#53064 garbled data when using utf8_german2_ci collation
+--echo #
+CREATE TABLE t1 (s1 VARCHAR(10) COLLATE utf8_german2_ci);
+INSERT INTO t1 VALUES ('a'),('ae'),('af');
+SELECT s1,hex(s1),hex(weight_string(s1)) FROM t1 ORDER BY s1;
+DROP TABLE t1;
+
+--echo #
--echo # WL#4013 Unicode german2 collation
--echo #
SET collation_connection=utf8_german2_ci;
diff --git a/mysql-test/t/ctype_ucs.test b/mysql-test/t/ctype_ucs.test
index 43e6daea285..268cf3a7adb 100644
--- a/mysql-test/t/ctype_ucs.test
+++ b/mysql-test/t/ctype_ucs.test
@@ -846,6 +846,20 @@ DROP TABLE t1;
--echo #
--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set collation_connection=ucs2_general_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+set collation_connection=ucs2_bin;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+--echo #
--echo # Bug#59145 valgrind warnings for uninitialized values in my_strtoll10_mb2
--echo #
SET NAMES latin1;
diff --git a/mysql-test/t/ctype_ujis.test b/mysql-test/t/ctype_ujis.test
index 4e1ee55e019..ede00a6647e 100644
--- a/mysql-test/t/ctype_ujis.test
+++ b/mysql-test/t/ctype_ujis.test
@@ -1321,3 +1321,30 @@ DROP TABLE t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names ujis;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+--source include/weight_string_8EA1.inc
+--source include/weight_string_8FA2C3.inc
+
+set collation_connection=ujis_bin;
+--source include/weight_string.inc
+--source include/weight_string_l1.inc
+--source include/weight_string_A1A1.inc
+--source include/weight_string_8EA1.inc
+--source include/weight_string_8FA2C3.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/ctype_utf16.test b/mysql-test/t/ctype_utf16.test
index 07e6a68e36f..a05f119ca93 100644
--- a/mysql-test/t/ctype_utf16.test
+++ b/mysql-test/t/ctype_utf16.test
@@ -790,3 +790,29 @@ SELECT 'a' AS id, REPEAT('bla bla', 100) AS body) t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set collation_connection=utf16_general_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+select hex(weight_string(_utf16 0xD800DC00));
+select hex(weight_string(_utf16 0xD800DC01));
+--source include/weight_string_l1.inc
+
+set collation_connection=utf16_bin;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
diff --git a/mysql-test/t/ctype_utf16_uca.test b/mysql-test/t/ctype_utf16_uca.test
index a6295c82dec..22292413b3a 100644
--- a/mysql-test/t/ctype_utf16_uca.test
+++ b/mysql-test/t/ctype_utf16_uca.test
@@ -249,6 +249,7 @@ SET @test_collation='utf16_swedish_ci';
SET collation_connection='utf16_unicode_ci';
-- source include/ctype_filesort.inc
-- source include/ctype_like_escape.inc
+-- source include/ctype_german.inc
--echo End of 4.1 tests
@@ -295,3 +296,27 @@ SET collation_connection=utf16_czech_ci;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set collation_connection=utf16_unicode_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+select hex(weight_string(_utf16 0xD800DC00 collate utf16_unicode_ci));
+select hex(weight_string(_utf16 0xD800DC01 collate utf16_unicode_ci));
+--source include/weight_string_l1.inc
+
+set @@collation_connection=utf16_czech_ci;
+--source include/weight_string_chde.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/ctype_utf16le.test b/mysql-test/t/ctype_utf16le.test
index d9637139774..a8326900847 100644
--- a/mysql-test/t/ctype_utf16le.test
+++ b/mysql-test/t/ctype_utf16le.test
@@ -726,5 +726,21 @@ DROP TABLE t1;
--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+SET NAMES utf8, collation_connection=utf16le_general_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+SELECT HEX(WEIGHT_STRING(_utf16le 0x00D800DC));
+SELECT HEX(WEIGHT_STRING(_utf16le 0x00D801DC));
+--source include/weight_string_l1.inc
+
+SET NAMES utf8, collation_connection=utf16le_bin;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+--echo #
--echo # End of 5.6 tests
--echo #
diff --git a/mysql-test/t/ctype_utf32.test b/mysql-test/t/ctype_utf32.test
index e00ba04fcc4..2fbe452a716 100644
--- a/mysql-test/t/ctype_utf32.test
+++ b/mysql-test/t/ctype_utf32.test
@@ -875,3 +875,30 @@ SELECT '2010-10-10 10:10:10' + INTERVAL GeometryType(GeomFromText('POINT(1 1)'))
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set collation_connection=utf32_general_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+select hex(weight_string(_utf32 0x10000));
+select hex(weight_string(_utf32 0x10001));
+--source include/weight_string_l1.inc
+
+set collation_connection=utf32_bin;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
+
diff --git a/mysql-test/t/ctype_utf32_uca.test b/mysql-test/t/ctype_utf32_uca.test
index 1d79fbe1616..786c9b6a64f 100644
--- a/mysql-test/t/ctype_utf32_uca.test
+++ b/mysql-test/t/ctype_utf32_uca.test
@@ -250,6 +250,7 @@ SET @test_collation='utf32_swedish_ci';
SET collation_connection='utf32_unicode_ci';
-- source include/ctype_filesort.inc
-- source include/ctype_like_escape.inc
+-- source include/ctype_german.inc
--echo End of 4.1 tests
@@ -318,3 +319,26 @@ DROP TABLE t1,t2;
--echo #
--echo # End of 5.5 tests
--echo #
+
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set collation_connection=utf32_unicode_ci;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+select hex(weight_string(_utf32 0x10000 collate utf32_unicode_ci));
+select hex(weight_string(_utf32 0x10001 collate utf32_unicode_ci));
+--source include/weight_string_l1.inc
+
+set @@collation_connection=utf32_czech_ci;
+--source include/weight_string_chde.inc
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test
index 176d7e58c77..aa830894427 100644
--- a/mysql-test/t/ctype_utf8.test
+++ b/mysql-test/t/ctype_utf8.test
@@ -1598,3 +1598,39 @@ SELECT 'a' AS id, REPEAT('bla bla', 100) AS body) t1;
--echo #
--echo # End of 5.5 tests
--echo #
+
+--echo #
+--echo # Start of 5.6 tests
+--echo #
+
+--echo #
+--echo # WL#3664 WEIGHT_STRING
+--echo #
+
+set names utf8;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+set @@collation_connection=utf8_bin;
+--source include/weight_string.inc
+--source include/weight_string_euro.inc
+--source include/weight_string_l1.inc
+
+--echo #
+--echo # Checking strnxfrm() with odd length
+--echo #
+set max_sort_length=5;
+select @@max_sort_length;
+create table t1 (a varchar(128) character set utf8 collate utf8_general_ci);
+insert into t1 values ('a'),('b'),('c');
+select * from t1 order by a;
+alter table t1 modify a varchar(128) character set utf8 collate utf8_bin;
+select * from t1 order by a;
+drop table t1;
+set max_sort_length=default;
+
+--echo #
+--echo # End of 5.6 tests
+--echo #
+
diff --git a/mysql-test/t/func_weight_string.test b/mysql-test/t/func_weight_string.test
new file mode 100644
index 00000000000..6c34ce1e460
--- /dev/null
+++ b/mysql-test/t/func_weight_string.test
@@ -0,0 +1,113 @@
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+set names latin1;
+
+#
+# If it's BLOB or BINARY or VARBINARY, then output = input.
+#
+select hex(weight_string(0x010203));
+
+#
+# "AS CHAR ( int )" causes padding on the right. The pad
+# character is always space, that is, 0x20 or 0x0020.
+# The padding occurs before the conversion to a weight.
+# The value of "int" is the number of characters, not the number of bytes.
+#
+select hex(weight_string('aa' as char(3)));
+
+#
+# The minimum value of 'int' is 1.
+#
+--error 1064
+select hex(weight_string('a' as char(-1)));
+--error 1064
+select hex(weight_string('a' as char(0)));
+select hex(weight_string('a' as char(1)));
+
+#
+# If 'int' is smaller than the length of 'string',
+# truncation will occur with no warning.
+#
+select hex(weight_string('ab' as char(1)));
+
+#
+# If "AS CHAR ( int )" is omitted, there is no padding and no truncation.
+#
+select hex(weight_string('ab'));
+
+#
+# "AS BINARY ( int )" is like CHAR(int) but causes padding of 0x00
+# so one doesn't have to use "CAST(string AS BINARY(int))".
+#
+select hex(weight_string('aa' as binary(3)));
+select hex(weight_string(cast('aa' as binary(3))));
+
+#
+# If and only if one specifies "LEVEL numeric-list" (not "range"),
+# one may follow any "number" with [ASC|DESC][REVERSE]
+#
+--error 1064
+select hex(weight_string('ab' level 1-1 ASC));
+--error 1064
+select hex(weight_string('ab' level 1-1 DESC));
+--error 1064
+select hex(weight_string('ab' level 1-1 REVERSE));
+
+#
+# If one says "DESC", then the weights come out NOTed
+# or negated for that level.
+# If one says "REVERSE", then the weights come out in
+# reverse order for that level, that is, starting with
+# the last character and ending with the first character.
+#
+select hex(weight_string('ab' level 1 ASC));
+select hex(weight_string('ab' level 1 DESC));
+select hex(weight_string('ab' level 1 REVERSE));
+select hex(weight_string('ab' level 1 DESC REVERSE));
+
+#
+# If the result length is less than or equal to the
+# maximum possible length for the VARBINARY data type,
+# then the result data type is VARBINARY. Otherwise
+# the result data type is BLOB.
+#
+create table t1 select weight_string('test') as w;
+show create table t1;
+drop table t1;
+create table t1 select weight_string(repeat('t',66000)) as w;
+show create table t1;
+drop table t1;
+
+#
+# If input is NULL, then output is NULL.
+#
+select weight_string(NULL);
+
+#
+# WEIGHT_STRING and REVERSE will not be a new reserved word.
+#
+select 1 as weight_string, 2 as reverse;
+
+#
+# Check that collation derivation is copied from the argument
+#
+select coercibility(weight_string('test'));
+select coercibility(weight_string('test' collate latin1_swedish_ci));
+
+#
+# Bug#33663 Character sets: weight_string function,
+# varchar column, wrong result
+#
+create table t1 (s1 varchar(5));
+insert into t1 values ('a'),(null);
+select hex(weight_string(s1)) from t1 order by s1;
+drop table t1;
+
+--echo #
+--echo # BUG#11898467 - SERVER CRASHES ON SELECT HEX(WEIGHT_STRING(STR AS [CHAR|BINARY](N))) IF N IS BIG
+--echo #
+SELECT HEX(WEIGHT_STRING('ab' AS CHAR(1000000000000000000)));
+SELECT HEX(WEIGHT_STRING('ab' AS BINARY(1000000000000000000)));
+
diff --git a/mysys/charset.c b/mysys/charset.c
index 0fea3c4c1cf..f9d1286088d 100644
--- a/mysys/charset.c
+++ b/mysys/charset.c
@@ -251,7 +251,8 @@ static int add_collation(struct charset_info_st *cs)
return MY_XML_ERROR;
newcs->caseup_multiply= newcs->casedn_multiply= 1;
-
+ newcs->levels_for_order= 1;
+
if (!strcmp(cs->csname,"ucs2") )
{
#if defined(HAVE_CHARSET_ucs2) && defined(HAVE_UCA_COLLATIONS)
@@ -296,6 +297,7 @@ static int add_collation(struct charset_info_st *cs)
simple_cs_init_functions(newcs);
newcs->mbminlen= 1;
newcs->mbmaxlen= 1;
+ newcs->strxfrm_multiply= 1;
if (simple_cs_is_full(newcs))
{
newcs->state |= MY_CS_LOADED;
diff --git a/sql/field.cc b/sql/field.cc
index 06744541fcc..c4f3db039c4 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -6509,7 +6509,13 @@ int Field_string::cmp(const uchar *a_ptr, const uchar *b_ptr)
void Field_string::sort_string(uchar *to,uint length)
{
uint tmp __attribute__((unused))=
- my_strnxfrm(field_charset, to, length, ptr, field_length);
+ field_charset->coll->strnxfrm(field_charset,
+ to, length,
+ char_length() *
+ field_charset->strxfrm_multiply,
+ ptr, field_length,
+ MY_STRXFRM_PAD_WITH_SPACE |
+ MY_STRXFRM_PAD_TO_MAXLEN);
DBUG_ASSERT(tmp == length);
}
@@ -6966,9 +6972,13 @@ void Field_varstring::sort_string(uchar *to,uint length)
length-= length_bytes;
}
- tot_length= my_strnxfrm(field_charset,
- to, length, ptr + length_bytes,
- tot_length);
+ tot_length= field_charset->coll->strnxfrm(field_charset,
+ to, length,
+ char_length() *
+ field_charset->strxfrm_multiply,
+ ptr + length_bytes, tot_length,
+ MY_STRXFRM_PAD_WITH_SPACE |
+ MY_STRXFRM_PAD_TO_MAXLEN);
DBUG_ASSERT(tot_length == length);
}
@@ -7583,8 +7593,11 @@ void Field_blob::sort_string(uchar *to,uint length)
}
memcpy(&blob, ptr+packlength, sizeof(char*));
- blob_length=my_strnxfrm(field_charset,
- to, length, blob, blob_length);
+ blob_length= field_charset->coll->strnxfrm(field_charset,
+ to, length, length,
+ blob, blob_length,
+ MY_STRXFRM_PAD_WITH_SPACE |
+ MY_STRXFRM_PAD_TO_MAXLEN);
DBUG_ASSERT(blob_length == length);
}
}
diff --git a/sql/filesort.cc b/sql/filesort.cc
index 7cb2306eb7c..8783aa96739 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -932,8 +932,12 @@ static void make_sortkey(register Sort_param *param,
memcpy(param->tmp_buffer,from,length);
from=param->tmp_buffer;
}
- tmp_length= my_strnxfrm(cs,to,sort_field->length,
- (uchar*) from, length);
+ tmp_length= cs->coll->strnxfrm(cs, to, sort_field->length,
+ item->max_char_length() *
+ cs->strxfrm_multiply,
+ (uchar*) from, length,
+ MY_STRXFRM_PAD_WITH_SPACE |
+ MY_STRXFRM_PAD_TO_MAXLEN);
DBUG_ASSERT(tmp_length == sort_field->length);
}
else
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 68237ef4951..68009d6ba84 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -3537,6 +3537,70 @@ String *Item_func_collation::val_str(String *str)
}
+void Item_func_weight_string::fix_length_and_dec()
+{
+ CHARSET_INFO *cs= args[0]->collation.collation;
+ collation.set(&my_charset_bin, args[0]->collation.derivation);
+ flags= my_strxfrm_flag_normalize(flags, cs->levels_for_order);
+ /*
+ Use result_length if it was given explicitly in constructor,
+ otherwise calculate max_length using argument's max_length
+ and "nweights".
+ */
+ max_length= result_length ? result_length :
+ cs->mbmaxlen * MY_MAX(args[0]->max_length, nweights);
+ maybe_null= 1;
+}
+
+
+/* Return a weight_string according to collation */
+String *Item_func_weight_string::val_str(String *str)
+{
+ String *res;
+ CHARSET_INFO *cs= args[0]->collation.collation;
+ uint tmp_length, frm_length;
+ DBUG_ASSERT(fixed == 1);
+
+ if (args[0]->result_type() != STRING_RESULT ||
+ !(res= args[0]->val_str(str)))
+ goto nl;
+
+ /*
+ Use result_length if it was given in constructor
+ explicitly, otherwise calculate result length
+ from argument and "nweights".
+ */
+ tmp_length= result_length ? result_length :
+ cs->coll->strnxfrmlen(cs, cs->mbmaxlen *
+ MY_MAX(res->length(), nweights));
+
+ if(tmp_length > current_thd->variables.max_allowed_packet)
+ {
+ push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
+ ER_WARN_ALLOWED_PACKET_OVERFLOWED,
+ ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(),
+ current_thd->variables.max_allowed_packet);
+ goto nl;
+ }
+
+ if (tmp_value.alloc(tmp_length))
+ goto nl;
+
+ frm_length= cs->coll->strnxfrm(cs,
+ (uchar *) tmp_value.ptr(), tmp_length,
+ nweights ? nweights : tmp_length,
+ (const uchar *) res->ptr(), res->length(),
+ flags);
+ tmp_value.length(frm_length);
+ null_value= 0;
+ return &tmp_value;
+
+nl:
+ null_value= 1;
+ return 0;
+}
+
+
String *Item_func_hex::val_str_ascii(String *str)
{
String *res;
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 9ae0c92673f..6bce7da7d52 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -1024,6 +1024,26 @@ public:
table_map not_null_tables() const { return 0; }
};
+class Item_func_weight_string :public Item_str_func
+{
+ String tmp_value;
+ uint flags;
+ uint nweights;
+ uint result_length;
+public:
+ Item_func_weight_string(Item *a, uint result_length_arg,
+ uint nweights_arg, uint flags_arg)
+ :Item_str_func(a)
+ {
+ nweights= nweights_arg;
+ flags= flags_arg;
+ result_length= result_length_arg;
+ }
+ const char *func_name() const { return "weight_string"; }
+ String *val_str(String *);
+ void fix_length_and_dec();
+};
+
class Item_func_crc32 :public Item_int_func
{
String value;
diff --git a/sql/lex.h b/sql/lex.h
index 470d55876f7..62a579944bb 100644
--- a/sql/lex.h
+++ b/sql/lex.h
@@ -494,6 +494,7 @@ static SYMBOL symbols[] = {
{ "RETURN", SYM(RETURN_SYM)},
{ "RETURNING", SYM(RETURNING_SYM)},
{ "RETURNS", SYM(RETURNS_SYM)},
+ { "REVERSE", SYM(REVERSE_SYM)},
{ "REVOKE", SYM(REVOKE)},
{ "RIGHT", SYM(RIGHT)},
{ "RLIKE", SYM(REGEXP)}, /* Like in mSQL2 */
@@ -647,6 +648,7 @@ static SYMBOL symbols[] = {
{ "WAIT", SYM(WAIT_SYM)},
{ "WARNINGS", SYM(WARNINGS)},
{ "WEEK", SYM(WEEK_SYM)},
+ { "WEIGHT_STRING", SYM(WEIGHT_STRING_SYM)},
{ "WHEN", SYM(WHEN_SYM)},
{ "WHERE", SYM(WHERE)},
{ "WHILE", SYM(WHILE_SYM)},
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 52865bc99de..43d178b7a90 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1438,6 +1438,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%token RETURNING_SYM
%token RETURNS_SYM /* SQL-2003-R */
%token RETURN_SYM /* SQL-2003-R */
+%token REVERSE_SYM
%token REVOKE /* SQL-2003-R */
%token RIGHT /* SQL-2003-R */
%token ROLLBACK_SYM /* SQL-2003-R */
@@ -1595,6 +1596,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%token WAIT_SYM
%token WARNINGS
%token WEEK_SYM
+%token WEIGHT_STRING_SYM
%token WHEN_SYM /* SQL-2003-R */
%token WHERE /* SQL-2003-R */
%token WHILE_SYM
@@ -1686,6 +1688,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%type <ulong_num>
ulong_num real_ulong_num merge_insert_types
+ ws_nweights
+ ws_level_flag_desc ws_level_flag_reverse ws_level_flags
+ opt_ws_levels ws_level_list ws_level_list_item ws_level_number
+ ws_level_range ws_level_list_or_range
%type <ulonglong_number>
ulonglong_num real_ulonglong_num size_number
@@ -6583,6 +6589,74 @@ opt_bin_mod:
| BINARY { Lex->type|= BINCMP_FLAG; }
;
+ws_nweights:
+ '(' real_ulong_num
+ {
+ if ($2 == 0)
+ {
+ my_parse_error(ER(ER_SYNTAX_ERROR));
+ MYSQL_YYABORT;
+ }
+ }
+ ')'
+ { $$= $2; }
+ ;
+
+ws_level_flag_desc:
+ ASC { $$= 0; }
+ | DESC { $$= 1 << MY_STRXFRM_DESC_SHIFT; }
+ ;
+
+ws_level_flag_reverse:
+ REVERSE_SYM { $$= 1 << MY_STRXFRM_REVERSE_SHIFT; } ;
+
+ws_level_flags:
+ /* empty */ { $$= 0; }
+ | ws_level_flag_desc { $$= $1; }
+ | ws_level_flag_desc ws_level_flag_reverse { $$= $1 | $2; }
+ | ws_level_flag_reverse { $$= $1 ; }
+ ;
+
+ws_level_number:
+ real_ulong_num
+ {
+ $$= $1 < 1 ? 1 : ($1 > MY_STRXFRM_NLEVELS ? MY_STRXFRM_NLEVELS : $1);
+ $$--;
+ }
+ ;
+
+ws_level_list_item:
+ ws_level_number ws_level_flags
+ {
+ $$= (1 | $2) << $1;
+ }
+ ;
+
+ws_level_list:
+ ws_level_list_item { $$= $1; }
+ | ws_level_list ',' ws_level_list_item { $$|= $3; }
+ ;
+
+ws_level_range:
+ ws_level_number '-' ws_level_number
+ {
+ uint start= $1;
+ uint end= $3;
+ for ($$= 0; start <= end; start++)
+ $$|= (1 << start);
+ }
+ ;
+
+ws_level_list_or_range:
+ ws_level_list { $$= $1; }
+ | ws_level_range { $$= $1; }
+ ;
+
+opt_ws_levels:
+ /* empty*/ { $$= 0; }
+ | LEVEL_SYM ws_level_list_or_range { $$= $2; }
+ ;
+
opt_primary:
/* empty */
| PRIMARY_SYM
@@ -9667,6 +9741,12 @@ function_call_conflict:
if ($$ == NULL)
MYSQL_YYABORT;
}
+ | REVERSE_SYM '(' expr ')'
+ {
+ $$= new (thd->mem_root) Item_func_reverse($3);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| ROW_COUNT_SYM '(' ')'
{
$$= new (thd->mem_root) Item_func_row_count();
@@ -9698,6 +9778,36 @@ function_call_conflict:
if ($$ == NULL)
MYSQL_YYABORT;
}
+ | WEIGHT_STRING_SYM '(' expr opt_ws_levels ')'
+ {
+ $$= new (thd->mem_root) Item_func_weight_string($3, 0, 0, $4);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ | WEIGHT_STRING_SYM '(' expr AS CHAR_SYM ws_nweights opt_ws_levels ')'
+ {
+ $$= new (thd->mem_root)
+ Item_func_weight_string($3, 0, $6,
+ $7 | MY_STRXFRM_PAD_WITH_SPACE);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ | WEIGHT_STRING_SYM '(' expr AS BINARY ws_nweights ')'
+ {
+ Item *item= new (thd->mem_root) Item_char_typecast($3, $6, &my_charset_bin);
+ if (item == NULL)
+ MYSQL_YYABORT;
+ $$= new (thd->mem_root)
+ Item_func_weight_string(item, 0, $6, MY_STRXFRM_PAD_WITH_SPACE);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
+ | WEIGHT_STRING_SYM '(' expr ',' ulong_num ',' ulong_num ',' ulong_num ')'
+ {
+ $$= new (thd->mem_root) Item_func_weight_string($3, $5, $7, $9);
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ }
| geometry_function
{
#ifdef HAVE_SPATIAL
@@ -14119,6 +14229,7 @@ keyword_sp:
| RESUME_SYM {}
| RETURNED_SQLSTATE_SYM {}
| RETURNS_SYM {}
+ | REVERSE_SYM {}
| ROLLUP_SYM {}
| ROUTINE_SYM {}
| ROWS_SYM {}
@@ -14194,6 +14305,7 @@ keyword_sp:
| WARNINGS {}
| WAIT_SYM {}
| WEEK_SYM {}
+ | WEIGHT_STRING_SYM {}
| WORK_SYM {}
| X509_SYM {}
| XML_SYM {}
diff --git a/strings/ctype-big5.c b/strings/ctype-big5.c
index cf9fc339280..38bdf86c64a 100644
--- a/strings/ctype-big5.c
+++ b/strings/ctype-big5.c
@@ -925,31 +925,35 @@ static int my_strnncollsp_big5(CHARSET_INFO * cs __attribute__((unused)),
}
-static size_t my_strnxfrm_big5(CHARSET_INFO *cs __attribute__((unused)),
- uchar *dest, size_t len,
- const uchar *src, size_t srclen)
+static size_t
+my_strnxfrm_big5(CHARSET_INFO *cs,
+ uchar *dst, size_t dstlen, uint nweights,
+ const uchar *src, size_t srclen, uint flags)
{
- uint16 e;
- size_t dstlen= len;
- uchar *dest_end= dest + dstlen;
-
- len = srclen;
- while (len-- && dest < dest_end)
+ uchar *d0= dst;
+ uchar *de= dst + dstlen;
+ const uchar *se= src + srclen;
+ const uchar *sort_order= cs->sort_order;
+
+ for (; dst < de && src < se && nweights; nweights--)
{
- if ((len > 0) && isbig5code(*src, *(src+1)))
+ if (cs->cset->ismbchar(cs, (const char*) src, (const char*) se))
{
- e = big5strokexfrm((uint16) big5code(*src, *(src+1)));
- *dest++ = big5head(e);
- if (dest < dest_end)
- *dest++ = big5tail(e);
- src +=2;
- len--;
- } else
- *dest++ = sort_order_big5[(uchar) *src++];
+ /*
+ Note, it is safe not to check (src < se)
+ in the code below, because ismbchar() would
+ not return TRUE if src was too short
+ */
+ uint16 e= big5strokexfrm((uint16) big5code(*src, *(src + 1)));
+ *dst++= big5head(e);
+ if (dst < de)
+ *dst++= big5tail(e);
+ src+= 2;
+ }
+ else
+ *dst++= sort_order ? sort_order[*src++] : *src++;
}
- if (dstlen > srclen)
- bfill(dest, dstlen - srclen, ' ');
- return dstlen;
+ return my_strxfrm_pad_desc_and_reverse(cs, d0, dst, de, nweights, flags, 0);
}
#if 0
@@ -6948,6 +6952,7 @@ struct charset_info_st my_charset_big5_chinese_ci=
0xF9D5, /* max_sort_char */
' ', /* pad char */
1, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_big5_handler,
&my_collation_big5_chinese_ci_handler
};
@@ -6980,6 +6985,7 @@ struct charset_info_st my_charset_big5_bin=
0xF9FE, /* max_sort_char */
' ', /* pad char */
1, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_big5_handler,
&my_collation_mb_bin_handler
};
diff --git a/strings/ctype-bin.c b/strings/ctype-bin.c
index 76e8da25fc2..52dae7912af 100644
--- a/strings/ctype-bin.c
+++ b/strings/ctype-bin.c
@@ -409,28 +409,17 @@ int my_wildcmp_bin(CHARSET_INFO *cs,
}
-static size_t my_strnxfrm_bin(CHARSET_INFO *cs __attribute__((unused)),
- uchar *dest, size_t dstlen,
- const uchar *src, size_t srclen)
+static size_t
+my_strnxfrm_8bit_bin(CHARSET_INFO *cs,
+ uchar * dst, size_t dstlen, uint nweights,
+ const uchar *src, size_t srclen, uint flags)
{
- if (dest != src)
- memcpy(dest, src, MY_MIN(dstlen,srclen));
- if (dstlen > srclen)
- bfill(dest + srclen, dstlen - srclen, 0);
- return dstlen;
-}
-
-
-static
-size_t my_strnxfrm_8bit_bin(CHARSET_INFO *cs __attribute__((unused)),
- uchar *dest, size_t dstlen,
- const uchar *src, size_t srclen)
-{
- if (dest != src)
- memcpy(dest, src, MY_MIN(dstlen,srclen));
- if (dstlen > srclen)
- bfill(dest + srclen, dstlen - srclen, ' ');
- return dstlen;
+ set_if_smaller(srclen, dstlen);
+ set_if_smaller(srclen, nweights);
+ if (dst != src)
+ memcpy(dst, src, srclen);
+ return my_strxfrm_pad_desc_and_reverse(cs, dst, dst + srclen, dst + dstlen,
+ nweights - srclen, flags, 0);
}
@@ -516,7 +505,7 @@ static MY_COLLATION_HANDLER my_collation_binary_handler =
NULL, /* init */
my_strnncoll_binary,
my_strnncollsp_binary,
- my_strnxfrm_bin,
+ my_strnxfrm_8bit_bin,
my_strnxfrmlen_simple,
my_like_range_simple,
my_wildcmp_bin,
@@ -586,6 +575,7 @@ struct charset_info_st my_charset_bin =
255, /* max_sort_char */
0, /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_binary_handler
};
diff --git a/strings/ctype-cp932.c b/strings/ctype-cp932.c
index 946cf4253d8..b3d08c5a54c 100644
--- a/strings/ctype-cp932.c
+++ b/strings/ctype-cp932.c
@@ -1794,30 +1794,6 @@ static int my_strnncollsp_cp932(CHARSET_INFO *cs __attribute__((unused)),
}
-
-static size_t my_strnxfrm_cp932(CHARSET_INFO *cs __attribute__((unused)),
- uchar *dest, size_t len,
- const uchar *src, size_t srclen)
-{
- uchar *d_end = dest + len;
- uchar *s_end = (uchar*) src + srclen;
- while (dest < d_end && src < s_end)
- {
- if (ismbchar_cp932(cs,(char*) src, (char*) s_end))
- {
- *dest++ = *src++;
- if (dest < d_end && src < s_end)
- *dest++ = *src++;
- }
- else
- *dest++ = sort_order_cp932[(uchar)*src++];
- }
- if (len > srclen)
- bfill(dest, len - srclen, ' ');
- return len;
-}
-
-
static const uint16 cp932_to_unicode[65536]=
{
0x0000, 0x0001, 0x0002, 0x0003, /* 0000 */
@@ -34785,7 +34761,7 @@ static MY_COLLATION_HANDLER my_collation_ci_handler =
NULL, /* init */
my_strnncoll_cp932,
my_strnncollsp_cp932,
- my_strnxfrm_cp932,
+ my_strnxfrm_mb,
my_strnxfrmlen_simple,
my_like_range_mb,
my_wildcmp_mb, /* wildcmp */
@@ -34855,6 +34831,7 @@ struct charset_info_st my_charset_cp932_japanese_ci=
0xFCFC, /* max_sort_char */
' ', /* pad char */
1, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_ci_handler
};
@@ -34886,6 +34863,7 @@ struct charset_info_st my_charset_cp932_bin=
0xFCFC, /* max_sort_char */
' ', /* pad char */
1, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_mb_bin_handler
};
diff --git a/strings/ctype-czech.c b/strings/ctype-czech.c
index 1418edfecb3..4698521bd16 100644
--- a/strings/ctype-czech.c
+++ b/strings/ctype-czech.c
@@ -166,7 +166,7 @@ static const struct wordvalue doubles[] = {
*/
#define ADD_TO_RESULT(dest, len, totlen, value) \
-if ((totlen) < (len)) { dest[totlen] = value; } (totlen++);
+{ if ((totlen) < (len)) { dest[totlen++]= value; } }
#define IS_END(p, src, len) (((char *)p - (char *)src) >= (len))
#define NEXT_CMP_VALUE(src, p, store, pass, value, len) \
@@ -287,13 +287,26 @@ int my_strnncollsp_czech(CHARSET_INFO * cs,
/*
+ Returns the number of bytes required for strnxfrm().
+*/
+static size_t
+my_strnxfrmlen_czech(CHARSET_INFO *cs
+ __attribute__((unused)), size_t len)
+{
+ return len * 4 + 4;
+}
+
+
+/*
Function strnxfrm, actually strxfrm, with Czech sorting, which expect
the length of the strings being specified
*/
-static size_t my_strnxfrm_czech(CHARSET_INFO *cs __attribute__((unused)),
- uchar *dest, size_t len,
- const uchar *src, size_t srclen)
+static size_t
+my_strnxfrm_czech(CHARSET_INFO *cs __attribute__((unused)),
+ uchar *dest, size_t len,
+ uint nweights_arg __attribute__((unused)),
+ const uchar *src, size_t srclen, uint flags)
{
int value;
const uchar *p, * store;
@@ -301,15 +314,23 @@ static size_t my_strnxfrm_czech(CHARSET_INFO *cs __attribute__((unused)),
size_t totlen = 0;
p = src; store = src;
+ if (!(flags & 0x0F)) /* All levels by default */
+ flags|= 0x0F;
+
do
{
+ int add= (1 << pass) & flags; /* If this level is needed */
NEXT_CMP_VALUE(src, p, store, pass, value, (int)srclen);
- ADD_TO_RESULT(dest, len, totlen, value);
+ if (add)
+ ADD_TO_RESULT(dest, len, totlen, value);
}
while (value);
- if (len > totlen)
- bfill(dest + totlen, len - totlen, ' ');
- return len;
+ if ((flags & MY_STRXFRM_PAD_TO_MAXLEN) && len > totlen)
+ {
+ memset(dest + totlen, ' ', len - totlen);
+ totlen= len;
+ }
+ return totlen;
}
#undef IS_END
@@ -592,7 +613,7 @@ static MY_COLLATION_HANDLER my_collation_latin2_czech_ci_handler =
my_strnncoll_czech,
my_strnncollsp_czech,
my_strnxfrm_czech,
- my_strnxfrmlen_simple,
+ my_strnxfrmlen_czech,
my_like_range_czech,
my_wildcmp_bin,
my_strcasecmp_8bit,
@@ -628,6 +649,7 @@ struct charset_info_st my_charset_latin2_czech_ci =
0, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 4, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_latin2_czech_ci_handler
};
diff --git a/strings/ctype-euc_kr.c b/strings/ctype-euc_kr.c
index 66b8b090241..b7065369258 100644
--- a/strings/ctype-euc_kr.c
+++ b/strings/ctype-euc_kr.c
@@ -9969,7 +9969,7 @@ static MY_COLLATION_HANDLER my_collation_ci_handler =
NULL, /* init */
my_strnncoll_simple, /* strnncoll */
my_strnncollsp_simple,
- my_strnxfrm_simple, /* strnxfrm */
+ my_strnxfrm_mb, /* strnxfrm */
my_strnxfrmlen_simple,
my_like_range_mb, /* like_range */
my_wildcmp_mb, /* wildcmp */
@@ -10038,6 +10038,7 @@ struct charset_info_st my_charset_euckr_korean_ci=
0xFEFE, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_ci_handler
};
@@ -10070,6 +10071,7 @@ struct charset_info_st my_charset_euckr_bin=
0xFEFE, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_mb_bin_handler
};
diff --git a/strings/ctype-eucjpms.c b/strings/ctype-eucjpms.c
index 59a9a43c0f5..d9033a234c4 100644
--- a/strings/ctype-eucjpms.c
+++ b/strings/ctype-eucjpms.c
@@ -67511,7 +67511,7 @@ static MY_COLLATION_HANDLER my_collation_ci_handler =
NULL, /* init */
my_strnncoll_simple,/* strnncoll */
my_strnncollsp_simple,
- my_strnxfrm_simple, /* strnxfrm */
+ my_strnxfrm_mb, /* strnxfrm */
my_strnxfrmlen_simple,
my_like_range_mb, /* like_range */
my_wildcmp_mb, /* wildcmp */
@@ -67581,6 +67581,7 @@ struct charset_info_st my_charset_eucjpms_japanese_ci=
0xFEFE, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_ci_handler
};
@@ -67613,6 +67614,7 @@ struct charset_info_st my_charset_eucjpms_bin=
0xFEFE, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_mb_bin_handler
};
diff --git a/strings/ctype-extra.c b/strings/ctype-extra.c
index addeeba8ba0..c690b6d0c18 100644
--- a/strings/ctype-extra.c
+++ b/strings/ctype-extra.c
@@ -6631,6 +6631,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -6663,6 +6664,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -6695,6 +6697,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -6727,6 +6730,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -6759,6 +6763,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -6791,6 +6796,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -6823,6 +6829,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -6855,6 +6862,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -6887,6 +6895,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -6919,6 +6928,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -6951,6 +6961,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -6983,6 +6994,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7015,6 +7027,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7047,6 +7060,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7079,6 +7093,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7111,6 +7126,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7143,6 +7159,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7175,6 +7192,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7207,6 +7225,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7239,6 +7258,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7271,6 +7291,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7303,6 +7324,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7335,6 +7357,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7367,6 +7390,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7399,6 +7423,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7431,6 +7456,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7463,6 +7489,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7495,6 +7522,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7527,6 +7555,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -7559,6 +7588,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7591,6 +7621,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7623,6 +7654,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7655,6 +7687,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -7687,6 +7720,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7719,6 +7753,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7751,6 +7786,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -7783,6 +7819,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7815,6 +7852,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -7847,6 +7885,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -7879,6 +7918,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -7911,6 +7951,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -7943,6 +7984,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -7975,6 +8017,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -8007,6 +8050,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -8039,6 +8083,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -8071,6 +8116,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -8103,6 +8149,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -8135,6 +8182,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -8167,6 +8215,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -8199,6 +8248,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -8231,6 +8281,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -8263,6 +8314,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -8295,6 +8347,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -8327,6 +8380,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -8359,6 +8413,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -8391,6 +8446,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -8423,6 +8479,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -8455,6 +8512,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -8487,6 +8545,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_bin_handler,
}
@@ -8519,6 +8578,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -8551,6 +8611,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
@@ -8582,6 +8643,7 @@ struct charset_info_st compiled_charsets[] = {
255, /* max_sort_char */
' ', /* pad_char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_8bit_simple_ci_handler,
}
diff --git a/strings/ctype-gb2312.c b/strings/ctype-gb2312.c
index 74be52a5c6d..0399660d311 100644
--- a/strings/ctype-gb2312.c
+++ b/strings/ctype-gb2312.c
@@ -6372,7 +6372,7 @@ static MY_COLLATION_HANDLER my_collation_ci_handler =
NULL, /* init */
my_strnncoll_simple, /* strnncoll */
my_strnncollsp_simple,
- my_strnxfrm_simple, /* strnxfrm */
+ my_strnxfrm_mb, /* strnxfrm */
my_strnxfrmlen_simple,
my_like_range_mb, /* like_range */
my_wildcmp_mb, /* wildcmp */
@@ -6441,6 +6441,7 @@ struct charset_info_st my_charset_gb2312_chinese_ci=
0xF7FE, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_ci_handler
};
@@ -6472,6 +6473,7 @@ struct charset_info_st my_charset_gb2312_bin=
0xF7FE, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_mb_bin_handler
};
diff --git a/strings/ctype-gbk.c b/strings/ctype-gbk.c
index dd617fd8548..f1b46ca4e6c 100644
--- a/strings/ctype-gbk.c
+++ b/strings/ctype-gbk.c
@@ -3525,31 +3525,35 @@ static int my_strnncollsp_gbk(CHARSET_INFO * cs __attribute__((unused)),
}
-static size_t my_strnxfrm_gbk(CHARSET_INFO *cs __attribute__((unused)),
- uchar *dest, size_t len,
- const uchar *src, size_t srclen)
+static size_t
+my_strnxfrm_gbk(CHARSET_INFO *cs,
+ uchar *dst, size_t dstlen, uint nweights,
+ const uchar *src, size_t srclen, uint flags)
{
- uint16 e;
- size_t dstlen= len;
- uchar *dest_end= dest + dstlen;
+ uchar *d0= dst;
+ uchar *de= dst + dstlen;
+ const uchar *se= src + srclen;
+ const uchar *sort_order= cs->sort_order;
- len = srclen;
- while (len-- && dest < dest_end)
+ for (; dst < de && src < se && nweights; nweights--)
{
- if ((len > 0) && isgbkcode(*src, *(src+1)))
+ if (cs->cset->ismbchar(cs, (const char*) src, (const char*) se))
{
- e = gbksortorder((uint16) gbkcode(*src, *(src+1)));
- *dest++ = gbkhead(e);
- if (dest < dest_end)
- *dest++ = gbktail(e);
- src+=2;
- len--;
- } else
- *dest++ = sort_order_gbk[(uchar) *src++];
+ /*
+ Note, it is safe not to check (src < se)
+ in the code below, because ismbchar() would
+ not return TRUE if src was too short
+ */
+ uint16 e= gbksortorder((uint16) gbkcode(*src, *(src + 1)));
+ *dst++= gbkhead(e);
+ if (dst < de)
+ *dst++= gbktail(e);
+ src+= 2;
+ }
+ else
+ *dst++= sort_order ? sort_order[*src++] : *src++;
}
- if (dstlen > srclen)
- bfill(dest, dstlen - srclen, ' ');
- return dstlen;
+ return my_strxfrm_pad_desc_and_reverse(cs, d0, dst, de, nweights, flags, 0);
}
@@ -10833,6 +10837,7 @@ struct charset_info_st my_charset_gbk_chinese_ci=
0xA967, /* max_sort_char */
' ', /* pad char */
1, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_ci_handler
};
@@ -10864,6 +10869,7 @@ struct charset_info_st my_charset_gbk_bin=
0xFEFE, /* max_sort_char */
' ', /* pad char */
1, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_mb_bin_handler
};
diff --git a/strings/ctype-latin1.c b/strings/ctype-latin1.c
index 759997dae2d..2c84f86fad0 100644
--- a/strings/ctype-latin1.c
+++ b/strings/ctype-latin1.c
@@ -452,6 +452,7 @@ struct charset_info_st my_charset_latin1=
255, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_8bit_simple_ci_handler
};
@@ -663,22 +664,25 @@ static int my_strnncollsp_latin1_de(CHARSET_INFO *cs __attribute__((unused)),
}
-static size_t my_strnxfrm_latin1_de(CHARSET_INFO *cs __attribute__((unused)),
- uchar *dest, size_t len,
- const uchar *src, size_t srclen)
+static size_t
+my_strnxfrm_latin1_de(CHARSET_INFO *cs,
+ uchar *dst, size_t dstlen, uint nweights,
+ const uchar* src, size_t srclen, uint flags)
{
- const uchar *de = dest + len;
- const uchar *se = src + srclen;
- for ( ; src < se && dest < de ; src++)
+ uchar *de= dst + dstlen;
+ const uchar *se= src + srclen;
+ uchar *d0= dst;
+ for ( ; src < se && dst < de && nweights; src++, nweights--)
{
- uchar chr=combo1map[*src];
- *dest++=chr;
- if ((chr=combo2map[*src]) && dest < de)
- *dest++=chr;
+ uchar chr= combo1map[*src];
+ *dst++= chr;
+ if ((chr= combo2map[*src]) && dst < de && nweights > 1)
+ {
+ *dst++= chr;
+ nweights--;
+ }
}
- if (dest < de)
- bfill(dest, de - dest, ' ');
- return (int) len;
+ return my_strxfrm_pad_desc_and_reverse(cs, d0, dst, de, nweights, flags, 0);
}
@@ -750,6 +754,7 @@ struct charset_info_st my_charset_latin1_german2_ci=
247, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_german2_ci_handler
};
@@ -782,6 +787,7 @@ struct charset_info_st my_charset_latin1_bin=
255, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_8bit_bin_handler
};
diff --git a/strings/ctype-mb.c b/strings/ctype-mb.c
index c5c8fd92842..4c3256e2db8 100644
--- a/strings/ctype-mb.c
+++ b/strings/ctype-mb.c
@@ -565,15 +565,106 @@ my_strnncollsp_mb_bin(CHARSET_INFO * cs __attribute__((unused)),
}
-static size_t my_strnxfrm_mb_bin(CHARSET_INFO *cs __attribute__((unused)),
- uchar *dest, size_t dstlen,
- const uchar *src, size_t srclen)
+/*
+ Copy one non-ascii character.
+ "dst" must have enough room for the character.
+ Note, we don't use sort_order[] in this macros.
+ This is correct even for case insensitive collations:
+ - basic Latin letters are processed outside this macros;
+ - for other characters sort_order[x] is equal to x.
+*/
+#define my_strnxfrm_mb_non_ascii_char(cs, dst, src, se) \
+{ \
+ switch (cs->cset->ismbchar(cs, (const char*) src, (const char*) se)) { \
+ case 4: \
+ *dst++= *src++; \
+ /* fall through */ \
+ case 3: \
+ *dst++= *src++; \
+ /* fall through */ \
+ case 2: \
+ *dst++= *src++; \
+ /* fall through */ \
+ case 0: \
+ *dst++= *src++; /* byte in range 0x80..0xFF which is not MB head */ \
+ } \
+}
+
+
+/*
+ For character sets with two or three byte multi-byte
+ characters having multibyte weights *equal* to their codes:
+ cp932, euckr, gb2312, sjis, eucjpms, ujis.
+*/
+size_t
+my_strnxfrm_mb(CHARSET_INFO *cs,
+ uchar *dst, size_t dstlen, uint nweights,
+ const uchar *src, size_t srclen, uint flags)
{
- if (dest != src)
- memcpy(dest, src, MY_MIN(dstlen, srclen));
- if (dstlen > srclen)
- bfill(dest + srclen, dstlen - srclen, ' ');
- return dstlen;
+ uchar *d0= dst;
+ uchar *de= dst + dstlen;
+ const uchar *se= src + srclen;
+ const uchar *sort_order= cs->sort_order;
+
+ DBUG_ASSERT(cs->mbmaxlen <= 4);
+
+ /*
+ If "srclen" is smaller than both "dstlen" and "nweights"
+ then we can run a simplified loop -
+ without checking "nweights" and "de".
+ */
+ if (dstlen >= srclen && nweights >= srclen)
+ {
+ if (sort_order)
+ {
+ /* Optimized version for a case insensitive collation */
+ for (; src < se; nweights--)
+ {
+ if (*src < 128) /* quickly catch ASCII characters */
+ *dst++= sort_order[*src++];
+ else
+ my_strnxfrm_mb_non_ascii_char(cs, dst, src, se);
+ }
+ }
+ else
+ {
+ /* Optimized version for a case sensitive collation (no sort_order) */
+ for (; src < se; nweights--)
+ {
+ if (*src < 128) /* quickly catch ASCII characters */
+ *dst++= *src++;
+ else
+ my_strnxfrm_mb_non_ascii_char(cs, dst, src, se);
+ }
+ }
+ goto pad;
+ }
+
+ /*
+ A thourough loop, checking all possible limits:
+ "se", "nweights" and "de".
+ */
+ for (; src < se && nweights && dst < de; nweights--)
+ {
+ int chlen;
+ if (*src < 128 ||
+ !(chlen= cs->cset->ismbchar(cs, (const char*) src, (const char*) se)))
+ {
+ /* Single byte character */
+ *dst++= sort_order ? sort_order[*src++] : *src++;
+ }
+ else
+ {
+ /* Multi-byte character */
+ int len= (dst + chlen <= de) ? chlen : de - dst;
+ memcpy(dst, src, len);
+ dst+= len;
+ src+= len;
+ }
+ }
+
+pad:
+ return my_strxfrm_pad_desc_and_reverse(cs, d0, dst, de, nweights, flags, 0);
}
@@ -1381,7 +1472,7 @@ MY_COLLATION_HANDLER my_collation_mb_bin_handler =
NULL, /* init */
my_strnncoll_mb_bin,
my_strnncollsp_mb_bin,
- my_strnxfrm_mb_bin,
+ my_strnxfrm_mb,
my_strnxfrmlen_simple,
my_like_range_mb,
my_wildcmp_mb_bin,
diff --git a/strings/ctype-simple.c b/strings/ctype-simple.c
index 91a9df9d50b..7a06570d5b5 100644
--- a/strings/ctype-simple.c
+++ b/strings/ctype-simple.c
@@ -73,27 +73,28 @@ size_t my_strnxfrmlen_simple(CHARSET_INFO *cs, size_t len)
size_t my_strnxfrm_simple(CHARSET_INFO * cs,
- uchar *dest, size_t len,
- const uchar *src, size_t srclen)
+ uchar *dst, size_t dstlen, uint nweights,
+ const uchar *src, size_t srclen, uint flags)
{
const uchar *map= cs->sort_order;
- size_t dstlen= len;
- set_if_smaller(len, srclen);
- if (dest != src)
+ uchar *d0= dst;
+ uint frmlen;
+ if ((frmlen= MY_MIN(dstlen, nweights)) > srclen)
+ frmlen= srclen;
+ if (dst != src)
{
const uchar *end;
- for ( end=src+len; src < end ; )
- *dest++= map[*src++];
+ for (end= src + frmlen; src < end;)
+ *dst++= map[*src++];
}
else
{
const uchar *end;
- for ( end=dest+len; dest < end ; dest++)
- *dest= (char) map[(uchar) *dest];
+ for (end= dst + frmlen; dst < end; dst++)
+ *dst= map[(uchar) *dst];
}
- if (dstlen > len)
- bfill(dest, dstlen - len, ' ');
- return dstlen;
+ return my_strxfrm_pad_desc_and_reverse(cs, d0, dst, d0 + dstlen,
+ nweights - frmlen, flags, 0);
}
@@ -1684,6 +1685,145 @@ my_bool my_propagate_complex(CHARSET_INFO *cs __attribute__((unused)),
}
+/*
+ Normalize strxfrm flags
+
+ SYNOPSIS:
+ my_strxfrm_flag_normalize()
+ flags - non-normalized flags
+ nlevels - number of levels
+
+ NOTES:
+ If levels are omitted, then 1-maximum is assumed.
+ If any level number is greater than the maximum,
+ it is treated as the maximum.
+
+ RETURN
+ normalized flags
+*/
+
+uint my_strxfrm_flag_normalize(uint flags, uint maximum)
+{
+ DBUG_ASSERT(maximum >= 1 && maximum <= MY_STRXFRM_NLEVELS);
+
+ /* If levels are omitted, then 1-maximum is assumed*/
+ if (!(flags & MY_STRXFRM_LEVEL_ALL))
+ {
+ static uint def_level_flags[]= {0, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F };
+ uint flag_pad= flags &
+ (MY_STRXFRM_PAD_WITH_SPACE | MY_STRXFRM_PAD_TO_MAXLEN);
+ flags= def_level_flags[maximum] | flag_pad;
+ }
+ else
+ {
+ uint i;
+ uint flag_lev= flags & MY_STRXFRM_LEVEL_ALL;
+ uint flag_dsc= (flags >> MY_STRXFRM_DESC_SHIFT) & MY_STRXFRM_LEVEL_ALL;
+ uint flag_rev= (flags >> MY_STRXFRM_REVERSE_SHIFT) & MY_STRXFRM_LEVEL_ALL;
+ uint flag_pad= flags &
+ (MY_STRXFRM_PAD_WITH_SPACE | MY_STRXFRM_PAD_TO_MAXLEN);
+
+ /*
+ If any level number is greater than the maximum,
+ it is treated as the maximum.
+ */
+ for (maximum--, flags= 0, i= 0; i < MY_STRXFRM_NLEVELS; i++)
+ {
+ uint src_bit= 1 << i;
+ if (flag_lev & src_bit)
+ {
+ uint dst_bit= 1 << MY_MIN(i, maximum);
+ flags|= dst_bit;
+ flags|= (flag_dsc & dst_bit) << MY_STRXFRM_DESC_SHIFT;
+ flags|= (flag_rev & dst_bit) << MY_STRXFRM_REVERSE_SHIFT;
+ }
+ }
+ flags|= flag_pad;
+ }
+
+ return flags;
+}
+
+
+/*
+ Apply DESC and REVERSE collation rules.
+
+ SYNOPSIS:
+ my_strxfrm_desc_and_reverse()
+ str - pointer to string
+ strend - end of string
+ flags - flags
+ level - which level, starting from 0.
+
+ NOTES:
+ Apply DESC or REVERSE or both flags.
+
+ If DESC flag is given, then the weights
+ come out NOTed or negated for that level.
+
+ If REVERSE flags is given, then the weights come out in
+ reverse order for that level, that is, starting with
+ the last character and ending with the first character.
+
+ If nether DESC nor REVERSE flags are give,
+ the string is not changed.
+
+*/
+void
+my_strxfrm_desc_and_reverse(uchar *str, uchar *strend,
+ uint flags, uint level)
+{
+ if (flags & (MY_STRXFRM_DESC_LEVEL1 << level))
+ {
+ if (flags & (MY_STRXFRM_REVERSE_LEVEL1 << level))
+ {
+ for (strend--; str <= strend;)
+ {
+ uchar tmp= *str;
+ *str++= ~*strend;
+ *strend--= ~tmp;
+ }
+ }
+ else
+ {
+ for (; str < strend; str++)
+ *str= ~*str;
+ }
+ }
+ else if (flags & (MY_STRXFRM_REVERSE_LEVEL1 << level))
+ {
+ for (strend--; str < strend;)
+ {
+ uchar tmp= *str;
+ *str++= *strend;
+ *strend--= tmp;
+ }
+ }
+}
+
+
+size_t
+my_strxfrm_pad_desc_and_reverse(CHARSET_INFO *cs,
+ uchar *str, uchar *frmend, uchar *strend,
+ uint nweights, uint flags, uint level)
+{
+ if (nweights && frmend < strend && (flags & MY_STRXFRM_PAD_WITH_SPACE))
+ {
+ uint fill_length= MY_MIN((uint) (strend - frmend), nweights * cs->mbminlen);
+ cs->cset->fill(cs, (char*) frmend, fill_length, cs->pad_char);
+ frmend+= fill_length;
+ }
+ my_strxfrm_desc_and_reverse(str, frmend, flags, level);
+ if ((flags & MY_STRXFRM_PAD_TO_MAXLEN) && frmend < strend)
+ {
+ uint fill_length= strend - frmend;
+ cs->cset->fill(cs, (char*) frmend, fill_length, cs->pad_char);
+ frmend= strend;
+ }
+ return frmend - str;
+}
+
+
MY_CHARSET_HANDLER my_charset_8bit_handler=
{
my_cset_init_8bit,
diff --git a/strings/ctype-sjis.c b/strings/ctype-sjis.c
index 2c3d2b34dab..dce9e5ad37f 100644
--- a/strings/ctype-sjis.c
+++ b/strings/ctype-sjis.c
@@ -1163,29 +1163,6 @@ static int my_strnncollsp_sjis(CHARSET_INFO *cs __attribute__((unused)),
-static size_t my_strnxfrm_sjis(CHARSET_INFO *cs __attribute__((unused)),
- uchar *dest, size_t len,
- const uchar *src, size_t srclen)
-{
- uchar *d_end = dest + len;
- uchar *s_end = (uchar*) src + srclen;
- while (dest < d_end && src < s_end)
- {
- if (ismbchar_sjis(cs,(char*) src, (char*) s_end))
- {
- *dest++ = *src++;
- if (dest < d_end && src < s_end)
- *dest++ = *src++;
- }
- else
- *dest++ = sort_order_sjis[(uchar)*src++];
- }
- if (len > srclen)
- bfill(dest, len - srclen, ' ');
- return len;
-}
-
-
/* SJIS->Unicode conversion table */
static uint16 sjis_to_unicode[65536]=
{
@@ -34156,7 +34133,7 @@ static MY_COLLATION_HANDLER my_collation_ci_handler =
NULL, /* init */
my_strnncoll_sjis,
my_strnncollsp_sjis,
- my_strnxfrm_sjis,
+ my_strnxfrm_mb,
my_strnxfrmlen_simple,
my_like_range_mb,
my_wildcmp_mb, /* wildcmp */
@@ -34226,6 +34203,7 @@ struct charset_info_st my_charset_sjis_japanese_ci=
0xFCFC, /* max_sort_char */
' ', /* pad char */
1, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_ci_handler
};
@@ -34257,6 +34235,7 @@ struct charset_info_st my_charset_sjis_bin=
0xFCFC, /* max_sort_char */
' ', /* pad char */
1, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_mb_bin_handler
};
diff --git a/strings/ctype-tis620.c b/strings/ctype-tis620.c
index d0b4f9b8862..c2ed01a0603 100644
--- a/strings/ctype-tis620.c
+++ b/strings/ctype-tis620.c
@@ -617,18 +617,26 @@ ret:
Ret: Conveted string size
*/
-static
-size_t my_strnxfrm_tis620(CHARSET_INFO *cs __attribute__((unused)),
- uchar *dest, size_t len,
- const uchar *src, size_t srclen)
+static size_t
+my_strnxfrm_tis620(const CHARSET_INFO *cs,
+ uchar *dst, size_t dstlen, uint nweights,
+ const uchar *src, size_t srclen, uint flags)
{
- size_t dstlen= len;
- len= (size_t) (strmake((char*) dest, (char*) src, MY_MIN(len, srclen)) -
- (char*) dest);
- len= thai2sortable(dest, len);
- if (dstlen > len)
- bfill(dest + len, dstlen - len, ' ');
- return dstlen;
+ size_t len, dstlen0= dstlen;
+ len= (uint) (strmake((char*) dst, (char*) src, MY_MIN(dstlen, srclen)) -
+ (char*) dst);
+ len= thai2sortable(dst, len);
+ set_if_smaller(dstlen, nweights);
+ set_if_smaller(len, dstlen);
+ len= my_strxfrm_pad_desc_and_reverse(cs, dst, dst + len, dst + dstlen,
+ dstlen - len, flags, 0);
+ if ((flags & MY_STRXFRM_PAD_TO_MAXLEN) && len < dstlen0)
+ {
+ uint fill_length= dstlen0 - len;
+ cs->cset->fill(cs, (char*) dst + len, fill_length, cs->pad_char);
+ len= dstlen0;
+ }
+ return len;
}
@@ -909,6 +917,7 @@ struct charset_info_st my_charset_tis620_thai_ci=
255, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_ci_handler
};
@@ -940,6 +949,7 @@ struct charset_info_st my_charset_tis620_bin=
255, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_8bit_bin_handler
};
diff --git a/strings/ctype-uca.c b/strings/ctype-uca.c
index 5d52cb7e517..6eb68385832 100644
--- a/strings/ctype-uca.c
+++ b/strings/ctype-uca.c
@@ -7636,33 +7636,49 @@ static void my_hash_sort_uca(CHARSET_INFO *cs,
Number of bytes that have been written into the binary image.
*/
-static size_t my_strnxfrm_uca(CHARSET_INFO *cs,
- my_uca_scanner_handler *scanner_handler,
- uchar *dst, size_t dstlen,
- const uchar *src, size_t srclen)
+
+static size_t
+my_strnxfrm_uca(CHARSET_INFO *cs,
+ my_uca_scanner_handler *scanner_handler,
+ uchar *dst, size_t dstlen, uint nweights,
+ const uchar *src, size_t srclen, uint flags)
{
- uchar *de= dst + (dstlen & (size_t) ~1); /* add even length for easier code */
+ uchar *d0= dst;
+ uchar *de= dst + dstlen;
int s_res;
my_uca_scanner scanner;
scanner_handler->init(&scanner, cs, &cs->uca->level[0], src, srclen);
- while (dst < de && (s_res= scanner_handler->next(&scanner)) >0)
+ for (; dst < de && nweights &&
+ (s_res= scanner_handler->next(&scanner)) > 0 ; nweights--)
{
- dst[0]= s_res >> 8;
- dst[1]= s_res & 0xFF;
- dst+= 2;
+ *dst++= s_res >> 8;
+ if (dst < de)
+ *dst++= s_res & 0xFF;
}
- s_res= my_space_weight(cs);
- while (dst < de)
+
+ if (dst < de && nweights && (flags & MY_STRXFRM_PAD_WITH_SPACE))
{
- dst[0]= s_res >> 8;
- dst[1]= s_res & 0xFF;
- dst+= 2;
+ uint space_count= MY_MIN((uint) (de - dst) / 2, nweights);
+ s_res= my_space_weight(cs);
+ for (; space_count ; space_count--)
+ {
+ *dst++= s_res >> 8;
+ *dst++= s_res & 0xFF;
+ }
}
- if (dstlen & 1) /* if odd number then fill the last char */
- *dst= '\0';
-
- return dstlen;
+ my_strxfrm_desc_and_reverse(d0, dst, flags, 0);
+ if ((flags & MY_STRXFRM_PAD_TO_MAXLEN) && dst < de)
+ {
+ s_res= my_space_weight(cs);
+ for ( ; dst < de; )
+ {
+ *dst++= s_res >> 8;
+ if (dst < de)
+ *dst++= s_res & 0xFF;
+ }
+ }
+ return dst - d0;
}
@@ -9461,11 +9477,11 @@ static void my_hash_sort_any_uca(CHARSET_INFO *cs,
}
static size_t my_strnxfrm_any_uca(CHARSET_INFO *cs,
- uchar *dst, size_t dstlen,
- const uchar *src, size_t srclen)
+ uchar *dst, size_t dstlen, uint nweights,
+ const uchar *src, size_t srclen, uint flags)
{
return my_strnxfrm_uca(cs, &my_any_uca_scanner_handler,
- dst, dstlen, src, srclen);
+ dst, dstlen, nweights, src, srclen, flags);
}
@@ -9500,11 +9516,11 @@ static void my_hash_sort_ucs2_uca(CHARSET_INFO *cs,
}
static size_t my_strnxfrm_ucs2_uca(CHARSET_INFO *cs,
- uchar *dst, size_t dstlen,
- const uchar *src, size_t srclen)
+ uchar *dst, size_t dstlen, uint nweights,
+ const uchar *src, size_t srclen, uint flags)
{
return my_strnxfrm_uca(cs, &my_any_uca_scanner_handler,
- dst, dstlen, src, srclen);
+ dst, dstlen, nweights, src, srclen, flags);
}
MY_COLLATION_HANDLER my_collation_ucs2_uca_handler =
@@ -9549,6 +9565,7 @@ struct charset_info_st my_charset_ucs2_unicode_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -9580,6 +9597,7 @@ struct charset_info_st my_charset_ucs2_icelandic_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -9611,6 +9629,7 @@ struct charset_info_st my_charset_ucs2_latvian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -9642,6 +9661,7 @@ struct charset_info_st my_charset_ucs2_romanian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -9673,6 +9693,7 @@ struct charset_info_st my_charset_ucs2_slovenian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -9704,6 +9725,7 @@ struct charset_info_st my_charset_ucs2_polish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -9735,6 +9757,7 @@ struct charset_info_st my_charset_ucs2_estonian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -9766,6 +9789,7 @@ struct charset_info_st my_charset_ucs2_spanish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -9797,6 +9821,7 @@ struct charset_info_st my_charset_ucs2_swedish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -9828,6 +9853,7 @@ struct charset_info_st my_charset_ucs2_turkish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -9859,6 +9885,7 @@ struct charset_info_st my_charset_ucs2_czech_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -9891,6 +9918,7 @@ struct charset_info_st my_charset_ucs2_danish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -9922,6 +9950,7 @@ struct charset_info_st my_charset_ucs2_lithuanian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -9953,6 +9982,7 @@ struct charset_info_st my_charset_ucs2_slovak_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -9984,6 +10014,7 @@ struct charset_info_st my_charset_ucs2_spanish2_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -10016,6 +10047,7 @@ struct charset_info_st my_charset_ucs2_roman_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -10048,6 +10080,7 @@ struct charset_info_st my_charset_ucs2_persian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -10080,6 +10113,7 @@ struct charset_info_st my_charset_ucs2_esperanto_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -10112,6 +10146,7 @@ struct charset_info_st my_charset_ucs2_hungarian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -10143,6 +10178,7 @@ struct charset_info_st my_charset_ucs2_sinhala_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -10176,6 +10212,7 @@ struct charset_info_st my_charset_ucs2_german2_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -10207,6 +10244,7 @@ struct charset_info_st my_charset_ucs2_croatian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_uca_handler
};
@@ -10288,6 +10326,7 @@ struct charset_info_st my_charset_utf8_unicode_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10320,6 +10359,7 @@ struct charset_info_st my_charset_utf8_icelandic_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10351,6 +10391,7 @@ struct charset_info_st my_charset_utf8_latvian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10382,6 +10423,7 @@ struct charset_info_st my_charset_utf8_romanian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10413,6 +10455,7 @@ struct charset_info_st my_charset_utf8_slovenian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10444,6 +10487,7 @@ struct charset_info_st my_charset_utf8_polish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10475,6 +10519,7 @@ struct charset_info_st my_charset_utf8_estonian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10506,6 +10551,7 @@ struct charset_info_st my_charset_utf8_spanish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10537,6 +10583,7 @@ struct charset_info_st my_charset_utf8_swedish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10568,6 +10615,7 @@ struct charset_info_st my_charset_utf8_turkish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10599,6 +10647,7 @@ struct charset_info_st my_charset_utf8_czech_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10631,6 +10680,7 @@ struct charset_info_st my_charset_utf8_danish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10662,6 +10712,7 @@ struct charset_info_st my_charset_utf8_lithuanian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10693,6 +10744,7 @@ struct charset_info_st my_charset_utf8_slovak_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10724,6 +10776,7 @@ struct charset_info_st my_charset_utf8_spanish2_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10755,6 +10808,7 @@ struct charset_info_st my_charset_utf8_roman_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10786,6 +10840,7 @@ struct charset_info_st my_charset_utf8_persian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10817,6 +10872,7 @@ struct charset_info_st my_charset_utf8_esperanto_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10848,6 +10904,7 @@ struct charset_info_st my_charset_utf8_hungarian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10879,6 +10936,7 @@ struct charset_info_st my_charset_utf8_sinhala_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10911,6 +10969,7 @@ struct charset_info_st my_charset_utf8_german2_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10942,6 +11001,7 @@ struct charset_info_st my_charset_utf8_croatian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_any_uca_handler
};
@@ -10983,6 +11043,7 @@ struct charset_info_st my_charset_utf8mb4_unicode_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11015,6 +11076,7 @@ struct charset_info_st my_charset_utf8mb4_icelandic_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11046,6 +11108,7 @@ struct charset_info_st my_charset_utf8mb4_latvian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11077,6 +11140,7 @@ struct charset_info_st my_charset_utf8mb4_romanian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11108,6 +11172,7 @@ struct charset_info_st my_charset_utf8mb4_slovenian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11139,6 +11204,7 @@ struct charset_info_st my_charset_utf8mb4_polish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11170,6 +11236,7 @@ struct charset_info_st my_charset_utf8mb4_estonian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11201,6 +11268,7 @@ struct charset_info_st my_charset_utf8mb4_spanish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11232,6 +11300,7 @@ struct charset_info_st my_charset_utf8mb4_swedish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11263,6 +11332,7 @@ struct charset_info_st my_charset_utf8mb4_turkish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11294,6 +11364,7 @@ struct charset_info_st my_charset_utf8mb4_czech_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11326,6 +11397,7 @@ struct charset_info_st my_charset_utf8mb4_danish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11357,6 +11429,7 @@ struct charset_info_st my_charset_utf8mb4_lithuanian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11388,6 +11461,7 @@ struct charset_info_st my_charset_utf8mb4_slovak_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11419,6 +11493,7 @@ struct charset_info_st my_charset_utf8mb4_spanish2_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11450,6 +11525,7 @@ struct charset_info_st my_charset_utf8mb4_roman_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11481,6 +11557,7 @@ struct charset_info_st my_charset_utf8mb4_persian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11512,6 +11589,7 @@ struct charset_info_st my_charset_utf8mb4_esperanto_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11543,6 +11621,7 @@ struct charset_info_st my_charset_utf8mb4_hungarian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11574,6 +11653,7 @@ struct charset_info_st my_charset_utf8mb4_sinhala_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11605,6 +11685,7 @@ struct charset_info_st my_charset_utf8mb4_german2_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11636,6 +11717,7 @@ struct charset_info_st my_charset_utf8mb4_croatian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_any_uca_handler
};
@@ -11691,6 +11773,7 @@ struct charset_info_st my_charset_utf32_unicode_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -11723,6 +11806,7 @@ struct charset_info_st my_charset_utf32_icelandic_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -11754,6 +11838,7 @@ struct charset_info_st my_charset_utf32_latvian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -11785,6 +11870,7 @@ struct charset_info_st my_charset_utf32_romanian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -11816,6 +11902,7 @@ struct charset_info_st my_charset_utf32_slovenian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -11847,6 +11934,7 @@ struct charset_info_st my_charset_utf32_polish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -11878,6 +11966,7 @@ struct charset_info_st my_charset_utf32_estonian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -11909,6 +11998,7 @@ struct charset_info_st my_charset_utf32_spanish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -11940,6 +12030,7 @@ struct charset_info_st my_charset_utf32_swedish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -11971,6 +12062,7 @@ struct charset_info_st my_charset_utf32_turkish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -12002,6 +12094,7 @@ struct charset_info_st my_charset_utf32_czech_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -12034,6 +12127,7 @@ struct charset_info_st my_charset_utf32_danish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -12065,6 +12159,7 @@ struct charset_info_st my_charset_utf32_lithuanian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -12096,6 +12191,7 @@ struct charset_info_st my_charset_utf32_slovak_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -12127,6 +12223,7 @@ struct charset_info_st my_charset_utf32_spanish2_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -12158,6 +12255,7 @@ struct charset_info_st my_charset_utf32_roman_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -12189,6 +12287,7 @@ struct charset_info_st my_charset_utf32_persian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -12220,6 +12319,7 @@ struct charset_info_st my_charset_utf32_esperanto_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -12251,6 +12351,7 @@ struct charset_info_st my_charset_utf32_hungarian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -12282,6 +12383,7 @@ struct charset_info_st my_charset_utf32_sinhala_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -12313,6 +12415,7 @@ struct charset_info_st my_charset_utf32_german2_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -12344,6 +12447,7 @@ struct charset_info_st my_charset_utf32_croatian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_uca_handler
};
@@ -12400,6 +12504,7 @@ struct charset_info_st my_charset_utf16_unicode_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -12432,6 +12537,7 @@ struct charset_info_st my_charset_utf16_icelandic_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -12463,6 +12569,7 @@ struct charset_info_st my_charset_utf16_latvian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -12494,6 +12601,7 @@ struct charset_info_st my_charset_utf16_romanian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -12525,6 +12633,7 @@ struct charset_info_st my_charset_utf16_slovenian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -12556,6 +12665,7 @@ struct charset_info_st my_charset_utf16_polish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -12587,6 +12697,7 @@ struct charset_info_st my_charset_utf16_estonian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -12618,6 +12729,7 @@ struct charset_info_st my_charset_utf16_spanish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -12649,6 +12761,7 @@ struct charset_info_st my_charset_utf16_swedish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -12680,6 +12793,7 @@ struct charset_info_st my_charset_utf16_turkish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -12711,6 +12825,7 @@ struct charset_info_st my_charset_utf16_czech_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -12743,6 +12858,7 @@ struct charset_info_st my_charset_utf16_danish_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -12774,6 +12890,7 @@ struct charset_info_st my_charset_utf16_lithuanian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -12805,6 +12922,7 @@ struct charset_info_st my_charset_utf16_slovak_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -12836,6 +12954,7 @@ struct charset_info_st my_charset_utf16_spanish2_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -12867,6 +12986,7 @@ struct charset_info_st my_charset_utf16_roman_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -12898,6 +13018,7 @@ struct charset_info_st my_charset_utf16_persian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -12929,6 +13050,7 @@ struct charset_info_st my_charset_utf16_esperanto_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -12960,6 +13082,7 @@ struct charset_info_st my_charset_utf16_hungarian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -12991,6 +13114,7 @@ struct charset_info_st my_charset_utf16_sinhala_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -13022,6 +13146,7 @@ struct charset_info_st my_charset_utf16_german2_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
@@ -13054,6 +13179,7 @@ struct charset_info_st my_charset_utf16_croatian_uca_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_uca_handler
};
diff --git a/strings/ctype-ucs2.c b/strings/ctype-ucs2.c
index a5845a26917..344039013f3 100644
--- a/strings/ctype-ucs2.c
+++ b/strings/ctype-ucs2.c
@@ -1711,6 +1711,7 @@ struct charset_info_st my_charset_utf16_general_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_general_ci_handler
};
@@ -1743,6 +1744,7 @@ struct charset_info_st my_charset_utf16_bin=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16_handler,
&my_collation_utf16_bin_handler
};
@@ -1878,6 +1880,7 @@ struct charset_info_st my_charset_utf16le_general_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16le_handler,
&my_collation_utf16_general_ci_handler
};
@@ -1910,6 +1913,7 @@ struct charset_info_st my_charset_utf16le_bin=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf16le_handler,
&my_collation_utf16_bin_handler
};
@@ -2802,6 +2806,7 @@ struct charset_info_st my_charset_utf32_general_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_general_ci_handler
};
@@ -2834,6 +2839,7 @@ struct charset_info_st my_charset_utf32_bin=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf32_handler,
&my_collation_utf32_bin_handler
};
@@ -3419,6 +3425,7 @@ struct charset_info_st my_charset_ucs2_general_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_general_ci_handler
};
@@ -3451,6 +3458,7 @@ struct charset_info_st my_charset_ucs2_general_mysql500_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_general_ci_handler
};
@@ -3483,6 +3491,7 @@ struct charset_info_st my_charset_ucs2_bin=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_ucs2_handler,
&my_collation_ucs2_bin_handler
};
diff --git a/strings/ctype-ujis.c b/strings/ctype-ujis.c
index 0f405825830..9a69995b278 100644
--- a/strings/ctype-ujis.c
+++ b/strings/ctype-ujis.c
@@ -67258,7 +67258,7 @@ static MY_COLLATION_HANDLER my_collation_ci_handler =
NULL, /* init */
my_strnncoll_simple,/* strnncoll */
my_strnncollsp_simple,
- my_strnxfrm_simple, /* strnxfrm */
+ my_strnxfrm_mb, /* strnxfrm */
my_strnxfrmlen_simple,
my_like_range_mb, /* like_range */
my_wildcmp_mb, /* wildcmp */
@@ -67328,6 +67328,7 @@ struct charset_info_st my_charset_ujis_japanese_ci=
0xFEFE, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_ci_handler
};
@@ -67360,6 +67361,7 @@ struct charset_info_st my_charset_ujis_bin=
0xFEFE, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_handler,
&my_collation_mb_bin_handler
};
diff --git a/strings/ctype-utf8.c b/strings/ctype-utf8.c
index ae891b43d37..207eaffb1a3 100644
--- a/strings/ctype-utf8.c
+++ b/strings/ctype-utf8.c
@@ -2083,7 +2083,7 @@ int my_wildcmp_unicode_impl(CHARSET_INFO *cs,
str+= scan;
result= my_wildcmp_unicode_impl(cs, str, str_end, wildstr, wildend,
escape, w_one, w_many,
- weights, recurse_level+1);
+ weights, recurse_level + 1);
if (result <= 0)
return result;
}
@@ -2104,6 +2104,71 @@ my_wildcmp_unicode(CHARSET_INFO *cs,
wildstr, wildend,
escape, w_one, w_many, weights, 1);
}
+
+
+/**
+ Pad buffer with weights for space characters.
+
+ @details
+ This functions fills the buffer pointed by "str"
+ with weights of space character. Not more than
+ "nweights" weights are put. If at some iteration
+ step only a half of weight can fit
+ (which is possible if buffer length is an odd number)
+ then a half of this weight is put - this gives
+ a little bit better ORDER BY result for long strings.
+
+ @str Buffer
+ @strend End of buffer
+ @nweights Number of weights
+
+ @return Result length
+*/
+
+static size_t
+my_strxfrm_pad_nweights_unicode(uchar *str, uchar *strend, size_t nweights)
+{
+ uchar *str0;
+ DBUG_ASSERT(str && str <= strend);
+ for (str0= str; str < strend && nweights; nweights--)
+ {
+ *str++= 0x00;
+ if (str < strend)
+ *str++= 0x20;
+ }
+ return str - str0;
+}
+
+
+/**
+ Pad buffer with weights for space characters.
+
+ @details
+ This functions fills the buffer pointed by "str"
+ with weights of space character. Putting half of weight
+ (when buffer length is an odd number) is OK.
+
+ @str Buffer
+ @strend End of buffer
+
+ @return Result length
+*/
+
+static size_t
+my_strxfrm_pad_unicode(uchar *str, uchar *strend)
+{
+ uchar *str0= str;
+ DBUG_ASSERT(str && str <= strend);
+ for ( ; str < strend ; )
+ {
+ *str++= 0x00;
+ if (str < strend)
+ *str++= 0x20;
+ }
+ return str - str0;
+}
+
+
/*
Store sorting weights using 2 bytes per character.
@@ -2115,23 +2180,24 @@ my_wildcmp_unicode(CHARSET_INFO *cs,
*/
size_t
my_strnxfrm_unicode(CHARSET_INFO *cs,
- uchar *dst, size_t dstlen,
- const uchar *src, size_t srclen)
+ uchar *dst, size_t dstlen, uint nweights,
+ const uchar *src, size_t srclen, uint flags)
{
- my_wc_t UNINIT_VAR(wc);
+ my_wc_t wc;
int res;
+ uchar *dst0= dst;
uchar *de= dst + dstlen;
- uchar *de_beg= de - 1;
- const uchar *se = src + srclen;
+ const uchar *se= src + srclen;
MY_UNICASE_INFO *uni_plane= (cs->state & MY_CS_BINSORT) ?
- NULL : cs->caseinfo;
+ NULL : cs->caseinfo;
+ LINT_INIT(wc);
DBUG_ASSERT(src);
-
- while (dst < de_beg)
+
+ for (; dst < de && nweights; nweights--)
{
- if ((res= cs->cset->mb_wc(cs,&wc, src, se)) <= 0)
+ if ((res= cs->cset->mb_wc(cs, &wc, src, se)) <= 0)
break;
- src+=res;
+ src+= res;
if (uni_plane)
my_tosort_unicode(uni_plane, &wc, cs->state);
@@ -2140,17 +2206,15 @@ my_strnxfrm_unicode(CHARSET_INFO *cs,
if (dst < de)
*dst++= (uchar) (wc & 0xFF);
}
-
- while (dst < de_beg) /* Fill the tail with keys for space character */
- {
- *dst++= 0x00;
- *dst++= 0x20;
- }
-
- if (dst < de) /* Clear the last byte, if "dstlen" was an odd number */
- *dst= 0x00;
-
- return dstlen;
+
+ if (dst < de && nweights && (flags & MY_STRXFRM_PAD_WITH_SPACE))
+ dst+= my_strxfrm_pad_nweights_unicode(dst, de, nweights);
+
+ my_strxfrm_desc_and_reverse(dst0, dst, flags, 0);
+
+ if ((flags & MY_STRXFRM_PAD_TO_MAXLEN) && dst < de)
+ dst+= my_strxfrm_pad_unicode(dst, de);
+ return dst - dst0;
}
@@ -2160,45 +2224,63 @@ my_strnxfrm_unicode(CHARSET_INFO *cs,
*/
size_t
my_strnxfrm_unicode_full_bin(CHARSET_INFO *cs,
- uchar *dst, size_t dstlen,
- const uchar *src, size_t srclen)
+ uchar *dst, size_t dstlen, uint nweights,
+ const uchar *src, size_t srclen, uint flags)
{
my_wc_t wc;
+ uchar *dst0= dst;
uchar *de= dst + dstlen;
- uchar *de_beg= de - 2; /* The beginning of the last chunk */
const uchar *se = src + srclen;
LINT_INIT(wc);
DBUG_ASSERT(src);
DBUG_ASSERT(cs->state & MY_CS_BINSORT);
- while (dst < de_beg)
+ for ( ; dst < de && nweights; nweights--)
{
int res;
if ((res= cs->cset->mb_wc(cs, &wc, src, se)) <= 0)
break;
src+= res;
*dst++= (uchar) (wc >> 16);
- *dst++= (uchar) ((wc >> 8) & 0xFF);
- *dst++= (uchar) (wc & 0xFF);
+ if (dst < de)
+ {
+ *dst++= (uchar) ((wc >> 8) & 0xFF);
+ if (dst < de)
+ *dst++= (uchar) (wc & 0xFF);
+ }
}
- while (dst < de_beg) /* Fill the tail with keys for space character */
+ if (flags & MY_STRXFRM_PAD_WITH_SPACE)
{
- *dst++= 0x00;
- *dst++= 0x00;
- *dst++= 0x20;
+ for ( ; dst < de && nweights; nweights--)
+ {
+ *dst++= 0x00;
+ if (dst < de)
+ {
+ *dst++= 0x00;
+ if (dst < de)
+ *dst++= 0x20;
+ }
+ }
}
+
+ my_strxfrm_desc_and_reverse(dst0, dst, flags, 0);
- /* Clear the last one or two bytes, if "dstlen" was not divisible by 3 */
- if (dst < de)
+ if (flags & MY_STRXFRM_PAD_TO_MAXLEN)
{
- *dst++= 0x00;
- if (dst < de)
- *dst= 0x00;
+ while (dst < de)
+ {
+ *dst++= 0x00;
+ if (dst < de)
+ {
+ *dst++= 0x00;
+ if (dst < de)
+ *dst++= 0x20;
+ }
+ }
}
-
- return dstlen;
+ return dst - dst0;
}
@@ -2944,7 +3026,7 @@ static uint my_mbcharlen_utf8(CHARSET_INFO *cs __attribute__((unused)),
}
-static MY_COLLATION_HANDLER my_collation_ci_handler =
+static MY_COLLATION_HANDLER my_collation_utf8_general_ci_handler =
{
NULL, /* init */
my_strnncoll_utf8,
@@ -2959,6 +3041,22 @@ static MY_COLLATION_HANDLER my_collation_ci_handler =
my_propagate_complex
};
+
+static MY_COLLATION_HANDLER my_collation_utf8_bin_handler =
+{
+ NULL, /* init */
+ my_strnncoll_mb_bin,
+ my_strnncollsp_mb_bin,
+ my_strnxfrm_unicode,
+ my_strnxfrmlen_utf8,
+ my_like_range_mb,
+ my_wildcmp_mb_bin,
+ my_strcasecmp_mb_bin,
+ my_instr_mb,
+ my_hash_sort_mb_bin,
+ my_propagate_simple
+};
+
MY_CHARSET_HANDLER my_charset_utf8_handler=
{
NULL, /* init */
@@ -3019,8 +3117,9 @@ struct charset_info_st my_charset_utf8_general_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
- &my_collation_ci_handler
+ &my_collation_utf8_general_ci_handler
};
@@ -3051,8 +3150,9 @@ struct charset_info_st my_charset_utf8_general_mysql500_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
- &my_collation_ci_handler
+ &my_collation_utf8_general_ci_handler
};
@@ -3083,8 +3183,9 @@ struct charset_info_st my_charset_utf8_bin=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
- &my_collation_mb_bin_handler
+ &my_collation_utf8_bin_handler
};
#ifdef HAVE_UTF8_GENERAL_CS
@@ -3111,7 +3212,6 @@ static int my_strnncoll_utf8_cs(CHARSET_INFO *cs,
while ( s < se && t < te )
{
- int plane;
s_res=my_utf8_uni(cs,&s_wc, s, se);
t_res=my_utf8_uni(cs,&t_wc, t, te);
@@ -3126,10 +3226,10 @@ static int my_strnncoll_utf8_cs(CHARSET_INFO *cs,
{
save_diff = ((int)s_wc) - ((int)t_wc);
}
- plane=(s_wc>>8) & 0xFF;
- s_wc = uni_plane[plane] ? uni_plane[plane][s_wc & 0xFF].sort : s_wc;
- plane=(t_wc>>8) & 0xFF;
- t_wc = uni_plane[plane] ? uni_plane[plane][t_wc & 0xFF].sort : t_wc;
+
+ my_tosort_unicode(uni_plane, &s_wc, cs->state);
+ my_tosort_unicode(uni_plane, &t_wc, cs->state);
+
if ( s_wc != t_wc )
{
return ((int) s_wc) - ((int) t_wc);
@@ -3249,11 +3349,10 @@ struct charset_info_st my_charset_utf8_general_cs=
to_lower_utf8, /* to_lower */
to_upper_utf8, /* to_upper */
to_upper_utf8, /* sort_order */
- NULL, /* contractions */
- NULL, /* sort_order_big*/
+ NULL, /* uca */
NULL, /* tab_to_uni */
NULL, /* tab_from_uni */
- my_unicase_default, /* caseinfo */
+ &my_unicase_default,/* caseinfo */
NULL, /* state_map */
NULL, /* ident_map */
1, /* strxfrm_multiply */
@@ -3265,6 +3364,7 @@ struct charset_info_st my_charset_utf8_general_cs=
255, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8_handler,
&my_collation_cs_handler
};
@@ -4570,6 +4670,7 @@ struct charset_info_st my_charset_filename=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_filename_handler,
&my_collation_filename_handler
};
@@ -5453,6 +5554,7 @@ struct charset_info_st my_charset_utf8mb4_general_ci=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_utf8mb4_general_ci_handler
};
@@ -5485,6 +5587,7 @@ struct charset_info_st my_charset_utf8mb4_bin=
0xFFFF, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 1, /* levels_for_order */
&my_charset_utf8mb4_handler,
&my_collation_utf8mb4_bin_handler
};
diff --git a/strings/ctype-win1250ch.c b/strings/ctype-win1250ch.c
index d1cd51a5d8d..a688373f48e 100644
--- a/strings/ctype-win1250ch.c
+++ b/strings/ctype-win1250ch.c
@@ -489,9 +489,11 @@ int my_strnncollsp_win1250ch(CHARSET_INFO * cs,
}
-static size_t my_strnxfrm_win1250ch(CHARSET_INFO * cs __attribute__((unused)),
- uchar *dest, size_t len,
- const uchar *src, size_t srclen)
+static size_t
+my_strnxfrm_win1250ch(CHARSET_INFO *cs __attribute__((unused)),
+ uchar *dest, size_t len,
+ uint nweights_arg __attribute__((unused)),
+ const uchar *src, size_t srclen, uint flags)
{
int value;
const uchar *p;
@@ -499,15 +501,23 @@ static size_t my_strnxfrm_win1250ch(CHARSET_INFO * cs __attribute__((unused)),
size_t totlen = 0;
p = src;
- do {
+ if (!(flags & 0x0F)) /* All levels by default */
+ flags|= 0x0F;
+
+ for (;;)
+ {
NEXT_CMP_VALUE(src, p, pass, value, (int)srclen);
- if (totlen <= len)
- dest[totlen] = value;
- totlen++;
- } while (value) ;
- if (len > totlen)
- bfill(dest + totlen, len - totlen, ' ');
- return len;
+ if (!value)
+ break;
+ if (totlen <= len && ((1 << pass) & flags))
+ dest[totlen++] = value;
+ }
+ if ((flags & MY_STRXFRM_PAD_TO_MAXLEN) && len > totlen)
+ {
+ memset(dest + totlen, 0x00, len - totlen);
+ totlen= len;
+ }
+ return totlen;
}
#undef IS_END
@@ -705,6 +715,7 @@ struct charset_info_st my_charset_cp1250_czech_ci =
0, /* max_sort_char */
' ', /* pad char */
0, /* escape_with_backslash_is_dangerous */
+ 2, /* levels_for_order */
&my_charset_8bit_handler,
&my_collation_czech_ci_handler
};