-
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
wrong result of timestampadd(month,1,date '2024-01-31') #41052
Comments
I think the behavior of tidb is more reasonable. mysql> select timestampadd(month,1,date '2024-03-30');
+-----------------------------------------+
| timestampadd(month,1,date '2024-03-30') |
+-----------------------------------------+
| 2024-04-30 |
+-----------------------------------------+
1 row in set (0.00 sec)
mysql> select timestampadd(month,1,date '2024-03-31');
+-----------------------------------------+
| timestampadd(month,1,date '2024-03-31') |
+-----------------------------------------+
| 2024-04-30 |
+-----------------------------------------+
1 row in set (0.00 sec) I reported a bug to MySQL https://bugs.mysql.com/bug.php?id=109941. Waiting for their verification. |
To fix this behavior, we can make the following modification: diff --git a/expression/builtin_time.go b/expression/builtin_time.go
index e97f2ef862..be33c81805 100644
--- a/expression/builtin_time.go
+++ b/expression/builtin_time.go
@@ -6180,6 +6180,10 @@ func addUnitToTime(unit string, t time.Time, v float64) (time.Time, bool, error)
return tb, true, nil
}
tb = t.AddDate(0, int(v), 0)
+ // For corner case: timestampadd(month,1,date '2024-01-31') = "2024-02-29", timestampadd(month,1,date '2024-01-30') = "2024-02-29"
+ for tb.Month() != t.Month()+1 {
+ tb = tb.AddDate(0, 0, -1)
+ }
case "QUARTER":
if !validAddMonth(v*3, t.Year(), int(t.Month())) {
return tb, true, nil |
As this bug report shows, it's a bug of MySQL, verified by the MySQL verification team. |
@xzhangxian1008: The label(s) In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
/remove-label may-affects-5.4 |
@MimeLyc: These labels are not set on the issue: In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
/remove-label may-affects-5.3 |
@MimeLyc: The label(s) In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
The issue if from https://ask.pingcap.com/t/timestampadd-function/419.
2. What did you expect to see? (Required)
MySQL result is expected, as following:
3. What did you see instead (Required)
4. What is your TiDB version? (Required)
The text was updated successfully, but these errors were encountered: