From 6854e606982a7e886591f44e2dfdb821bcd9c57c Mon Sep 17 00:00:00 2001 From: yibin Date: Thu, 25 Jul 2024 09:54:05 +0800 Subject: [PATCH] session, config, sessionctx, executor: Set tidb_opt_projection_push_down to false when tidb upgrades from versions older than 8.3.0 to 8.3.0 and later (#54861) ref pingcap/tidb#51876 --- pkg/config/config.go | 7 ++++--- pkg/executor/set_test.go | 10 ++++++++++ pkg/session/bootstrap.go | 4 ++++ pkg/sessionctx/variable/sysvar.go | 2 +- pkg/sessionctx/variable/tidb_vars.go | 1 + 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 419d048f417e4..3534f06b0a2e6 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -711,9 +711,7 @@ type Performance struct { TCPNoDelay bool `toml:"tcp-no-delay" json:"tcp-no-delay"` CrossJoin bool `toml:"cross-join" json:"cross-join"` DistinctAggPushDown bool `toml:"distinct-agg-push-down" json:"distinct-agg-push-down"` - // Whether enable projection push down for coprocessors (both tikv & tiflash), default false. - ProjectionPushDown bool `toml:"projection-push-down" json:"projection-push-down"` - MaxTxnTTL uint64 `toml:"max-txn-ttl" json:"max-txn-ttl"` + MaxTxnTTL uint64 `toml:"max-txn-ttl" json:"max-txn-ttl"` // Deprecated MemProfileInterval string `toml:"-" json:"-"` @@ -754,6 +752,9 @@ type Performance struct { // ConcurrentlyInitStats indicates whether to use concurrency to init stats. ConcurrentlyInitStats bool `toml:"concurrently-init-stats" json:"concurrently-init-stats"` + + // Deprecated: this config will not have any effect + ProjectionPushDown bool `toml:"projection-push-down" json:"projection-push-down"` } // PlanCache is the PlanCache section of the config. diff --git a/pkg/executor/set_test.go b/pkg/executor/set_test.go index 9068a1a195c04..e350d0264dff8 100644 --- a/pkg/executor/set_test.go +++ b/pkg/executor/set_test.go @@ -967,6 +967,16 @@ func TestSetVar(t *testing.T) { tk.MustQuery("select @@session.tidb_txn_entry_size_limit, @@global.tidb_txn_entry_size_limit").Check(testkit.Rows("2048 4096")) tk.MustExec("set global tidb_txn_entry_size_limit = 0") tk.MustQuery("select @@session.tidb_txn_entry_size_limit, @@global.tidb_txn_entry_size_limit").Check(testkit.Rows("2048 0")) + + // test for tidb_opt_projection_push_down + tk.MustQuery("select @@session.tidb_opt_projection_push_down, @@global.tidb_opt_projection_push_down").Check(testkit.Rows("1 1")) + tk.MustExec("set global tidb_opt_projection_push_down = 'OFF'") + tk.MustQuery("select @@session.tidb_opt_projection_push_down, @@global.tidb_opt_projection_push_down").Check(testkit.Rows("1 0")) + tk.MustExec("set session tidb_opt_projection_push_down = 'OFF'") + tk.MustQuery("select @@session.tidb_opt_projection_push_down, @@global.tidb_opt_projection_push_down").Check(testkit.Rows("0 0")) + tk.MustExec("set global tidb_opt_projection_push_down = 'on'") + tk.MustQuery("select @@session.tidb_opt_projection_push_down, @@global.tidb_opt_projection_push_down").Check(testkit.Rows("0 1")) + require.Error(t, tk.ExecToErr("set global tidb_opt_projection_push_down = 'UNKNOWN'")) } func TestSetCollationAndCharset(t *testing.T) { diff --git a/pkg/session/bootstrap.go b/pkg/session/bootstrap.go index a0f5bb51d34a4..adaae4cdb5f91 100644 --- a/pkg/session/bootstrap.go +++ b/pkg/session/bootstrap.go @@ -3065,6 +3065,10 @@ func upgradeToVer210(s sessiontypes.Session, ver int64) { // Check if tidb_analyze_column_options exists in mysql.GLOBAL_VARIABLES. // If not, set tidb_analyze_column_options to ALL since this is the old behavior before we introduce this variable. initGlobalVariableIfNotExists(s, variable.TiDBAnalyzeColumnOptions, model.AllColumns.String()) + + // Check if tidb_opt_projection_push_down exists in mysql.GLOBAL_VARIABLES. + // If not, set tidb_opt_projection_push_down to Off since this is the old behavior before we introduce this variable. + initGlobalVariableIfNotExists(s, variable.TiDBOptProjectionPushDown, variable.Off) } func upgradeToVer211(s sessiontypes.Session, ver int64) { diff --git a/pkg/sessionctx/variable/sysvar.go b/pkg/sessionctx/variable/sysvar.go index f3fb13dee7ef6..b4e5dacb9dc31 100644 --- a/pkg/sessionctx/variable/sysvar.go +++ b/pkg/sessionctx/variable/sysvar.go @@ -211,7 +211,7 @@ var defaultSysVars = []*SysVar{ } return nil }}, - {Scope: ScopeSession, Name: TiDBOptProjectionPushDown, Value: BoolToOnOff(config.GetGlobalConfig().Performance.ProjectionPushDown), Type: TypeBool, SetSession: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal | ScopeSession, Name: TiDBOptProjectionPushDown, Value: BoolToOnOff(DefOptEnableProjectionPushDown), Type: TypeBool, SetSession: func(s *SessionVars, val string) error { s.AllowProjectionPushDown = TiDBOptOn(val) return nil }}, diff --git a/pkg/sessionctx/variable/tidb_vars.go b/pkg/sessionctx/variable/tidb_vars.go index cf073f1a2430d..2dc5792824058 100644 --- a/pkg/sessionctx/variable/tidb_vars.go +++ b/pkg/sessionctx/variable/tidb_vars.go @@ -1507,6 +1507,7 @@ const ( DefGroupConcatMaxLen = uint64(1024) DefDefaultWeekFormat = "0" DefTiDBEnableLazyCursorFetch = false + DefOptEnableProjectionPushDown = true ) // Process global variables.