Skip to content

Commit 4692385

Browse files
committed
Bug#37285902: Illegal mix of collations NONE vs. COERCIBLE
The problem is that an unexpected error message is reported from a SELECT statement that involves multiple functions and columns and strings with multiple collations. For details, see the analysis in the bug report. In essence, an IFNULL function returns a binary collation and collation derivation NONE. The result of IFNULL is used in a LIKE clause. Derivation NONE is disallowed in this context, thus an error is reported. This is behaviour according to documentation. However, we can change the semantics slightly and thus accept the problematic query. The change is to lower the strength of collation derivation NONE to be less than the strength of any other collation derivation. This means that when an expression with derivation NONE is used e.g. in a LIKE expression, then the other operand will determine the comparison collation to be used by LIKE. The change can be used with minimal impact on existing functionality, in fact it causes no changes in existing test suite. In addition, we simplify the collation determination slightly and provide more comprehensive documentation. We also change collation aggregation as implemented in agg_item_collations() to only consider collations with the same (and highest) strength when determining the result collation. This might seem dangerous since it means that operands with possibly incompatible character sets but lesser strength are now allowed. However we have already implemented code that converts operands with different character sets into the character set determined for the operation, and report errors if strings are actually invalid, thus pushing some error rejection from the resolver stage into the execution stage. We also rename the previous IGNORABLE derivation to NULL, since it is only used for NULL values, and since it is no longer ignorable given that NONE now has lesser strength. We leave a hole in the "strength" values for the former NONE strength, in order that as few COERCIBILITY() calls as possible return values that are incompatible with the previous implementation. A special problem was hit with resolving of aggregated types for the result columns of set operations. The new way of determining character set and collation works fine when all aggregated items are processed in one operation, but an anomaly was discovered for set operations, since type aggregation is handled for pairs of items. We have therefore implemented a new function Item_aggregate_type::unify_types() that unifies the types from a set of items. Query_term_set_op::prepare_query_term() has been refactored so that it may call the new unify_types() function. It has also been changed so that the type holder objects are created and finalized in one place, which is just after all query term children have been resolved in a non-recursive set operation, and just before resolving the first recursive query term in a recursive set operation. The actual preparation of type holder objects is performed in a new function Query_term_set_op::prepare_type_holders(). Finally, an earlier mistake was discovered and corrected. The call to report_conversion_error() inside Item::convert_charset() had collation arguments reversed. Fixing this caused a few minor changes in result test files. Change-Id: Ie30906758078559fcba8ae881125e039bab9298a
1 parent c87b40b commit 4692385

21 files changed

+854
-291
lines changed

