Skip to content

Commit

Permalink
sql: replace planDataSource fields in joinNode
Browse files Browse the repository at this point in the history
The `planDataSource` fields of `joinNode` have been replaced by
`planNode` fields.

Release note: None
  • Loading branch information
mgartner committed Dec 20, 2024
1 parent 780aead commit 293bdde
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
8 changes: 4 additions & 4 deletions pkg/sql/distsql_physical_planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,11 +619,11 @@ func checkSupportForPlanNode(
if err := checkExprForDistSQL(n.pred.onCond, distSQLVisitor); err != nil {
return cannotDistribute, err
}
recLeft, err := checkSupportForPlanNode(ctx, n.left.plan, distSQLVisitor, sd)
recLeft, err := checkSupportForPlanNode(ctx, n.left, distSQLVisitor, sd)
if err != nil {
return cannotDistribute, err
}
recRight, err := checkSupportForPlanNode(ctx, n.right.plan, distSQLVisitor, sd)
recRight, err := checkSupportForPlanNode(ctx, n.right, distSQLVisitor, sd)
if err != nil {
return cannotDistribute, err
}
Expand Down Expand Up @@ -3789,11 +3789,11 @@ func getTypesForPlanResult(node planNode, planToStreamColMap []int) ([]*types.T,
func (dsp *DistSQLPlanner) createPlanForJoin(
ctx context.Context, planCtx *PlanningCtx, n *joinNode,
) (*PhysicalPlan, error) {
leftPlan, err := dsp.createPhysPlanForPlanNode(ctx, planCtx, n.left.plan)
leftPlan, err := dsp.createPhysPlanForPlanNode(ctx, planCtx, n.left)
if err != nil {
return nil, err
}
rightPlan, err := dsp.createPhysPlanForPlanNode(ctx, planCtx, n.right.plan)
rightPlan, err := dsp.createPhysPlanForPlanNode(ctx, planCtx, n.right)
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/sql/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
// joinNode is a planNode whose rows are the result of a join operation.
type joinNode struct {
// The data sources.
left planDataSource
right planDataSource
left planNode
right planNode

// pred represents the join predicate.
pred *joinPredicate
Expand All @@ -41,8 +41,8 @@ type joinNode struct {
}

func (p *planner) makeJoinNode(
left planDataSource,
right planDataSource,
left planNode,
right planNode,
pred *joinPredicate,
estimatedLeftRowCount, estimatedRightRowCount uint64,
) *joinNode {
Expand Down Expand Up @@ -73,6 +73,6 @@ func (n *joinNode) Values() tree.Datums {

// Close implements the planNode interface.
func (n *joinNode) Close(ctx context.Context) {
n.right.plan.Close(ctx)
n.left.plan.Close(ctx)
n.right.Close(ctx)
n.left.Close(ctx)
}
28 changes: 16 additions & 12 deletions pkg/sql/opt_exec_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,11 @@ func (ef *execFactory) ConstructHashJoin(
estimatedLeftRowCount, estimatedRightRowCount uint64,
) (exec.Node, error) {
p := ef.planner
leftSrc := asDataSource(left)
rightSrc := asDataSource(right)
pred := makePredicate(joinType, leftSrc.columns, rightSrc.columns, extraOnCond)
leftPlan := left.(planNode)
rightPlan := right.(planNode)
leftCols := planColumns(leftPlan)
rightCols := planColumns(rightPlan)
pred := makePredicate(joinType, leftCols, rightCols, extraOnCond)

numEqCols := len(leftEqCols)
pred.leftEqualityIndices = leftEqCols
Expand All @@ -430,13 +432,13 @@ func (ef *execFactory) ConstructHashJoin(
pred.rightColNames = nameBuf[numEqCols:]

for i := range leftEqCols {
pred.leftColNames[i] = tree.Name(leftSrc.columns[leftEqCols[i]].Name)
pred.rightColNames[i] = tree.Name(rightSrc.columns[rightEqCols[i]].Name)
pred.leftColNames[i] = tree.Name(leftCols[leftEqCols[i]].Name)
pred.rightColNames[i] = tree.Name(rightCols[rightEqCols[i]].Name)
}
pred.leftEqKey = leftEqColsAreKey
pred.rightEqKey = rightEqColsAreKey

return p.makeJoinNode(leftSrc, rightSrc, pred, estimatedLeftRowCount, estimatedRightRowCount), nil
return p.makeJoinNode(leftPlan, rightPlan, pred, estimatedLeftRowCount, estimatedRightRowCount), nil
}

// ConstructApplyJoin is part of the exec.Factory interface.
Expand Down Expand Up @@ -465,10 +467,12 @@ func (ef *execFactory) ConstructMergeJoin(
) (exec.Node, error) {
var err error
p := ef.planner
leftSrc := asDataSource(left)
rightSrc := asDataSource(right)
pred := makePredicate(joinType, leftSrc.columns, rightSrc.columns, onCond)
node := p.makeJoinNode(leftSrc, rightSrc, pred, estimatedLeftRowCount, estimatedRightRowCount)
leftPlan := left.(planNode)
rightPlan := right.(planNode)
leftCols := planColumns(leftPlan)
rightCols := planColumns(rightPlan)
pred := makePredicate(joinType, leftCols, rightCols, onCond)
node := p.makeJoinNode(leftPlan, rightPlan, pred, estimatedLeftRowCount, estimatedRightRowCount)
pred.leftEqKey = leftEqColsAreKey
pred.rightEqKey = rightEqColsAreKey

Expand All @@ -481,8 +485,8 @@ func (ef *execFactory) ConstructMergeJoin(
pred.rightColNames = make(tree.NameList, n)
for i := 0; i < n; i++ {
leftColIdx, rightColIdx := leftOrdering[i].ColIdx, rightOrdering[i].ColIdx
pred.leftColNames[i] = tree.Name(leftSrc.columns[leftColIdx].Name)
pred.rightColNames[i] = tree.Name(rightSrc.columns[rightColIdx].Name)
pred.leftColNames[i] = tree.Name(leftCols[leftColIdx].Name)
pred.rightColNames[i] = tree.Name(rightCols[rightColIdx].Name)
}

// Set up node.props, which tells the distsql planner to maintain the
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ func (v *planVisitor) visitInternal(plan planNode, name string) {
n.input = v.visit(n.input)

case *joinNode:
n.left.plan = v.visit(n.left.plan)
n.right.plan = v.visit(n.right.plan)
n.left = v.visit(n.left)
n.right = v.visit(n.right)

case *invertedFilterNode:
n.input = v.visit(n.input)
Expand Down

0 comments on commit 293bdde

Please sign in to comment.