From 16a249e3cbc22163c836700a670c3f013913db85 Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 16 Jan 2023 11:25:48 +0800 Subject: [PATCH 1/2] This is an automated cherry-pick of #40568 Signed-off-by: ti-chi-bot --- executor/seqtest/prepared_test.go | 42 +++++++++++++++++++++++++++++++ planner/core/point_get_plan.go | 4 +-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/executor/seqtest/prepared_test.go b/executor/seqtest/prepared_test.go index b8f9c860dbbaa..62f078e9aa39b 100644 --- a/executor/seqtest/prepared_test.go +++ b/executor/seqtest/prepared_test.go @@ -937,3 +937,45 @@ func TestPreparedIssue17419(t *testing.T) { // _, ok := tk1.Session().ShowProcess().Plan.(*plannercore.Execute) // require.True(t, ok) } +<<<<<<< HEAD +======= + +func TestLimitUnsupportedCase(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(a int, key(a))") + tk.MustExec("prepare stmt from 'select * from t limit ?'") + + tk.MustExec("set @a = 1.2") + tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") + tk.MustExec("set @a = 1.") + tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") + tk.MustExec("set @a = '0'") + tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") + tk.MustExec("set @a = '1'") + tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") + tk.MustExec("set @a = 1_2") + tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") +} + +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()) +} +>>>>>>> ee6d291f4e (planner: fix prepare explain index out of range bug (#40568)) diff --git a/planner/core/point_get_plan.go b/planner/core/point_get_plan.go index afb34814f7196..3055d57e8c060 100644 --- a/planner/core/point_get_plan.go +++ b/planner/core/point_get_plan.go @@ -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 } @@ -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 } From d6fdc6c0423ae947a02051dea283ca6aea4324ed Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 16 Jan 2023 11:40:08 +0800 Subject: [PATCH 2/2] fix ut --- executor/seqtest/prepared_test.go | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/executor/seqtest/prepared_test.go b/executor/seqtest/prepared_test.go index 62f078e9aa39b..b8d81a5f5206c 100644 --- a/executor/seqtest/prepared_test.go +++ b/executor/seqtest/prepared_test.go @@ -937,45 +937,21 @@ func TestPreparedIssue17419(t *testing.T) { // _, ok := tk1.Session().ShowProcess().Plan.(*plannercore.Execute) // require.True(t, ok) } -<<<<<<< HEAD -======= - -func TestLimitUnsupportedCase(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(a int, key(a))") - tk.MustExec("prepare stmt from 'select * from t limit ?'") - - tk.MustExec("set @a = 1.2") - tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") - tk.MustExec("set @a = 1.") - tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") - tk.MustExec("set @a = '0'") - tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") - tk.MustExec("set @a = '1'") - tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") - tk.MustExec("set @a = 1_2") - tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") -} func TestIssue38323(t *testing.T) { - store := testkit.CreateMockStore(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.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()) } ->>>>>>> ee6d291f4e (planner: fix prepare explain index out of range bug (#40568))