[MDEV-9886] Illegal mix of collations with a view comparing a field to a binary constant Created: 2016-04-08  Updated: 2017-10-07  Resolved: 2017-10-07

Status: Closed
Project: MariaDB Server
Component/s: Character Sets
Affects Version/s: 10.0, 10.1, 10.2, 10.3
Fix Version/s: 10.0.33, 10.1.29, 10.2.10, 10.3.2

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None


 Description   

This script:

SET NAMES latin1;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a TEXT CHARACTER SET gbk);
INSERT INTO t1 VALUES (0xEE5D);
SELECT a<> 0xEE5D AS a FROM t1;

correctly returns one row:

+------+
| a    |
+------+
|    0 |
+------+

Now if I put the same SELECT into a VIEW and query it:

DROP VIEW IF EXISTS v1;
CREATE VIEW v1 AS SELECT a<> 0xEE5D AS a FROM t1;
SELECT * FROM v1;

it returns an error:

ERROR 1267 (HY000): Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (latin1_swedish_ci,COERCIBLE) for operation '<>'



 Comments   
Comment by Alexander Barkov [ 2017-10-06 ]

The problem happens because the view query is written to the frm file as:

query=select `test`.`t1`.`a` <> \'î]\' AS `a` from `test`.`t1`

Notice, the hex hybrid literal 0xEE5D was replaced to a quoted character string literal, so it's misinterpreted during the view open time on SELECT.

Comment by Alexander Barkov [ 2017-10-07 ]

Not repeatable in 5.5, as it uses a slightly different code in agg_item_set_converter to detect if conversion is needed:
String::needs_conversion() vs Item::safe_charset_converter().

Generated at Thu Feb 08 07:38:03 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.