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

planner: ban baseline evolution feature #26333

Merged
merged 21 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a8443d3
planner: ban baseline evolution feature
Reminiscent Jul 19, 2021
9655712
Merge branch 'master' of https://github.com/pingcap/tidb into forbidB…
Reminiscent Jul 19, 2021
527ccd9
fix format
Reminiscent Jul 19, 2021
021f123
fix ut
Reminiscent Jul 20, 2021
9c957bf
Merge branch 'master' of https://github.com/pingcap/tidb into forbidB…
Reminiscent Jul 20, 2021
f6b3c30
fixup
Reminiscent Aug 2, 2021
441c767
Merge branch 'master' of https://github.com/pingcap/tidb into forbidB…
Reminiscent Aug 2, 2021
197ace0
Merge branch 'master' into forbidBaselineEvolution
eurekaka Aug 2, 2021
13842bd
address comments
Reminiscent Aug 3, 2021
34b8184
Merge branch 'master' of https://github.com/pingcap/tidb into forbidB…
Reminiscent Aug 3, 2021
0ee830b
Merge branch 'forbidBaselineEvolution' of https://github.com/Reminisc…
Reminiscent Aug 3, 2021
5756178
address comments
Reminiscent Aug 4, 2021
98ba826
Merge branch 'master' of https://github.com/pingcap/tidb into forbidB…
Reminiscent Aug 4, 2021
0a8ef1e
Merge branch 'master' into forbidBaselineEvolution
qw4990 Aug 4, 2021
eae9ae7
Merge branch 'master' into forbidBaselineEvolution
ti-chi-bot Aug 4, 2021
0259d4a
Merge branch 'master' into forbidBaselineEvolution
ti-chi-bot Aug 4, 2021
3f0e4b2
Merge branch 'master' into forbidBaselineEvolution
ti-chi-bot Aug 4, 2021
68a0b01
Merge branch 'master' into forbidBaselineEvolution
ti-chi-bot Aug 4, 2021
af6a7e3
fix ut
Reminiscent Aug 5, 2021
9c6f681
Merge branch 'forbidBaselineEvolution' of https://github.com/Reminisc…
Reminiscent Aug 5, 2021
c5738c9
Merge branch 'master' into forbidBaselineEvolution
ti-chi-bot Aug 5, 2021
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
78 changes: 78 additions & 0 deletions bindinfo/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/bindinfo"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/kv"
Expand Down Expand Up @@ -1093,6 +1094,12 @@ func (s *testSuite) TestCaptureBaselinesDefaultDB(c *C) {
}

