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: remove unnecessary methods in global binding handler #58343

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 1 addition & 29 deletions pkg/bindinfo/global_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions pkg/bindinfo/global_handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion pkg/bindinfo/internal/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions pkg/executor/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 0 additions & 2 deletions pkg/planner/core/common_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 1 addition & 6 deletions pkg/planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down