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

CONCAT negative decimal value is chopping last digit in TiDB #29417

Closed
ramanich1 opened this issue Nov 3, 2021 · 8 comments · Fixed by #29687
Closed

CONCAT negative decimal value is chopping last digit in TiDB #29417

ramanich1 opened this issue Nov 3, 2021 · 8 comments · Fixed by #29687
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. severity/critical sig/execution SIG execution type/bug This issue is a bug.

Comments

@ramanich1
Copy link
Collaborator

Bug Report

1. Minimal reproduce step (Required)

drop table if exists t1;
create table t1 (f1 decimal(5,5));
insert into t1 values (-0.12345);
select concat(f1),f1 from t1;

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

mysql> drop table if exists t1;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> create table t1 (f1 decimal(5,5));
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t1 values (-0.12345);
Query OK, 1 row affected (0.00 sec)

mysql> select concat(f1),f1 from t1;
+------------+----------+
| concat(f1) | f1       |
+------------+----------+
| -0.12345   | -0.12345 |
+------------+----------+
1 row in set (0.00 sec)

3. What did you see instead (Required)

mysql> drop table if exists t1;
Query OK, 0 rows affected (0.22 sec)

mysql> create table t1 (f1 decimal(5,5));
Query OK, 0 rows affected (0.09 sec)

mysql> insert into t1 values (-0.12345);
Query OK, 1 row affected (0.02 sec)

mysql> select concat(f1),f1 from t1;
+------------+----------+
| concat(f1) | f1       |
+------------+----------+
| -0.1234    | -0.12345 |
+------------+----------+
1 row in set, 1 warning (0.01 sec)

4. What is your TiDB version? (Required)

+-------------------------+--------------------------------------------------------------------------+
| Variable_name           | Value                                                                    |
+-------------------------+--------------------------------------------------------------------------+
| innodb_version          | 5.6.25                                                                   |
| protocol_version        | 10                                                                       |
| tidb_analyze_version    | 2                                                                        |
| tidb_row_format_version | 2                                                                        |
| tls_version             | TLSv1,TLSv1.1,TLSv1.2                                                    |
| version                 | 5.7.25-TiDB-v5.2.1                                                       |
| version_comment         | TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible |
| version_compile_machine | x86_64                                                                   |
| version_compile_os      | osx10.8                                                                  |
+-------------------------+--------------------------------------------------------------------------+
9 rows in set (0.00 sec)
@ramanich1 ramanich1 added the type/bug This issue is a bug. label Nov 3, 2021
@aytrack
Copy link
Contributor

aytrack commented Nov 4, 2021

TIDB

mysql> select concat(f1),f1 from t1;
Field   1:  `concat(f1)`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       VAR_STRING
Collation:  utf8mb4_bin (46)
Length:     28
Max_length: 7
Decimals:   31
Flags:

Field   2:  `f1`
Catalog:    `def`
Database:   `test`
Table:      `t1`
Org_table:  `t1`
Type:       NEWDECIMAL
Collation:  binary (63)
Length:     7
Max_length: 8
Decimals:   5
Flags:      NUM


+------------+----------+
| concat(f1) | f1       |
+------------+----------+
| -0.1234    | -0.12345 |
+------------+----------+
1 row in set, 1 warning (0.00 sec)

mysql> select concat(cast(f1 as char)) from t1;
Field   1:  `concat(cast(f1 as char))`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       MEDIUM_BLOB
Collation:  utf8mb4_bin (46)
Length:     67108860
Max_length: 8
Decimals:   31
Flags:


+--------------------------+
| concat(cast(f1 as char)) |
+--------------------------+
| -0.12345                 |
+--------------------------+
1 row in set (0.00 sec)

Mysql 8.0.26

mysql> select concat(f1),f1 from t1;select concat(f1),f1 from t1;
Field   1:  `concat(f1)`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       VAR_STRING
Collation:  utf8mb4_general_ci (45)
Length:     28
Max_length: 8
Decimals:   31
Flags:

Field   2:  `f1`
Catalog:    `def`
Database:   `hchwang`
Table:      `t1`
Org_table:  `t1`
Type:       NEWDECIMAL
Collation:  binary (63)
Length:     7
Max_length: 8
Decimals:   5
Flags:      NUM


+------------+----------+
| concat(f1) | f1       |
+------------+----------+
| -0.12345   | -0.12345 |
+------------+----------+
1 row in set (0.04 sec)

@aytrack aytrack added the sig/execution SIG execution label Nov 4, 2021
@morgo
Copy link
Contributor

morgo commented Nov 4, 2021

I think this is critical? Decimal is precison math, and the scenario is not unexpected for user-supplied queries.

@aytrack aytrack 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. severity/critical labels Nov 4, 2021
@aytrack
Copy link
Contributor

aytrack commented Nov 4, 2021

I think this is critical? Decimal is precison math, and the scenario is not unexpected for user-supplied queries.

yes, and it affects all versions.

@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.

@cyliu0
Copy link
Contributor

cyliu0 commented Nov 24, 2021

Crc32 has been affected by this too. Already fixed in master. In case someone will be curious about different crc32 results in different versions of TiDB
image

@guo-shaoge
Copy link
Collaborator

Crc32 has been affected by this too. Already fixed in master. In case someone will be curious about different crc32 results in different versions of TiDB image

Can you please paste the schema of jxtest.

@cyliu0
Copy link
Contributor

cyliu0 commented Nov 26, 2021

k is decimal(8,8)

@guo-shaoge
Copy link
Collaborator

THX. So according to the definition of k, the outputs of crc32(k) and concat_ws() are both reasonable.(Also same with MySQL).

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. severity/critical sig/execution SIG execution type/bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants