-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,8 +120,8 @@ type StatementContext struct { | |
RuntimeStatsColl *execdetails.RuntimeStatsColl | ||
TableIDs []int64 | ||
IndexIDs []int64 | ||
NowTs time.Time | ||
SysTs time.Time | ||
jackysp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
nowTs time.Time // use this variable for now/current_timestamp calculation/cache for one stmt | ||
stmtTimeCached bool | ||
StmtType string | ||
OriginalSQL string | ||
digestMemo struct { | ||
|
@@ -132,6 +132,21 @@ type StatementContext struct { | |
Tables []TableEntry | ||
} | ||
|
||
// GetNowTsCached getter for nowTs, if not set get now time and cache it | ||
func (sc *StatementContext) GetNowTsCached() time.Time { | ||
if !sc.stmtTimeCached { | ||
now := time.Now() | ||
sc.nowTs = now | ||
sc.stmtTimeCached = true | ||
} | ||
return sc.nowTs | ||
} | ||
|
||
// 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 commentThe 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 commentThe 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 |
||
sc.stmtTimeCached = false | ||
} | ||
|
||
// SQLDigest gets normalized and digest for provided sql. | ||
// it will cache result after first calling. | ||
func (sc *StatementContext) SQLDigest() (normalized, sqlDigest string) { | ||
|
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