mysql-test/r/ctype_recoding.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ select * from t1 where a=concat(_koi8r'
200200
a
201201
����
202202
select * from t1 where a=_latin1'����';
203-
ERROR HY000: Cannot convert string '\xD7\xC1\xD3\xD1' from cp1251 to latin1
203+
ERROR HY000: Cannot convert string '\xD7\xC1\xD3\xD1' from latin1 to cp1251
204204
drop table t1;
205205
set names latin1;
206206
set names ascii;
@@ -284,5 +284,5 @@ t1 CREATE TABLE `t1` (
284284
) ENGINE=ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
285285
drop table t1;
286286
create table t1(a char character set latin1 default _cp1251 0xFF);
287-
ERROR HY000: Cannot convert string '\xFF' from latin1 to cp1251
287+
ERROR HY000: Cannot convert string '\xFF' from cp1251 to latin1
288288
End of 4.1 tests

mysql-test/r/ctype_utf8mb4.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,9 +2341,9 @@ DROP TABLE t2;
23412341
CREATE TABLE t1 (utf8mb4 VARCHAR(10) CHARACTER SET utf8mb4);
23422342
INSERT INTO t1 VALUES (x'f48fbfbf');
23432343
SELECT CONCAT(utf8mb4, _utf8mb3 '�') FROM t1;
2344-
ERROR HY000: Cannot convert string '\xBF' from utf8mb4 to utf8mb3
2344+
ERROR HY000: Cannot convert string '\xBF' from utf8mb3 to utf8mb4
23452345
SELECT CONCAT('a', _utf8mb3 '�') FROM t1;
2346-
ERROR HY000: Cannot convert string '\xBF' from utf8mb4 to utf8mb3
2346+
ERROR HY000: Cannot convert string '\xBF' from utf8mb3 to utf8mb4
23472347
DROP TABLE t1;
23482348
#
23492349
# Bug#51675 Server crashes on inserting 4 byte char.

mysql-test/r/ctype_utf8mb4_heap.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,9 +2371,9 @@ DROP TABLE t2;
23712371
CREATE TABLE t1 (utf8mb4 VARCHAR(10) CHARACTER SET utf8mb4) ENGINE heap;
23722372
INSERT INTO t1 VALUES (x'f48fbfbf');
23732373
SELECT CONCAT(utf8mb4, _utf8mb3 '�') FROM t1;
2374-
ERROR HY000: Cannot convert string '\xBF' from utf8mb4 to utf8mb3
2374+
ERROR HY000: Cannot convert string '\xBF' from utf8mb3 to utf8mb4
23752375
SELECT CONCAT('a', _utf8mb3 '�') FROM t1;
2376-
ERROR HY000: Cannot convert string '\xBF' from utf8mb4 to utf8mb3
2376+
ERROR HY000: Cannot convert string '\xBF' from utf8mb3 to utf8mb4
23772377
DROP TABLE t1;
23782378
#
23792379
# End of 5.5 tests

mysql-test/r/ctype_utf8mb4_innodb.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,9 +2523,9 @@ DROP TABLE t2;
25232523
CREATE TABLE t1 (utf8mb4 VARCHAR(10) CHARACTER SET utf8mb4) ENGINE InnoDB;
25242524
INSERT INTO t1 VALUES (x'f48fbfbf');
25252525
SELECT CONCAT(utf8mb4, _utf8mb3 '�') FROM t1;
2526-
ERROR HY000: Cannot convert string '\xBF' from utf8mb4 to utf8mb3
2526+
ERROR HY000: Cannot convert string '\xBF' from utf8mb3 to utf8mb4
25272527
SELECT CONCAT('a', _utf8mb3 '�') FROM t1;
2528-
ERROR HY000: Cannot convert string '\xBF' from utf8mb4 to utf8mb3
2528+
ERROR HY000: Cannot convert string '\xBF' from utf8mb3 to utf8mb4
25292529
DROP TABLE t1;
25302530
#
25312531
# End of 5.5 tests

mysql-test/r/ctype_utf8mb4_myisam.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,9 +2527,9 @@ DROP TABLE t2;
25272527
CREATE TABLE t1 (utf8mb4 VARCHAR(10) CHARACTER SET utf8mb4) ENGINE MyISAM;
25282528
INSERT INTO t1 VALUES (x'f48fbfbf');
25292529
SELECT CONCAT(utf8mb4, _utf8mb3 '�') FROM t1;
2530-
ERROR HY000: Cannot convert string '\xBF' from utf8mb4 to utf8mb3
2530+
ERROR HY000: Cannot convert string '\xBF' from utf8mb3 to utf8mb4
25312531
SELECT CONCAT('a', _utf8mb3 '�') FROM t1;
2532-
ERROR HY000: Cannot convert string '\xBF' from utf8mb4 to utf8mb3
2532+
ERROR HY000: Cannot convert string '\xBF' from utf8mb3 to utf8mb4
25332533
DROP TABLE t1;
25342534
#
25352535
# End of 5.5 tests

mysql-test/r/derived.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4791,7 +4791,7 @@ SELECT * FROM (SELECT _utf8mb4 'a' AS a) AS dt UNION SELECT c FROM t;
47914791
a
47924792
a
47934793
SELECT _utf8mb4 '±' AS a UNION SELECT c FROM t;
4794-
ERROR HY000: Cannot convert string '\xC2\xB1' from utf8mb4 to latin2
4794+
ERROR HY000: Cannot convert string '\xC3\x82\xC2\xB1' from utf8mb4 to latin2
47954795
SELECT * FROM (SELECT _utf8mb4 '±' AS a) AS dt UNION SELECT c FROM t;
47964796
ERROR HY000: Cannot convert string '\xC2\xB1' from utf8mb4 to latin2
47974797
SELECT _utf8mb4 'a' AS a UNION SELECT d FROM t;

mysql-test/r/func_gconcat.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ select collation(group_concat(a,_koi8r'test')) from t1;
499499
collation(group_concat(a,_koi8r'test'))
500500
cp1250_general_ci
501501
select collation(group_concat(a,_koi8r 0xC1C2)) from t1;
502-
ERROR HY000: Cannot convert string '\xC1\xC2' from cp1250 to koi8r
502+
ERROR HY000: Cannot convert string '\xC1\xC2' from koi8r to cp1250
503503
select collation(group_concat(a,b)) from t1;
504504
ERROR HY000: Illegal mix of collations (cp1250_general_ci,IMPLICIT) and (koi8r_general_ci,IMPLICIT) for operation 'group_concat'
505505
drop table t1;

mysql-test/r/func_str.result

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,107 @@ QUOTE('A')
443443
'A'
444444
'A'
445445
DROP TABLE t1;
446+
SELECT '1' COLLATE latin1_swedish_ci = '1' COLLATE latin1_swedish_ci;
447+
'1' COLLATE latin1_swedish_ci = '1' COLLATE latin1_swedish_ci
448+
1
449+
SELECT CONCAT('1' COLLATE latin1_swedish_ci, '2' COLLATE latin1_swedish_ci);
450+
CONCAT('1' COLLATE latin1_swedish_ci, '2' COLLATE latin1_swedish_ci)
451+
12
452+
SELECT '1' COLLATE latin1_swedish_ci = '1' COLLATE latin1_general_ci;
453+
ERROR HY000: Illegal mix of collations (latin1_swedish_ci,EXPLICIT) and (latin1_general_ci,EXPLICIT) for operation '='
454+
SELECT CONCAT('1' COLLATE latin1_swedish_ci, '2' COLLATE latin1_general_ci);
455+
ERROR HY000: Illegal mix of collations (latin1_swedish_ci,EXPLICIT) and (latin1_general_ci,EXPLICIT) for operation 'concat'
456+
SELECT '1' COLLATE latin1_swedish_ci = '1';
457+
'1' COLLATE latin1_swedish_ci = '1'
458+
1
459+
SELECT CONCAT('1' COLLATE latin1_swedish_ci, '2');
460+
CONCAT('1' COLLATE latin1_swedish_ci, '2')
461+
12
462+
CREATE TABLE t1(
463+
b0 VARBINARY(10),
464+
c0 VARCHAR(10) COLLATE utf8mb4_bin,
465+
c1 VARCHAR(10) COLLATE utf8mb4_0900_ai_ci,
466+
c2 VARCHAR(10) COLLATE utf8mb4_0900_as_cs,
467+
c3 VARCHAR(10) COLLATE utf8mb3_general_ci,
468+
c4 VARCHAR(10) COLLATE utf16_general_ci,
469+
c5 VARCHAR(10) COLLATE utf32_unicode_ci,
470+
c6 VARCHAR(10) COLLATE ascii_general_ci,
471+
c7 VARCHAR(10) COLLATE latin1_swedish_ci,
472+
c8 VARCHAR(10) COLLATE latin2_general_ci
473+
);
474+
Warnings:
475+
Warning 3778 'utf8mb3_general_ci' is a collation of the deprecated character set UTF8MB3. Please consider using UTF8MB4 with an appropriate collation instead.
476+
INSERT INTO t1 VALUES
477+
(x'e6f8e5', 'abc', 'abc', 'ABC', 'æøå', 'abc', 'abc', 'abc', 'æøå', 'abc');
478+
SELECT c1 = b0 FROM t1;
479+
c1 = b0
480+
0
481+
SELECT CONCAT(c1, b0) FROM t1;
482+
CONCAT(c1, b0)
483+
abc���
484+
SELECT c1 = c0 FROM t1;
485+
c1 = c0
486+
1
487+
SELECT CONCAT(c1, c0) FROM t1;
488+
CONCAT(c1, c0)
489+
abcabc
490+
SELECT c1 = c2 FROM t1;
491+
ERROR HY000: Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT) and (utf8mb4_0900_as_cs,IMPLICIT) for operation '='
492+
SELECT CONCAT(c1, c2) FROM t1;
493+
CONCAT(c1, c2)
494+
abcABC
495+
SELECT c1 = c3 FROM t1;
496+
c1 = c3
497+
0
498+
SELECT CONCAT(c1, c3) FROM t1;
499+
CONCAT(c1, c3)
500+
abcæøå
501+
SELECT c1 = c4 FROM t1;
502+
c1 = c4
503+
1
504+
SELECT CONCAT(c1, c4) FROM t1;
505+
CONCAT(c1, c4)
506+
abcabc
507+
SELECT c1 = c5 FROM t1;
508+
c1 = c5
509+
1
510+
SELECT CONCAT(c1, c5) FROM t1;
511+
CONCAT(c1, c5)
512+
abcabc
513+
SELECT c1 = c6 FROM t1;
514+
c1 = c6
515+
1
516+
SELECT CONCAT(c1, c6) FROM t1;
517+
CONCAT(c1, c6)
518+
abcabc
519+
SELECT c1 = c7 FROM t1;
520+
c1 = c7
521+
0
522+
SELECT CONCAT(c1, c7) FROM t1;
523+
CONCAT(c1, c7)
524+
abcæøå
525+
SELECT c1 = c8 FROM t1;
526+
c1 = c8
527+
1
528+
SELECT CONCAT(c1, c8) FROM t1;
529+
CONCAT(c1, c8)
530+
abcabc
531+
SELECT c7 = c8 FROM t1;
532+
ERROR HY000: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (latin2_general_ci,IMPLICIT) for operation '='
533+
SELECT CONCAT(c7, c8) FROM t1;
534+
ERROR HY000: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (latin2_general_ci,IMPLICIT) for operation 'concat'
535+
SELECT DATABASE() = _utf8mb4'æøå';
536+
DATABASE() = _utf8mb4'æøå'
537+
0
538+
SELECT CONCAT(DATABASE(), _utf8mb4'æøå');
539+
CONCAT(DATABASE(), _utf8mb4'æøå')
540+
test���
541+
SELECT DATABASE() = _utf8mb4'āđē';
542+
DATABASE() = _utf8mb4'āđē'
543+
0
544+
SELECT CONCAT(DATABASE(), _utf8mb4'āđē');
545+
CONCAT(DATABASE(), _utf8mb4'āđē')
546+
test???
446547
select 1=_latin1'1';
447548
1=_latin1'1'
448549
1
@@ -479,6 +580,33 @@ select concat(_latin1'a',_latin2'a',_latin5'a',_latin7'a');
479580
ERROR HY000: Illegal mix of collations for operation 'concat'
480581
select concat_ws(_latin1'a',_latin2'a');
481582
ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (latin2_general_ci,COERCIBLE) for operation 'concat_ws'
583+
SELECT CONCAT(_utf8mb4'æøå', 1);
584+
CONCAT(_utf8mb4'æøå', 1)
585+
���1
586+
SELECT CONCAT(_utf8mb4'āđē', 1);
587+
CONCAT(_utf8mb4'āđē', 1)
588+
???1
589+
SELECT _utf8mb4'æøå' = NULL;
590+
_utf8mb4'æøå' = NULL
591+
NULL
592+
SELECT CONCAT(_utf8mb4'æøå', NULL);
593+
CONCAT(_utf8mb4'æøå', NULL)
594+
NULL
595+
SELECT c3 = CONCAT(c1, c2) FROM t1;
596+
c3 = CONCAT(c1, c2)
597+
0
598+
SELECT GREATEST(c3, CONCAT(c1, c2)) FROM t1;
599+
GREATEST(c3, CONCAT(c1, c2))
600+
æøå
601+
SELECT COERCIBILITY(CONCAT(c1, c2)) FROM t1;
602+
COERCIBILITY(CONCAT(c1, c2))
603+
7
604+
SELECT CONCAT(c1, c2) = CONCAT(c1, c2) FROM t1;
605+
ERROR HY000: Illegal mix of collations (utf8mb4_bin,NONE) and (utf8mb4_bin,NONE) for operation '='
606+
SELECT CONCAT(CONCAT(c1, c2), CONCAT(c1, c2)) FROM t1;
607+
CONCAT(CONCAT(c1, c2), CONCAT(c1, c2))
608+
abcABCabcABC
609+
DROP TABLE t1;
482610
select FIELD('b','A','B');
483611
FIELD('b','A','B')
484612
2
@@ -6021,3 +6149,31 @@ BETWEEN '2037' AND ( -71 * ( -1552207807 * 440370369 ) )
60216149
COLLATE utf8mb4_et_0900_as_cs;
60226150
ERROR 22003: BIGINT value is out of range in '(-(71) * (-(1552207807) * 440370369))'
60236151
DROP TABLE customer_demographics;
6152+
#
6153+
# Bug#37285902: Illegal mix of collations NONE vs. COERCIBLE
6154+
#
6155+
CREATE TABLE t1(
6156+
id DECIMAL(38,0)
6157+
);
6158+
CREATE TABLE t2(
6159+
name VARCHAR(150) COLLATE utf8mb4_0900_as_cs
6160+
);
6161+
WITH cte0 AS
6162+
(SELECT CAST(t1.id AS CHAR(38)) AS c2
6163+
FROM t1
6164+
),
6165+
cte1 AS
6166+
(SELECT t2.name AS c1
6167+
FROM t2
6168+
),
6169+
cte2 AS
6170+
(SELECT d3.c1 AS c1, d1.c2 AS c2
6171+
FROM cte0 AS d1 LEFT JOIN cte1 AS d3 ON TRUE
6172+
WHERE IFNULL(d3.c1, d1.c2) LIKE 'Vision Operations'
6173+
)
6174+
SELECT * FROM cte2;
6175+
c1 c2
6176+
SELECT IFNULL(name, CAST(t1.id AS CHAR(38))) LIKE 'Vision Operations'
6177+
FROM t1 LEFT JOIN t2 ON TRUE;
6178+
IFNULL(name, CAST(t1.id AS CHAR(38))) LIKE 'Vision Operations'
6179+
DROP TABLE t1, t2;

