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

Case when statement dealing with null logic return a wrong result. #57644

Open
yanghy233 opened this issue Nov 23, 2024 · 2 comments
Open

Case when statement dealing with null logic return a wrong result. #57644

yanghy233 opened this issue Nov 23, 2024 · 2 comments
Labels
affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.4 type/bug The issue is confirmed as a bug.

Comments

@yanghy233
Copy link

yanghy233 commented Nov 23, 2024

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  1. schema.
create table `t2`
(
    `vkey` integer,
    `c16`  double,
    primary key (`vkey`)
);
insert into `t2` (`vkey`, `c16`)
values (4, 1.73);
  1. sql statement.
select case when
(
    select (
               ((null) in
                (select ((case when ((`t2`.`c16`) <> (-3.12)) then (`t2`.`vkey`) else (`t2`.`vkey`) end
                            ) is null))
                   ) is not null)
    from `t2`
)
then 11
else 22
end as `result`;

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

MySQL and TIDB have different execution results in the above case.

The correct result in MySQL 8:

mysql> select case when
    -> (
    ->     select (
    ->                ((null) in
    ->                 (select ((case when ((`t2`.`c16`) <> (-3.12)) then (`t2`.`vkey`) else (`t2`.`vkey`) end
    ->                             ) is null))
    ->                    ) is not null)
    ->     from `t2`
    -> )
    -> then 11
    -> else 22
    -> end as `result`;
+--------+
| result |
+--------+
|     22 |
+--------+
1 row in set (0.00 sec)

3. What did you see instead (Required)

In TiDB v8.1.1:

MySQL [test]> select case when
    -> (
    ->     select (
    ->                ((null) in
    ->                 (select ((case when ((`t2`.`c16`) <> (-3.12)) then (`t2`.`vkey`) else (`t2`.`vkey`) end
    ->                             ) is null))
    ->                    ) is not null)
    ->     from `t2`
    -> )
    -> then 11
    -> else 22
    -> end as `result`;
+--------+
| result |
+--------+
|     11 |
+--------+
1 row in set (0.00 sec)

4. What is your TiDB version? (Required)

tidb v8.1.1

@yanghy233 yanghy233 added the type/bug The issue is confirmed as a bug. label Nov 23, 2024
@yanghy233
Copy link
Author

/label affects-8.1

@ti-chi-bot ti-chi-bot bot added the affects-8.1 This bug affects the 8.1.x(LTS) versions. label Nov 23, 2024
@yanghy233
Copy link
Author

Also affects TiDB v8.4
/label affects-8.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.4 type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

1 participant