Skip to content

Commit

Permalink
refactor: avoid scary global state
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <andres@planetscale.com>
  • Loading branch information
systay committed May 16, 2024
1 parent 490bfa7 commit 76e47cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 0 additions & 2 deletions go/vt/vtgate/planbuilder/operators/apply_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ func (aj *ApplyJoin) AddJoinPredicate(ctx *plancontext.PlanningContext, expr sql
col := breakExpressionInLHSandRHSForApplyJoin(ctx, pred, TableID(aj.LHS))
aj.JoinPredicates.add(col)
ctx.AddJoinPredicates(pred, col.RHSExpr)
ctx.JoinPredInProgress = pred
rhs = rhs.AddPredicate(ctx, col.RHSExpr)
ctx.JoinPredInProgress = nil
}
aj.RHS = rhs
}
Expand Down
11 changes: 6 additions & 5 deletions go/vt/vtgate/planbuilder/plancontext/planning_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ type PlanningContext struct {
SemTable *semantics.SemTable
VSchema VSchema

// JoinPredInProgress is used to track the current join predicate being processed.
JoinPredInProgress sqlparser.Expr

// joinPredicates maps each original join predicate (key) to a slice of
// variations of the RHS predicates (value). This map is used to handle
// different scenarios in join planning, where the RHS predicates are
Expand Down Expand Up @@ -194,8 +191,12 @@ func (ctx *PlanningContext) execOnJoinPredicateEqual(joinPred sqlparser.Expr, fn

func (ctx *PlanningContext) RewriteDerivedTableExpression(expr sqlparser.Expr, tableInfo semantics.TableInfo) sqlparser.Expr {
modifiedExpr := semantics.RewriteDerivedTableExpression(expr, tableInfo)
if ctx.JoinPredInProgress != nil {
ctx.AddJoinPredicates(ctx.JoinPredInProgress, modifiedExpr)
for key, expr := range ctx.joinPredicates {
for _, rhsExpr := range expr {
if ctx.SemTable.EqualsExpr(rhsExpr, rhsExpr) {
ctx.joinPredicates[key] = append(ctx.joinPredicates[key], modifiedExpr)
}
}
}
return modifiedExpr
}

0 comments on commit 76e47cc

Please sign in to comment.