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

TIMEDIFF with fraction doesn't function in TiDB #31680

Closed
espresso98 opened this issue Jan 13, 2022 · 1 comment · Fixed by #32896
Closed

TIMEDIFF with fraction doesn't function in TiDB #31680

espresso98 opened this issue Jan 13, 2022 · 1 comment · Fixed by #32896
Assignees
Labels
affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@espresso98
Copy link
Collaborator

Bug Report

TIMEDIFF(expr1,expr2) returns expr1 − expr2 expressed as a time value.
TiDB returns NULL values in time data with fraction in default sql mode.

1. Minimal reproduce step

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a TIME(6));
INSERT INTO t1 VALUES ('-01:00:00.000001');
INSERT INTO t1 VALUES ('-01:00:00.000000');
INSERT INTO t1 VALUES ('-00:00:00.000001');
INSERT INTO t1 VALUES ('00:00:00.000000');
INSERT INTO t1 VALUES ('00:00:00.000001');
INSERT INTO t1 VALUES ('01:00:00.000000');
INSERT INTO t1 VALUES ('01:00:00.000001');

SELECT a, TIMEDIFF(a, '00:00:00.000001') FROM t1;
SELECT a, TIMEDIFF('00:00:00.000001', a) FROM t1;
DROP TABLE t1;

2. What did you expect to see?

mysql> SELECT a, TIMEDIFF(a, '00:00:00.000001') FROM t1;
+------------------+--------------------------------+
| a                | TIMEDIFF(a, '00:00:00.000001') |
+------------------+--------------------------------+
| -01:00:00.000001 | -01:00:00.000002               |
| -01:00:00.000000 | -01:00:00.000001               |
| -00:00:00.000001 | -00:00:00.000002               |
| 00:00:00.000000  | -00:00:00.000001               |
| 00:00:00.000001  | 00:00:00.000000                |
| 01:00:00.000000  | 00:59:59.999999                |
| 01:00:00.000001  | 01:00:00.000000                |
+------------------+--------------------------------+

mysql> SELECT a, TIMEDIFF('00:00:00.000001', a) FROM t1;
+------------------+--------------------------------+
| a                | TIMEDIFF('00:00:00.000001', a) |
+------------------+--------------------------------+
| -01:00:00.000001 | 01:00:00.000002                |
| -01:00:00.000000 | 01:00:00.000001                |
| -00:00:00.000001 | 00:00:00.000002                |
| 00:00:00.000000  | 00:00:00.000001                |
| 00:00:00.000001  | 00:00:00.000000                |
| 01:00:00.000000  | -00:59:59.999999               |
| 01:00:00.000001  | -01:00:00.000000               |
+------------------+--------------------------------+

3. What did you see instead

tidb> SELECT a, TIMEDIFF(a, '00:00:00.000001') FROM t1;
+------------------+--------------------------------+
| a                | TIMEDIFF(a, '00:00:00.000001') |
+------------------+--------------------------------+
| -01:00:00.000001 | NULL                           |
| -01:00:00.000000 | NULL                           |
| -00:00:00.000001 | NULL                           |
| 00:00:00.000000  | NULL                           |
| 00:00:00.000001  | NULL                           |
| 01:00:00.000000  | NULL                           |
| 01:00:00.000001  | NULL                           |
+------------------+--------------------------------+

tidb> SELECT a, TIMEDIFF('00:00:00.000001', a) FROM t1;
+------------------+--------------------------------+
| a                | TIMEDIFF('00:00:00.000001', a) |
+------------------+--------------------------------+
| -01:00:00.000001 | NULL                           |
| -01:00:00.000000 | NULL                           |
| -00:00:00.000001 | NULL                           |
| 00:00:00.000000  | NULL                           |
| 00:00:00.000001  | NULL                           |
| 01:00:00.000000  | NULL                           |
| 01:00:00.000001  | NULL                           |
+------------------+--------------------------------+

4. What is your TiDB version?

tidb_version(): Release Version: v5.5.0-alpha-105-gaabd4e04d
Edition: Community
Git Commit Hash: aabd4e04d994eb91663abaa80865daec4cf970a6
Git Branch: master
UTC Build Time: 2022-01-13 05:36:36
GoVersion: go1.17.2
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
@espresso98 espresso98 added the type/bug The issue is confirmed as a bug. label Jan 13, 2022
@ChenPeng2013 ChenPeng2013 added severity/major sig/execution SIG execution affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. labels Jan 14, 2022
@Defined2014
Copy link
Contributor

/assign

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. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. 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.

3 participants