diff --git a/pkg/bindinfo/capture_test.go b/pkg/bindinfo/capture_test.go index c39ab547cc9e8..86e4b12d5e5cb 100644 --- a/pkg/bindinfo/capture_test.go +++ b/pkg/bindinfo/capture_test.go @@ -268,11 +268,6 @@ func TestCapturePreparedStmt(t *testing.T) { tk.MustUseIndex("select /*+ use_index(t,idx_b) */ * from t where b = 1 and c > 1", "idx_c(c)") tk.MustExec("admin flush bindings") - tk.MustExec("admin evolve bindings") - rows = tk.MustQuery("show global bindings").Rows() - require.Len(t, rows, 1) - require.Equal(t, "select * from `test` . `t` where `b` = ? and `c` > ?", rows[0][0]) - require.Equal(t, "SELECT /*+ use_index(@`sel_1` `test`.`t` `idx_c`), no_order_index(@`sel_1` `test`.`t` `idx_c`)*/ * FROM `test`.`t` WHERE `b` = ? AND `c` > ?", rows[0][1]) } func TestCapturePlanBaselineIgnoreTiFlash(t *testing.T) { diff --git a/pkg/bindinfo/global_handle.go b/pkg/bindinfo/global_handle.go index a9dff9b5701ca..713cbbdc889b3 100644 --- a/pkg/bindinfo/global_handle.go +++ b/pkg/bindinfo/global_handle.go @@ -82,9 +82,6 @@ type GlobalBindingHandle interface { // Methods for memory control. - // Size returns the size of bind info cache. - Size() int - // SetBindingCacheCapacity reset the capacity for the bindingCache. SetBindingCacheCapacity(capacity int64) @@ -94,12 +91,6 @@ type GlobalBindingHandle interface { // GetMemCapacity returns the memory capacity for the bind cache. GetMemCapacity() (memCapacity int64) - // Clear resets the bind handle. It is only used for test. - Clear() - - // FlushGlobalBindings flushes the Bindings in temp maps to storage and loads them into cache. - FlushGlobalBindings() error - // Methods for Auto Capture. // CaptureBaselines is used to automatically capture plan baselines. @@ -215,7 +206,7 @@ func (h *globalBindingHandle) LoadFromStorageToCache(fullLoad bool) (err error) metrics.BindingCacheMemUsage.Set(float64(h.GetMemUsage())) metrics.BindingCacheMemLimit.Set(float64(h.GetMemCapacity())) - metrics.BindingCacheNumBindings.Set(float64(h.Size())) + metrics.BindingCacheNumBindings.Set(float64(len(h.getCache().GetAllBindings()))) }() for _, row := range rows { @@ -492,12 +483,6 @@ func (h *globalBindingHandle) AddInvalidGlobalBinding(invalidBinding Binding) { h.invalidBindings.add(invalidBinding) } -// Size returns the size of bind info cache. -func (h *globalBindingHandle) Size() int { - size := len(h.getCache().GetAllBindings()) - return size -} - // MatchGlobalBinding returns the matched binding for this statement. func (h *globalBindingHandle) MatchGlobalBinding(sctx sessionctx.Context, fuzzyDigest string, tableNames []*ast.TableName) (matchedBinding Binding, isMatched bool) { return h.getCache().FuzzyMatchingBinding(sctx, fuzzyDigest, tableNames) @@ -662,19 +647,6 @@ func (*paramMarkerChecker) Leave(in ast.Node) (ast.Node, bool) { return in, true } -// Clear resets the bind handle. It is only used for test. -func (h *globalBindingHandle) Clear() { - h.setCache(newFuzzyBindingCache(h.LoadBindingsFromStorage)) - h.setLastUpdateTime(types.ZeroTimestamp) - h.invalidBindings.reset() -} - -// FlushGlobalBindings flushes the Bindings in temp maps to storage and loads them into cache. -func (h *globalBindingHandle) FlushGlobalBindings() error { - h.DropInvalidGlobalBinding() - return h.LoadFromStorageToCache(false) -} - func (h *globalBindingHandle) callWithSCtx(wrapTxn bool, f func(sctx sessionctx.Context) error) (err error) { resource, err := h.sPool.Get() if err != nil { diff --git a/pkg/bindinfo/global_handle_test.go b/pkg/bindinfo/global_handle_test.go index 2d11516cb84f8..8268ca0ce3009 100644 --- a/pkg/bindinfo/global_handle_test.go +++ b/pkg/bindinfo/global_handle_test.go @@ -133,7 +133,7 @@ func TestBindParse(t *testing.T) { bindHandle := bindinfo.NewGlobalBindingHandle(&mockSessionPool{tk.Session()}) err := bindHandle.LoadFromStorageToCache(true) require.NoError(t, err) - require.Equal(t, 1, bindHandle.Size()) + require.Equal(t, 1, len(bindHandle.GetAllGlobalBindings())) stmt, err := parser.New().ParseOneStmt("select * from test . t", "", "") require.NoError(t, err) @@ -266,7 +266,7 @@ func TestSetBindingStatusWithoutBindingInCache(t *testing.T) { bindinfo.Manual + "', '" + sqlDigest.String() + "', '')") tk.MustExec("insert into mysql.bind_info values('select * from `test` . `t` where `a` > ?', 'SELECT /*+ USE_INDEX(`t` `idx_a`)*/ * FROM `test`.`t` WHERE `a` > 10', 'test', 'enabled', '2000-01-02 09:00:00', '2000-01-02 09:00:00', '', '','" + bindinfo.Manual + "', '" + sqlDigest.String() + "', '')") - dom.BindHandle().Clear() + dom.BindHandle().Reset() tk.MustExec("set binding disabled for select * from t where a > 10") tk.MustExec("admin reload bindings") rows := tk.MustQuery("show global bindings").Rows() @@ -281,7 +281,7 @@ func TestSetBindingStatusWithoutBindingInCache(t *testing.T) { bindinfo.Manual + "', '" + sqlDigest.String() + "', '')") tk.MustExec("insert into mysql.bind_info values('select * from `test` . `t` where `a` > ?', 'SELECT * FROM `test`.`t` WHERE `a` > 10', 'test', 'disabled', '2000-01-02 09:00:00', '2000-01-02 09:00:00', '', '','" + bindinfo.Manual + "', '" + sqlDigest.String() + "', '')") - dom.BindHandle().Clear() + dom.BindHandle().Reset() tk.MustExec("set binding enabled for select * from t where a > 10") tk.MustExec("admin reload bindings") rows = tk.MustQuery("show global bindings").Rows() @@ -465,7 +465,7 @@ func TestGlobalBinding(t *testing.T) { bindHandle := bindinfo.NewGlobalBindingHandle(&mockSessionPool{tk.Session()}) err = bindHandle.LoadFromStorageToCache(true) require.NoError(t, err) - require.Equal(t, 1, bindHandle.Size()) + require.Equal(t, 1, len(bindHandle.GetAllGlobalBindings())) _, fuzzyDigest = norm.NormalizeStmtForBinding(stmt, norm.WithFuzz(true)) binding, matched = dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt)) @@ -488,7 +488,7 @@ func TestGlobalBinding(t *testing.T) { bindHandle = bindinfo.NewGlobalBindingHandle(&mockSessionPool{tk.Session()}) err = bindHandle.LoadFromStorageToCache(true) require.NoError(t, err) - require.Equal(t, 0, bindHandle.Size()) + require.Equal(t, 0, len(bindHandle.GetAllGlobalBindings())) _, fuzzyDigest = norm.NormalizeStmtForBinding(stmt, norm.WithFuzz(true)) _, matched = dom.BindHandle().MatchGlobalBinding(tk.Session(), fuzzyDigest, bindinfo.CollectTableNames(stmt)) diff --git a/pkg/bindinfo/internal/testutil.go b/pkg/bindinfo/internal/testutil.go index bddc8ce9ff997..59bfb7cfb2bd5 100644 --- a/pkg/bindinfo/internal/testutil.go +++ b/pkg/bindinfo/internal/testutil.go @@ -28,7 +28,7 @@ import ( // UtilCleanBindingEnv cleans the binding environment. func UtilCleanBindingEnv(tk *testkit.TestKit, dom *domain.Domain) { tk.MustExec("delete from mysql.bind_info where source != 'builtin'") - dom.BindHandle().Clear() + dom.BindHandle().Reset() } // UtilNormalizeWithDefaultDB normalizes the SQL and returns the normalized SQL and its digest. diff --git a/pkg/executor/bind.go b/pkg/executor/bind.go index 7cfbf32c39647..09894b82dd31d 100644 --- a/pkg/executor/bind.go +++ b/pkg/executor/bind.go @@ -49,8 +49,6 @@ func (e *SQLBindExec) Next(_ context.Context, req *chunk.Chunk) error { return e.flushBindings() case plannercore.OpCaptureBindings: e.captureBindings() - case plannercore.OpEvolveBindings: - return nil // not support yet case plannercore.OpReloadBindings: return e.reloadBindings() case plannercore.OpSetBindingStatus: @@ -159,7 +157,7 @@ func (e *SQLBindExec) createSQLBind() error { } func (e *SQLBindExec) flushBindings() error { - return domain.GetDomain(e.Ctx()).BindHandle().FlushGlobalBindings() + return domain.GetDomain(e.Ctx()).BindHandle().LoadFromStorageToCache(false) } func (e *SQLBindExec) captureBindings() { diff --git a/pkg/planner/core/common_plans.go b/pkg/planner/core/common_plans.go index 888f9677e94d8..8af04b610c7e7 100644 --- a/pkg/planner/core/common_plans.go +++ b/pkg/planner/core/common_plans.go @@ -290,8 +290,6 @@ const ( OpFlushBindings // OpCaptureBindings is used to capture plan bindings. OpCaptureBindings - // OpEvolveBindings is used to evolve plan binding. - OpEvolveBindings // OpReloadBindings is used to reload plan binding. OpReloadBindings // OpSetBindingStatus is used to set binding status. diff --git a/pkg/planner/core/planbuilder.go b/pkg/planner/core/planbuilder.go index 6d04ca7f35e90..1e0e6b157014b 100644 --- a/pkg/planner/core/planbuilder.go +++ b/pkg/planner/core/planbuilder.go @@ -1567,12 +1567,7 @@ func (b *PlanBuilder) buildAdmin(ctx context.Context, as *ast.AdminStmt) (base.P case ast.AdminCaptureBindings: return &SQLBindPlan{SQLBindOp: OpCaptureBindings}, nil case ast.AdminEvolveBindings: - 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 + return nil, errors.Errorf("Cannot enable baseline evolution feature, it is not generally available now") case ast.AdminReloadBindings: return &SQLBindPlan{SQLBindOp: OpReloadBindings}, nil case ast.AdminReloadStatistics: