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

expression: wrong results when comparing Decimal and BigInt #12301

Closed
qw4990 opened this issue Sep 23, 2019 · 0 comments · Fixed by #12312
Closed

expression: wrong results when comparing Decimal and BigInt #12301

qw4990 opened this issue Sep 23, 2019 · 0 comments · Fixed by #12312
Assignees
Labels
type/bug This issue is a bug.

Comments

@qw4990
Copy link
Contributor

qw4990 commented Sep 23, 2019

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.
    The reason causing this problem is that when casting a bigint like bigint(11) to decimal, we use the zerofill-length 11 as its type size, so we will do cast(bigint(11) as decimal(11, 0)), which may cause Overflow error.
create table t (
    d decimal(19, 0),
    i bigint(11)
);
insert into t values (123456789012, 123456789012);
select * from t where d = i;
  1. What did you expect to see?
mysql> create table t (
    ->     d decimal(19, 0),
    ->     i bigint(11)
    -> );
Query OK, 0 rows affected (0.03 sec)

mysql> 
mysql> insert into t values (123456789012, 123456789012);
Query OK, 1 row affected (0.00 sec)

mysql> select * from t where d = i;
+--------------+--------------+
| d            | i            |
+--------------+--------------+
| 123456789012 | 123456789012 |
+--------------+--------------+
1 row in set (0.00 sec)
  1. What did you see instead?
mysql> create table t (
    ->     d decimal(19, 0),
    ->     i bigint(11)
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t values (123456789012, 123456789012);
Query OK, 1 row affected (0.00 sec)

mysql> select * from t where d = i;
Empty set, 1 warning (0.00 sec)
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
mysql> select tidb_version();
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                                               |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v4.0.0-alpha-309-g181c3a890
Git Commit Hash: 181c3a890df60eee486382cab40415db34d30b2a
Git Branch: master
UTC Build Time: 2019-09-23 03:33:16
GoVersion: go version go1.12 darwin/amd64
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant