From 0557606fe3b9d1f1c2880dd1e976d828f4eb8733 Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Fri, 6 Jan 2023 12:20:22 +0800 Subject: [PATCH 01/25] commit --- planner/core/logical_plan_builder.go | 66 +++++++++++++++++++++++++++- planner/core/plan_cache_test.go | 24 ++++++++++ 2 files changed, 88 insertions(+), 2 deletions(-) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 592bb55f79619..4af0dddbda765 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -2041,17 +2041,79 @@ func getUintFromNode(ctx sessionctx.Context, n ast.Node) (uVal uint64, isNull bo return 0, false, false } +// getUintFromLimitNode gets uint64 value from ast.Node. +// For ordinary statement, node should be uint64 constant value. +// For prepared statement, node is string. We should convert it to uint64. +func getUintFromLimitNode(ctx sessionctx.Context, n ast.Node) (uVal uint64, isNull bool, isExpectedType bool) { + var val interface{} + switch v := n.(type) { + case *driver.ValueExpr: + val = v.GetValue() + case *driver.ParamMarkerExpr: + if !v.InExecute { + return 0, false, true + } + if expected := checkParamTypeExpected(v); !expected { + return 0, false, false + } + param, err := expression.ParamMarkerExpression(ctx, v, false) + if err != nil { + return 0, false, false + } + str, isNull, err := expression.GetStringFromConstant(ctx, param) + if err != nil { + return 0, false, false + } + if isNull { + return 0, true, true + } + val = str + default: + return 0, false, false + } + switch v := val.(type) { + case uint64: + return v, false, true + case int64: + if v >= 0 { + return uint64(v), false, true + } + case string: + sc := ctx.GetSessionVars().StmtCtx + uVal, err := types.StrToUint(sc, v, false) + if err != nil { + return 0, false, false + } + return uVal, false, true + } + return 0, false, false +} + +// check param type for plan cache, only allow int now +// eg: set @a = 1; +func checkParamTypeExpected(param *driver.ParamMarkerExpr) bool { + val := param.GetValue() + switch v := val.(type) { + case int64: + if v >= 0 { + return true + } + return false + } + return false +} + func extractLimitCountOffset(ctx sessionctx.Context, limit *ast.Limit) (count uint64, offset uint64, err error) { var isExpectedType bool if limit.Count != nil { - count, _, isExpectedType = getUintFromNode(ctx, limit.Count) + count, _, isExpectedType = getUintFromLimitNode(ctx, limit.Count) if !isExpectedType { return 0, 0, ErrWrongArguments.GenWithStackByArgs("LIMIT") } } if limit.Offset != nil { - offset, _, isExpectedType = getUintFromNode(ctx, limit.Offset) + offset, _, isExpectedType = getUintFromLimitNode(ctx, limit.Offset) if !isExpectedType { return 0, 0, ErrWrongArguments.GenWithStackByArgs("LIMIT") } diff --git a/planner/core/plan_cache_test.go b/planner/core/plan_cache_test.go index d7d47e55bc62e..8f5e120d2f76e 100644 --- a/planner/core/plan_cache_test.go +++ b/planner/core/plan_cache_test.go @@ -458,3 +458,27 @@ func TestUncacheableReason(t *testing.T) { // show the corresponding un-cacheable reason at execute-stage as well tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: query has 'limit ?' is un-cacheable")) } + +func TestUnsupportedLimitCase(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", "incorrect arguments to limit in plan cache") + + tk.MustExec("set @a = 1.") + tk.MustGetErrMsg("execute stmt using @a", "incorrect arguments to limit in plan cache") + + tk.MustExec("set @a = '0'") + tk.MustGetErrMsg("execute stmt using @a", "incorrect arguments to limit in plan cache") + + tk.MustExec("set @a = '1'") + tk.MustGetErrMsg("execute stmt using @a", "incorrect arguments to limit in plan cache") + + tk.MustExec("set @a = 1_2") + tk.MustGetErrMsg("execute stmt using @a", "incorrect arguments to limit in plan cache") +} From a7239440857524722ff9c4c50336a9d813faeac1 Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Fri, 6 Jan 2023 14:19:28 +0800 Subject: [PATCH 02/25] Update logical_plan_builder.go --- planner/core/logical_plan_builder.go | 1 - 1 file changed, 1 deletion(-) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 4af0dddbda765..2209a53f877f1 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -2098,7 +2098,6 @@ func checkParamTypeExpected(param *driver.ParamMarkerExpr) bool { if v >= 0 { return true } - return false } return false } From d1b95cf778a79ecb051d78553ff466d0fea84012 Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Fri, 6 Jan 2023 14:27:14 +0800 Subject: [PATCH 03/25] Update logical_plan_builder.go --- planner/core/logical_plan_builder.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 2209a53f877f1..1e77da346c262 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -2093,11 +2093,8 @@ func getUintFromLimitNode(ctx sessionctx.Context, n ast.Node) (uVal uint64, isNu // eg: set @a = 1; func checkParamTypeExpected(param *driver.ParamMarkerExpr) bool { val := param.GetValue() - switch v := val.(type) { - case int64: - if v >= 0 { - return true - } + if valInt64, ok := val.(int64); ok && valInt64 >= 0 { + return true } return false } From 463b85f05a75941685f4eb9d00ca3a2225c6daac Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Fri, 6 Jan 2023 14:39:32 +0800 Subject: [PATCH 04/25] Update plan_cache_test.go --- planner/core/plan_cache_test.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/planner/core/plan_cache_test.go b/planner/core/plan_cache_test.go index 8f5e120d2f76e..1cef46843877a 100644 --- a/planner/core/plan_cache_test.go +++ b/planner/core/plan_cache_test.go @@ -466,19 +466,15 @@ func TestUnsupportedLimitCase(t *testing.T) { 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", "incorrect arguments to limit in plan cache") + 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", "incorrect arguments to limit in plan cache") - + tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") tk.MustExec("set @a = '0'") - tk.MustGetErrMsg("execute stmt using @a", "incorrect arguments to limit in plan cache") - + tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") tk.MustExec("set @a = '1'") - tk.MustGetErrMsg("execute stmt using @a", "incorrect arguments to limit in plan cache") - + tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") tk.MustExec("set @a = 1_2") - tk.MustGetErrMsg("execute stmt using @a", "incorrect arguments to limit in plan cache") + tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") } From ed925f96742dbc97a4cbc9f5ba21ee5da28f9075 Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Fri, 6 Jan 2023 15:16:07 +0800 Subject: [PATCH 05/25] fix ut --- executor/seqtest/prepared_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/executor/seqtest/prepared_test.go b/executor/seqtest/prepared_test.go index 5edbed52b4e13..f3c81522be83a 100644 --- a/executor/seqtest/prepared_test.go +++ b/executor/seqtest/prepared_test.go @@ -280,11 +280,11 @@ func TestPreparedLimitOffset(t *testing.T) { r.Check(testkit.Rows("2")) tk.MustExec(`set @a=1.1`) - r = tk.MustQuery(`execute stmt_test_1 using @a, @b;`) - r.Check(testkit.Rows("2")) + _, err := tk.Exec(`execute stmt_test_1 using @a, @b;`) + require.True(t, plannercore.ErrWrongArguments.Equal(err)) tk.MustExec(`set @c="-1"`) - _, err := tk.Exec("execute stmt_test_1 using @c, @c") + _, err = tk.Exec("execute stmt_test_1 using @c, @c") require.True(t, plannercore.ErrWrongArguments.Equal(err)) stmtID, _, _, err := tk.Session().PrepareStmt("select id from prepare_test limit ?") From 5c383c8f47057b8b254aed616e9c6bf15f6ae7b4 Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 9 Jan 2023 10:33:18 +0800 Subject: [PATCH 06/25] Update logical_plan_builder.go --- planner/core/logical_plan_builder.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 1e77da346c262..5f08948d6e5ba 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -2093,7 +2093,12 @@ func getUintFromLimitNode(ctx sessionctx.Context, n ast.Node) (uVal uint64, isNu // eg: set @a = 1; func checkParamTypeExpected(param *driver.ParamMarkerExpr) bool { val := param.GetValue() - if valInt64, ok := val.(int64); ok && valInt64 >= 0 { + switch v := val.(type) { + case int64: + if v >= 0 { + return true + } + case uint64: return true } return false From b7c7c597ffeecefa2030b804442e5b532a57cd53 Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 9 Jan 2023 11:46:02 +0800 Subject: [PATCH 07/25] Update logical_plan_builder.go --- planner/core/logical_plan_builder.go | 69 ++++++---------------------- 1 file changed, 13 insertions(+), 56 deletions(-) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 5f08948d6e5ba..ac2f1040c5b79 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -162,7 +162,7 @@ func (a *aggOrderByResolver) Enter(inNode ast.Node) (ast.Node, bool) { a.exprDepth++ if n, ok := inNode.(*driver.ParamMarkerExpr); ok { if a.exprDepth == 1 { - _, isNull, isExpectedType := getUintFromNode(a.ctx, n) + _, isNull, isExpectedType := getUintFromNode(a.ctx, n, false) // For constant uint expression in top level, it should be treated as position expression. if !isNull && isExpectedType { return expression.ConstructPositionExpr(n), true @@ -1999,7 +1999,7 @@ CheckReferenced: // getUintFromNode gets uint64 value from ast.Node. // For ordinary statement, node should be uint64 constant value. // For prepared statement, node is string. We should convert it to uint64. -func getUintFromNode(ctx sessionctx.Context, n ast.Node) (uVal uint64, isNull bool, isExpectedType bool) { +func getUintFromNode(ctx sessionctx.Context, n ast.Node, mustInt64OrUint64 bool) (uVal uint64, isNull bool, isExpectedType bool) { var val interface{} switch v := n.(type) { case *driver.ValueExpr: @@ -2008,53 +2008,10 @@ func getUintFromNode(ctx sessionctx.Context, n ast.Node) (uVal uint64, isNull bo if !v.InExecute { return 0, false, true } - param, err := expression.ParamMarkerExpression(ctx, v, false) - if err != nil { - return 0, false, false - } - str, isNull, err := expression.GetStringFromConstant(ctx, param) - if err != nil { - return 0, false, false - } - if isNull { - return 0, true, true - } - val = str - default: - return 0, false, false - } - switch v := val.(type) { - case uint64: - return v, false, true - case int64: - if v >= 0 { - return uint64(v), false, true - } - case string: - sc := ctx.GetSessionVars().StmtCtx - uVal, err := types.StrToUint(sc, v, false) - if err != nil { - return 0, false, false - } - return uVal, false, true - } - return 0, false, false -} - -// getUintFromLimitNode gets uint64 value from ast.Node. -// For ordinary statement, node should be uint64 constant value. -// For prepared statement, node is string. We should convert it to uint64. -func getUintFromLimitNode(ctx sessionctx.Context, n ast.Node) (uVal uint64, isNull bool, isExpectedType bool) { - var val interface{} - switch v := n.(type) { - case *driver.ValueExpr: - val = v.GetValue() - case *driver.ParamMarkerExpr: - if !v.InExecute { - return 0, false, true - } - if expected := checkParamTypeExpected(v); !expected { - return 0, false, false + if mustInt64OrUint64 { + if expected := checkParamTypeInt64OrUint64(v); !expected { + return 0, false, false + } } param, err := expression.ParamMarkerExpression(ctx, v, false) if err != nil { @@ -2089,9 +2046,9 @@ func getUintFromLimitNode(ctx sessionctx.Context, n ast.Node) (uVal uint64, isNu return 0, false, false } -// check param type for plan cache, only allow int now +// check param type for plan cache limit, only allow int64 and uint64 now // eg: set @a = 1; -func checkParamTypeExpected(param *driver.ParamMarkerExpr) bool { +func checkParamTypeInt64OrUint64(param *driver.ParamMarkerExpr) bool { val := param.GetValue() switch v := val.(type) { case int64: @@ -2108,13 +2065,13 @@ func extractLimitCountOffset(ctx sessionctx.Context, limit *ast.Limit) (count ui offset uint64, err error) { var isExpectedType bool if limit.Count != nil { - count, _, isExpectedType = getUintFromLimitNode(ctx, limit.Count) + count, _, isExpectedType = getUintFromNode(ctx, limit.Count, true) if !isExpectedType { return 0, 0, ErrWrongArguments.GenWithStackByArgs("LIMIT") } } if limit.Offset != nil { - offset, _, isExpectedType = getUintFromLimitNode(ctx, limit.Offset) + offset, _, isExpectedType = getUintFromNode(ctx, limit.Offset, true) if !isExpectedType { return 0, 0, ErrWrongArguments.GenWithStackByArgs("LIMIT") } @@ -2895,7 +2852,7 @@ func (g *gbyResolver) Enter(inNode ast.Node) (ast.Node, bool) { case *driver.ParamMarkerExpr: g.isParam = true if g.exprDepth == 1 { - _, isNull, isExpectedType := getUintFromNode(g.ctx, n) + _, isNull, isExpectedType := getUintFromNode(g.ctx, n, false) // For constant uint expression in top level, it should be treated as position expression. if !isNull && isExpectedType { return expression.ConstructPositionExpr(n), true @@ -6268,7 +6225,7 @@ func (b *PlanBuilder) buildWindowFunctionFrameBound(_ context.Context, spec *ast if bound.Type == ast.CurrentRow { return bound, nil } - numRows, _, _ := getUintFromNode(b.ctx, boundClause.Expr) + numRows, _, _ := getUintFromNode(b.ctx, boundClause.Expr, false) bound.Num = numRows return bound, nil } @@ -6584,7 +6541,7 @@ func (b *PlanBuilder) checkOriginWindowFrameBound(bound *ast.FrameBound, spec *a if bound.Unit != ast.TimeUnitInvalid { return ErrWindowRowsIntervalUse.GenWithStackByArgs(getWindowName(spec.Name.O)) } - _, isNull, isExpectedType := getUintFromNode(b.ctx, bound.Expr) + _, isNull, isExpectedType := getUintFromNode(b.ctx, bound.Expr, false) if isNull || !isExpectedType { return ErrWindowFrameIllegal.GenWithStackByArgs(getWindowName(spec.Name.O)) } From 87ad59880a93e15e570622e9019872f260e2f49c Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 9 Jan 2023 11:49:37 +0800 Subject: [PATCH 08/25] rename --- planner/core/logical_plan_builder.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index ac2f1040c5b79..3f205875b7a80 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -1999,7 +1999,7 @@ CheckReferenced: // getUintFromNode gets uint64 value from ast.Node. // For ordinary statement, node should be uint64 constant value. // For prepared statement, node is string. We should convert it to uint64. -func getUintFromNode(ctx sessionctx.Context, n ast.Node, mustInt64OrUint64 bool) (uVal uint64, isNull bool, isExpectedType bool) { +func getUintFromNode(ctx sessionctx.Context, n ast.Node, mustInt64orUint64 bool) (uVal uint64, isNull bool, isExpectedType bool) { var val interface{} switch v := n.(type) { case *driver.ValueExpr: @@ -2008,7 +2008,7 @@ func getUintFromNode(ctx sessionctx.Context, n ast.Node, mustInt64OrUint64 bool) if !v.InExecute { return 0, false, true } - if mustInt64OrUint64 { + if mustInt64orUint64 { if expected := checkParamTypeInt64OrUint64(v); !expected { return 0, false, false } From 6094e462014a5643237cedea333653f0bed2fb72 Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 9 Jan 2023 11:50:21 +0800 Subject: [PATCH 09/25] reanme --- planner/core/logical_plan_builder.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 3f205875b7a80..88b4d4d7beb9c 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -2009,7 +2009,7 @@ func getUintFromNode(ctx sessionctx.Context, n ast.Node, mustInt64orUint64 bool) return 0, false, true } if mustInt64orUint64 { - if expected := checkParamTypeInt64OrUint64(v); !expected { + if expected := checkParamTypeInt64orUint64(v); !expected { return 0, false, false } } @@ -2048,7 +2048,7 @@ func getUintFromNode(ctx sessionctx.Context, n ast.Node, mustInt64orUint64 bool) // check param type for plan cache limit, only allow int64 and uint64 now // eg: set @a = 1; -func checkParamTypeInt64OrUint64(param *driver.ParamMarkerExpr) bool { +func checkParamTypeInt64orUint64(param *driver.ParamMarkerExpr) bool { val := param.GetValue() switch v := val.(type) { case int64: From 7c3a2cc88ae534f47c9aadee2657d2692db8cabf Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 9 Jan 2023 16:10:26 +0800 Subject: [PATCH 10/25] test --- planner/core/logical_plan_builder.go | 31 ++++++++++++----------- planner/core/plan_cache_test.go | 38 ++++++++++++++-------------- 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 718abd013db5c..a01b601b22543 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -2009,9 +2009,10 @@ func getUintFromNode(ctx sessionctx.Context, n ast.Node, mustInt64orUint64 bool) return 0, false, true } if mustInt64orUint64 { - if expected := checkParamTypeInt64orUint64(v); !expected { - return 0, false, false - } + //if expected := checkParamTypeInt64orUint64(v); !expected { + // return 0, false, false + //} + logutil.BgLogger().Info("test") } param, err := expression.ParamMarkerExpression(ctx, v, false) if err != nil { @@ -2048,18 +2049,18 @@ func getUintFromNode(ctx sessionctx.Context, n ast.Node, mustInt64orUint64 bool) // check param type for plan cache limit, only allow int64 and uint64 now // eg: set @a = 1; -func checkParamTypeInt64orUint64(param *driver.ParamMarkerExpr) bool { - val := param.GetValue() - switch v := val.(type) { - case int64: - if v >= 0 { - return true - } - case uint64: - return true - } - return false -} +//func checkParamTypeInt64orUint64(param *driver.ParamMarkerExpr) bool { +// val := param.GetValue() +// switch v := val.(type) { +// case int64: +// if v >= 0 { +// return true +// } +// case uint64: +// return true +// } +// return false +//} func extractLimitCountOffset(ctx sessionctx.Context, limit *ast.Limit) (count uint64, offset uint64, err error) { diff --git a/planner/core/plan_cache_test.go b/planner/core/plan_cache_test.go index 1cef46843877a..1f33fcd49f3e6 100644 --- a/planner/core/plan_cache_test.go +++ b/planner/core/plan_cache_test.go @@ -459,22 +459,22 @@ func TestUncacheableReason(t *testing.T) { tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: query has 'limit ?' is un-cacheable")) } -func TestUnsupportedLimitCase(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 TestUnsupportedLimitCase(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") +//} From e44d8ca46c5dec00391aed3862c0577720c777e3 Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 9 Jan 2023 16:15:10 +0800 Subject: [PATCH 11/25] Update prepared_test.go --- executor/seqtest/prepared_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/executor/seqtest/prepared_test.go b/executor/seqtest/prepared_test.go index f3c81522be83a..376e517754133 100644 --- a/executor/seqtest/prepared_test.go +++ b/executor/seqtest/prepared_test.go @@ -279,13 +279,13 @@ func TestPreparedLimitOffset(t *testing.T) { r := tk.MustQuery(`execute stmt_test_1 using @a, @b;`) r.Check(testkit.Rows("2")) - tk.MustExec(`set @a=1.1`) - _, err := tk.Exec(`execute stmt_test_1 using @a, @b;`) - require.True(t, plannercore.ErrWrongArguments.Equal(err)) - - tk.MustExec(`set @c="-1"`) - _, err = tk.Exec("execute stmt_test_1 using @c, @c") - require.True(t, plannercore.ErrWrongArguments.Equal(err)) + //tk.MustExec(`set @a=1.1`) + //_, err := tk.Exec(`execute stmt_test_1 using @a, @b;`) + //require.True(t, plannercore.ErrWrongArguments.Equal(err)) + // + //tk.MustExec(`set @c="-1"`) + //_, err = tk.Exec("execute stmt_test_1 using @c, @c") + //require.True(t, plannercore.ErrWrongArguments.Equal(err)) stmtID, _, _, err := tk.Session().PrepareStmt("select id from prepare_test limit ?") require.NoError(t, err) From 49855b001098c04301995afb6754f091fe98074e Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 9 Jan 2023 16:48:11 +0800 Subject: [PATCH 12/25] Update logical_plan_builder.go --- planner/core/logical_plan_builder.go | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index a01b601b22543..258bb6a94e6de 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -2009,9 +2009,9 @@ func getUintFromNode(ctx sessionctx.Context, n ast.Node, mustInt64orUint64 bool) return 0, false, true } if mustInt64orUint64 { - //if expected := checkParamTypeInt64orUint64(v); !expected { - // return 0, false, false - //} + if expected := checkParamTypeInt64orUint64(v); !expected { + return 0, false, false + } logutil.BgLogger().Info("test") } param, err := expression.ParamMarkerExpression(ctx, v, false) @@ -2049,18 +2049,18 @@ func getUintFromNode(ctx sessionctx.Context, n ast.Node, mustInt64orUint64 bool) // check param type for plan cache limit, only allow int64 and uint64 now // eg: set @a = 1; -//func checkParamTypeInt64orUint64(param *driver.ParamMarkerExpr) bool { -// val := param.GetValue() -// switch v := val.(type) { -// case int64: -// if v >= 0 { -// return true -// } -// case uint64: -// return true -// } -// return false -//} +func checkParamTypeInt64orUint64(param *driver.ParamMarkerExpr) bool { + val := param.GetValue() + switch v := val.(type) { + case int64: + if v >= 0 { + return true + } + case uint64: + return true + } + return false +} func extractLimitCountOffset(ctx sessionctx.Context, limit *ast.Limit) (count uint64, offset uint64, err error) { From 850b34a24914b7a5d97ee3c7bea96fe62682104a Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 9 Jan 2023 17:20:01 +0800 Subject: [PATCH 13/25] amazing --- planner/core/logical_plan_builder.go | 1 - planner/core/plan_cache_test.go | 38 ++++++++++++++-------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 258bb6a94e6de..718abd013db5c 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -2012,7 +2012,6 @@ func getUintFromNode(ctx sessionctx.Context, n ast.Node, mustInt64orUint64 bool) if expected := checkParamTypeInt64orUint64(v); !expected { return 0, false, false } - logutil.BgLogger().Info("test") } param, err := expression.ParamMarkerExpression(ctx, v, false) if err != nil { diff --git a/planner/core/plan_cache_test.go b/planner/core/plan_cache_test.go index 1f33fcd49f3e6..1cef46843877a 100644 --- a/planner/core/plan_cache_test.go +++ b/planner/core/plan_cache_test.go @@ -459,22 +459,22 @@ func TestUncacheableReason(t *testing.T) { tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: query has 'limit ?' is un-cacheable")) } -//func TestUnsupportedLimitCase(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 TestUnsupportedLimitCase(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") +} From 253f14ac0ff3ea473ec0fb6ed5d6199a96e0a96e Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 9 Jan 2023 20:49:50 +0800 Subject: [PATCH 14/25] Update plan_cache_test.go --- planner/core/plan_cache_test.go | 38 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/planner/core/plan_cache_test.go b/planner/core/plan_cache_test.go index 1cef46843877a..1f33fcd49f3e6 100644 --- a/planner/core/plan_cache_test.go +++ b/planner/core/plan_cache_test.go @@ -459,22 +459,22 @@ func TestUncacheableReason(t *testing.T) { tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: query has 'limit ?' is un-cacheable")) } -func TestUnsupportedLimitCase(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 TestUnsupportedLimitCase(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") +//} From eddee4ffb683b86e53548ad167b961bb0aa51c84 Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 9 Jan 2023 21:25:03 +0800 Subject: [PATCH 15/25] Update plan_cache_test.go --- planner/core/plan_cache_test.go | 38 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/planner/core/plan_cache_test.go b/planner/core/plan_cache_test.go index 1f33fcd49f3e6..37e5fdfe9c83f 100644 --- a/planner/core/plan_cache_test.go +++ b/planner/core/plan_cache_test.go @@ -459,22 +459,22 @@ func TestUncacheableReason(t *testing.T) { tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: query has 'limit ?' is un-cacheable")) } -//func TestUnsupportedLimitCase(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 TestUnsupportedLimitCase(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 1 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") +} From f9e204f907ba1446335cb7db2e24ccf25ad41fe9 Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 9 Jan 2023 21:56:04 +0800 Subject: [PATCH 16/25] Update plan_cache_test.go --- planner/core/plan_cache_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/planner/core/plan_cache_test.go b/planner/core/plan_cache_test.go index 37e5fdfe9c83f..e537f1ee3df0b 100644 --- a/planner/core/plan_cache_test.go +++ b/planner/core/plan_cache_test.go @@ -477,4 +477,5 @@ func TestUnsupportedLimitCase(t *testing.T) { 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") + tk.MustExec("deallocate prepare stmt") } From 00e2abd6f1c69f85910cba6fd67f6c4db59f1d52 Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 9 Jan 2023 22:36:10 +0800 Subject: [PATCH 17/25] Update plan_cache_test.go --- planner/core/plan_cache_test.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/planner/core/plan_cache_test.go b/planner/core/plan_cache_test.go index e537f1ee3df0b..dea7f6378344d 100644 --- a/planner/core/plan_cache_test.go +++ b/planner/core/plan_cache_test.go @@ -469,13 +469,14 @@ func TestUnsupportedLimitCase(t *testing.T) { 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") - tk.MustExec("deallocate prepare stmt") + //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") + //_, err := tk.Exec("execute stmt using @a") + //require.True(t, plannercore.ErrWrongArguments.Equal(err)) } From f774bd6e67fdac4f9350424d3c83b194ef4d2e33 Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 9 Jan 2023 22:49:04 +0800 Subject: [PATCH 18/25] Update plan_cache_test.go --- planner/core/plan_cache_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/planner/core/plan_cache_test.go b/planner/core/plan_cache_test.go index dea7f6378344d..38a323c18bc7e 100644 --- a/planner/core/plan_cache_test.go +++ b/planner/core/plan_cache_test.go @@ -468,7 +468,10 @@ func TestUnsupportedLimitCase(t *testing.T) { tk.MustExec("prepare stmt from 'select 1 limit ?'") tk.MustExec("set @a = 1.2") - tk.MustGetErrMsg("execute stmt using @a", "[planner:1210]Incorrect arguments to LIMIT") + _, err := tk.Exec("execute stmt using @a") + require.True(t, plannercore.ErrWrongArguments.Equal(err)) + + //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'") From 55bac3bedcc0503fb5f1980425f1615b896bbf14 Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 9 Jan 2023 22:58:37 +0800 Subject: [PATCH 19/25] Update plan_cache_test.go --- planner/core/plan_cache_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/planner/core/plan_cache_test.go b/planner/core/plan_cache_test.go index 38a323c18bc7e..7d218973dab72 100644 --- a/planner/core/plan_cache_test.go +++ b/planner/core/plan_cache_test.go @@ -467,10 +467,7 @@ func TestUnsupportedLimitCase(t *testing.T) { tk.MustExec("create table t(a int, key(a))") tk.MustExec("prepare stmt from 'select 1 limit ?'") - tk.MustExec("set @a = 1.2") - _, err := tk.Exec("execute stmt using @a") - require.True(t, plannercore.ErrWrongArguments.Equal(err)) - + //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") From 858d59f3ca1f65d9ab7fa3ec4db2dccafb8bdb37 Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 9 Jan 2023 23:07:59 +0800 Subject: [PATCH 20/25] Update plan_cache_test.go --- planner/core/plan_cache_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planner/core/plan_cache_test.go b/planner/core/plan_cache_test.go index 7d218973dab72..8da9a85a0e0b4 100644 --- a/planner/core/plan_cache_test.go +++ b/planner/core/plan_cache_test.go @@ -459,7 +459,7 @@ func TestUncacheableReason(t *testing.T) { tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: query has 'limit ?' is un-cacheable")) } -func TestUnsupportedLimitCase(t *testing.T) { +func TestLimitUnsupportedCase(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") From d11cafe181e7eb2e0fd0217dedf49bf92110c05d Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 9 Jan 2023 23:17:37 +0800 Subject: [PATCH 21/25] Update plan_cache_test.go --- planner/core/plan_cache_test.go | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/planner/core/plan_cache_test.go b/planner/core/plan_cache_test.go index 8da9a85a0e0b4..19a84af2bb1f0 100644 --- a/planner/core/plan_cache_test.go +++ b/planner/core/plan_cache_test.go @@ -459,24 +459,24 @@ func TestUncacheableReason(t *testing.T) { tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: query has 'limit ?' is un-cacheable")) } -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 1 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") - //_, err := tk.Exec("execute stmt using @a") - //require.True(t, plannercore.ErrWrongArguments.Equal(err)) -} +//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 1 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") +//_, err := tk.Exec("execute stmt using @a") +//require.True(t, plannercore.ErrWrongArguments.Equal(err)) +//} From 32e433799db07c802300fb6769d869253504f6da Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 9 Jan 2023 23:32:25 +0800 Subject: [PATCH 22/25] Update plan_cache_test.go --- planner/core/plan_cache_test.go | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/planner/core/plan_cache_test.go b/planner/core/plan_cache_test.go index 19a84af2bb1f0..ec49d3381158e 100644 --- a/planner/core/plan_cache_test.go +++ b/planner/core/plan_cache_test.go @@ -459,24 +459,24 @@ func TestUncacheableReason(t *testing.T) { tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: query has 'limit ?' is un-cacheable")) } -//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 1 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") -//_, err := tk.Exec("execute stmt using @a") -//require.True(t, plannercore.ErrWrongArguments.Equal(err)) -//} +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 st from 'select 1 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") + //_, err := tk.Exec("execute stmt using @a") + //require.True(t, plannercore.ErrWrongArguments.Equal(err)) +} From 68546d58dc67b9f3578924208e7671619e7e3b7f Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 9 Jan 2023 23:44:20 +0800 Subject: [PATCH 23/25] test --- executor/seqtest/prepared_test.go | 9 +++++++ planner/core/plan_cache_test.go | 42 +++++++++++++++---------------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/executor/seqtest/prepared_test.go b/executor/seqtest/prepared_test.go index 376e517754133..e06a5f77e8275 100644 --- a/executor/seqtest/prepared_test.go +++ b/executor/seqtest/prepared_test.go @@ -767,3 +767,12 @@ func TestPreparedIssue17419(t *testing.T) { // _, ok := tk1.Session().ShowProcess().Plan.(*plannercore.Execute) // 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 st from 'select 1 limit ?'") +} diff --git a/planner/core/plan_cache_test.go b/planner/core/plan_cache_test.go index ec49d3381158e..dcceb900bc2f3 100644 --- a/planner/core/plan_cache_test.go +++ b/planner/core/plan_cache_test.go @@ -459,24 +459,24 @@ func TestUncacheableReason(t *testing.T) { tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: query has 'limit ?' is un-cacheable")) } -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 st from 'select 1 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") - //_, err := tk.Exec("execute stmt using @a") - //require.True(t, plannercore.ErrWrongArguments.Equal(err)) -} +//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 st from 'select 1 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") +//_, err := tk.Exec("execute stmt using @a") +//require.True(t, plannercore.ErrWrongArguments.Equal(err)) +//} From d269e8c2446cb913dd154e05abe3109e9a99f16f Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Mon, 9 Jan 2023 23:55:07 +0800 Subject: [PATCH 24/25] Update prepared_test.go --- executor/seqtest/prepared_test.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/executor/seqtest/prepared_test.go b/executor/seqtest/prepared_test.go index e06a5f77e8275..609092ca6b928 100644 --- a/executor/seqtest/prepared_test.go +++ b/executor/seqtest/prepared_test.go @@ -772,7 +772,18 @@ 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 st from 'select 1 limit ?'") + 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") } From d556fc81f6618c283e7014666d4a5afce3d7e406 Mon Sep 17 00:00:00 2001 From: fzzf678 <108643977+fzzf678@users.noreply.github.com> Date: Tue, 10 Jan 2023 00:04:01 +0800 Subject: [PATCH 25/25] WhyThisWorks --- executor/seqtest/prepared_test.go | 14 +++++++------- planner/core/plan_cache_test.go | 22 ---------------------- 2 files changed, 7 insertions(+), 29 deletions(-) diff --git a/executor/seqtest/prepared_test.go b/executor/seqtest/prepared_test.go index 609092ca6b928..77d75551530c7 100644 --- a/executor/seqtest/prepared_test.go +++ b/executor/seqtest/prepared_test.go @@ -279,13 +279,13 @@ func TestPreparedLimitOffset(t *testing.T) { r := tk.MustQuery(`execute stmt_test_1 using @a, @b;`) r.Check(testkit.Rows("2")) - //tk.MustExec(`set @a=1.1`) - //_, err := tk.Exec(`execute stmt_test_1 using @a, @b;`) - //require.True(t, plannercore.ErrWrongArguments.Equal(err)) - // - //tk.MustExec(`set @c="-1"`) - //_, err = tk.Exec("execute stmt_test_1 using @c, @c") - //require.True(t, plannercore.ErrWrongArguments.Equal(err)) + tk.MustExec(`set @a=1.1`) + _, err := tk.Exec(`execute stmt_test_1 using @a, @b;`) + require.True(t, plannercore.ErrWrongArguments.Equal(err)) + + tk.MustExec(`set @c="-1"`) + _, err = tk.Exec("execute stmt_test_1 using @c, @c") + require.True(t, plannercore.ErrWrongArguments.Equal(err)) stmtID, _, _, err := tk.Session().PrepareStmt("select id from prepare_test limit ?") require.NoError(t, err) diff --git a/planner/core/plan_cache_test.go b/planner/core/plan_cache_test.go index dcceb900bc2f3..d7d47e55bc62e 100644 --- a/planner/core/plan_cache_test.go +++ b/planner/core/plan_cache_test.go @@ -458,25 +458,3 @@ func TestUncacheableReason(t *testing.T) { // show the corresponding un-cacheable reason at execute-stage as well tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 skip plan-cache: query has 'limit ?' is un-cacheable")) } - -//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 st from 'select 1 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") -//_, err := tk.Exec("execute stmt using @a") -//require.True(t, plannercore.ErrWrongArguments.Equal(err)) -//}