Skip to content

Commit 131a097

Browse files
committed
sql: make getPlanDistribution a method on planner
This will simplify the following commit a bit. Release note: None
1 parent 13b301a commit 131a097

File tree

7 files changed

+12
-38
lines changed

7 files changed

+12
-38
lines changed

pkg/sql/apply_join.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,7 @@ func runPlanInsidePlan(
315315
}
316316
}
317317

318-
distributePlan, distSQLProhibitedErr := getPlanDistribution(
319-
ctx, plannerCopy.Descriptors().HasUncommittedTypes(),
320-
plannerCopy.SessionData(), plan.main, &plannerCopy.distSQLVisitor,
321-
)
318+
distributePlan, distSQLProhibitedErr := plannerCopy.getPlanDistribution(ctx, plan.main)
322319
distributeType := DistributionType(LocalDistribution)
323320
if distributePlan.WillDistribute() {
324321
distributeType = FullDistribution

pkg/sql/conn_executor_exec.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,10 +3028,7 @@ func (ex *connExecutor) dispatchToExecutionEngine(
30283028
}
30293029
}
30303030
}
3031-
distributePlan, distSQLProhibitedErr := getPlanDistribution(
3032-
ctx, planner.Descriptors().HasUncommittedTypes(),
3033-
ex.sessionData(), planner.curPlan.main, &planner.distSQLVisitor,
3034-
)
3031+
distributePlan, distSQLProhibitedErr := planner.getPlanDistribution(ctx, planner.curPlan.main)
30353032
if afterGetPlanDistribution != nil {
30363033
afterGetPlanDistribution()
30373034
}

