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

bug: case when then return wrong results #6944

Closed
1 of 2 tasks
xudong963 opened this issue Aug 2, 2022 · 1 comment · Fixed by #6950
Closed
1 of 2 tasks

bug: case when then return wrong results #6944

xudong963 opened this issue Aug 2, 2022 · 1 comment · Fixed by #6950
Assignees
Labels
A-planner Area: planner/optimizer C-bug Category: something isn't working

Comments

@xudong963
Copy link
Member

Search before asking

  • I had searched in the issues and found no similar issues.

Version

main

What's Wrong?

databend

mysql> select
    ->        case a+1 when b then 111 when c then 222
    ->         when d then 333  when e then 444 else 555 end as col6
    -> from t1
    -> order by col6;
+------+
| col6 |
+------+
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
|  111 |
+------+

pg

postgres=# select
postgres-#        case a+1 when b then 111 when c then 222
postgres-#         when d then 333  when e then 444 else 555 end as col6
postgres-# from t1
postgres-# order by col6;
 col6
------
  111
  111
  111
  111
  222
  222
  222
  333
  333
  333
  333
  333
  333
  333
  333
  333
  444
  444
  444
  444
  444
  555
  555
  555
  555
  555
  555
  555
  555
  555
(30 rows)

How to Reproduce?

Use table t1 in https://github.com/datafuselabs/databend/blob/main/tests/logictest/suites/ydb/select1-1.test

Then run

select
       case a+1 when b then 111 when c then 222
        when d then 333  when e then 444 else 555 end as col6
from t1
order by col6;

Are you willing to submit PR?

  • Yes I am willing to submit a PR!
@xudong963 xudong963 added C-bug Category: something isn't working A-planner Area: planner/optimizer labels Aug 2, 2022
@sundy-li
Copy link
Member

sundy-li commented Aug 2, 2022

CASE case_value
    WHEN when_value THEN statement_list
    [WHEN when_value THEN statement_list] ...
    [ELSE statement_list]
END CASE

This is case expression with case_value, it should rewrite to

CASE
    WHEN when_value  = case_value THEN statement_list
    [WHEN when_value  = case_value THEN statement_list] ...
    [ELSE statement_list]
END CASE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-planner Area: planner/optimizer C-bug Category: something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants