Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncation of UTF8mb4 values when the UNION statement for binary and non-binary charsets #31678

Closed
Alkaagr81 opened this issue Jan 13, 2022 · 1 comment · Fixed by #37242
Closed
Assignees
Labels
affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@Alkaagr81
Copy link
Collaborator

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Do --binary-as-hex=false for better output

CREATE TABLE t1 (c VARCHAR(11)) CHARACTER SET utf8mb4;
CREATE TABLE t2 (b CHAR(1) CHARACTER SET binary, i INT);
INSERT INTO t1 (c) VALUES ('н1234567890');
INSERT INTO t2 (b, i) VALUES ('1', 1);
SELECT c FROM t1 UNION SELECT b FROM t2;
SELECT c FROM t1 UNION SELECT i FROM t2;
SELECT i FROM t2 UNION SELECT c FROM t1;
SELECT b FROM t2 UNION SELECT c FROM t1;

DROP TABLE t1, t2;

2. What did you expect to see? (Required)

mysql> CREATE TABLE t1 (c VARCHAR(11)) CHARACTER SET utf8mb4;
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE TABLE t2 (b CHAR(1) CHARACTER SET binary, i INT);
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO t1 (c) VALUES ('н1234567890');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO t2 (b, i) VALUES ('1', 1);
Query OK, 1 row affected (0.00 sec)

mysql> SELECT c FROM t1 UNION SELECT b FROM t2;
+--------------+
| c            |
+--------------+
| н1234567890  |
| 1            |
+--------------+
2 rows in set (0.00 sec)

mysql> SELECT c FROM t1 UNION SELECT i FROM t2;
+--------------+
| c            |
+--------------+
| н1234567890  |
| 1            |
+--------------+
2 rows in set (0.00 sec)

mysql> SELECT i FROM t2 UNION SELECT c FROM t1;
+--------------+
| i            |
+--------------+
| 1            |
| н1234567890  |
+--------------+
2 rows in set (0.00 sec)

mysql> SELECT b FROM t2 UNION SELECT c FROM t1;
+--------------+
| b            |
+--------------+
| 1            |
| н1234567890  |
+--------------+
2 rows in set (0.01 sec)

3. What did you see instead (Required)

mysql> CREATE TABLE t1 (c VARCHAR(11)) CHARACTER SET utf8mb4;
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE TABLE t2 (b CHAR(1) CHARACTER SET binary, i INT);
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO t1 (c) VALUES ('н1234567890');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO t2 (b, i) VALUES ('1', 1);
Query OK, 1 row affected (0.00 sec)

mysql> SELECT c FROM t1 UNION SELECT b FROM t2;
+-------------+
| c           |
+-------------+
| н123456789  |
| 1           |
+-------------+
2 rows in set, 1 warning (0.02 sec)

mysql> SELECT c FROM t1 UNION SELECT i FROM t2;
+--------------+
| c            |
+--------------+
| н1234567890  |
| 1            |
+--------------+
2 rows in set (0.00 sec)

mysql> SELECT i FROM t2 UNION SELECT c FROM t1;
+--------------+
| i            |
+--------------+
| н1234567890  |
| 1            |
+--------------+
2 rows in set (0.01 sec)

mysql> SELECT b FROM t2 UNION SELECT c FROM t1;
+-------------+
| b           |
+-------------+
| н123456789  |
| 1           |
+-------------+
2 rows in set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+------------------------------------------+
| Level   | Code | Message                                  |
+---------+------+------------------------------------------+
| Warning | 1406 | Data Too Long, field len 11, data len 12 |
+---------+------+------------------------------------------+
1 row in set (0.00 sec)

4. What is your TiDB version? (Required)

| Release Version: v5.5.0-alpha-60-g8c70432b0-dirty
Edition: Community
Git Commit Hash: 8c70432b000d648e9ea26cc57a7fe79d2e67d341
Git Branch: master
UTC Build Time: 2022-01-07 17:47:06
GoVersion: go1.16.9
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false | 
@Alkaagr81 Alkaagr81 added the type/bug The issue is confirmed as a bug. label Jan 13, 2022
@ChenPeng2013 ChenPeng2013 added affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. severity/major sig/sql-infra SIG: SQL Infra labels Jan 14, 2022
@bb7133 bb7133 changed the title Truncation of UTF8mb4 values when the UNION statement forces collation to the binary charset Truncation of UTF8mb4 values when the UNION statement for binary and non-binary charsets Jan 14, 2022
@CbcWestwolf
Copy link
Member

/assign bb7133

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants