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)