From 43e8271ada5089d6c099f915617a9a6f55860b45 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/3] 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 11dae5e570767..701cddddfad63 100644 --- a/executor/seqtest/prepared_test.go +++ b/executor/seqtest/prepared_test.go @@ -767,3 +767,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 de69438257f4e..48a35029a51b3 100644 --- a/planner/core/point_get_plan.go +++ b/planner/core/point_get_plan.go @@ -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 } @@ -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 } From d5bc6da96ac883c8c5d4aa69c0d843eef453a14b Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Wed, 18 Jan 2023 14:41:09 +0800 Subject: [PATCH 2/3] Update prepared_test.go --- executor/seqtest/prepared_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/executor/seqtest/prepared_test.go b/executor/seqtest/prepared_test.go index 701cddddfad63..8b5d2ecedc612 100644 --- a/executor/seqtest/prepared_test.go +++ b/executor/seqtest/prepared_test.go @@ -767,8 +767,6 @@ 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) @@ -808,4 +806,3 @@ func TestIssue38323(t *testing.T) { 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)) From 9b3f8691c56bf583190ae62a57a9bf61391f66b0 Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Wed, 18 Jan 2023 14:41:57 +0800 Subject: [PATCH 3/3] Update prepared_test.go --- executor/seqtest/prepared_test.go | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/executor/seqtest/prepared_test.go b/executor/seqtest/prepared_test.go index 8b5d2ecedc612..2aee215d0f230 100644 --- a/executor/seqtest/prepared_test.go +++ b/executor/seqtest/prepared_test.go @@ -768,26 +768,6 @@ func TestPreparedIssue17419(t *testing.T) { // require.True(t, ok) } -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)