Skip to content

*: fix microseconds behaviour in DATE_ADD()#11280

Merged
wshwsh12 merged 3 commits into
pingcap:masterfrom
wshwsh12:fix_date_frac
Jul 17, 2019
Merged

*: fix microseconds behaviour in DATE_ADD()#11280
wshwsh12 merged 3 commits into
pingcap:masterfrom
wshwsh12:fix_date_frac

Conversation

@wshwsh12
Copy link
Copy Markdown
Contributor

What problem does this PR solve?

#11257
Before the pr:

mysql> select DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 SECOND_MICROSECOND);
+----------------------------------------------------------------+
| DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 SECOND_MICROSECOND) |
+----------------------------------------------------------------+
| 2007-03-28 22:08:27.980000                                     |
+----------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 MINUTE_MICROSECOND);
+----------------------------------------------------------------+
| DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 MINUTE_MICROSECOND) |
+----------------------------------------------------------------+
| 2007-03-28 22:08:27.980000                                     |
+----------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 HOUR_MICROSECOND);
+--------------------------------------------------------------+
| DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 HOUR_MICROSECOND) |
+--------------------------------------------------------------+
| 2007-03-28 22:08:27.980000                                   |
+--------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 DAY_MICROSECOND);
+-------------------------------------------------------------+
| DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 DAY_MICROSECOND) |
+-------------------------------------------------------------+
| 2007-03-28 22:08:27.980000                                  |
+-------------------------------------------------------------+
1 row in set (0.00 sec)

This pr:

mysql> select DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 SECOND_MICROSECOND);
+----------------------------------------------------------------+
| DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 SECOND_MICROSECOND) |
+----------------------------------------------------------------+
| 2007-03-28 22:08:27.800000                                     |
+----------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 MINUTE_MICROSECOND);
+----------------------------------------------------------------+
| DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 MINUTE_MICROSECOND) |
+----------------------------------------------------------------+
| 2007-03-28 22:08:27.800000                                     |
+----------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 HOUR_MICROSECOND);
+--------------------------------------------------------------+
| DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 HOUR_MICROSECOND) |
+--------------------------------------------------------------+
| 2007-03-28 22:08:27.800000                                   |
+--------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 DAY_MICROSECOND);
+-------------------------------------------------------------+
| DATE_ADD('2007-03-28 22:08:28',INTERVAL -2 DAY_MICROSECOND) |
+-------------------------------------------------------------+
| 2007-03-28 22:08:27.800000                                  |
+-------------------------------------------------------------+
1 row in set (0.00 sec)

What is changed and how it works?

When using parseTimeValue function to get microseconds from string, It will use func alignFrac to generate alignment frac.
Before this pr, the func hasn't consider the possible that the beginning of the string is a '-'.
e.g. 123 -> 123000 ,-123 -> -12300 (the '-' occupy a space)

This pr, fix the logic of the function. If the string is started with a '-', do a special treatment.
-123 -> -123000

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

Code changes

  • Has exported function/method change

Side effects

  • Increased code complexity

Related changes

  • Need to cherry-pick to the release branch

@wshwsh12 wshwsh12 added the type/bugfix This PR fixes a bug. label Jul 16, 2019
@wshwsh12
Copy link
Copy Markdown
Contributor Author

/run-all-tests

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 16, 2019

Codecov Report

Merging #11280 into master will increase coverage by 0.1459%.
The diff coverage is n/a.

@@               Coverage Diff               @@
##             master     #11280       +/-   ##
===============================================
+ Coverage   81.3302%   81.4762%   +0.146%     
===============================================
  Files           423        423               
  Lines         90344      90689      +345     
===============================================
+ Hits          73477      73890      +413     
+ Misses        11554      11499       -55     
+ Partials       5313       5300       -13

Copy link
Copy Markdown
Contributor

@SunRunAway SunRunAway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants