-
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
concat(ifnull(time(3)) returns different results from MySQL #29498
Comments
I took a look at this. The minimal testcase is: DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (t3 TIME(3), d DATE);
INSERT INTO t1 VALUES ('00:00:00.567', '2002-01-01');
SELECT CONCAT(IFNULL(t3, d)) AS col1 FROM t1; Because IFNULL returns t3 (since t3 is not null), which (not accounting for type conversion) this should be: SELECT CONCAT(t3) AS col1 FROM t1; Which (not accounting for type conversion) becomes: SELECT t3 AS col1 FROM t1; So the specific problem is type conversion. TiDB gets it right if the query is just |
I had a related comment here. |
/assign @XuHuaiyu |
The Length should be tidb> SELECT IFNULL(t3, d) AS col1 FROM t1;
Field 1: `col1`
Catalog: `def`
Database: ``
Table: ``
Org_table: ``
Type: DATETIME
Collation: utf8mb4_bin (46)
Length: 14
Max_length: 23
Decimals: 3
Flags:
+-------------------------+
| col1 |
+-------------------------+
| 2021-12-03 00:00:00.567 |
+-------------------------+
1 row in set (0.00 sec) |
We need to add a check after line 145 tidb/expression/builtin_control.go Lines 145 to 146 in cec4acb
Like this: if resultEvalType == types.ETDatetime {
// the `+1` is the length of the decimal point
resultFieldType.Flen = mysql.MaxDatetimeWidthNoFsp + mathutil.Max(lhs.Decimal, rhs.Decimal) + 1
} |
PR: #30588 |
/label affects-5.0 |
/label affects-5.1 |
Reproduced it on local dev machine. |
this PR will also solve cases of "case when" and "union". However, since every func has its own flen compute logic, other funcs may has similar problems too. But some func is difficult to change since it may change the behavior, such as: issue#26485 |
Please check whether the issue should be labeled with 'affects-x.y' or 'fixes-x.y.z', and then remove 'needs-more-info' label. |
Bug Report
SET TIMESTAMP doesn't take effect.
1. Minimal reproduce step (Required)
2. What did you expect to see? (Required)
3. What did you see instead (Required)
4. What is your TiDB version? (Required)
The text was updated successfully, but these errors were encountered: