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

Incompatible with MySQL when using expressions returning enum as WHERE conditions #23114

Closed
dyzsr opened this issue Mar 4, 2021 · 3 comments · Fixed by #24542
Closed

Incompatible with MySQL when using expressions returning enum as WHERE conditions #23114

dyzsr opened this issue Mar 4, 2021 · 3 comments · Fixed by #24542
Assignees
Labels
affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. component/expression severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@dyzsr
Copy link
Contributor

dyzsr commented Mar 4, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

drop table if exists e;
create table e(e enum('c', 'b', 'a'));
insert into e values ('a'),('b'),('a'),('b');
select e from e where if(e>1, e, e);
select e from e where case e when 1 then e else e end;

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

MySQL 8.0.22

mysql root@localhost:test> select e from e where if(e>1, e, e);
+---+
| e |
+---+
| a |
| b |
| a |
| b |
+---+
4 rows in set
Time: 0.007s

mysql root@localhost:test> select e from e where case e when 1 then e else e end;
+---+
| e |
+---+
| a |
| b |
| a |
| b |
+---+
4 rows in set
Time: 0.013s

mysql root@localhost:test> select if(e>1,e,e)='a' from e
+-----------------+
| if(e>1,e,e)='a' |
+-----------------+
| 1               |
| 0               |
| 0               |
+-----------------+
3 rows in set
Time: 0.060s

mysql root@localhost:test> select if(e>1,e,e)=1 from e
+---------------+
| if(e>1,e,e)=1 |
+---------------+
| 0             |
| 0             |
| 1             |
+---------------+
3 rows in set
Time: 0.008s

3. What did you see instead (Required)

mysql root@127.0.0.1:test> select e from e where if(e>1, e, e);
+---+
| e |
+---+
0 rows in set
Time: 0.009s

mysql root@127.0.0.1:test> select e from e where case e when 1 then e else e end;
+---+
| e |
+---+
0 rows in set
Time: 0.011s

mysql root@127.0.0.1:test> select if(e>1,e,e)='a' from e;
+-----------------+
| if(e>1,e,e)='a' |
+-----------------+
| 1               |
| 0               |
| 0               |
+-----------------+
3 rows in set
Time: 3.559s

mysql root@127.0.0.1:test> select if(e>1,e,e)=1 from e;
+---------------+
| if(e>1,e,e)=1 |
+---------------+
| 0             |
| 0             |
| 0             |
+---------------+
3 rows in set
Time: 0.014s

4. What is your TiDB version? (Required)

tidb_version() | Release Version: v4.0.0-beta.2-2275-g5f73c822c
Edition: Community
Git Commit Hash: 5f73c822cabbf5dab31f37fa17437c2b041fd516
Git Branch: master
UTC Build Time: 2021-03-04 09:55:51
GoVersion: go1.15
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false

5. Root cause analysis

The eval type of if(e>1, e, e) is evaluated as ETString. Enum value 'a' as string becomes 0 when converting to int.

Maybe we should consider adding Enum/Set as separate eval types.
Related RFC: https://github.com/tikv/rfcs/pull/57/files

@dyzsr dyzsr added the type/bug The issue is confirmed as a bug. label Mar 4, 2021
@dyzsr
Copy link
Contributor Author

dyzsr commented Mar 4, 2021

/sig execution
/component expression

@guo-shaoge
Copy link
Collaborator

drop table t1;
create table t1(c1 enum('a', 'b'));
insert into t1 values('a');
select if(c1 > -1, c1, 1) > 1 from t1;

mysql> select (case when c1 then c1 end) > 1 from t1;
ERROR 1105 (HY000): baseBuiltinFunc.evalInt() should never be called, please contact the TiDB team for help

Same reason here: Expression don't return enum/set type when deduce type.

CaseWhen expr's eval function is builtinCaseWhenStringSig, which only implement EvalString, but GT expr need EvalInt().

@ti-srebot
Copy link
Contributor

Please edit this comment or add a new comment to complete the following information

Not a bug

  1. Remove the 'type/bug' label
  2. Add notes to indicate why it is not a bug

Duplicate bug

  1. Add the 'type/duplicate' label
  2. Add the link to the original bug

Bug

Note: Make Sure that 'component', and 'severity' labels are added
Example for how to fill out the template: #20100

1. Root Cause Analysis (RCA) (optional)

2. Symptom (optional)

3. All Trigger Conditions (optional)

4. Workaround (optional)

5. Affected versions

6. Fixed versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. component/expression severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants