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

SUBTIME function returns wrong result in DATETIME(N) type #31868

Closed
espresso98 opened this issue Jan 20, 2022 · 2 comments · Fixed by #32903
Closed

SUBTIME function returns wrong result in DATETIME(N) type #31868

espresso98 opened this issue Jan 20, 2022 · 2 comments · Fixed by #32903
Assignees
Labels
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 5.4.x versions. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@espresso98
Copy link
Collaborator

Bug Report

1. Minimal reproduce step

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a DATETIME(6));
INSERT INTO t1 VALUES ('1000-01-01 01:00:00.000000');
INSERT INTO t1 VALUES ('1000-01-01 01:00:00.000001');
INSERT INTO t1 VALUES ('2001-01-01 01:00:00.000000');
INSERT INTO t1 VALUES ('2001-01-01 01:00:00.000001');
SELECT a, SUBTIME(a, '00:00:00.000001') FROM t1 ORDER BY a;
SELECT a, SUBTIME(a, '10:00:00.000001') FROM t1 ORDER BY a;
DROP TABLE t1;

2. What did you expect to see?

mysql> SELECT a, SUBTIME(a, '00:00:00.000001') FROM t1 ORDER BY a;
+----------------------------+-------------------------------+
| a                          | SUBTIME(a, '00:00:00.000001') |
+----------------------------+-------------------------------+
| 1000-01-01 01:00:00.000000 | 1000-01-01 00:59:59.999999    |
| 1000-01-01 01:00:00.000001 | 1000-01-01 01:00:00.000000    |
| 2001-01-01 01:00:00.000000 | 2001-01-01 00:59:59.999999    |
| 2001-01-01 01:00:00.000001 | 2001-01-01 01:00:00.000000    |
+----------------------------+-------------------------------+

mysql> SELECT a, SUBTIME(a, '10:00:00.000001') FROM t1 ORDER BY a;
+----------------------------+-------------------------------+
| a                          | SUBTIME(a, '10:00:00.000001') |
+----------------------------+-------------------------------+
| 1000-01-01 01:00:00.000000 | 0999-12-31 14:59:59.999999    |
| 1000-01-01 01:00:00.000001 | 0999-12-31 15:00:00.000000    |
| 2001-01-01 01:00:00.000000 | 2000-12-31 14:59:59.999999    |
| 2001-01-01 01:00:00.000001 | 2000-12-31 15:00:00.000000    |
+----------------------------+-------------------------------+

3. What did you see instead

tidb> SELECT a, SUBTIME(a, '00:00:00.000001') FROM t1 ORDER BY a;
+----------------------------+-------------------------------+
| a                          | SUBTIME(a, '00:00:00.000001') |
+----------------------------+-------------------------------+
| 1000-01-01 01:00:00.000000 | 2169-02-09 00:09:07.419102    |
| 1000-01-01 01:00:00.000001 | 2169-02-09 00:09:07.419103    |
| 2001-01-01 01:00:00.000000 | 2001-01-01 00:59:59.999999    |
| 2001-01-01 01:00:00.000001 | 2001-01-01 01:00:00.000000    |
+----------------------------+-------------------------------+

tidb> SELECT a, SUBTIME(a, '10:00:00.000001') FROM t1 ORDER BY a;
+----------------------------+-------------------------------+
| a                          | SUBTIME(a, '10:00:00.000001') |
+----------------------------+-------------------------------+
| 1000-01-01 01:00:00.000000 | 2169-02-08 14:09:07.419102    |
| 1000-01-01 01:00:00.000001 | 2169-02-08 14:09:07.419103    |
| 2001-01-01 01:00:00.000000 | 2000-12-31 14:59:59.999999    |
| 2001-01-01 01:00:00.000001 | 2000-12-31 15:00:00.000000    |
+----------------------------+-------------------------------+

4. What is your TiDB version?

tidb_version(): Release Version: v5.5.0-alpha-154-gc589ee547
Edition: Community
Git Commit Hash: c589ee5471e05430f7f888190780a27fddb9ce7a
Git Branch: master
UTC Build Time: 2022-01-19 21:56:30
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 20, 2022
@jebter jebter added 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 5.4.x versions. labels Jan 24, 2022
@Defined2014
Copy link
Contributor

The root case is gotime.Duration only support about 290 years. If the a within 290 years, the result is correct.

@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-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 5.4.x 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.

4 participants