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

builtin func char() has different result between MySQL when value is illegal UTF8 character #29685

Closed
Defined2014 opened this issue Nov 11, 2021 · 3 comments · Fixed by #30288
Assignees
Labels
affects-5.3 This bug affects 5.3.x versions. severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@Defined2014
Copy link
Contributor

Bug Report

builtin func char() has different result between MySQL when value is illegal UTF8 character

1. Minimal reproduce step (Required)

select char(123456 using utf8);
show warnings;

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

mysql> select char(123456 using utf8);
+-------------------------+
| char(123456 using utf8) |
+-------------------------+
| NULL                    |
+-------------------------+
1 row in set, 2 warnings (0.00 sec)
mysql> show warnings;
+---------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                                                                     |
+---------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 3719 | 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous. |
| Warning | 1300 | Invalid utf8mb3 character string: 'E240'                                                                                                                                    |
+---------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

3. What did you see instead (Required)

mysql> select char(123456 using utf8);
+-------------------------+
| char(123456 using utf8) |
+-------------------------+
| �@                      |
+-------------------------+
1 row in set (0.01 sec)
mysql> show warnings;
Empty set (0.00 sec)

4. What is your TiDB version? (Required)

mysql> SELECT tidb_version();
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                                             |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v5.2.0-alpha-2186-g2bdebedfc
Edition: Community
Git Commit Hash: 2bdebedfc042e340c7826d0ac96f635f3949a8b3
Git Branch: master
UTC Build Time: 2021-11-11 05:47:41
GoVersion: go1.16.6
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
@Defined2014 Defined2014 added the type/bug The issue is confirmed as a bug. label Nov 11, 2021
@Defined2014
Copy link
Contributor Author

Defined2014 commented Nov 11, 2021

We didn't check the param for char() is UTF8 character or not. And we should check it. The convert also has same problem. Seems if builtin functions support using utf8, they will have same problem.

code

drop table if exists t;
create table t (a binary(20));
insert into t values (0x1e240);
select convert(t.a using utf8) from t;

result which should be NULL

mysql> select convert(t.a using utf8) from t;
+-------------------------+
| convert(t.a using utf8) |
+-------------------------+
| �@                      |
+-------------------------+
1 row in set (0.00 sec)

@Defined2014
Copy link
Contributor Author

/assign

@github-actions
Copy link

Please check whether the issue should be labeled with 'affects-x.y' or 'fixes-x.y.z', and then remove 'needs-more-info' label.

@jebter jebter added the affects-5.3 This bug affects 5.3.x versions. label Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.3 This bug affects 5.3.x versions. severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
3 participants