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

Wrong collation for select concat(unix_timestamp(datetime)*1000, '') from t #24296

Closed
tiancaiamao opened this issue Apr 26, 2021 · 1 comment · Fixed by #24297
Closed

Wrong collation for select concat(unix_timestamp(datetime)*1000, '') from t #24296

tiancaiamao opened this issue Apr 26, 2021 · 1 comment · Fixed by #24297
Assignees
Labels
severity/critical type/bug The issue is confirmed as a bug.

Comments

@tiancaiamao
Copy link
Contributor

tiancaiamao commented Apr 26, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

mysql -h 127.0.0.1 -u root -P 4000 --column-type-info

mysql> create table t (dt datetime not null);
mysql> insert into t values ('2021-04-26 14:52:33');
mysql> select concat(unix_timestamp(dt)*1000, '') from t;
Field   1:  `concat(unix_timestamp(dt)*1000, '')`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       VAR_STRING
Collation:  binary (63)
Length:     20
Max_length: 13
Decimals:   31
Flags:      NOT_NULL BINARY 


+--------------------------------------------------------------------------+
| concat(unix_timestamp(dt)*1000, '')                                      |
+--------------------------------------------------------------------------+
| 0x31363139343139393533303030                                             |
+--------------------------------------------------------------------------+
1 row in set (0.01 sec)

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

mysql> select concat(unix_timestamp(dt)*1000, '') from t;
Field   1:  `concat(unix_timestamp(dt)*1000, '')`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       VAR_STRING
Collation:  utf8mb4_bin (46)
Length:     80
Max_length: 13
Decimals:   31
Flags:      


+-------------------------------------+
| concat(unix_timestamp(dt)*1000, '') |
+-------------------------------------+
| 1619419953000                       |
+-------------------------------------+
1 row in set (0.00 sec)

3. What did you see instead (Required)

+--------------------------------------------------------------------------+
| concat(unix_timestamp(dt)*1000, '')                                      |
+--------------------------------------------------------------------------+
| 0x31363139343139393533303030                                             |
+--------------------------------------------------------------------------+
1 row in set (0.01 sec)

4. What is your TiDB version? (Required)

This bug was introduced in 4.0.11 by #19186
It also exists on 5.0 and master.

The collation of concat(cast(mul(unix_timestamp(test.t.dt), 1000), var_string(20)), '') should be utf8mb4 but get binary after this change https://github.com/pingcap/tidb/pull/19186/files#diff-3556e9d098f2adc7f39a39054ebb397bf08d9141b3f0dbba52d9f109f439f45aR162-R163

@ti-srebot
Copy link
Contributor

Please edit this comment or add a new comment to complete the following information

Not a bug

  1. Remove the 'type/bug' label
  2. Add notes to indicate why it is not a bug

Duplicate bug

  1. Add the 'type/duplicate' label
  2. Add the link to the original bug

Bug

Note: Make Sure that 'component', and 'severity' labels are added
Example for how to fill out the template: #20100

1. Root Cause Analysis (RCA) (optional)

2. Symptom (optional)

3. All Trigger Conditions (optional)

4. Workaround (optional)

5. Affected versions

6. Fixed versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/critical type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants