From 2ef3ac9e34b84661cca561aa7ab5e0f3f3b1746c Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Fri, 17 May 2024 19:26:43 +0800 Subject: [PATCH] planner: skip fast-point-get for select-into-outfile statements (#53364) close pingcap/tidb#42093 --- pkg/executor/select_into_test.go | 12 ++++++++++++ pkg/planner/core/point_get_plan.go | 3 +++ 2 files changed, 15 insertions(+) diff --git a/pkg/executor/select_into_test.go b/pkg/executor/select_into_test.go index 0737683fe1b44..0587c13d9711f 100644 --- a/pkg/executor/select_into_test.go +++ b/pkg/executor/select_into_test.go @@ -55,6 +55,18 @@ func TestSelectIntoFileExists(t *testing.T) { require.True(t, strings.Contains(err.Error(), outfile)) } +func TestSelectIntoOutfilePointGet(t *testing.T) { + outfile := randomSelectFilePath("TestSelectIntoOutfilePointGet") + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + + tk.MustExec(`create table t (id int not null, primary key (id) /*T![clustered_index] CLUSTERED */ );`) + tk.MustExec(`insert into t values(1);`) + tk.MustExec(fmt.Sprintf("select * from t where id = 1 into outfile %q", outfile)) + cmpAndRm("1\n", outfile, t) +} + func TestSelectIntoOutfileTypes(t *testing.T) { outfile := randomSelectFilePath("TestSelectIntoOutfileTypes") store := testkit.CreateMockStore(t) diff --git a/pkg/planner/core/point_get_plan.go b/pkg/planner/core/point_get_plan.go index 26c71c3e0a2ef..6218296f08bc1 100644 --- a/pkg/planner/core/point_get_plan.go +++ b/pkg/planner/core/point_get_plan.go @@ -873,6 +873,9 @@ func TryFastPlan(ctx base.PlanContext, node ast.Node) (p base.Plan) { ctx.GetSessionVars().PlanColumnID.Store(0) switch x := node.(type) { case *ast.SelectStmt: + if x.SelectIntoOpt != nil { + return nil + } defer func() { vars := ctx.GetSessionVars() if vars.SelectLimit != math2.MaxUint64 && p != nil {