Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkingrei committed Mar 7, 2024
1 parent 5be0588 commit c5aa2db
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pkg/bindinfo/binding_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
// fuzzy matching, loading binding if cache miss automatically (TODO).
type FuzzyBindingCache interface {
// FuzzyMatchingBinding supports fuzzy matching on bindings.
FuzzyMatchingBinding(sctx sessionctx.Context, fuzzyDigest string, tableNames []*ast.TableName) (bindings Binding, isMatched bool)
FuzzyMatchingBinding(sctx sessionctx.Context, fuzzyDigest string, tableNames []*ast.TableName) (bindings Binding, isMatched bool, isMissed bool)

// Copy copies this cache.
Copy() (c FuzzyBindingCache, err error)
Expand Down Expand Up @@ -69,7 +69,7 @@ func newFuzzyBindingCache(loadBindingFromStorageFunc func(string) (Bindings, err
}
}

func (fbc *fuzzyBindingCache) FuzzyMatchingBinding(sctx sessionctx.Context, fuzzyDigest string, tableNames []*ast.TableName) (matchedBinding Binding, isMatched bool) {
func (fbc *fuzzyBindingCache) FuzzyMatchingBinding(sctx sessionctx.Context, fuzzyDigest string, tableNames []*ast.TableName) (matchedBinding Binding, isMatched bool, isMissed bool) {
matchedBinding, isMatched, missingSQLDigest := fbc.getFromMemory(sctx, fuzzyDigest, tableNames)
if len(missingSQLDigest) == 0 {
return
Expand All @@ -80,7 +80,7 @@ func (fbc *fuzzyBindingCache) FuzzyMatchingBinding(sctx sessionctx.Context, fuzz
fbc.loadFromStore(missingSQLDigest) // loadFromStore's SetBinding has a Mutex inside, so it's safe to call it without lock
matchedBinding, isMatched, _ = fbc.getFromMemory(sctx, fuzzyDigest, tableNames)
if !isMatched {
sctx.GetSessionVars().StmtCtx.AppendWarning(errors.New("failed to load bindings, optimization process without bindings"))
isMissed = true
}
return
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/bindinfo/binding_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package bindinfo

import (
"errors"
"strings"
"sync"

Expand Down Expand Up @@ -86,8 +87,11 @@ func matchSQLBinding(sctx sessionctx.Context, stmtNode ast.StmtNode, info *Bindi
if globalHandle == nil {
return
}
if binding, matched := globalHandle.MatchGlobalBinding(sctx, fuzzyDigest, tableNames); matched {
binding, matched, isMissed := globalHandle.MatchGlobalBinding(sctx, fuzzyDigest, tableNames)
if matched {
return binding, matched, metrics.ScopeGlobal
} else if isMissed {
sctx.GetSessionVars().StmtCtx.AppendWarning(errors.New("failed to load bindings, optimization process without bindings"))
}
return
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/bindinfo/global_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type GlobalBindingHandle interface {
// Methods for create, get, drop global sql bindings.

// MatchGlobalBinding returns the matched binding for this statement.
MatchGlobalBinding(sctx sessionctx.Context, fuzzyDigest string, tableNames []*ast.TableName) (matchedBinding Binding, isMatched bool)
MatchGlobalBinding(sctx sessionctx.Context, fuzzyDigest string, tableNames []*ast.TableName) (matchedBinding Binding, isMatched bool, isMissed bool)

// GetAllGlobalBindings returns all bind records in cache.
GetAllGlobalBindings() (bindings Bindings)
Expand Down Expand Up @@ -465,7 +465,7 @@ func (h *globalBindingHandle) Size() int {
}

// MatchGlobalBinding returns the matched binding for this statement.
func (h *globalBindingHandle) MatchGlobalBinding(sctx sessionctx.Context, fuzzyDigest string, tableNames []*ast.TableName) (matchedBinding Binding, isMatched bool) {
func (h *globalBindingHandle) MatchGlobalBinding(sctx sessionctx.Context, fuzzyDigest string, tableNames []*ast.TableName) (matchedBinding Binding, isMatched bool, isMissed bool) {
return h.getCache().FuzzyMatchingBinding(sctx, fuzzyDigest, tableNames)
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/bindinfo/session_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ func (h *sessionBindingHandle) DropSessionBinding(sqlDigest string) error {

// MatchSessionBinding returns the matched binding for this statement.
func (h *sessionBindingHandle) MatchSessionBinding(sctx sessionctx.Context, fuzzyDigest string, tableNames []*ast.TableName) (matchedBinding Binding, isMatched bool) {
return h.ch.FuzzyMatchingBinding(sctx, fuzzyDigest, tableNames)
matchedBinding, isMatched, _ = h.ch.FuzzyMatchingBinding(sctx, fuzzyDigest, tableNames)
return
}

// GetAllSessionBindings return all session bind info.
Expand Down

0 comments on commit c5aa2db

Please sign in to comment.