func (s *testSuite) TestCapturePreparedStmt(c *C) {
originalVal := config.CheckTableBeforeDrop
config.CheckTableBeforeDrop = true
defer func() {
config.CheckTableBeforeDrop = originalVal
}()

tk := testkit.NewTestKit(c, s.store)
s.cleanBindingEnv(tk)
stmtsummary.StmtSummaryByDigestMap.Clear()
Expand Down Expand Up @@ -1166,6 +1173,12 @@ func (s *testSuite) TestDropSingleBindings(c *C) {
}

func (s *testSuite) TestDMLEvolveBaselines(c *C) {
originalVal := config.CheckTableBeforeDrop
config.CheckTableBeforeDrop = true
defer func() {
config.CheckTableBeforeDrop = originalVal
}()

tk := testkit.NewTestKit(c, s.store)
s.cleanBindingEnv(tk)
tk.MustExec("use test")
Expand Down Expand Up @@ -1226,6 +1239,12 @@ func (s *testSuite) TestDMLEvolveBaselines(c *C) {
}

func (s *testSuite) TestAddEvolveTasks(c *C) {
originalVal := config.CheckTableBeforeDrop
config.CheckTableBeforeDrop = true
defer func() {
config.CheckTableBeforeDrop = originalVal
}()

tk := testkit.NewTestKit(c, s.store)
s.cleanBindingEnv(tk)
tk.MustExec("use test")
Expand All @@ -1252,6 +1271,12 @@ func (s *testSuite) TestAddEvolveTasks(c *C) {
}

func (s *testSuite) TestRuntimeHintsInEvolveTasks(c *C) {
originalVal := config.CheckTableBeforeDrop
config.CheckTableBeforeDrop = true
defer func() {
config.CheckTableBeforeDrop = originalVal
}()

tk := testkit.NewTestKit(c, s.store)
s.cleanBindingEnv(tk)
tk.MustExec("use test")
Expand Down Expand Up @@ -1447,6 +1472,12 @@ func (s *testSuite) TestDefaultDB(c *C) {
}

func (s *testSuite) TestEvolveInvalidBindings(c *C) {
originalVal := config.CheckTableBeforeDrop
config.CheckTableBeforeDrop = true
defer func() {
config.CheckTableBeforeDrop = originalVal
}()

tk := testkit.NewTestKit(c, s.store)
s.cleanBindingEnv(tk)
tk.MustExec("use test")
Expand Down Expand Up @@ -1507,6 +1538,12 @@ func (s *testSuite) TestPrivileges(c *C) {
}

func (s *testSuite) TestHintsSetEvolveTask(c *C) {
originalVal := config.CheckTableBeforeDrop
config.CheckTableBeforeDrop = true
defer func() {
config.CheckTableBeforeDrop = originalVal
}()

tk := testkit.NewTestKit(c, s.store)
s.cleanBindingEnv(tk)
tk.MustExec("use test")
Expand Down Expand Up @@ -1631,6 +1668,12 @@ func (s *testSuite) TestCapturePlanBaselineIgnoreTiFlash(c *C) {
}

func (s *testSuite) TestNotEvolvePlanForReadStorageHint(c *C) {
originalVal := config.CheckTableBeforeDrop
config.CheckTableBeforeDrop = true
defer func() {
config.CheckTableBeforeDrop = originalVal
}()

tk := testkit.NewTestKit(c, s.store)
s.cleanBindingEnv(tk)
tk.MustExec("use test")
Expand Down Expand Up @@ -1704,6 +1747,12 @@ func (s *testSuite) TestBindingWithIsolationRead(c *C) {
}

func (s *testSuite) TestReCreateBindAfterEvolvePlan(c *C) {
originalVal := config.CheckTableBeforeDrop
config.CheckTableBeforeDrop = true
defer func() {
config.CheckTableBeforeDrop = originalVal
}()

tk := testkit.NewTestKit(c, s.store)
s.cleanBindingEnv(tk)
tk.MustExec("use test")
Expand Down Expand Up @@ -1765,6 +1814,12 @@ func (s *testSuite) TestInvisibleIndex(c *C) {
}

func (s *testSuite) TestBindingSource(c *C) {
originalVal := config.CheckTableBeforeDrop
config.CheckTableBeforeDrop = true
defer func() {
config.CheckTableBeforeDrop = originalVal
}()

tk := testkit.NewTestKit(c, s.store)
s.cleanBindingEnv(tk)
tk.MustExec("use test")
Expand Down Expand Up @@ -1990,6 +2045,12 @@ func (s *testSuite) TestUpdateSubqueryCapture(c *C) {
}

func (s *testSuite) TestIssue20417(c *C) {
originalVal := config.CheckTableBeforeDrop
config.CheckTableBeforeDrop = true
defer func() {
config.CheckTableBeforeDrop = originalVal
}()

tk := testkit.NewTestKit(c, s.store)
s.cleanBindingEnv(tk)
tk.MustExec("use test")
Expand Down Expand Up @@ -2058,6 +2119,23 @@ func (s *testSuite) TestIssue20417(c *C) {
tk.MustExec("set @@tidb_evolve_plan_baselines=0")
}

func (s *testSuite) TestForbidEvolvePlanBaseLinesBeforeGA(c *C) {
originalVal := config.CheckTableBeforeDrop
config.CheckTableBeforeDrop = false
defer func() {
config.CheckTableBeforeDrop = originalVal
}()

tk := testkit.NewTestKit(c, s.store)
s.cleanBindingEnv(tk)
err := tk.ExecToErr("set @@tidb_evolve_plan_baselines=0")
c.Assert(err, Equals, nil)
err = tk.ExecToErr("set @@tidb_evolve_plan_baselines=1")
c.Assert(err, ErrorMatches, "Cannot enable baseline evolution feature, it is not generally available now")
err = tk.ExecToErr("admin evolve bindings")
c.Assert(err, ErrorMatches, "Cannot enable baseline evolution feature, it is not generally available now")
}

func (s *testSuite) TestCaptureWithZeroSlowLogThreshold(c *C) {
tk := testkit.NewTestKit(c, s.store)
s.cleanBindingEnv(tk)
Expand Down
7 changes: 6 additions & 1 deletion planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,12 @@ func (b *PlanBuilder) buildAdmin(ctx context.Context, as *ast.AdminStmt) (Plan,
case ast.AdminCaptureBindings:
return &SQLBindPlan{SQLBindOp: OpCaptureBindings}, nil
case ast.AdminEvolveBindings:
return &SQLBindPlan{SQLBindOp: OpEvolveBindings}, nil
var err error
// The 'baseline evolution' only work in the test environment before the feature is GA.
if !config.CheckTableBeforeDrop {
err = errors.Errorf("Cannot enable baseline evolution feature, it is not generally available now")
}
return &SQLBindPlan{SQLBindOp: OpEvolveBindings}, err
case ast.AdminReloadBindings:
return &SQLBindPlan{SQLBindOp: OpReloadBindings}, nil
case ast.AdminShowTelemetry:
Expand Down
3 changes: 3 additions & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,9 @@ func (s *session) SetGlobalSysVar(name, value string) (err error) {
if value, err = sv.Validate(s.sessionVars, value, variable.ScopeGlobal); err != nil {
return err
}
if sv.Name == "tidb_evolve_plan_baselines" && strings.EqualFold("ON", value) && !config.CheckTableBeforeDrop {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use the variable TiDBEvolvePlanBaselines instead of a literal string tidb_evolve_plan_baselines.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And are sv.Name and value standardized here? What if tidb_EVOLVE_plan_baselines or on?

return errors.Errorf("Cannot enable baseline evolution feature, it is not generally available now")
}
if err = sv.SetGlobalFromHook(s.sessionVars, value, false); err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ func (sv *SysVar) SetSessionFromHook(s *SessionVars, val string) error {
return err
}
}
// The 'baseline evolution' only work in the test environment before the feature is GA.
if sv.Name == "tidb_evolve_plan_baselines" && strings.EqualFold("ON", val) && !config.CheckTableBeforeDrop {
return errors.Errorf("Cannot enable baseline evolution feature, it is not generally available now")
}
s.systems[sv.Name] = val

// Call the Set function on all the aliases for this sysVar
Expand Down