Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
systay committed Feb 20, 2025
1 parent df126a2 commit e82817a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions go/vt/vtgate/planbuilder/operators/op_to_ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func buildValues(op *Values, qb *queryBuilder) {
apa := semantics.EmptyTableSet()
for _, ae := range qb.ctx.ValuesJoinColumns[op.Name] {
apa = apa.Merge(qb.ctx.SemTable.RecursiveDeps(ae.Expr))
fmt.Printf("%v\n", apa)
}

tableName := getTableName(qb.ctx, apa)
Expand Down
9 changes: 7 additions & 2 deletions go/vt/vtgate/planbuilder/operators/query_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,15 @@ func runPushDownRewriters(ctx *plancontext.PlanningContext, root Operator) Opera

func tryPushValues(ctx *plancontext.PlanningContext, in *Values) (Operator, *ApplyResult) {
switch src := in.Source.(type) {
case *Values:
// we can merge two values operators into one
cols := ctx.ValuesJoinColumns[in.Name]
ctx.ValuesJoinColumns[src.Name] = append(ctx.ValuesJoinColumns[src.Name], cols...)
ctx.ValueJoins[in.Name] = ctx.ValueJoins[src.Name]
return src, Rewrote("merged two values operators")
case *ValuesJoin:
src.LHS = in.Clone([]Operator{src.LHS})
src.RHS = in.Clone([]Operator{src.RHS})
return src, Rewrote("pushed values under value join")
return src, Rewrote("pushed values to the LHS of values join")
case *Filter:
return Swap(in, src, "pushed values under filter")
case *Route:
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtgate/planbuilder/operators/values_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (vj *ValuesJoin) GetOrdering(ctx *plancontext.PlanningContext) []OrderBy {
}

func (vj *ValuesJoin) planOffsets(ctx *plancontext.PlanningContext) Operator {
exprs := ctx.ValuesJoinColumns[vj.ValuesDestination]
exprs := ctx.GetColumns(vj.ValuesDestination)
for _, jc := range vj.JoinColumns {
newExprs := vj.planOffsetsForLHSExprs(ctx, jc.LHS)
exprs = append(exprs, newExprs...)
Expand All @@ -172,7 +172,7 @@ func (vj *ValuesJoin) planOffsets(ctx *plancontext.PlanningContext) Operator {
newExprs := vj.planOffsetsForLHSExprs(ctx, jc.LHS)
exprs = append(exprs, newExprs...)
}
ctx.ValuesJoinColumns[vj.ValuesDestination] = exprs
ctx.SetColumns(vj.ValuesDestination, exprs)
return vj
}

Expand Down
9 changes: 9 additions & 0 deletions go/vt/vtgate/planbuilder/plancontext/planning_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,15 @@ func (ctx *PlanningContext) ActiveCTE() *ContextCTE {
return ctx.CurrentCTE[len(ctx.CurrentCTE)-1]
}

func (ctx *PlanningContext) GetColumns(joinName string) []*sqlparser.AliasedExpr {
valuesName := ctx.ValueJoins[joinName]
return ctx.ValuesJoinColumns[valuesName]
}
func (ctx *PlanningContext) SetColumns(joinName string, cols []*sqlparser.AliasedExpr) {
valuesName := ctx.ValueJoins[joinName]
ctx.ValuesJoinColumns[valuesName] = cols
}

func (ctx *PlanningContext) UseMirror() *PlanningContext {
if ctx.isMirrored {
panic(vterrors.VT13001("cannot mirror already mirrored planning context"))
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/testdata/onecase.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"comment": "Add your test case here for debugging and run go test -run=One.",
"query": "",
"query": "select /*vt+ ALLOW_VALUES_JOIN */ user.foo, user_extra.user_id, user_metadata.name from user, user_extra, user_metadata where user.id = user_extra.toto and user_extra.age = user_metadata.age",
"plan": {
}
}
Expand Down

0 comments on commit e82817a

Please sign in to comment.