From aba09b9d2a3b24ba6e6f3effa2bd44839bc19971 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Tue, 20 Feb 2024 21:03:35 +0800 Subject: [PATCH] planner: return an error when using prepared protocol with select-into statement (#49357) (#49365) close pingcap/tidb#49166 --- pkg/planner/core/plan_cache_utils.go | 6 +++++- pkg/planner/core/plan_cacheable_checker_test.go | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/planner/core/plan_cache_utils.go b/pkg/planner/core/plan_cache_utils.go index b3c5bbcded942..7fa772016880f 100644 --- a/pkg/planner/core/plan_cache_utils.go +++ b/pkg/planner/core/plan_cache_utils.go @@ -90,9 +90,13 @@ func GeneratePlanCacheStmtWithAST(ctx context.Context, sctx sessionctx.Context, return nil, nil, 0, ErrPrepareDDL } - switch paramStmt.(type) { + switch stmt := paramStmt.(type) { case *ast.ImportIntoStmt, *ast.LoadDataStmt, *ast.PrepareStmt, *ast.ExecuteStmt, *ast.DeallocateStmt, *ast.NonTransactionalDMLStmt: return nil, nil, 0, ErrUnsupportedPs + case *ast.SelectStmt: + if stmt.SelectIntoOpt != nil { + return nil, nil, 0, ErrUnsupportedPs + } } // Prepare parameters should NOT over 2 bytes(MaxUint16) diff --git a/pkg/planner/core/plan_cacheable_checker_test.go b/pkg/planner/core/plan_cacheable_checker_test.go index 533b8d1fc8334..62fc3578b7899 100644 --- a/pkg/planner/core/plan_cacheable_checker_test.go +++ b/pkg/planner/core/plan_cacheable_checker_test.go @@ -348,6 +348,14 @@ func TestCacheable(t *testing.T) { require.True(t, core.Cacheable(stmt, is)) } +func TestIssue49166(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec(`create table t (c int)`) + tk.MustContainErrMsg(`prepare stmt from "select c from t limit 1 into outfile 'text'"`, "This command is not supported in the prepared statement protocol yet") +} + func TestNonPreparedPlanCacheable(t *testing.T) { store := testkit.CreateMockStore(t)