diff --git a/parser/opcode/opcode.go b/parser/opcode/opcode.go index 14b541cfbd5fa..f809ef45c3ce7 100644 --- a/parser/opcode/opcode.go +++ b/parser/opcode/opcode.go @@ -134,5 +134,5 @@ var opsLiteral = map[Op]string{ // Format the ExprNode into a Writer. func (o Op) Format(w io.Writer) { - fmt.Fprintf(w, opsLiteral[o]) + fmt.Fprintf(w, "%s", opsLiteral[o]) } diff --git a/parser/opcode/opcode_test.go b/parser/opcode/opcode_test.go index 98e4f9d85cf99..a4c2821b249f1 100644 --- a/parser/opcode/opcode_test.go +++ b/parser/opcode/opcode_test.go @@ -13,7 +13,10 @@ package opcode -import "testing" +import ( + "bytes" + "testing" +) func TestT(t *testing.T) { op := Plus @@ -21,6 +24,18 @@ func TestT(t *testing.T) { t.Fatalf("invalid op code") } + if len(Ops) != len(opsLiteral) { + t.Error("inconsistent count ops and opsliteral") + } + var buf bytes.Buffer + for op := range Ops { + op.Format(&buf) + if buf.String() != opsLiteral[op] { + t.Error("format op fail", op) + } + buf.Reset() + } + // Test invalid opcode defer func() { recover() diff --git a/session/session.go b/session/session.go index 2e0b7b7c1e056..0732b0f5b079e 100644 --- a/session/session.go +++ b/session/session.go @@ -401,6 +401,7 @@ func (s *session) CommitTxn(ctx context.Context) error { if err != nil { label = metrics.LblError } + s.sessionVars.TxnCtx.Cleanup() metrics.TransactionCounter.WithLabelValues(label).Inc() return errors.Trace(err) } @@ -418,6 +419,7 @@ func (s *session) RollbackTxn(ctx context.Context) error { } s.cleanRetryInfo() s.txn.changeToInvalid() + s.sessionVars.TxnCtx.Cleanup() s.sessionVars.SetStatusFlag(mysql.ServerStatusInTrans, false) return errors.Trace(err) } diff --git a/session/txn.go b/session/txn.go index f6182da78c220..b57059f9892cb 100644 --- a/session/txn.go +++ b/session/txn.go @@ -195,6 +195,10 @@ func (st *TxnState) cleanup() { delete(st.mutations, key) } if st.dirtyTableOP != nil { + empty := dirtyTableOperation{} + for i := 0; i < len(st.dirtyTableOP); i++ { + st.dirtyTableOP[i] = empty + } st.dirtyTableOP = st.dirtyTableOP[:0] } } diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index 6f0a8a00804e2..42328538afc92 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -118,6 +118,15 @@ func (tc *TransactionContext) UpdateDeltaForTable(tableID int64, delta int64, co tc.TableDeltaMap[tableID] = item } +// Cleanup clears up transaction info that no longer use. +func (tc *TransactionContext) Cleanup() { + //tc.InfoSchema = nil; we cannot do it now, because some operation like handleFieldList depend on this. + tc.DirtyDB = nil + tc.Binlog = nil + tc.Histroy = nil + tc.TableDeltaMap = nil +} + // ClearDelta clears the delta map. func (tc *TransactionContext) ClearDelta() { tc.TableDeltaMap = nil