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: fix prepare explain index out of range bug (#40568) #40603

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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