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

return wrong result using decimal column #28254

Closed
ChenPeng2013 opened this issue Sep 22, 2021 · 2 comments · Fixed by #28827
Closed

return wrong result using decimal column #28254

ChenPeng2013 opened this issue Sep 22, 2021 · 2 comments · Fixed by #28827
Assignees
Labels
affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. epic/plan-cache severity/critical sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@ChenPeng2013
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

prepared-plan-cache.enable = true

use test;
drop table if exists PK_GCOL_STORED9816;
CREATE TABLE `PK_GCOL_STORED9816` (
  `COL102` decimal(55,0) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
insert into PK_GCOL_STORED9816 values(9710290195629059011);
prepare stmt from 'select count(*) from PK_GCOL_STORED9816 where col102 > ?;';
set @a=9860178624005968368;
execute stmt using @a;
set @a=-7235178122860450591;
execute stmt using @a;
select count(*) from PK_GCOL_STORED9816 where col102 > -7235178122860450591;

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

release-4.0 & release-5.0

mysql> execute stmt using @a;
+----------+
| count(*) |
+----------+
|        1 |
+----------+
1 row in set (0.00 sec)

mysql> select count(*) from PK_GCOL_STORED9816 where col102 > -7235178122860450591;
+----------+
| count(*) |
+----------+
|        1 |
+----------+
1 row in set (0.01 sec)

3. What did you see instead (Required)

release-5.1 & release-5.2 & master

mysql> execute stmt using @a;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.00 sec)

mysql> select count(*) from PK_GCOL_STORED9816 where col102 > -7235178122860450591;
+----------+
| count(*) |
+----------+
|        1 |
+----------+
1 row in set (0.01 sec)

4. What is your TiDB version? (Required)

Release Version: v5.1.1-58-gdc079337e
Edition: Community
Git Commit Hash: dc079337ef0c9d78eec2d2acb1eb31e12117d29b
Git Branch: release-5.1
UTC Build Time: 2021-09-22 02:01:55
GoVersion: go1.16.5
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
@ChenPeng2013 ChenPeng2013 added type/bug The issue is confirmed as a bug. sig/planner SIG: Planner severity/critical epic/plan-cache affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. labels Sep 22, 2021
@qw4990 qw4990 self-assigned this Sep 22, 2021
@qw4990
Copy link
Contributor

qw4990 commented Oct 14, 2021

The root cause is that the type of the parameter a changes.
In the first processing, the a=9860178624005968368 is parsed as a uint value since its value is large than MaxInt64=9223372036854775807.
And then in the second processing, a becomes negative which is out of uint range, and our plan-cache cannot be aware of this change, which causes this problem.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. epic/plan-cache severity/critical sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants