Skip to content

Commit 94cfa8b

Browse files
authored
planner: output a warning if plan rebuilding fails when reusing a cached plan (#46278)
close #46159
1 parent 533998e commit 94cfa8b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

planner/core/plan_cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ func RebuildPlan4CachedPlan(p Plan) (ok bool) {
351351
sc.InPreparedPlanBuilding = true
352352
defer func() { sc.InPreparedPlanBuilding = false }()
353353
if err := rebuildRange(p); err != nil {
354-
// TODO: log or warn this error.
354+
sc.AppendWarning(errors.Errorf("skip plan-cache: plan rebuild failed, %s", err.Error()))
355355
return false // fail to rebuild ranges
356356
}
357357
if !sc.UseCache {

planner/core/plan_cache_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,6 +2446,18 @@ func TestIssue45378(t *testing.T) {
24462446
tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1"))
24472447
}
24482448

2449+
func TestIssue46159(t *testing.T) {
2450+
store := testkit.CreateMockStore(t)
2451+
tk := testkit.NewTestKit(t, store)
2452+
tk.MustExec("use test")
2453+
tk.MustExec(`create table t (a varchar(10), key(a(5)))`)
2454+
tk.MustExec(`prepare st from 'select a from t use index(a) where a=?'`)
2455+
tk.MustExec(`set @a='a'`)
2456+
tk.MustQuery(`execute st using @a`).Check(testkit.Rows())
2457+
tk.MustQuery(`execute st using @a`).Check(testkit.Rows())
2458+
tk.MustQuery(`show warnings`).Check(testkit.Rows("Warning 1105 skip plan-cache: plan rebuild failed, rebuild to get an unsafe range"))
2459+
}
2460+
24492461
func TestBuiltinFuncFlen(t *testing.T) {
24502462
// same as TestIssue45378 and TestIssue45253
24512463
store := testkit.CreateMockStore(t)

0 commit comments

Comments
 (0)