github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/distsql_plan_ctas.go (about) 1 // Copyright 2019 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package sql 12 13 import ( 14 "context" 15 16 "github.com/cockroachdb/cockroach/pkg/kv" 17 "github.com/cockroachdb/cockroach/pkg/sql/execinfrapb" 18 "github.com/cockroachdb/cockroach/pkg/sql/rowexec" 19 "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" 20 "github.com/cockroachdb/errors" 21 ) 22 23 // PlanAndRunCTAS plans and runs the CREATE TABLE AS command. 24 func PlanAndRunCTAS( 25 ctx context.Context, 26 dsp *DistSQLPlanner, 27 planner *planner, 28 txn *kv.Txn, 29 isLocal bool, 30 in planMaybePhysical, 31 out execinfrapb.ProcessorCoreUnion, 32 recv *DistSQLReceiver, 33 ) { 34 planCtx := dsp.NewPlanningCtx(ctx, planner.ExtendedEvalContext(), txn, !isLocal) 35 planCtx.planner = planner 36 planCtx.stmtType = tree.Rows 37 38 physPlan, err := dsp.createPhysPlan(planCtx, in) 39 if err != nil { 40 recv.SetError(errors.Wrapf(err, "constructing distSQL plan")) 41 return 42 } 43 physPlan.AddNoGroupingStage( 44 out, execinfrapb.PostProcessSpec{}, rowexec.CTASPlanResultTypes, execinfrapb.Ordering{}, 45 ) 46 47 // The bulk row writers will emit a binary encoded BulkOpSummary. 48 physPlan.PlanToStreamColMap = []int{0} 49 physPlan.ResultTypes = rowexec.CTASPlanResultTypes 50 51 // Make copy of evalCtx as Run might modify it. 52 evalCtxCopy := planner.ExtendedEvalContextCopy() 53 dsp.FinalizePlan(planCtx, physPlan) 54 dsp.Run(planCtx, txn, physPlan, recv, evalCtxCopy, nil /* finishedSetupFn */)() 55 }