Skip to content

Commit

Permalink
planner: return an error when using prepared protocol with select-int…
Browse files Browse the repository at this point in the history
…o statement (#49357) (#49365)

close #49166
  • Loading branch information
ti-chi-bot authored Feb 20, 2024
1 parent 75b2e1f commit aba09b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/planner/core/plan_cache_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions pkg/planner/core/plan_cacheable_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit aba09b9

Please sign in to comment.