mysql-test/r/func_test.result

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ SELECT GREATEST(dt.a, t.a) FROM t, (SELECT _utf8mb4 'a') AS dt(a);
948948
GREATEST(dt.a, t.a)
949949
a
950950
SELECT GREATEST(_utf8mb4 '±', a) FROM t;
951-
ERROR HY000: Cannot convert string '\xC3\x82\xC2\xB1' from ascii to utf8mb4
951+
ERROR HY000: Cannot convert string '\xC3\x82\xC2\xB1' from utf8mb4 to ascii
952952
SELECT GREATEST(dt.a, t.a) FROM t, (SELECT _utf8mb4 '±') AS dt(a);
953953
ERROR HY000: Cannot convert string '\xC3\x82\xC2\xB1' from utf8mb4 to ascii
954954
SELECT GREATEST(_utf8mb4 'a', b) FROM t;
@@ -970,7 +970,7 @@ SELECT GREATEST(dt.a, t.c) FROM t, (SELECT _utf8mb4 'a') AS dt(a);
970970
GREATEST(dt.a, t.c)
971971
a
972972
SELECT GREATEST(_utf8mb4 '±', c) FROM t;
973-
ERROR HY000: Cannot convert string '\xC3\x82\xC2\xB1' from latin2 to utf8mb4
973+
ERROR HY000: Cannot convert string '\xC3\x82\xC2\xB1' from utf8mb4 to latin2
974974
SELECT GREATEST(dt.a, t.c) FROM t, (SELECT _utf8mb4 '±') AS dt(a);
975975
ERROR HY000: Cannot convert string '\xC3\x82\xC2\xB1' from utf8mb4 to latin2
976976
SELECT GREATEST(_utf8mb4 'a', d) FROM t;
@@ -986,7 +986,7 @@ SELECT GREATEST(dt.a, t.a) FROM t, (SELECT _latin1 'a') AS dt(a);
986986
GREATEST(dt.a, t.a)
987987
a
988988
SELECT GREATEST(_latin1 'Ã¥', a) FROM t;
989-
ERROR HY000: Cannot convert string '\xC3\x83\xC2\xA5' from ascii to latin1
989+
ERROR HY000: Cannot convert string '\xC3\x83\xC2\xA5' from latin1 to ascii
990990
SELECT GREATEST(dt.a, t.a) FROM t, (SELECT _latin1 'Ã¥') AS dt(a);
991991
ERROR HY000: Cannot convert string '\xC3\x83\xC2\xA5' from latin1 to ascii
992992
SELECT GREATEST(_latin1 'a', c) FROM t;
@@ -996,7 +996,7 @@ SELECT GREATEST(dt.a, t.c) FROM t, (SELECT _latin1 'a') AS dt(a);
996996
GREATEST(dt.a, t.c)
997997
a
998998
SELECT GREATEST(_latin1 'Ã¥', c) FROM t;
999-
ERROR HY000: Cannot convert string '\xC3\x83\xC2\xA5' from latin2 to latin1
999+
ERROR HY000: Cannot convert string '\xC3\x83\xC2\xA5' from latin1 to latin2
10001000
SELECT GREATEST(dt.a, t.c) FROM t, (SELECT _latin1 'Ã¥') AS dt(a);
10011001
ERROR HY000: Cannot convert string '\xC3\x83\xC2\xA5' from latin1 to latin2
10021002
DROP TABLE t;

