Skip to content

Commit

Permalink
refactor: use hashColumns instead of the bare slice
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Dec 7, 2023
1 parent c292fe5 commit d1163ec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ func (jc *hashJoinColumns) addLeft(expr sqlparser.Expr) {
})
}

func (jc *hashJoinColumns) add(expr sqlparser.Expr) {
jc.columns = append(jc.columns, hashJoinColumn{
expr: expr,
})
}

func (jc *hashJoinColumns) addRight(expr sqlparser.Expr) {
jc.columns = append(jc.columns, hashJoinColumn{
expr: expr,
Expand Down
19 changes: 10 additions & 9 deletions go/vt/vtgate/planbuilder/operators/hash_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type (
// These columns are the output columns of the hash join. While in operator mode we keep track of complex expression,
// but once we move to the engine primitives, the hash join only passes through column from either left or right.
// anything more complex will be solved by a projection on top of the hash join
columns []hashJoinColumn
columns *hashJoinColumns

// After offset planning

Expand Down Expand Up @@ -82,14 +82,15 @@ func NewHashJoin(lhs, rhs Operator, outerJoin bool) *HashJoin {
LHS: lhs,
RHS: rhs,
LeftJoin: outerJoin,
columns: &hashJoinColumns{},
}
return hj
}

func (hj *HashJoin) Clone(inputs []Operator) Operator {
kopy := *hj
kopy.LHS, kopy.RHS = inputs[0], inputs[1]
kopy.columns = slices.Clone(hj.columns)
kopy.columns = &hashJoinColumns{columns: slices.Clone(hj.columns.columns)}
kopy.LHSKeys = slices.Clone(hj.LHSKeys)
kopy.RHSKeys = slices.Clone(hj.RHSKeys)
return &kopy
Expand All @@ -115,8 +116,8 @@ func (hj *HashJoin) AddColumn(ctx *plancontext.PlanningContext, reuseExisting bo
}
}

hj.columns = append(hj.columns, hashJoinColumn{expr: expr.Expr})
return len(hj.columns) - 1
hj.columns.add(expr.Expr)
return len(hj.columns.columns) - 1
}

func (hj *HashJoin) planOffsets(ctx *plancontext.PlanningContext) Operator {
Expand All @@ -132,7 +133,7 @@ func (hj *HashJoin) planOffsets(ctx *plancontext.PlanningContext) Operator {
}

needsProj := false
eexprs := slice.Map(hj.columns, func(in hashJoinColumn) *ProjExpr {
eexprs := slice.Map(hj.columns.columns, func(in hashJoinColumn) *ProjExpr {
var column *ProjExpr
var pureOffset bool

Expand Down Expand Up @@ -161,7 +162,7 @@ func (hj *HashJoin) planOffsets(ctx *plancontext.PlanningContext) Operator {
}

func (hj *HashJoin) FindCol(ctx *plancontext.PlanningContext, expr sqlparser.Expr, _ bool) int {
for offset, col := range hj.columns {
for offset, col := range hj.columns.columns {
if ctx.SemTable.EqualsExprWithDeps(expr, col.expr) {
return offset
}
Expand All @@ -170,7 +171,7 @@ func (hj *HashJoin) FindCol(ctx *plancontext.PlanningContext, expr sqlparser.Exp
}

func (hj *HashJoin) GetColumns(*plancontext.PlanningContext) []*sqlparser.AliasedExpr {
return slice.Map(hj.columns, func(from hashJoinColumn) *sqlparser.AliasedExpr {
return slice.Map(hj.columns.columns, func(from hashJoinColumn) *sqlparser.AliasedExpr {
return aeWrap(from.expr)
})
}
Expand All @@ -185,8 +186,8 @@ func (hj *HashJoin) ShortDescription() string {
})
cmp := strings.Join(comparisons, " AND ")

if len(hj.columns) > 0 {
cols := slice.Map(hj.columns, func(from hashJoinColumn) (result string) {
if len(hj.columns.columns) > 0 {
cols := slice.Map(hj.columns.columns, func(from hashJoinColumn) (result string) {
switch from.side {
case Unknown:
result = "U"
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/operators/query_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func tryPushProjection(
func pushProjectionThroughHashJoin(p *Projection, hj *HashJoin) (Operator, *ApplyResult) {
cols := p.Columns.GetColumns()
for _, col := range cols {
hj.columns = append(hj.columns, hashJoinColumn{expr: col.Expr})
hj.columns.add(col.Expr)
}
return hj, Rewrote("merged projection into hash join")
}
Expand Down

0 comments on commit d1163ec

Please sign in to comment.