summaryrefslogtreecommitdiff
path: root/mysql-test
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 /mysql-test
parentde8e306b6921ab32aedde957594e570166a7fce1 (diff)
downloadmariadb-git-426d246f5b8a4c598a913838b625e05e63ccb41f.tar.gz
MDEV-5163 Merge WEIGHT_STRING function from MySQL-5.6
Diffstat (limited to 'mysql-test')
-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
76 files changed, 13191 insertions, 548 deletions
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)));
+