-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
expression: fix enum and set type expression in where clause #22785
expression: fix enum and set type expression in where clause #22785
Conversation
Signed-off-by: lzmhhh123 <[email protected]>
Signed-off-by: lzmhhh123 <[email protected]>
/build |
expression/expression.go
Outdated
@@ -459,7 +459,8 @@ func toBool(sc *stmtctx.StatementContext, tp *types.FieldType, eType types.EvalT | |||
if tp.Hybrid() { | |||
switch tp.Tp { | |||
case mysql.TypeEnum, mysql.TypeSet: | |||
fVal = float64(len(sVal)) | |||
// Enum and Set type value to bool is always true. | |||
fVal = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reference in the mysql manual?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mysql> create table t(a enum("a", "b", "c"));
Query OK, 0 rows affected (0.02 sec)
mysql> insert into t values('a'),('b');
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> set @@sql_mode='';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> insert into t values("");
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> select * from t;
+------+
| a |
+------+
| a |
| b |
| |
+------+
3 rows in set (0.00 sec)
mysql> select * from t where a;
+------+
| a |
+------+
| a |
| b |
+------+
2 rows in set (0.00 sec)
Signed-off-by: lzmhhh123 <[email protected]>
expression/expression.go
Outdated
fVal = float64(len(sVal)) | ||
if fVal == 0 { | ||
// Check whether "" in set type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change this comment to:
The elements listed in the column specification are assigned index numbers, beginning with 1. The index value of the empty string error value (distinguish from a “normal” empty string) is 0. Thus we need to check whether it's an empty string error value when `fVal==0`
Signed-off-by: lzmhhh123 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/merge |
Your auto merge job has been accepted, waiting for:
|
/run-all-tests |
Signed-off-by: ti-srebot <[email protected]>
cherry pick to release-4.0 in PR #22814 |
Signed-off-by: ti-srebot <[email protected]>
cherry pick to release-5.0-rc in PR #22815 |
Signed-off-by: lzmhhh123 [email protected]
What problem does this PR solve?
Issue Number: close #22717
What is changed and how it works?
How it Works:
Related changes
Check List
Tests
Release note