Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
GuptaManan100 committed Feb 21, 2025
1 parent c558b3f commit deb7922
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
14 changes: 9 additions & 5 deletions go/vt/vtgate/planbuilder/operators/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,23 @@ func breakValuesJoinExpressionInLHS(ctx *plancontext.PlanningContext,
expr sqlparser.Expr,
lhs semantics.TableSet,
) (result valuesJoinColumn) {
result.Original = expr
result.Original = sqlparser.Clone(expr)
result.PureLHS = true
_ = sqlparser.Walk(func(node sqlparser.SQLNode) (kontinue bool, err error) {
result.RHS = expr
_ = sqlparser.Rewrite(expr, func(cursor *sqlparser.Cursor) bool {
node := cursor.Node()
col, ok := node.(*sqlparser.ColName)
if !ok {
return true, nil
return true
}
if ctx.SemTable.RecursiveDeps(col) == lhs {
result.LHS = append(result.LHS, col)
// TODO: Fine all the LHS columns, and
// rewrite the expression to use the value join name and the column.
} else {
result.PureLHS = false
}
return true, nil
}, expr)
return true
}, nil)
return
}
37 changes: 18 additions & 19 deletions go/vt/vtgate/planbuilder/operators/op_to_ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package operators

import (
"fmt"
"strings"

"vitess.io/vitess/go/slice"
"vitess.io/vitess/go/vt/sqlparser"
Expand Down Expand Up @@ -156,28 +155,28 @@ func buildValues(op *Values, qb *queryBuilder) {
apa = apa.Merge(qb.ctx.SemTable.RecursiveDeps(ae.Expr))
}

tableName := getTableName(qb.ctx, apa)
tableName := op.Name

qb.addTableExpr(tableName, tableName, TableID(op), expr, nil, op.getColumnNamesFromCtx(qb.ctx))
}

func getTableName(ctx *plancontext.PlanningContext, id semantics.TableSet) string {
var names []string
for _, ts := range id.Constituents() {
ti, err := ctx.SemTable.TableInfoFor(ts)
if err != nil {
names = append(names, "X")
continue
}
name, err := ti.Name()
if err != nil {
names = append(names, "X")
continue
}
names = append(names, name.Name.String())
}
return strings.Join(names, "_")
}
//func getTableName(ctx *plancontext.PlanningContext, id semantics.TableSet) string {
// var names []string
// for _, ts := range id.Constituents() {
// ti, err := ctx.SemTable.TableInfoFor(ts)
// if err != nil {
// names = append(names, "X")
// continue
// }
// name, err := ti.Name()
// if err != nil {
// names = append(names, "X")
// continue
// }
// names = append(names, name.Name.String())
// }
// return strings.Join(names, "_")
//}

func buildDelete(op *Delete, qb *queryBuilder) {
qb.stmt = &sqlparser.Delete{
Expand Down
1 change: 1 addition & 0 deletions go/vt/vtgate/planbuilder/operators/values_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type (

valuesJoinColumn struct {
Original sqlparser.Expr
RHS sqlparser.Expr
LHS []sqlparser.Expr
PureLHS bool
}
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 deb7922

Please sign in to comment.