Skip to content
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

bindinfo: rename tidb_opt_enable_universal_binding as tidb_opt_enable_fuzzy_binding #50081

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions pkg/bindinfo/universal_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ func TestUniversalBindingBasic(t *testing.T) {
for _, useDB := range []string{"test", "test1", "test2"} {
tk.MustExec("use " + useDB)
for _, testDB := range []string{"", "test.", "test1.", "test2."} {
tk.MustExec(`set @@tidb_opt_enable_universal_binding=1`) // enabled
tk.MustExec(`set @@tidb_opt_enable_fuzzy_binding=1`) // enabled
require.True(t, tk.MustUseIndex(fmt.Sprintf("select * from %vt", testDB), idx))
tk.MustQuery(`select @@last_plan_from_binding`).Check(testkit.Rows("1"))
require.True(t, tk.MustUseIndex(fmt.Sprintf("select * from %vt", testDB), idx))
tk.MustQuery(`show warnings`).Check(testkit.Rows()) // no warning
tk.MustExec(`set @@tidb_opt_enable_universal_binding=0`) // disabled
tk.MustQuery(`show warnings`).Check(testkit.Rows()) // no warning
tk.MustExec(`set @@tidb_opt_enable_fuzzy_binding=0`) // disabled
tk.MustQuery(fmt.Sprintf("select * from %vt", testDB))
tk.MustQuery(`select @@last_plan_from_binding`).Check(testkit.Rows("0"))
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestUniversalBindingPriority(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)

tk.MustExec(`set @@tidb_opt_enable_universal_binding=1`)
tk.MustExec(`set @@tidb_opt_enable_fuzzy_binding=1`)
tk.MustExec(`use test`)
tk.MustExec(`create table t (a int, b int, c int, d int, e int, key(a), key(b), key(c), key(d), key(e))`)

Expand All @@ -152,11 +152,11 @@ func TestUniversalBindingPriority(t *testing.T) {
tk.MustQuery(`select @@last_plan_from_binding`).Check(testkit.Rows("1"))

// global normal takes effect again if disable universal bindings
tk.MustExec(`set @@tidb_opt_enable_universal_binding=0`)
tk.MustExec(`set @@tidb_opt_enable_fuzzy_binding=0`)
tk.MustExec(`create global binding using select /*+ use_index(t, b) */ * from t`)
tk.MustUseIndex(`select * from t`, "b")
tk.MustQuery(`select @@last_plan_from_binding`).Check(testkit.Rows("1"))
tk.MustExec(`set @@tidb_opt_enable_universal_binding=1`)
tk.MustExec(`set @@tidb_opt_enable_fuzzy_binding=1`)

// session normal > session universal
tk.MustExec(`create session binding using select /*+ use_index(t, d) */ * from t`)
Expand Down Expand Up @@ -212,10 +212,10 @@ func TestUniversalBindingSwitch(t *testing.T) {
tk1.MustExec(`use test1`)
tk1.MustQuery(`select * from test.t`).Check(testkit.Rows())
tk1.MustQuery(`select @@last_plan_from_binding`).Check(testkit.Rows("0"))
tk1.MustExec(`set @@tidb_opt_enable_universal_binding=1`)
tk1.MustExec(`set @@tidb_opt_enable_fuzzy_binding=1`)
tk1.MustUseIndex(`select * from test.t`, "b")
tk1.MustQuery(`select @@last_plan_from_binding`).Check(testkit.Rows("1"))
tk1.MustExec(`set @@tidb_opt_enable_universal_binding=0`)
tk1.MustExec(`set @@tidb_opt_enable_fuzzy_binding=0`)
tk1.MustQuery(`select * from test.t`).Check(testkit.Rows())
tk1.MustQuery(`select @@last_plan_from_binding`).Check(testkit.Rows("0"))

Expand All @@ -225,18 +225,18 @@ func TestUniversalBindingSwitch(t *testing.T) {
tk2.MustExec(`create global universal binding using select /*+ use_index(t, b) */ * from t`)
tk2.MustQuery(`select * from test.t`).Check(testkit.Rows())
tk2.MustQuery(`select @@last_plan_from_binding`).Check(testkit.Rows("0"))
tk2.MustExec(`set @@tidb_opt_enable_universal_binding=1`)
tk2.MustExec(`set @@tidb_opt_enable_fuzzy_binding=1`)
tk2.MustUseIndex(`select * from test.t`, "b")
tk2.MustQuery(`select @@last_plan_from_binding`).Check(testkit.Rows("1"))
tk2.MustExec(`set @@tidb_opt_enable_universal_binding=0`)
tk2.MustExec(`set @@tidb_opt_enable_fuzzy_binding=0`)
tk2.MustQuery(`select * from test.t`).Check(testkit.Rows())
tk2.MustQuery(`select @@last_plan_from_binding`).Check(testkit.Rows("0"))

// the default value is off
tk3 := testkit.NewTestKit(t, store)
tk3.MustQuery(`select @@tidb_opt_enable_universal_binding`).Check(testkit.Rows("0"))
tk3.MustQuery(`show session variables like 'tidb_opt_enable_universal_binding'`).Check(testkit.Rows("tidb_opt_enable_universal_binding OFF"))
tk3.MustQuery(`show global variables like 'tidb_opt_enable_universal_binding'`).Check(testkit.Rows("tidb_opt_enable_universal_binding OFF"))
tk3.MustQuery(`select @@tidb_opt_enable_fuzzy_binding`).Check(testkit.Rows("0"))
tk3.MustQuery(`show session variables like 'tidb_opt_enable_fuzzy_binding'`).Check(testkit.Rows("tidb_opt_enable_fuzzy_binding OFF"))
tk3.MustQuery(`show global variables like 'tidb_opt_enable_fuzzy_binding'`).Check(testkit.Rows("tidb_opt_enable_fuzzy_binding OFF"))
}

func TestUniversalBindingSetVar(t *testing.T) {
Expand All @@ -247,20 +247,20 @@ func TestUniversalBindingSetVar(t *testing.T) {
tk.MustExec(`create table t (a int, b int, key(a), key(b))`)
tk.MustExec(`create universal binding using select /*+ use_index(t, a) */ * from t`)

tk.MustExec(`set @@tidb_opt_enable_universal_binding=0`)
tk.MustExec(`set @@tidb_opt_enable_fuzzy_binding=0`)
tk.MustExec(`select * from t`)
tk.MustQuery(`select @@last_plan_from_binding`).Check(testkit.Rows("0"))
tk.MustExec(`select /*+ set_var(tidb_opt_enable_universal_binding=1) */ * from t`)
tk.MustExec(`select /*+ set_var(tidb_opt_enable_fuzzy_binding=1) */ * from t`)
tk.MustQuery(`select @@last_plan_from_binding`).Check(testkit.Rows("1"))
tk.MustExec(`select /*+ set_var(tidb_opt_enable_universal_binding=0) */ * from t`)
tk.MustExec(`select /*+ set_var(tidb_opt_enable_fuzzy_binding=0) */ * from t`)
tk.MustQuery(`select @@last_plan_from_binding`).Check(testkit.Rows("0"))

tk.MustExec(`set @@tidb_opt_enable_universal_binding=1`)
tk.MustExec(`set @@tidb_opt_enable_fuzzy_binding=1`)
tk.MustExec(`select * from t`)
tk.MustQuery(`select @@last_plan_from_binding`).Check(testkit.Rows("1"))
tk.MustExec(`select /*+ set_var(tidb_opt_enable_universal_binding=0) */ * from t`)
tk.MustExec(`select /*+ set_var(tidb_opt_enable_fuzzy_binding=0) */ * from t`)
tk.MustQuery(`select @@last_plan_from_binding`).Check(testkit.Rows("0"))
tk.MustExec(`select /*+ set_var(tidb_opt_enable_universal_binding=1) */ * from t`)
tk.MustExec(`select /*+ set_var(tidb_opt_enable_fuzzy_binding=1) */ * from t`)
tk.MustQuery(`select @@last_plan_from_binding`).Check(testkit.Rows("1"))
}

Expand Down Expand Up @@ -323,7 +323,7 @@ func TestUniversalBindingHints(t *testing.T) {
tk.MustExec(`create table t2 (a int, b int, c int, d int, key(a), key(b), key(c), key(d))`)
tk.MustExec(`create table t3 (a int, b int, c int, d int, key(a), key(b), key(c), key(d))`)
}
tk.MustExec(`set @@tidb_opt_enable_universal_binding=1`)
tk.MustExec(`set @@tidb_opt_enable_fuzzy_binding=1`)

for _, c := range []struct {
binding string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ func TestUniversalBindingFromHistory(t *testing.T) {
})

tk.MustExec(`admin reload bindings`)
tk.MustExec(`set @@tidb_opt_enable_universal_binding=1`)
tk.MustExec(`set @@tidb_opt_enable_fuzzy_binding=1`)
tk.MustExec(`create database test2`)
tk.MustExec(`use test2`)
tk.MustExec(`create table t (a int, b int, c int, key(a), key(b), key(c))`)
Expand Down
4 changes: 2 additions & 2 deletions pkg/sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1389,8 +1389,8 @@ type SessionVars struct {
// EnableNonPreparedPlanCacheForDML indicates whether to enable non-prepared plan cache for DML statements.
EnableNonPreparedPlanCacheForDML bool

// EnableUniversalBinding indicates whether to enable universal binding.
EnableUniversalBinding bool
// EnableFuzzyBinding indicates whether to enable fuzzy binding.
EnableFuzzyBinding bool

// PlanCacheInvalidationOnFreshStats controls if plan cache will be invalidated automatically when
// related stats are analyzed after the plan cache is generated.
Expand Down
4 changes: 2 additions & 2 deletions pkg/sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -1214,8 +1214,8 @@ var defaultSysVars = []*SysVar{
s.EnableNonPreparedPlanCacheForDML = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptEnableUniversalBinding, Value: BoolToOnOff(false), Type: TypeBool, IsHintUpdatableVerfied: true, SetSession: func(s *SessionVars, val string) error {
s.EnableUniversalBinding = TiDBOptOn(val)
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptEnableFuzzyBinding, Value: BoolToOnOff(false), Type: TypeBool, IsHintUpdatableVerfied: true, SetSession: func(s *SessionVars, val string) error {
s.EnableFuzzyBinding = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBNonPreparedPlanCacheSize, Value: strconv.FormatUint(uint64(DefTiDBNonPreparedPlanCacheSize), 10), Type: TypeUnsigned, MinValue: 1, MaxValue: 100000, SetSession: func(s *SessionVars, val string) error {
Expand Down
4 changes: 2 additions & 2 deletions pkg/sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,8 @@ const (
// TiDBEvolvePlanBaselines indicates whether the evolution of plan baselines is enabled.
TiDBEvolvePlanBaselines = "tidb_evolve_plan_baselines"

// TiDBOptEnableUniversalBinding indicates whether to enable the universal binding.
TiDBOptEnableUniversalBinding = "tidb_opt_enable_universal_binding"
// TiDBOptEnableFuzzyBinding indicates whether to enable the universal binding.
TiDBOptEnableFuzzyBinding = "tidb_opt_enable_fuzzy_binding"

// TiDBEnableExtendedStats indicates whether the extended statistics feature is enabled.
TiDBEnableExtendedStats = "tidb_enable_extended_stats"
Expand Down