Skip to content

Commit

Permalink
planner: fix prepare explain index out of range bug (#40568) (#40603)
Browse files Browse the repository at this point in the history
close #38323
  • Loading branch information
ti-chi-bot authored Feb 14, 2023
1 parent e826aa7 commit b4372fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 19 additions & 0 deletions executor/seqtest/prepared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,3 +767,22 @@ func TestPreparedIssue17419(t *testing.T) {
// _, ok := tk1.Session().ShowProcess().Plan.(*plannercore.Execute)
// require.True(t, ok)
}

func TestIssue38323(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(id int, k int);")

tk.MustExec("prepare stmt from 'explain select * from t where id = ? and k = ? group by id, k';")
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: not a SELECT/UPDATE/INSERT/DELETE/SET statement"))
tk.MustExec("set @a = 1;")
tk.MustExec("execute stmt using @a, @a")
tk.MustQuery("execute stmt using @a, @a").Check(tk.MustQuery("explain select * from t where id = 1 and k = 1 group by id, k").Rows())

tk.MustExec("prepare stmt from 'explain select * from t where ? = id and ? = k group by id, k';")
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: not a SELECT/UPDATE/INSERT/DELETE/SET statement"))
tk.MustExec("set @a = 1;")
tk.MustQuery("execute stmt using @a, @a").Check(tk.MustQuery("explain select * from t where 1 = id and 1 = k group by id, k").Rows())
}
4 changes: 2 additions & 2 deletions planner/core/point_get_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ func getNameValuePairs(ctx sessionctx.Context, tbl *model.TableInfo, tblName mod
case *driver.ValueExpr:
d = x.Datum
case *driver.ParamMarkerExpr:
con, err = expression.ParamMarkerExpression(ctx, x, true)
con, err = expression.ParamMarkerExpression(ctx, x, false)
if err != nil {
return nil, false
}
Expand All @@ -1368,7 +1368,7 @@ func getNameValuePairs(ctx sessionctx.Context, tbl *model.TableInfo, tblName mod
case *driver.ValueExpr:
d = x.Datum
case *driver.ParamMarkerExpr:
con, err = expression.ParamMarkerExpression(ctx, x, true)
con, err = expression.ParamMarkerExpression(ctx, x, false)
if err != nil {
return nil, false
}
Expand Down

0 comments on commit b4372fd

Please sign in to comment.