-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
executor, expression: fix current_timestamp/now not consistent in one stmt like MySQL #11342
Conversation
@jackysp PTAL |
/run-all-tests |
Codecov Report
@@ Coverage Diff @@
## master #11342 +/- ##
================================================
- Coverage 81.4278% 81.2403% -0.1876%
================================================
Files 423 423
Lines 90851 90172 -679
================================================
- Hits 73978 73256 -722
- Misses 11588 11603 +15
- Partials 5285 5313 +28 |
Codecov Report
@@ Coverage Diff @@
## master #11342 +/- ##
================================================
- Coverage 81.2969% 81.2774% -0.0195%
================================================
Files 423 423
Lines 90381 90399 +18
================================================
- Hits 73477 73474 -3
- Misses 11598 11609 +11
- Partials 5306 5316 +10 |
/run-all-tests |
/run-all-tests |
1 similar comment
/run-all-tests |
@jackysp PTAL |
sessionctx/stmtctx/stmtctx.go
Outdated
} | ||
|
||
// ReSetNowTs resetter for nowTs, clear cached time flag | ||
func (sc *StatementContext) ReSetNowTs() { |
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.
func (sc *StatementContext) ReSetNowTs() { | |
func (sc *StatementContext) ResetNowTs() { |
sessionctx/stmtctx/stmtctx.go
Outdated
@@ -393,6 +409,7 @@ func (sc *StatementContext) ResetForRetry() { | |||
sc.mu.Unlock() | |||
sc.TableIDs = sc.TableIDs[:0] | |||
sc.IndexIDs = sc.IndexIDs[:0] | |||
sc.ReSetNowTs() |
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.
I think we should not reset when retrying. Transaction retry is an automatic implicit behavior. It is possible that current_timestamp has been returned to the client. If it is reset here, the user may be bothered. For example,
begin;
insert xxx current_timestamp;
select now(); -- The user might think this value is bigger than the previous insert.
commit; -- It is better do not reset current here, if the retry is needed.
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.
PTAL @lysu
var nowTs = &b.ctx.GetSessionVars().StmtCtx.NowTs | ||
if nowTs.Equal(time.Time{}) { | ||
*nowTs = time.Now() | ||
nowTs, err := getStmtTimestamp(b.ctx) |
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.
would this impact the prepare plan cache which has the NOW()
builtin function?
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.
plan cache will not cache now function results, every time execution will recaculate now() function. This change make now/current_time func call same results within one sql statement
} | ||
|
||
// ResetNowTs resetter for nowTs, clear cached time flag | ||
func (sc *StatementContext) ResetNowTs() { |
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.
It seems we do not need this function anymore. It is only used in the test.
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.
maybe leave this as it's correspond to newly added Get interface. Future devs will not write "*timeNows = xxx/time.Time{}" like code and forget to reset stmtTimeCached flag
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
…unction results refactor related statement time related interface and some time function implementations
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
cherry pick to release-2.1 failed |
cherry pick to release-3.0 failed |
…cap#11342) cherry-pick to release-2.1 branch
What problem does this PR solve?
MySQL will set time to “”time_cache“ structure before doing one command(COM_XXX)
later expresission calculation will use this timestamp as time value
TiDB logic different and default column calculation and now expr calculation will try to get timestamp twice.
more details see jira issue#4391
eg:
TiDB
MySQL
What is changed and how it works?
Check List
Tests
Code changes
Side effects
Related changes