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

expression: short-cut expressions may get more warnings than needed #56481

Closed
gengliqi opened this issue Oct 8, 2024 · 1 comment · Fixed by #56482
Closed

expression: short-cut expressions may get more warnings than needed #56481

gengliqi opened this issue Oct 8, 2024 · 1 comment · Fixed by #56482
Labels
severity/moderate type/bug The issue is confirmed as a bug.

Comments

@gengliqi
Copy link
Contributor

gengliqi commented Oct 8, 2024

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

mysql> create table test.t(f1 char(1));
Query OK, 0 rows affected (0.07 sec)

mysql> insert into test.t values ('a'),('b'),('1');
Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select (cast(f1 as float) = 1) or (cast(f1 as float) = 2) from test.t;
+----------------------------------------------------+
| (cast(f1 as float) = 1) or (cast(f1 as float) = 2) |
+----------------------------------------------------+
|                                                  0 |
|                                                  0 |
|                                                  1 |
+----------------------------------------------------+
3 rows in set, 6 warnings (0.00 sec)

mysql> show warnings;
+---------+------+---------------------------------------+
| Level   | Code | Message                               |
+---------+------+---------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'a' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'b' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'a' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'a' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'b' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'b' |
+---------+------+---------------------------------------+
6 rows in set (0.00 sec)

mysql> select (cast(f1 as float) != 1) and (cast(f1 as float) != 2) from test.t;
+-------------------------------------------------------+
| (cast(f1 as float) != 1) and (cast(f1 as float) != 2) |
+-------------------------------------------------------+
|                                                     1 |
|                                                     1 |
|                                                     0 |
+-------------------------------------------------------+
3 rows in set, 6 warnings (0.00 sec)

mysql> show warnings;
+---------+------+---------------------------------------+
| Level   | Code | Message                               |
+---------+------+---------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'a' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'b' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'a' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'a' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'b' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'b' |
+---------+------+---------------------------------------+
6 rows in set (0.00 sec)

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

MySQL 8.0
mysql> create table test.t(f1 char(1));
Query OK, 0 rows affected (0.03 sec)

mysql> insert into test.t values ('a'),('b'),('1');
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select (cast(f1 as float) = 1) or (cast(f1 as float) = 2) from test.t;
+----------------------------------------------------+
| (cast(f1 as float) = 1) or (cast(f1 as float) = 2) |
+----------------------------------------------------+
|                                                  0 |
|                                                  0 |
|                                                  1 |
+----------------------------------------------------+
3 rows in set, 4 warnings (0.02 sec)

mysql> show warnings;
+---------+------+---------------------------------------+
| Level   | Code | Message                               |
+---------+------+---------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'a' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'a' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'b' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'b' |
+---------+------+---------------------------------------+
4 rows in set (0.00 sec)

mysql> select (cast(f1 as float) != 1) and (cast(f1 as float) != 2) from test.t;
+-------------------------------------------------------+
| (cast(f1 as float) != 1) and (cast(f1 as float) != 2) |
+-------------------------------------------------------+
|                                                     1 |
|                                                     1 |
|                                                     0 |
+-------------------------------------------------------+
3 rows in set, 4 warnings (0.00 sec)

mysql> show warnings;
+---------+------+---------------------------------------+
| Level   | Code | Message                               |
+---------+------+---------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'a' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'a' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'b' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'b' |
+---------+------+---------------------------------------+
4 rows in set (0.00 sec)

3. What did you see instead (Required)

6 warnings other than 4 warnings.

4. What is your TiDB version? (Required)

master

@gengliqi gengliqi added the type/bug The issue is confirmed as a bug. label Oct 8, 2024
@gengliqi
Copy link
Contributor Author

gengliqi commented Oct 8, 2024

/severity moderate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/moderate type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant