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: output a SQL warning if binding loading is triggered #51774

Merged
merged 4 commits into from Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/bindinfo/binding_cache.go
Expand Up @@ -153,6 +153,10 @@ func (fbc *fuzzyBindingCache) loadFromStore(sctx sessionctx.Context, missingSQLD
if intest.InTest && sctx.Value(LoadBindingNothing) != nil {
return
}
defer func(start time.Time) {
sctx.GetSessionVars().StmtCtx.AppendWarning(errors.New("loading binding from storage takes " + time.Since(start).String()))
}(time.Now())

for _, sqlDigest := range missingSQLDigest {
start := time.Now()
bindings, err := fbc.loadBindingFromStorageFunc(sctx, sqlDigest)
Expand All @@ -173,7 +177,7 @@ func (fbc *fuzzyBindingCache) loadFromStore(sctx sessionctx.Context, missingSQLD
// When the memory capacity of bing_cache is not enough,
// there will be some memory-related errors in multiple places.
// Only needs to be handled once.
logutil.BindLogger().Warn("BindHandle.Update", zap.Error(err))
logutil.BindLogger().Warn("update binding cache error", zap.Error(err))
}
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/bindinfo/tests/timeout/BUILD.bazel
Expand Up @@ -12,6 +12,7 @@ go_test(
"//pkg/bindinfo",
"//pkg/testkit",
"//pkg/testkit/testsetup",
"@com_github_stretchr_testify//require",
"@org_uber_go_goleak//:goleak",
],
)
18 changes: 18 additions & 0 deletions pkg/bindinfo/tests/timeout/timeout_test.go
Expand Up @@ -20,8 +20,26 @@ import (

"github.com/pingcap/tidb/pkg/bindinfo"
"github.com/pingcap/tidb/pkg/testkit"
"github.com/stretchr/testify/require"
)

func TestLoadBindingWarn(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec(`use test`)
tk.MustExec(`create table t1 (a int)`)
tk.MustExec(`create global binding using select * from t1`)
tk.MustExec(`select * from t1`)
tk.MustQuery(`show warnings`).Check(testkit.Rows()) // no warning

sctx := tk.Session()
sctx.SetValue(bindinfo.GetBindingReturnNilAlways, true)
tk.MustExec(`select * from t1`)
warnings := tk.MustQuery(`show warnings`)
require.True(t, len(warnings.Rows()) == 1)
sctx.ClearValue(bindinfo.GetBindingReturnNilAlways)
}

func TestFuzzyBindingHintsWithSourceReturningTimeout(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down