Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
  • Loading branch information
frouioui committed Feb 18, 2025
1 parent 35b65ef commit 73f2520
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
18 changes: 15 additions & 3 deletions go/vt/vtgate/planbuilder/operators/query_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func runRewriters(ctx *plancontext.PlanningContext, root Operator) Operator {
case *RecurseCTE:
return tryMergeRecurse(ctx, in)
case *Values:
return tryPushValues(in)
return tryPushValues(ctx, in)
default:
return in, NoRewrite
}
Expand All @@ -121,8 +121,20 @@ func runRewriters(ctx *plancontext.PlanningContext, root Operator) Operator {
return FixedPointBottomUp(root, TableID, visitor, stopAtRoute)
}

func tryPushValues(in *Values) (Operator, *ApplyResult) {
if src, ok := in.Source.(*Route); ok {
func tryPushValues(ctx *plancontext.PlanningContext, in *Values) (Operator, *ApplyResult) {
switch src := in.Source.(type) {
case *ValuesJoin:
src.LHS = in.Clone([]Operator{src.LHS})
src.RHS = in.Clone([]Operator{src.RHS})
return src, Rewrote("pushed values under value join")
case *Filter:
return Swap(in, src, "pushed values under filter")
// case *Values:
// ctx.ValuesJoinColumns
case *Route:
if !reachedPhase(ctx, initialPlanning) {
return in, NoRewrite
}
return Swap(in, src, "pushed values under route")
}
return in, NoRewrite
Expand Down
4 changes: 4 additions & 0 deletions go/vt/vtgate/planbuilder/operators/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ type Values struct {

func (v *Values) Clone(inputs []Operator) Operator {
clone := *v

if len(inputs) > 0 {
clone.Source = inputs[0]
}
return &clone
}

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": "select /*vt+ ALLOW_VALUES_JOIN */ user.foo, user_extra.user_id from user, user_extra where user.id = user_extra.toto",
"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": {
"QueryType": "SELECT",
"Original": "select user.foo, user_extra.user_id from user, user_extra where user.id = user_extra.toto",
Expand Down

0 comments on commit 73f2520

Please sign in to comment.