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

TiDB and MySQL behave differently when multiply EXISTS result and a signed integer #56641

Closed
r33s3n6 opened this issue Oct 14, 2024 · 1 comment · Fixed by #57277
Closed

TiDB and MySQL behave differently when multiply EXISTS result and a signed integer #56641

r33s3n6 opened this issue Oct 14, 2024 · 1 comment · Fixed by #57277
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@r33s3n6
Copy link

r33s3n6 commented Oct 14, 2024

1. Minimal reproduce step (Required)

select 
  ((exists (select 1)) * -5) as c1,
  (true * -5) as c2,
  ((0 in (0)) * -5) as c3
;

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

mysql> select 
    ->   ((exists (select 1)) * -5) as c1,
    ->   (true * -5) as c2,
    ->   ((0 in (0)) * -5) as c3
    -> ;
+----+----+----+
| c1 | c2 | c3 |
+----+----+----+
| -5 | -5 | -5 |
+----+----+----+
1 row in set (0.00 sec)

3. What did you see instead (Required)

mysql> select 
    ->   ((exists (select 1)) * -5) as c1,
    ->   (true * -5) as c2,
    ->   ((0 in (0)) * -5) as c3
    -> ;
+----------------------+----+----+
| c1                   | c2 | c3 |
+----------------------+----+----+
| 18446744073709551611 | -5 | -5 |
+----------------------+----+----+
1 row in set (0.00 sec)

4. What is your TiDB version? (Required)

Release Version: v8.4.0-alpha-370-gf773b6eeb4
Edition: Community
Git Commit Hash: f773b6eeb4593a3e2c998c265f491a016570a426
Git Branch: HEAD
UTC Build Time: 2024-10-11 02:08:09
GoVersion: go1.23.2
Race Enabled: false
Check Table Before Drop: false
Store: tikv

about us

We are the BASS team from the School of Cyber Science and Technology at Beihang University. Our main focus is on system software security, operating systems, and program analysis research, as well as the development of automated program testing frameworks for detecting software defects. Using our self-developed database vulnerability testing tool, we have identified the above-mentioned vulnerabilities in TiDB that may lead to database logic error.

@windtalker
Copy link
Contributor

The root cause is the return type of exists (select 1) has unsigned flag in TiDB, while it is a signed int in MySQL

@ti-chi-bot ti-chi-bot bot added the affects-8.5 This bug affects the 8.5.x(LTS) versions. label Nov 1, 2024
@windtalker windtalker added affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. and removed may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 may-affects-8.1 labels Nov 11, 2024
@XuHuaiyu XuHuaiyu added sig/planner SIG: Planner and removed sig/execution SIG execution labels Nov 12, 2024
@ti-chi-bot ti-chi-bot bot closed this as completed in 2d9f829 Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. severity/major 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.

4 participants