Skip to content

Commit

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

func TestIssue38323(t *testing.T) {
store, _, clean := testkit.CreateMockStoreAndDomain(t)
defer clean()
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.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.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 @@ -1207,7 +1207,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 @@ -1221,7 +1221,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 dd5ff49

Please sign in to comment.