Skip to content

Commit

Permalink
session, config, sessionctx, executor: Set tidb_opt_projection_push_d…
Browse files Browse the repository at this point in the history
…own to false when tidb upgrades from versions older than 8.3.0 to 8.3.0 and later (#54861)

ref #51876
  • Loading branch information
yibin87 authored Jul 25, 2024
1 parent 8f98b4e commit 6854e60
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
7 changes: 4 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"-"`

Expand Down Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions pkg/executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}},
Expand Down
1 change: 1 addition & 0 deletions pkg/sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,7 @@ const (
DefGroupConcatMaxLen = uint64(1024)
DefDefaultWeekFormat = "0"
DefTiDBEnableLazyCursorFetch = false
DefOptEnableProjectionPushDown = true
)

// Process global variables.
Expand Down

0 comments on commit 6854e60

Please sign in to comment.