-
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
expression: fix issue that results of unix_timestamp()-unix_timestamp(now())
is wrong and not stable
#9884
Conversation
Codecov Report
@@ Coverage Diff @@
## master #9884 +/- ##
================================================
- Coverage 77.4806% 77.2959% -0.1847%
================================================
Files 404 404
Lines 81663 81655 -8
================================================
- Hits 63273 63116 -157
- Misses 13679 13854 +175
+ Partials 4711 4685 -26 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -3371,7 +3371,7 @@ func (s *testSuite3) TestCurrentTimestampValueSelection(c *C) { | |||
tk.MustQuery("select id from t where t0 = ?", t0).Check(testkit.Rows("1")) | |||
tk.MustQuery("select id from t where t1 = ?", t1).Check(testkit.Rows("1")) | |||
tk.MustQuery("select id from t where t2 = ?", t2).Check(testkit.Rows("1")) | |||
time.Sleep(time.Second / 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two calls of now()
around this sleep()
.
One is used to insert a record t0=now()
and the other is used to update it set t0=now()
.
Before this PR, since now()
rounds the result, so we can assume that these two calls of now()
must get two time with different seconds and the update operation really happens.
After this PR, this assumption is broken, so I increase the waiting time to ensure they can get two time with different seconds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rest LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/run-all-tests |
1 similar comment
/run-all-tests |
unix_timestamp()-unix_timestamp(now())
is wrong and not stableunix_timestamp()-unix_timestamp(now())
is wrong and not stable
/run-all-tests |
unix_timestamp()-unix_timestamp(now())
is wrong and not stableunix_timestamp()-unix_timestamp(now())
is wrong and not stable
/run-all-tests |
…p(now())` is wrong and not stable (pingcap#9884)
What problem does this PR solve?
Fix #9710
In MySQL,
Now()
andUnixTimestamp()
will truncate the result while they will round the result in TiDB.These results below from MySQL 5.7 can prove it.
What is changed and how it works?
Let
Now()
andUnixTimestamp()
truncate the result instead of rounding it.Check List
Tests