-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Incorrect return type about if function when argument type contains bit #26358
Comments
Seems that the return type in MySQL is var_string and TiDB is LongLong |
@yuqi1129 are you interested in fixing it? |
@ichn-hu , Yes, I am working on this |
/assign @yuqi1129 let me know if you have any problems |
It seems that tidb returns type tidb> select if (b, b,1) from t4;
Field 1: `if (b, b,1)`
Catalog: `def`
Database: ``
Table: ``
Org_table: ``
Type: NEWDECIMAL
Collation: binary (63)
Length: 12
Max_length: 4
Decimals: 0
Flags: NOT_NULL MULTIPLE_KEY BINARY NUM
+-------------+
| if (b, b,1) |
+-------------+
| 1 |
| 1 |
| 1000 |
+-------------+
3 rows in set (0.00 sec) |
@XuHuaiyu , Yes, it's |
Correct: MySQL is |
I test with MySQL 5.7 and 8.0. mysql> select if(b, b,1) from t4;
+------------+
| if(b, b,1) |
+------------+
| 1 |
| |
| è |
+------------+
3 rows in set (0.00 sec) And in MySQL 8.0, the return type is mysql> select if(b, b,1) from t4;
Field 1: `if(b, b,1)`
Catalog: `def`
Database: ``
Table: ``
Org_table: ``
Type: NEWDECIMAL
Collation: binary (63)
Length: 11
Max_length: 3
Decimals: 0
Flags: BINARY NUM
+------------+
| if(b, b,1) |
+------------+
| 1 |
| |
| è |
+------------+
3 rows in set (0.01 sec) I highly doubt the output given by @yuqi1129 is wrong because select if (b, b,1) from t4;
+--------------------------+
| if (b, b,1) |
+--------------------------+
| 0x31 |
| 0x0001 |
| 0x03C3A8 |
+--------------------------+
3 rows in set (0.03 sec) For now, my conclusion is the output of TiDB is more suitable than MySQL. There is other evidence that can prove it's probably a bug of MySQL. mysql> select hex(if(b, b,1)) from t4;
+-----------------+
| hex(if(b, b,1)) |
+-----------------+
| 1 |
| 1 |
| 3E8 |
+-----------------+
3 rows in set (0.00 sec)
mysql> select bin(if(b, b,1)) from t4;
+-----------------+
| bin(if(b, b,1)) |
+-----------------+
| 1 |
| 0 |
| 0 |
+-----------------+
3 rows in set, 2 warnings (0.00 sec)
mysql> show warnings;
+---------+------+------------------------------------------+
| Level | Code | Message |
+---------+------+------------------------------------------+
| Warning | 1292 | Truncated incorrect DECIMAL value: '' |
| Warning | 1292 | Truncated incorrect DECIMAL value: 'è' |
+---------+------+------------------------------------------+
2 rows in set (0.00 sec)
mysql> select bin(b) from t4;
+------------+
| bin(b) |
+------------+
| 0 |
| 1 |
| 1111101000 |
+------------+
3 rows in set (0.08 sec) TiDB mysql> select hex(if(b, b,1)) from t4;
+-----------------+
| hex(if(b, b,1)) |
+-----------------+
| 1 |
| 1 |
| 3E8 |
+-----------------+
3 rows in set (0.00 sec)
mysql> select bin(if(b, b,1)) from t4;
+-----------------+
| bin(if(b, b,1)) |
+-----------------+
| 1 |
| 1 |
| 1111101000 |
+-----------------+
3 rows in set (0.00 sec)
mysql> select bin(b) from t4;
+------------+
| bin(b) |
+------------+
| 0 |
| 1 |
| 1111101000 |
+------------+
3 rows in set (0.00 sec) |
@zanmato1984 Do you mind taking a look? I think we can lower the severity or just close this issue. |
According to @gengliqi 's description, I think:
I would consider this a MySQL bug and TiDB is (surprisingly) better, i.e., more self-consistent, than MySQL. So I'm closing this issue as a non-bug, as well as the associated PR (which we don't see a respond to the review comment for a long time). Feel free to reopen this issue if you have any question. Thanks. |
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
Run master and do the following
2. What did you expect to see? (Required)
3. What did you see instead (Required)
4. What is your TiDB version? (Required)
Master
The text was updated successfully, but these errors were encountered: