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

Result of DATE_ADD function is different from mysql.(YEAR overflow) #11256

Closed
wshwsh12 opened this issue Jul 15, 2019 · 1 comment
Closed

Result of DATE_ADD function is different from mysql.(YEAR overflow) #11256

wshwsh12 opened this issue Jul 15, 2019 · 1 comment
Assignees
Labels
component/expression type/bug The issue is confirmed as a bug.

Comments

@wshwsh12
Copy link
Contributor

wshwsh12 commented Jul 15, 2019

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.
select DATE_ADD('2000-04-13 07:17:02',INTERVAL -1465647104 YEAR);
select DATE_ADD('2008-11-23 22:47:31',INTERVAL 266076160 QUARTER);
  1. What did you expect to see?
mysql> select DATE_ADD('2000-04-13 07:17:02',INTERVAL -1465647104 YEAR);
+-----------------------------------------------------------+
| DATE_ADD('2000-04-13 07:17:02',INTERVAL -1465647104 YEAR) |
+-----------------------------------------------------------+
| NULL                                                      |
+-----------------------------------------------------------+
1 row in set, 1 warning (0.01 sec)

mysql> select DATE_ADD('2008-11-23 22:47:31',INTERVAL 266076160 QUARTER);
+------------------------------------------------------------+
| DATE_ADD('2008-11-23 22:47:31',INTERVAL 266076160 QUARTER) |
+------------------------------------------------------------+
| NULL                                                       |
+------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
  1. What did you see instead?
mysql> select DATE_ADD('2000-04-13 07:17:02',INTERVAL -1465647104 YEAR);
+-----------------------------------------------------------+
| DATE_ADD('2000-04-13 07:17:02',INTERVAL -1465647104 YEAR) |
+-----------------------------------------------------------+
| 2000-04-13 07:17:02                                       |
+-----------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select DATE_ADD('2008-11-23 22:47:31',INTERVAL 266076160 QUARTER);
+------------------------------------------------------------+
| DATE_ADD('2008-11-23 22:47:31',INTERVAL 266076160 QUARTER) |
+------------------------------------------------------------+
| 2008-11-23 22:47:31                                        |
+------------------------------------------------------------+
1 row in set (0.00 sec)
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
| Release Version: v3.0.0-rc.1-338-g3f1d234e2
Git Commit Hash: 3f1d234e2036a3163f7774ff106fa6397d585287
Git Branch: master
UTC Build Time: 2019-07-15 08:34:52
GoVersion: go version go1.12.6 darwin/amd64
Race Enabled: false
TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
Check Table Before Drop: false |
@wshwsh12 wshwsh12 added the type/bug The issue is confirmed as a bug. label Jul 15, 2019
@wshwsh12 wshwsh12 self-assigned this Jul 15, 2019
@wshwsh12 wshwsh12 changed the title Result of DATE_ADD function is different from mysql.(YEAR,HOUR_MINUTE,QUARTER) Result of DATE_ADD function is different from mysql.(YEAR overflow) Jul 19, 2019
@AndrewDi
Copy link
Contributor

It seems like our MysqlTime function will convert invalid year to uint16, and this will reset invalid int.

tidb/types/time.go

Lines 204 to 214 in 5611acd

func FromDate(year int, month int, day int, hour int, minute int, second int, microsecond int) MysqlTime {
return MysqlTime{
uint16(year),
uint8(month),
uint8(day),
hour,
uint8(minute),
uint8(second),
uint32(microsecond),
}
}

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

No branches or pull requests

2 participants