Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operator planner refactor #13294

Merged
merged 18 commits into from
Jun 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove unused debug method
Signed-off-by: Andres Taylor <andres@planetscale.com>
systay committed Jun 10, 2023
commit d8f69f04da5b3b4996314e6bd2bc74a9703fa9bd
6 changes: 0 additions & 6 deletions go/vt/vtgate/planbuilder/operators/aggregator.go
Original file line number Diff line number Diff line change
@@ -163,12 +163,6 @@ func (a *Aggregator) GetColumns() (columns []*sqlparser.AliasedExpr, err error)
return a.Columns, nil
}

func (a *Aggregator) Description() ops.OpDescription {
return ops.OpDescription{
OperatorType: "Aggregator",
}
}

func (a *Aggregator) ShortDescription() string {
columnns := slices2.Map(a.Columns, func(from *sqlparser.AliasedExpr) string {
return sqlparser.String(from)
15 changes: 0 additions & 15 deletions go/vt/vtgate/planbuilder/operators/apply_join.go
Original file line number Diff line number Diff line change
@@ -287,21 +287,6 @@ func (a *ApplyJoin) addOffset(offset int) {
a.Columns = append(a.Columns, offset)
}

func (a *ApplyJoin) Description() ops.OpDescription {
other := map[string]any{}
if len(a.Columns) > 0 {
other["OutputColumns"] = a.Columns
}
if a.Predicate != nil {
other["Predicate"] = sqlparser.String(a.Predicate)
}
return ops.OpDescription{
OperatorType: "Join",
Variant: "Apply",
Other: other,
}
}

func (a *ApplyJoin) ShortDescription() string {
pred := sqlparser.String(a.Predicate)
columns := slices2.Map(a.ColumnsAST, func(from JoinColumn) string {
14 changes: 0 additions & 14 deletions go/vt/vtgate/planbuilder/operators/correlated_subquery.go
Original file line number Diff line number Diff line change
@@ -70,13 +70,6 @@ func (s *SubQueryOp) SetInputs(ops []ops.Operator) {
s.Outer, s.Inner = ops[0], ops[1]
}

func (s *SubQueryOp) Description() ops.OpDescription {
return ops.OpDescription{
OperatorType: "SubQuery",
Variant: "Apply",
}
}

func (s *SubQueryOp) ShortDescription() string {
return ""
}
@@ -114,13 +107,6 @@ func (c *CorrelatedSubQueryOp) SetInputs(ops []ops.Operator) {
c.Outer, c.Inner = ops[0], ops[1]
}

func (c *CorrelatedSubQueryOp) Description() ops.OpDescription {
return ops.OpDescription{
OperatorType: "SubQuery",
Variant: "Correlated",
}
}

func (c *CorrelatedSubQueryOp) ShortDescription() string {
return ""
}
6 changes: 0 additions & 6 deletions go/vt/vtgate/planbuilder/operators/delete.go
Original file line number Diff line number Diff line change
@@ -62,12 +62,6 @@ func (d *Delete) GetOrdering() ([]ops.OrderBy, error) {
return nil, nil
}

func (d *Delete) Description() ops.OpDescription {
return ops.OpDescription{
OperatorType: "Delete",
}
}

func (d *Delete) ShortDescription() string {
return fmt.Sprintf("%s.%s %s", d.VTable.Keyspace.Name, d.VTable.Name.String(), sqlparser.String(d.AST.Where))
}
6 changes: 0 additions & 6 deletions go/vt/vtgate/planbuilder/operators/derived.go
Original file line number Diff line number Diff line change
@@ -257,12 +257,6 @@ func (d *Derived) setQP(qp *QueryProjection) {
d.QP = qp
}

func (d *Derived) Description() ops.OpDescription {
return ops.OpDescription{
OperatorType: "Derived",
}
}

func (d *Derived) ShortDescription() string {
return d.Alias
}
6 changes: 0 additions & 6 deletions go/vt/vtgate/planbuilder/operators/distinct.go
Original file line number Diff line number Diff line change
@@ -112,12 +112,6 @@ func (d *Distinct) GetColumns() ([]*sqlparser.AliasedExpr, error) {
return d.Source.GetColumns()
}

func (d *Distinct) Description() ops.OpDescription {
return ops.OpDescription{
OperatorType: "Distinct",
}
}

func (d *Distinct) ShortDescription() string {
return ""
}
9 changes: 0 additions & 9 deletions go/vt/vtgate/planbuilder/operators/filter.go
Original file line number Diff line number Diff line change
@@ -137,15 +137,6 @@ func (f *Filter) planOffsets(ctx *plancontext.PlanningContext) error {
return nil
}

func (f *Filter) Description() ops.OpDescription {
return ops.OpDescription{
OperatorType: "Filter",
Other: map[string]any{
"Predicate": sqlparser.String(sqlparser.AndExpressions(f.Predicates...)),
},
}
}

func (f *Filter) ShortDescription() string {
return sqlparser.String(sqlparser.AndExpressions(f.Predicates...))
}
6 changes: 0 additions & 6 deletions go/vt/vtgate/planbuilder/operators/horizon.go
Original file line number Diff line number Diff line change
@@ -109,12 +109,6 @@ func (h *Horizon) setQP(qp *QueryProjection) {
h.QP = qp
}

func (h *Horizon) Description() ops.OpDescription {
return ops.OpDescription{
OperatorType: "Horizon",
}
}

func (h *Horizon) ShortDescription() string {
return ""
}
6 changes: 0 additions & 6 deletions go/vt/vtgate/planbuilder/operators/insert.go
Original file line number Diff line number Diff line change
@@ -86,12 +86,6 @@ type Generate struct {
added bool
}

func (i *Insert) Description() ops.OpDescription {
return ops.OpDescription{
OperatorType: "Insert",
}
}

func (i *Insert) ShortDescription() string {
return i.VTable.String()
}
9 changes: 0 additions & 9 deletions go/vt/vtgate/planbuilder/operators/join.go
Original file line number Diff line number Diff line change
@@ -159,15 +159,6 @@ func (j *Join) AddJoinPredicate(ctx *plancontext.PlanningContext, expr sqlparser
return nil
}

func (j *Join) Description() ops.OpDescription {
return ops.OpDescription{
OperatorType: "Join",
Other: map[string]any{
"Predicate": sqlparser.String(j.Predicate),
},
}
}

func (j *Join) ShortDescription() string {
return sqlparser.String(j.Predicate)
}
14 changes: 0 additions & 14 deletions go/vt/vtgate/planbuilder/operators/limit.go
Original file line number Diff line number Diff line change
@@ -73,20 +73,6 @@ func (l *Limit) GetOrdering() ([]ops.OrderBy, error) {
return l.Source.GetOrdering()
}

func (l *Limit) Description() ops.OpDescription {
other := map[string]any{}
if l.AST.Offset != nil {
other["Offset"] = sqlparser.String(l.AST.Offset)
}
if l.AST.Rowcount != nil {
other["RowCount"] = sqlparser.String(l.AST.Rowcount)
}
return ops.OpDescription{
OperatorType: "Limit",
Other: other,
}
}

func (l *Limit) ShortDescription() string {
return sqlparser.String(l.AST)
}
10 changes: 0 additions & 10 deletions go/vt/vtgate/planbuilder/operators/ops/op.go
Original file line number Diff line number Diff line change
@@ -49,7 +49,6 @@ type (

GetColumns() ([]*sqlparser.AliasedExpr, error)

Description() OpDescription
ShortDescription() string

GetOrdering() ([]OrderBy, error)
@@ -62,13 +61,4 @@ type (
// See GroupBy#SimplifiedExpr for more details about this
SimplifiedExpr sqlparser.Expr
}

OpDescription struct {
OperatorType string
Variant string `json:",omitempty"`
Other map[string]any `json:",omitempty"`

// This field will be filled in by the JSON producer. No need to set it manually
Inputs []OpDescription `json:",omitempty"`
}
)
20 changes: 1 addition & 19 deletions go/vt/vtgate/planbuilder/operators/ops/to_json.go
Original file line number Diff line number Diff line change
@@ -17,31 +17,13 @@ limitations under the License.
package ops

import (
"encoding/json"
"fmt"
"reflect"

"github.com/xlab/treeprint"
)

// ToJSON is a debug only function. It can panic, so do not use this in production code
func ToJSON(op Operator) string {
descr := buildDescriptionTree(op)
out, err := json.MarshalIndent(descr, "", " ")
if err != nil {
panic(err)
}
return string(out)
}

func buildDescriptionTree(op Operator) OpDescription {
descr := op.Description()
for _, in := range op.Inputs() {
descr.Inputs = append(descr.Inputs, buildDescriptionTree(in))
}
return descr
}

// ToTree returns the operator as ascii tree. Should only be used for debugging
func ToTree(op Operator) string {
tree := asTree(op, nil)
return tree.String()
7 changes: 0 additions & 7 deletions go/vt/vtgate/planbuilder/operators/ordering.go
Original file line number Diff line number Diff line change
@@ -105,13 +105,6 @@ func (o *Ordering) planOffsets(ctx *plancontext.PlanningContext) error {
return nil
}

func (o *Ordering) Description() ops.OpDescription {
return ops.OpDescription{
OperatorType: "Ordering",
Other: map[string]any{},
}
}

func (o *Ordering) ShortDescription() string {
ordering := slices2.Map(o.Order, func(o ops.OrderBy) string {
return sqlparser.String(o.Inner)
24 changes: 0 additions & 24 deletions go/vt/vtgate/planbuilder/operators/projection.go
Original file line number Diff line number Diff line change
@@ -164,30 +164,6 @@ func (p *Projection) AllOffsets() (cols []int) {
return
}

func (p *Projection) Description() ops.OpDescription {
var columns []string
for i, col := range p.Projections {
aliasExpr := p.Columns[i]
if aliasExpr.Expr == col.GetExpr() {
columns = append(columns, sqlparser.String(aliasExpr))
} else {
columns = append(columns, fmt.Sprintf("%s AS %s", sqlparser.String(col.GetExpr()), aliasExpr.ColumnName()))
}
}

other := map[string]any{
"OutputColumns": strings.Join(columns, ", "),
}
if p.TableID != nil {
other["Derived"] = true
other["Alias"] = p.Alias
}
return ops.OpDescription{
OperatorType: "Projection",
Other: other,
}
}

func (p *Projection) ShortDescription() string {
var columns []string
if p.Alias != "" {
7 changes: 0 additions & 7 deletions go/vt/vtgate/planbuilder/operators/querygraph.go
Original file line number Diff line number Diff line change
@@ -222,13 +222,6 @@ func (qt *QueryTable) Clone() *QueryTable {
}
}

func (qg *QueryGraph) Description() ops.OpDescription {
return ops.OpDescription{
OperatorType: "QueryGraph",
Other: map[string]any{"Tables": qg.tableNames()},
}
}

func (qg *QueryGraph) tableNames() (tables []string) {
for _, table := range qg.Tables {
tables = append(tables, sqlparser.String(table.Table))
10 changes: 0 additions & 10 deletions go/vt/vtgate/planbuilder/operators/route.go
Original file line number Diff line number Diff line change
@@ -699,16 +699,6 @@ func (r *Route) getOffsetFor(ctx *plancontext.PlanningContext, order ops.OrderBy
return offset, nil
}

func (r *Route) Description() ops.OpDescription {
return ops.OpDescription{
OperatorType: "Route",
Other: map[string]any{
"OpCode": r.Routing.OpCode(),
"Keyspace": r.Routing.Keyspace(),
},
}
}

func (r *Route) ShortDescription() string {
first := r.Routing.OpCode().String()

12 changes: 0 additions & 12 deletions go/vt/vtgate/planbuilder/operators/subquery.go
Original file line number Diff line number Diff line change
@@ -127,18 +127,6 @@ func createSubqueryFromStatement(ctx *plancontext.PlanningContext, stmt sqlparse
return subq, nil
}

func (s *SubQuery) Description() ops.OpDescription {
return ops.OpDescription{
OperatorType: "SubQuery",
}
}

func (s *SubQueryInner) Description() ops.OpDescription {
return ops.OpDescription{
OperatorType: "SubQueryInner",
}
}

func (s *SubQuery) ShortDescription() string {
return ""
}
11 changes: 0 additions & 11 deletions go/vt/vtgate/planbuilder/operators/table.go
Original file line number Diff line number Diff line change
@@ -113,17 +113,6 @@ func addColumn(ctx *plancontext.PlanningContext, op ColNameColumns, e sqlparser.
return offset, nil
}

func (to *Table) Description() ops.OpDescription {
var columns []string
for _, col := range to.Columns {
columns = append(columns, sqlparser.String(col))
}
return ops.OpDescription{
OperatorType: "Table",
Other: map[string]any{"Columns": columns},
}
}

func (to *Table) ShortDescription() string {
return to.VTable.String()
}
6 changes: 0 additions & 6 deletions go/vt/vtgate/planbuilder/operators/union.go
Original file line number Diff line number Diff line change
@@ -190,12 +190,6 @@ func (u *Union) Compact(*plancontext.PlanningContext) (ops.Operator, *rewrite.Ap

func (u *Union) NoLHSTableSet() {}

func (u *Union) Description() ops.OpDescription {
return ops.OpDescription{
OperatorType: "Union",
}
}

func (u *Union) ShortDescription() string {
return ""
}
6 changes: 0 additions & 6 deletions go/vt/vtgate/planbuilder/operators/update.go
Original file line number Diff line number Diff line change
@@ -65,12 +65,6 @@ func (u *Update) TablesUsed() []string {
return nil
}

func (u *Update) Description() ops.OpDescription {
return ops.OpDescription{
OperatorType: "Update",
}
}

func (u *Update) ShortDescription() string {
return u.VTable.String()
}
4 changes: 0 additions & 4 deletions go/vt/vtgate/planbuilder/operators/vindex.go
Original file line number Diff line number Diff line change
@@ -154,10 +154,6 @@ func (v *Vindex) TablesUsed() []string {
return []string{v.Table.Table.Name.String()}
}

func (v *Vindex) Description() ops.OpDescription {
return ops.OpDescription{OperatorType: "Vindex"}
}

func (v *Vindex) ShortDescription() string {
return v.Vindex.String()
}