mysql-test/suite/collations/r/binary.result

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,73 @@ Abc
6161
abc
6262
abc
6363
SELECT col_bin FROM t UNION SELECT col_0900_bin FROM t;
64-
ERROR HY000: Illegal mix of collations for operation 'UNION'
64+
ERROR HY000: Illegal mix of collations (utf8mb4_bin,IMPLICIT) and (utf8mb4_0900_bin,IMPLICIT) for operation 'UNION'
6565
SELECT col_0900_bin FROM t UNION SELECT col_bin FROM t;
66-
ERROR HY000: Illegal mix of collations for operation 'UNION'
66+
ERROR HY000: Illegal mix of collations (utf8mb4_0900_bin,IMPLICIT) and (utf8mb4_bin,IMPLICIT) for operation 'UNION'
6767
SELECT col_bin FROM t UNION SELECT col_0900_bin FROM t
6868
UNION SELECT col_aici FROM t;
69-
ERROR HY000: Illegal mix of collations for operation 'UNION'
70-
SELECT col_bin FROM t UNION SELECT col_0900_bin FROM t
71-
UNION SELECT col_aici COLLATE utf8mb4_0900_ai_ci FROM t;
72-
col_bin
69+
ERROR HY000: Illegal mix of collations (utf8mb4_bin,IMPLICIT), (utf8mb4_0900_bin,IMPLICIT), (utf8mb4_0900_ai_ci,IMPLICIT) for operation 'UNION'
70+
# Add an explicit collation in the first query term.
71+
# The explicit collation is used.
72+
SELECT col_aici COLLATE utf8mb4_0900_ai_ci FROM t
73+
UNION
74+
SELECT col_bin FROM t
75+
UNION
76+
SELECT col_0900_bin FROM t;
77+
col_aici COLLATE utf8mb4_0900_ai_ci
7378
ABC
7479
Abc
7580
abc
7681
abc
77-
SELECT col_bin FROM t UNION SELECT col_0900_bin FROM t
78-
UNION SELECT col_aici COLLATE utf8mb4_bin FROM t;
79-
col_bin
82+
SELECT col_aici COLLATE utf8mb4_bin FROM t
83+
UNION
84+
SELECT col_bin FROM t
85+
UNION
86+
SELECT col_0900_bin FROM t;
87+
col_aici COLLATE utf8mb4_bin
8088
ABC
8189
Abc
8290
abc
83-
SELECT col_bin FROM t UNION SELECT col_0900_bin FROM t
84-
UNION SELECT col_aici COLLATE utf8mb4_0900_bin FROM t;
85-
col_bin
91+
SELECT col_aici COLLATE utf8mb4_0900_bin FROM t
92+
UNION
93+
SELECT col_bin FROM t
94+
UNION
95+
SELECT col_0900_bin FROM t;
96+
col_aici COLLATE utf8mb4_0900_bin
97+
ABC
98+
ABC
99+
Abc
100+
Abc
101+
abc
102+
abc
103+
# Add an explicit collation in the last query term.
104+
# The explicit collation is used, so same result as
105+
# above.
106+
SELECT col_aici FROM t
107+
UNION
108+
SELECT col_bin FROM t
109+
UNION
110+
SELECT col_0900_bin COLLATE utf8mb4_0900_ai_ci FROM t;
111+
col_aici
112+
ABC
113+
Abc
114+
abc
115+
abc
116+
SELECT col_aici FROM t
117+
UNION
118+
SELECT col_bin FROM t
119+
UNION
120+
SELECT col_0900_bin COLLATE utf8mb4_bin FROM t;
121+
col_aici
122+
ABC
123+
Abc
124+
abc
125+
SELECT col_aici FROM t
126+
UNION
127+
SELECT col_bin FROM t
128+
UNION
129+
SELECT col_0900_bin COLLATE utf8mb4_0900_bin FROM t;
130+
col_aici
86131
ABC
87132
ABC
88133
Abc

0 commit comments

Comments
 (0)