Skip to content

Commit

Permalink
Gen4: moved gen4 select plan to selectGen4 and renamed all code from …
Browse files Browse the repository at this point in the history
…v4 to Gen4

Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Jun 2, 2021
1 parent 4c33b2b commit 2ef2c0f
Show file tree
Hide file tree
Showing 17 changed files with 214 additions and 189 deletions.
6 changes: 3 additions & 3 deletions go/vt/vtgate/planbuilder/concatenate.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ func (c *concatenate) Wireup(plan logicalPlan, jt *jointab) error {
return c.rhs.Wireup(plan, jt)
}

func (c *concatenate) WireupV4(semTable *semantics.SemTable) error {
err := c.lhs.WireupV4(semTable)
func (c *concatenate) WireupGen4(semTable *semantics.SemTable) error {
err := c.lhs.WireupGen4(semTable)
if err != nil {
return err
}
return c.rhs.WireupV4(semTable)
return c.rhs.WireupGen4(semTable)
}

func (c *concatenate) SupplyVar(from, to int, col *sqlparser.ColName, varname string) {
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtgate/planbuilder/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ type subqueryInfo struct {
// origin is chosen as the default.
func (pb *primitiveBuilder) findOrigin(expr sqlparser.Expr, reservedVars *sqlparser.ReservedVars) (pullouts []*pulloutSubquery, origin logicalPlan, pushExpr sqlparser.Expr, err error) {
// highestOrigin tracks the highest origin referenced by the expression.
// Default is the First.
highestOrigin := First(pb.plan)
// Default is the first.
highestOrigin := first(pb.plan)

// subqueries tracks the list of subqueries encountered.
var subqueries []subqueryInfo
Expand Down
6 changes: 3 additions & 3 deletions go/vt/vtgate/planbuilder/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ func (jb *join) Wireup(plan logicalPlan, jt *jointab) error {
}

// Wireup2 implements the logicalPlan interface
func (jb *join) WireupV4(semTable *semantics.SemTable) error {
err := jb.Right.WireupV4(semTable)
func (jb *join) WireupGen4(semTable *semantics.SemTable) error {
err := jb.Right.WireupGen4(semTable)
if err != nil {
return err
}
return jb.Left.WireupV4(semTable)
return jb.Left.WireupGen4(semTable)
}

// SupplyVar implements the logicalPlan interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,63 +22,63 @@ import (
"vitess.io/vitess/go/vt/vtgate/semantics"
)

var _ logicalPlan = (*joinV4)(nil)
var _ logicalPlan = (*joinGen4)(nil)

// joinV4 is used to build a Join primitive.
// It's used to build an inner join and only used by the V4 planner
type joinV4 struct {
// joinGen4 is used to build a Join primitive.
// It's used to build an inner join and only used by the Gen4 planner
type joinGen4 struct {
// Left and Right are the nodes for the join.
Left, Right logicalPlan
Cols []int
Vars map[string]int
}

// Order implements the logicalPlan interface
func (j *joinV4) Order() int {
func (j *joinGen4) Order() int {
panic("implement me")
}

// ResultColumns implements the logicalPlan interface
func (j *joinV4) ResultColumns() []*resultColumn {
func (j *joinGen4) ResultColumns() []*resultColumn {
panic("implement me")
}

// Reorder implements the logicalPlan interface
func (j *joinV4) Reorder(i int) {
func (j *joinGen4) Reorder(i int) {
panic("implement me")
}

// Wireup implements the logicalPlan interface
func (j *joinV4) Wireup(lp logicalPlan, jt *jointab) error {
func (j *joinGen4) Wireup(lp logicalPlan, jt *jointab) error {
panic("implement me")
}

// Wireup2 implements the logicalPlan interface
func (j *joinV4) WireupV4(semTable *semantics.SemTable) error {
err := j.Left.WireupV4(semTable)
func (j *joinGen4) WireupGen4(semTable *semantics.SemTable) error {
err := j.Left.WireupGen4(semTable)
if err != nil {
return err
}
return j.Right.WireupV4(semTable)
return j.Right.WireupGen4(semTable)
}

// SupplyVar implements the logicalPlan interface
func (j *joinV4) SupplyVar(from, to int, col *sqlparser.ColName, varname string) {
func (j *joinGen4) SupplyVar(from, to int, col *sqlparser.ColName, varname string) {
panic("implement me")
}

// SupplyCol implements the logicalPlan interface
func (j *joinV4) SupplyCol(col *sqlparser.ColName) (rc *resultColumn, colNumber int) {
func (j *joinGen4) SupplyCol(col *sqlparser.ColName) (rc *resultColumn, colNumber int) {
panic("implement me")
}

// SupplyWeightString implements the logicalPlan interface
func (j *joinV4) SupplyWeightString(colNumber int) (weightcolNumber int, err error) {
func (j *joinGen4) SupplyWeightString(colNumber int) (weightcolNumber int, err error) {
panic("implement me")
}

// Primitive implements the logicalPlan interface
func (j *joinV4) Primitive() engine.Primitive {
func (j *joinGen4) Primitive() engine.Primitive {
return &engine.Join{
Left: j.Left.Primitive(),
Right: j.Right.Primitive(),
Expand All @@ -88,16 +88,16 @@ func (j *joinV4) Primitive() engine.Primitive {
}

// Inputs implements the logicalPlan interface
func (j *joinV4) Inputs() []logicalPlan {
func (j *joinGen4) Inputs() []logicalPlan {
panic("implement me")
}

// Rewrite implements the logicalPlan interface
func (j *joinV4) Rewrite(inputs ...logicalPlan) error {
func (j *joinGen4) Rewrite(inputs ...logicalPlan) error {
panic("implement me")
}

// Solves implements the logicalPlan interface
func (j *joinV4) ContainsTables() semantics.TableSet {
func (j *joinGen4) ContainsTables() semantics.TableSet {
return j.Left.ContainsTables().Merge(j.Right.ContainsTables())
}
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/jointree_transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func transformJoinPlan(n *joinPlan, semTable *semantics.SemTable) (logicalPlan,
if err != nil {
return nil, err
}
return &joinV4{
return &joinGen4{
Left: lhs,
Right: rhs,
Cols: n.columns,
Expand Down
16 changes: 8 additions & 8 deletions go/vt/vtgate/planbuilder/logical_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ type logicalPlan interface {
// the lhs nodes.
Wireup(lp logicalPlan, jt *jointab) error

// WireupV4 does the wire up work for the V4 planner
WireupV4(semTable *semantics.SemTable) error
// WireupGen4 does the wire up work for the Gen4 planner
WireupGen4(semTable *semantics.SemTable) error

// SupplyVar finds the common root between from and to. If it's
// the common root, it supplies the requested var to the rhs tree.
Expand Down Expand Up @@ -83,7 +83,7 @@ type logicalPlan interface {
Rewrite(inputs ...logicalPlan) error

// ContainsTables keeps track which query tables are being solved by this logical plan
// This is only applicable for plans that have been built with the V4 planner
// This is only applicable for plans that have been built with the Gen4 planner
ContainsTables() semantics.TableSet
}

Expand Down Expand Up @@ -118,14 +118,14 @@ func visit(node logicalPlan, visitor planVisitor) (logicalPlan, error) {
return node, nil
}

// First returns the first logical plan of the tree,
// first returns the first logical plan of the tree,
// which is usually the left most leaf.
func First(input logicalPlan) logicalPlan {
func first(input logicalPlan) logicalPlan {
inputs := input.Inputs()
if len(inputs) == 0 {
return input
}
return First(inputs[0])
return first(inputs[0])
}

//-------------------------------------------------------------------------
Expand Down Expand Up @@ -158,8 +158,8 @@ func (bc *logicalPlanCommon) Wireup(plan logicalPlan, jt *jointab) error {
return bc.input.Wireup(plan, jt)
}

func (bc *logicalPlanCommon) WireupV4(semTable *semantics.SemTable) error {
return bc.input.WireupV4(semTable)
func (bc *logicalPlanCommon) WireupGen4(semTable *semantics.SemTable) error {
return bc.input.WireupGen4(semTable)
}

func (bc *logicalPlanCommon) SupplyVar(from, to int, col *sqlparser.ColName, varname string) {
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtgate/planbuilder/memory_sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ func (ms *memorySort) Wireup(plan logicalPlan, jt *jointab) error {
return ms.input.Wireup(plan, jt)
}

func (ms *memorySort) WireupV4(semTable *semantics.SemTable) error {
return ms.input.WireupV4(semTable)
func (ms *memorySort) WireupGen4(semTable *semantics.SemTable) error {
return ms.input.WireupGen4(semTable)
}
4 changes: 2 additions & 2 deletions go/vt/vtgate/planbuilder/merge_sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ func (ms *mergeSort) Wireup(plan logicalPlan, jt *jointab) error {
return ms.input.Wireup(plan, jt)
}

func (ms *mergeSort) WireupV4(semTable *semantics.SemTable) error {
return ms.input.WireupV4(semTable)
func (ms *mergeSort) WireupGen4(semTable *semantics.SemTable) error {
return ms.input.WireupGen4(semTable)
}
4 changes: 2 additions & 2 deletions go/vt/vtgate/planbuilder/ordered_aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,6 @@ func (oa *orderedAggregate) Wireup(plan logicalPlan, jt *jointab) error {
return oa.input.Wireup(plan, jt)
}

func (oa *orderedAggregate) WireupV4(semTable *semantics.SemTable) error {
return oa.input.WireupV4(semTable)
func (oa *orderedAggregate) WireupGen4(semTable *semantics.SemTable) error {
return oa.input.WireupGen4(semTable)
}
16 changes: 8 additions & 8 deletions go/vt/vtgate/planbuilder/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func escapeNewLines(in string) string {
return strings.ReplaceAll(in, "\n", "\\n")
}

func testFile(t *testing.T, filename, tempDir string, vschema *vschemaWrapper, checkV4equalPlan bool) {
func testFile(t *testing.T, filename, tempDir string, vschema *vschemaWrapper, checkGen4equalPlan bool) {
var checkAllTests = false
t.Run(filename, func(t *testing.T) {
expected := &strings.Builder{}
Expand Down Expand Up @@ -478,14 +478,14 @@ func testFile(t *testing.T, filename, tempDir string, vschema *vschemaWrapper, c
// - it produces a different but accepted plan - this is shown using the accepted plan
// - or it produces a different plan that has not yet been accepted, or it fails to produce a plan
// this is shown by not having any info at all after the result for the V3 planner
// with this last expectation, it is an error if the V4 planner
// with this last expectation, it is an error if the Gen4 planner
// produces the same plan as the V3 planner does
testName := fmt.Sprintf("%d V4: %s", tcase.lineno, tcase.comments)
testName := fmt.Sprintf("%d Gen4: %s", tcase.lineno, tcase.comments)
if !empty || checkAllTests {
t.Run(testName, func(t *testing.T) {
if out != tcase.output2ndPlanner {
fail = true
t.Errorf("V4 - %s:%d\nDiff:\n%s\n[%s] \n[%s]", filename, tcase.lineno, cmp.Diff(tcase.output2ndPlanner, out), tcase.output, out)
t.Errorf("Gen4 - %s:%d\nDiff:\n%s\n[%s] \n[%s]", filename, tcase.lineno, cmp.Diff(tcase.output2ndPlanner, out), tcase.output, out)

}
if err != nil {
Expand All @@ -499,9 +499,9 @@ func testFile(t *testing.T, filename, tempDir string, vschema *vschemaWrapper, c
}
})
} else {
if out == tcase.output && checkV4equalPlan {
if out == tcase.output && checkGen4equalPlan {
t.Run(testName, func(t *testing.T) {
t.Errorf("V4 - %s:%d\nplanner produces same output as V3", filename, tcase.lineno)
t.Errorf("Gen4 - %s:%d\nplanner produces same output as V3", filename, tcase.lineno)
})
}
}
Expand Down Expand Up @@ -658,10 +658,10 @@ func BenchmarkPlanner(b *testing.B) {
b.Run(filename+"-v3", func(b *testing.B) {
benchmarkPlanner(b, V3, testCases, vschema)
})
b.Run(filename+"-v4", func(b *testing.B) {
b.Run(filename+"-gen4", func(b *testing.B) {
benchmarkPlanner(b, Gen4, testCases, vschema)
})
b.Run(filename+"-v4left2right", func(b *testing.B) {
b.Run(filename+"-gen4left2right", func(b *testing.B) {
benchmarkPlanner(b, Gen4Left2Right, testCases, vschema)
})
}
Expand Down
6 changes: 3 additions & 3 deletions go/vt/vtgate/planbuilder/pullout_subquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ func (ps *pulloutSubquery) Wireup(plan logicalPlan, jt *jointab) error {
}

// Wireup2 implements the logicalPlan interface
func (ps *pulloutSubquery) WireupV4(semTable *semantics.SemTable) error {
if err := ps.underlying.WireupV4(semTable); err != nil {
func (ps *pulloutSubquery) WireupGen4(semTable *semantics.SemTable) error {
if err := ps.underlying.WireupGen4(semTable); err != nil {
return err
}
return ps.subquery.WireupV4(semTable)
return ps.subquery.WireupGen4(semTable)
}

// SupplyVar implements the logicalPlan interface
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (rb *route) SetLimit(limit *sqlparser.Limit) {
}

// Wireup2 implements the logicalPlan interface
func (rb *route) WireupV4(semTable *semantics.SemTable) error {
func (rb *route) WireupGen4(semTable *semantics.SemTable) error {
rb.prepareTheAST()

rb.eroute.Query = sqlparser.String(rb.Select)
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/route_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func newBuildSelectPlan(sel *sqlparser.Select, vschema ContextVSchema) (engine.P
return nil, err
}

if err := plan.WireupV4(semTable); err != nil {
if err := plan.WireupGen4(semTable); err != nil {
return nil, err
}
return plan.Primitive(), nil
Expand Down
Loading

0 comments on commit 2ef2c0f

Please sign in to comment.