-
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
session: move more session vars to stmt context for retrying #8034
Conversation
create table t (i int key);
insert into t values (1);
begin;
insert into t values (10);
update t set i = i + row_count();
-- before the following commit, run `update t set i = i - 1;` in another session.
commit; we got
I think it should be
|
/run-all-tests |
PTAL @disksing @tiancaiamao |
Sorry I'm not really familiar with |
PTAL @zimulala |
session/session.go
Outdated
@@ -111,10 +110,9 @@ type StmtHistory struct { | |||
// Add appends a stmt to history list. | |||
func (h *StmtHistory) Add(stmtID uint32, st sqlexec.Statement, stmtCtx *stmtctx.StatementContext, params ...interface{}) { |
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.
stmtCtx *stmtctx.StatementContext
can be remove too
PTAL @coocood if you are free. |
This comment has been minimized.
This comment has been minimized.
/run-all-tests |
sessionctx/stmtctx/stmtctx.go
Outdated
// PrevAffectedRows is the affected-rows value(DDL is 0, DML is the number of affected rows). | ||
PrevAffectedRows int64 | ||
// params for prepared statements | ||
PreparedParams []interface{} |
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 []types.Datum to []interface{} ?
executor/executor.go
Outdated
@@ -1175,6 +1175,7 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { | |||
sc.MemTracker = memory.NewTracker(s.Text(), vars.MemQuotaQuery) | |||
sc.NowTs = time.Time{} | |||
sc.SysTs = time.Time{} | |||
sc.PreparedParams = []interface{}{} |
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 put PreparedParams
in SessionVars
can avoid re-allocating memory before every execution.
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 not set it to nil
/run-all-tests |
PTAL @tiancaiamao |
LGTM |
4 similar comments
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.
Reviewed 12 of 12 files at r1.
Reviewable status: complete! all files reviewed, all discussions resolved
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.
miss approve by reviewable
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
What problem does this PR solve?
Some session variables should be in statement context e.g. prev-affected rows and last insert id. If not the behavior will be incorrect when retrying.
What is changed and how it works?
Move the session variables to statement context.
Check List
Tests
Code changes
Related changes
PTAL @tiancaiamao @disksing
This change is