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

The collation of JSON is inconsistent with MySQL when process with builtin func #31320

Closed
Defined2014 opened this issue Jan 5, 2022 · 2 comments · Fixed by #31576
Closed
Labels
severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@Defined2014
Copy link
Contributor

Defined2014 commented Jan 5, 2022

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table t (a char(20), b blob(100), c binary(100), d json, e timestamp, f set('a一','b二','c三','d四'), g text, h enum('a一','b二','c三','d四') default 'c三');
insert into t values ('abcABC一二三abcABC', 'abcABC一二三abcABC', 0xe2e2, '{"abcABC一二三abcABC": "abcABC一二三abcABC"}', '2018-10-13', 1, 'abcABC一二三abcABC', 'a一');
select lpad(d, 5, 0xE4B880) from t;
select rpad(d, 5, 0xE4B880) from t;

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

mysql> select lpad(d, 5, 0xE4B880) from t;
+----------------------+
| lpad(d, 5, 0xE4B880) |
+----------------------+
| {"abc                |
+----------------------+
1 row in set (0.00 sec)

mysql> select rpad(d, 5, 0xE4B880) from t;
+----------------------+
| rpad(d, 5, 0xE4B880) |
+----------------------+
| {"abc                |
+----------------------+
1 row in set (0.00 sec)

3. What did you see instead (Required)

mysql> select lpad(d, 5, 0xE4B880) from t;
+--------------------------------------------+
| lpad(d, 5, 0xE4B880)                       |
+--------------------------------------------+
| 0x7B22616263                               |
+--------------------------------------------+
1 row in set (0.00 sec)

mysql> select rpad(d, 5, 0xE4B880) from t;
+--------------------------------------------+
| rpad(d, 5, 0xE4B880)                       |
+--------------------------------------------+
| 0x7B22616263                               |
+--------------------------------------------+
1 row in set (0.00 sec)

4. What is your TiDB version? (Required)

@Defined2014 Defined2014 added the type/bug The issue is confirmed as a bug. label Jan 5, 2022
@xiongjiwei
Copy link
Contributor

lpad(f, 5, 0xE4B880), lpad(h, 5, 0xE4B880) is bug of mysql
see https://bugs.mysql.com/bug.php?id=105668

@Defined2014
Copy link
Contributor Author

Defined2014 commented Jan 12, 2022

The root cause is retType of builtin func with json is not same as MySQL

SQLs

create table t(a json);
insert into t values ('{"a":"b"}');
select collation(upper(a)) from t;
select collation(a) from t;

mysql

mysql> select collation(upper(c)) from t;
+---------------------+
| collation(upper(a)) |
+---------------------+
| utf8mb4_bin         |
+---------------------+
1 row in set (0.01 sec)

mysql> select collation(c) from t;
+--------------+
| collation(a) |
+--------------+
| binary       |
+--------------+
1 row in set (0.00 sec)

TiDB

mysql> select collation(upper(a)) from t;
+---------------------+
| collation(upper(a)) |
+---------------------+
| binary              |
+---------------------+
1 row in set (0.00 sec)

mysql> select collation(a) from t;
+--------------+
| collation(a) |
+--------------+
| binary       |
+--------------+
1 row in set (0.00 sec)

Ref:
https://github.com/mysql/mysql-server/blob/3290a66c89eb1625a7058e0ef732432b6952b435/sql/item.h#L1534

@Defined2014 Defined2014 changed the title LPAD and RPAD are not compatible with mysql The collation of JSON is inconsistent with MySQL when process with builtin func Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/moderate 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.

4 participants