pkg/sql/distsql_running.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,10 +1896,7 @@ func (dsp *DistSQLPlanner) planAndRunSubquery(
18961896
skipDistSQLDiagramGeneration bool,
18971897
mustUseLeafTxn bool,
18981898
) error {
1899-
subqueryDistribution, distSQLProhibitedErr := getPlanDistribution(
1900-
ctx, planner.Descriptors().HasUncommittedTypes(),
1901-
planner.SessionData(), subqueryPlan.plan, &planner.distSQLVisitor,
1902-
)
1899+
subqueryDistribution, distSQLProhibitedErr := planner.getPlanDistribution(ctx, subqueryPlan.plan)
19031900
distribute := DistributionType(LocalDistribution)
19041901
if subqueryDistribution.WillDistribute() {
19051902
distribute = FullDistribution
@@ -2507,10 +2504,7 @@ func (dsp *DistSQLPlanner) planAndRunPostquery(
25072504
associateNodeWithComponents func(exec.Node, execComponents),
25082505
addTopLevelQueryStats func(stats *topLevelQueryStats),
25092506
) error {
2510-
postqueryDistribution, distSQLProhibitedErr := getPlanDistribution(
2511-
ctx, planner.Descriptors().HasUncommittedTypes(),
2512-
planner.SessionData(), postqueryPlan, &planner.distSQLVisitor,
2513-
)
2507+
postqueryDistribution, distSQLProhibitedErr := planner.getPlanDistribution(ctx, postqueryPlan)
25142508
distribute := DistributionType(LocalDistribution)
25152509
if postqueryDistribution.WillDistribute() {
25162510
distribute = FullDistribution

pkg/sql/exec_util.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,12 +2079,8 @@ func shouldDistributeGivenRecAndMode(
20792079
// remote node to the gateway.
20802080
// TODO(yuzefovich): this will be easy to solve once the DistSQL spec factory is
20812081
// completed but is quite annoying to do at the moment.
2082-
func getPlanDistribution(
2083-
ctx context.Context,
2084-
txnHasUncommittedTypes bool,
2085-
sd *sessiondata.SessionData,
2086-
plan planMaybePhysical,
2087-
distSQLVisitor *distSQLExprCheckVisitor,
2082+
func (p *planner) getPlanDistribution(
2083+
ctx context.Context, plan planMaybePhysical,
20882084
) (_ physicalplan.PlanDistribution, distSQLProhibitedErr error) {
20892085
if plan.isPhysicalPlan() {
20902086
// TODO(#47473): store the distSQLProhibitedErr for DistSQL spec factory
@@ -2095,10 +2091,11 @@ func getPlanDistribution(
20952091
// If this transaction has modified or created any types, it is not safe to
20962092
// distribute due to limitations around leasing descriptors modified in the
20972093
// current transaction.
2098-
if txnHasUncommittedTypes {
2094+
if p.Descriptors().HasUncommittedDescriptors() {
20992095
return physicalplan.LocalPlan, nil
21002096
}
21012097

2098+
sd := p.SessionData()
21022099
if sd.DistSQLMode == sessiondatapb.DistSQLOff {
21032100
return physicalplan.LocalPlan, nil
21042101
}
@@ -2108,7 +2105,7 @@ func getPlanDistribution(
21082105
return physicalplan.LocalPlan, nil
21092106
}
21102107

2111-
rec, err := checkSupportForPlanNode(ctx, plan.planNode, distSQLVisitor, sd)
2108+
rec, err := checkSupportForPlanNode(ctx, plan.planNode, &p.distSQLVisitor, sd)
21122109
if err != nil {
21132110
// Don't use distSQL for this request.
21142111
log.VEventf(ctx, 1, "query not supported for distSQL: %s", err)

pkg/sql/explain_plan.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ func (e *explainPlanNode) startExec(params runParams) error {
5858
// Note that we delay adding the annotation about the distribution until
5959
// after the plan is finalized (when the physical plan is successfully
6060
// created).
61-
distribution, _ := getPlanDistribution(
62-
params.ctx, params.p.Descriptors().HasUncommittedTypes(),
63-
params.extendedEvalCtx.SessionData(), plan.main, &params.p.distSQLVisitor,
64-
)
61+
distribution, _ := params.p.getPlanDistribution(params.ctx, plan.main)
6562

6663
outerSubqueries := params.p.curPlan.subqueryPlans
6764
distSQLPlanner := params.extendedEvalCtx.DistSQLPlanner

pkg/sql/explain_vec.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ type explainVecNode struct {
3636
func (n *explainVecNode) startExec(params runParams) error {
3737
n.run.values = make(tree.Datums, 1)
3838
distSQLPlanner := params.extendedEvalCtx.DistSQLPlanner
39-
distribution, _ := getPlanDistribution(
40-
params.ctx, params.p.Descriptors().HasUncommittedTypes(),
41-
params.extendedEvalCtx.SessionData(), n.plan.main, &params.p.distSQLVisitor,
42-
)
39+
distribution, _ := params.p.getPlanDistribution(params.ctx, n.plan.main)
4340
outerSubqueries := params.p.curPlan.subqueryPlans
4441
planCtx := newPlanningCtxForExplainPurposes(distSQLPlanner, params, n.plan.subqueryPlans, distribution)
4542
defer func() {

pkg/sql/schema_changer.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -477,12 +477,7 @@ func (sc *SchemaChanger) backfillQueryIntoTable(
477477
}
478478
}
479479
}
480-
481-
planDistribution, _ := getPlanDistribution(
482-
ctx, localPlanner.Descriptors().HasUncommittedTypes(),
483-
localPlanner.extendedEvalCtx.SessionData(),
484-
localPlanner.curPlan.main, &localPlanner.distSQLVisitor,
485-
)
480+
planDistribution, _ := localPlanner.getPlanDistribution(ctx, localPlanner.curPlan.main)
486481
isLocal := !planDistribution.WillDistribute()
487482
out := execinfrapb.ProcessorCoreUnion{BulkRowWriter: &execinfrapb.BulkRowWriterSpec{
488483
Table: *table.TableDesc(),

0 commit comments

Comments
 (0)