From 15356cdd88e3ecf9947dbcb0bd379ec8d3a23706 Mon Sep 17 00:00:00 2001 From: Ewan Chou Date: Thu, 17 Mar 2016 10:31:18 +0800 Subject: [PATCH] tidb: remove RestrictedSQLExecutorKey variable in context. This variable was intended to prevent restricted SQL from being committed. But it is executed at statement level, will never be committed, so this is not needed. Also, when begin a new transaction in executing restricted SQL, If 'autocommit' is 'on'. This variable makes the new transaction into a unwanted `InTrans` state, so following statements will not be autocommited. --- session.go | 14 -------------- util/sqlexec/restricted_sql_executor.go | 8 -------- 2 files changed, 22 deletions(-) diff --git a/session.go b/session.go index 18efafdfc3..691558ff3f 100644 --- a/session.go +++ b/session.go @@ -45,7 +45,6 @@ import ( "github.com/pingcap/tidb/store/localstore" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/util" - "github.com/pingcap/tidb/util/sqlexec" "github.com/pingcap/tidb/util/types" ) @@ -251,11 +250,6 @@ func (s *session) Retry() error { // ExecRestrictedSQL implements SQLHelper interface. // This is used for executing some restricted sql statements. func (s *session) ExecRestrictedSQL(ctx context.Context, sql string) (ast.RecordSet, error) { - if ctx.Value(&sqlexec.RestrictedSQLExecutorKeyType{}) != nil { - // We do not support run this function concurrently. - // TODO: Maybe we should remove this restriction latter. - return nil, errors.New("Should not call ExecRestrictedSQL concurrently.") - } rawStmts, err := Parse(ctx, sql) if err != nil { return nil, errors.Trace(err) @@ -273,8 +267,6 @@ func (s *session) ExecRestrictedSQL(ctx context.Context, sql string) (ast.Record // For example only support DML on system meta table. // TODO: Add more restrictions. log.Debugf("Executing %s [%s]", st.OriginText(), sql) - ctx.SetValue(&sqlexec.RestrictedSQLExecutorKeyType{}, true) - defer ctx.ClearValue(&sqlexec.RestrictedSQLExecutorKeyType{}) rs, err := st.Exec(ctx) return rs, errors.Trace(err) } @@ -331,9 +323,6 @@ func (s *session) SetGlobalSysVar(ctx context.Context, name string, value string // IsAutocommit checks if it is in the auto-commit mode. func (s *session) isAutocommit(ctx context.Context) bool { - if ctx.Value(&sqlexec.RestrictedSQLExecutorKeyType{}) != nil { - return false - } autocommit, ok := variable.GetSessionVars(ctx).Systems["autocommit"] if !ok { if s.initing { @@ -357,9 +346,6 @@ func (s *session) isAutocommit(ctx context.Context) bool { } func (s *session) ShouldAutocommit(ctx context.Context) bool { - if ctx.Value(&sqlexec.RestrictedSQLExecutorKeyType{}) != nil { - return false - } // With START TRANSACTION, autocommit remains disabled until you end // the transaction with COMMIT or ROLLBACK. if variable.GetSessionVars(ctx).Status&mysql.ServerStatusInTrans == 0 && s.isAutocommit(ctx) { diff --git a/util/sqlexec/restricted_sql_executor.go b/util/sqlexec/restricted_sql_executor.go index e0efc30fd4..93d47a9632 100644 --- a/util/sqlexec/restricted_sql_executor.go +++ b/util/sqlexec/restricted_sql_executor.go @@ -18,14 +18,6 @@ import ( "github.com/pingcap/tidb/context" ) -// RestrictedSQLExecutorKeyType is a dummy type to avoid naming collision in session. -type RestrictedSQLExecutorKeyType struct{} - -// String implements Stringer interface. -func (k *RestrictedSQLExecutorKeyType) String() string { - return "restricted_sql_executor" -} - // RestrictedSQLExecutor is an interface provides executing restricted sql statement. // Why we need this interface? // When we execute some management statements, we need to operate system tables.