Skip to content

Commit e1e849d

Browse files
committed
v3: revamp: planBuilder->primitiveBuilder
Signed-off-by: Sugu Sougoumarane <ssougou@gmail.com>
1 parent d60fe25 commit e1e849d

File tree

16 files changed

+52
-52
lines changed

16 files changed

+52
-52
lines changed

go/vt/vtgate/planbuilder/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type builder interface {
5757

5858
// PushFilter pushes a WHERE or HAVING clause expression
5959
// to the specified origin.
60-
PushFilter(pb *planBuilder, filter sqlparser.Expr, whereType string, origin builder) error
60+
PushFilter(pb *primitiveBuilder, filter sqlparser.Expr, whereType string, origin builder) error
6161

6262
// PushSelect pushes the select expression to the specified
6363
// originator. If successful, the originator must create

go/vt/vtgate/planbuilder/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func buildDeletePlan(del *sqlparser.Delete, vschema ContextVSchema) (*engine.Del
3333
edel := &engine.Delete{
3434
Query: generateQuery(del),
3535
}
36-
pb := newPlanBuilder(vschema, newJointab(sqlparser.GetBindvars(del)))
36+
pb := newPrimitiveBuilder(vschema, newJointab(sqlparser.GetBindvars(del)))
3737
if err := pb.processTableExprs(del.TableExprs); err != nil {
3838
return nil, err
3939
}

go/vt/vtgate/planbuilder/expr.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func skipParenthesis(node sqlparser.Expr) sqlparser.Expr {
7979
//
8080
// If an expression has no references to the current query, then the left-most
8181
// origin is chosen as the default.
82-
func (pb *planBuilder) findOrigin(expr sqlparser.Expr) (origin builder, err error) {
82+
func (pb *primitiveBuilder) findOrigin(expr sqlparser.Expr) (origin builder, err error) {
8383
highestOrigin := pb.bldr.First()
8484
var subroutes []*route
8585
err = sqlparser.Walk(func(node sqlparser.SQLNode) (kontinue bool, err error) {
@@ -93,7 +93,7 @@ func (pb *planBuilder) findOrigin(expr sqlparser.Expr) (origin builder, err erro
9393
highestOrigin = newOrigin
9494
}
9595
case *sqlparser.Subquery:
96-
spb := newPlanBuilder(pb.vschema, pb.jt)
96+
spb := newPrimitiveBuilder(pb.vschema, pb.jt)
9797
switch stmt := node.Select.(type) {
9898
case *sqlparser.Select:
9999
if err := spb.processSelect(stmt, pb.st); err != nil {
@@ -158,7 +158,7 @@ func hasSubquery(node sqlparser.SQLNode) bool {
158158
return has
159159
}
160160

161-
func (pb *planBuilder) validateSubquerySamePlan(nodes ...sqlparser.SQLNode) bool {
161+
func (pb *primitiveBuilder) validateSubquerySamePlan(nodes ...sqlparser.SQLNode) bool {
162162
var keyspace string
163163
if rb, ok := pb.bldr.(*route); ok {
164164
keyspace = rb.ERoute.Keyspace.Name
@@ -176,7 +176,7 @@ func (pb *planBuilder) validateSubquerySamePlan(nodes ...sqlparser.SQLNode) bool
176176
if !inSubQuery {
177177
return true, nil
178178
}
179-
spb := newPlanBuilder(pb.vschema, pb.jt)
179+
spb := newPrimitiveBuilder(pb.vschema, pb.jt)
180180
if err := spb.processSelect(nodeType, pb.st); err != nil {
181181
samePlan = false
182182
return false, err
@@ -194,7 +194,7 @@ func (pb *planBuilder) validateSubquerySamePlan(nodes ...sqlparser.SQLNode) bool
194194
if !inSubQuery {
195195
return true, nil
196196
}
197-
spb := newPlanBuilder(pb.vschema, pb.jt)
197+
spb := newPrimitiveBuilder(pb.vschema, pb.jt)
198198
if err := spb.processUnion(nodeType, pb.st); err != nil {
199199
samePlan = false
200200
return false, err

go/vt/vtgate/planbuilder/from.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,23 @@ import (
3030

3131
// processTableExprs analyzes the FROM clause. It produces a builder
3232
// with all the routes identified.
33-
func (pb *planBuilder) processTableExprs(tableExprs sqlparser.TableExprs) error {
33+
func (pb *primitiveBuilder) processTableExprs(tableExprs sqlparser.TableExprs) error {
3434
if len(tableExprs) == 1 {
3535
return pb.processTableExpr(tableExprs[0])
3636
}
3737

3838
if err := pb.processTableExpr(tableExprs[0]); err != nil {
3939
return err
4040
}
41-
rpb := newPlanBuilder(pb.vschema, pb.jt)
41+
rpb := newPrimitiveBuilder(pb.vschema, pb.jt)
4242
if err := rpb.processTableExprs(tableExprs[1:]); err != nil {
4343
return err
4444
}
4545
return pb.join(rpb, nil)
4646
}
4747

4848
// processTableExpr produces a builder subtree for the given TableExpr.
49-
func (pb *planBuilder) processTableExpr(tableExpr sqlparser.TableExpr) error {
49+
func (pb *primitiveBuilder) processTableExpr(tableExpr sqlparser.TableExpr) error {
5050
switch tableExpr := tableExpr.(type) {
5151
case *sqlparser.AliasedTableExpr:
5252
return pb.processAliasedTable(tableExpr)
@@ -73,12 +73,12 @@ func (pb *planBuilder) processTableExpr(tableExpr sqlparser.TableExpr) error {
7373
// versatile than a subquery. If a subquery becomes a route, then any result
7474
// columns that represent underlying vindex columns are also exposed as
7575
// vindex columns.
76-
func (pb *planBuilder) processAliasedTable(tableExpr *sqlparser.AliasedTableExpr) error {
76+
func (pb *primitiveBuilder) processAliasedTable(tableExpr *sqlparser.AliasedTableExpr) error {
7777
switch expr := tableExpr.Expr.(type) {
7878
case sqlparser.TableName:
7979
return pb.buildTablePrimitive(tableExpr, expr)
8080
case *sqlparser.Subquery:
81-
spb := newPlanBuilder(pb.vschema, pb.jt)
81+
spb := newPrimitiveBuilder(pb.vschema, pb.jt)
8282
switch stmt := expr.Select.(type) {
8383
case *sqlparser.Select:
8484
if err := spb.processSelect(stmt, nil); err != nil {
@@ -136,7 +136,7 @@ func (pb *planBuilder) processAliasedTable(tableExpr *sqlparser.AliasedTableExpr
136136
}
137137

138138
// buildTablePrimitive builds a primitive based on the table name.
139-
func (pb *planBuilder) buildTablePrimitive(tableExpr *sqlparser.AliasedTableExpr, tableName sqlparser.TableName) error {
139+
func (pb *primitiveBuilder) buildTablePrimitive(tableExpr *sqlparser.AliasedTableExpr, tableName sqlparser.TableName) error {
140140
alias := tableName
141141
if !tableExpr.As.IsEmpty() {
142142
alias = sqlparser.TableName{Name: tableExpr.As}
@@ -202,7 +202,7 @@ func (pb *planBuilder) buildTablePrimitive(tableExpr *sqlparser.AliasedTableExpr
202202
// processJoin produces a builder subtree for the given Join.
203203
// If the left and right nodes can be part of the same route,
204204
// then it's a route. Otherwise, it's a join.
205-
func (pb *planBuilder) processJoin(ajoin *sqlparser.JoinTableExpr) error {
205+
func (pb *primitiveBuilder) processJoin(ajoin *sqlparser.JoinTableExpr) error {
206206
switch ajoin.Join {
207207
case sqlparser.JoinStr, sqlparser.StraightJoinStr, sqlparser.LeftJoinStr:
208208
case sqlparser.RightJoinStr:
@@ -213,7 +213,7 @@ func (pb *planBuilder) processJoin(ajoin *sqlparser.JoinTableExpr) error {
213213
if err := pb.processTableExpr(ajoin.LeftExpr); err != nil {
214214
return err
215215
}
216-
rpb := newPlanBuilder(pb.vschema, pb.jt)
216+
rpb := newPrimitiveBuilder(pb.vschema, pb.jt)
217217
if err := rpb.processTableExpr(ajoin.RightExpr); err != nil {
218218
return err
219219
}
@@ -234,7 +234,7 @@ func convertToLeftJoin(ajoin *sqlparser.JoinTableExpr) {
234234
ajoin.Join = sqlparser.LeftJoinStr
235235
}
236236

237-
func (pb *planBuilder) join(rpb *planBuilder, ajoin *sqlparser.JoinTableExpr) error {
237+
func (pb *primitiveBuilder) join(rpb *primitiveBuilder, ajoin *sqlparser.JoinTableExpr) error {
238238
if ajoin != nil && ajoin.Condition.Using != nil {
239239
return errors.New("unsupported: join with USING(column_list) clause")
240240
}
@@ -291,7 +291,7 @@ nomerge:
291291
// see if the primitive can be improved. The operation can fail if
292292
// the expression contains a non-pushable subquery. ajoin can be nil
293293
// if the join is on a ',' operator.
294-
func (pb *planBuilder) mergeRoutes(rpb *planBuilder, ajoin *sqlparser.JoinTableExpr) error {
294+
func (pb *primitiveBuilder) mergeRoutes(rpb *primitiveBuilder, ajoin *sqlparser.JoinTableExpr) error {
295295
lRoute := pb.bldr.(*route)
296296
rRoute := rpb.bldr.(*route)
297297
sel := lRoute.Select.(*sqlparser.Select)
@@ -330,7 +330,7 @@ func (pb *planBuilder) mergeRoutes(rpb *planBuilder, ajoin *sqlparser.JoinTableE
330330
// isSameRoute returns true if the join constraint makes the routes
331331
// mergeable by unique vindex. The constraint has to be an equality
332332
// like a.id = b.id where both columns have the same unique vindex.
333-
func (pb *planBuilder) isSameRoute(rpb *planBuilder, filter sqlparser.Expr) bool {
333+
func (pb *primitiveBuilder) isSameRoute(rpb *primitiveBuilder, filter sqlparser.Expr) bool {
334334
lRoute := pb.bldr.(*route)
335335
rRoute := rpb.bldr.(*route)
336336

go/vt/vtgate/planbuilder/insert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
// buildInsertPlan builds the route for an INSERT statement.
3131
func buildInsertPlan(ins *sqlparser.Insert, vschema ContextVSchema) (*engine.Insert, error) {
32-
pb := newPlanBuilder(vschema, newJointab(sqlparser.GetBindvars(ins)))
32+
pb := newPrimitiveBuilder(vschema, newJointab(sqlparser.GetBindvars(ins)))
3333
aliased := &sqlparser.AliasedTableExpr{Expr: ins.Table}
3434
if err := pb.processAliasedTable(aliased); err != nil {
3535
return nil, err

go/vt/vtgate/planbuilder/join.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type join struct {
6868
// newJoin makes a new join using the two planBuilder. ajoin can be nil
6969
// if the join is on a ',' operator. lpb will contain the resulting join.
7070
// rpb will be discarded.
71-
func newJoin(lpb, rpb *planBuilder, ajoin *sqlparser.JoinTableExpr) error {
71+
func newJoin(lpb, rpb *primitiveBuilder, ajoin *sqlparser.JoinTableExpr) error {
7272
// This function converts ON clauses to WHERE clauses. The WHERE clause
7373
// scope can see all tables, whereas the ON clause can only see the
7474
// participants of the JOIN. However, since the ON clause doesn't allow
@@ -148,7 +148,7 @@ func (jb *join) ResultColumns() []*resultColumn {
148148
}
149149

150150
// PushFilter satisfies the builder interface.
151-
func (jb *join) PushFilter(pb *planBuilder, filter sqlparser.Expr, whereType string, origin builder) error {
151+
func (jb *join) PushFilter(pb *primitiveBuilder, filter sqlparser.Expr, whereType string, origin builder) error {
152152
if jb.isOnLeft(origin.Order()) {
153153
return jb.Left.PushFilter(pb, filter, whereType, origin)
154154
}

go/vt/vtgate/planbuilder/limit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (l *limit) ResultColumns() []*resultColumn {
7373
}
7474

7575
// PushFilter satisfies the builder interface.
76-
func (l *limit) PushFilter(_ *planBuilder, _ sqlparser.Expr, whereType string, _ builder) error {
76+
func (l *limit) PushFilter(_ *primitiveBuilder, _ sqlparser.Expr, whereType string, _ builder) error {
7777
panic("BUG: unreachable")
7878
}
7979

go/vt/vtgate/planbuilder/ordered_aggregate.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type orderedAggregate struct {
6464
// that a primitive is needed to handle the aggregation, it builds an orderedAggregate
6565
// primitive and returns it. It returns a groupByHandler if there is aggregation it
6666
// can handle.
67-
func (pb *planBuilder) checkAggregates(sel *sqlparser.Select) (groupByHandler, error) {
67+
func (pb *primitiveBuilder) checkAggregates(sel *sqlparser.Select) (groupByHandler, error) {
6868
rb, isRoute := pb.bldr.(*route)
6969
if isRoute && rb.IsSingle() {
7070
return rb, nil
@@ -175,7 +175,7 @@ func nodeHasAggregates(node sqlparser.SQLNode) bool {
175175
// we don't search the ResultColumns because they're not created yet. Also,
176176
// error conditions are treated as no match for simplicity; They will be
177177
// subsequently caught downstream.
178-
func (pb *planBuilder) groupByHasUniqueVindex(sel *sqlparser.Select, rb *route) bool {
178+
func (pb *primitiveBuilder) groupByHasUniqueVindex(sel *sqlparser.Select, rb *route) bool {
179179
for _, expr := range sel.GroupBy {
180180
var matchedExpr sqlparser.Expr
181181
switch node := expr.(type) {
@@ -258,7 +258,7 @@ func (oa *orderedAggregate) ResultColumns() []*resultColumn {
258258
}
259259

260260
// PushFilter satisfies the builder interface.
261-
func (oa *orderedAggregate) PushFilter(_ *planBuilder, _ sqlparser.Expr, whereType string, _ builder) error {
261+
func (oa *orderedAggregate) PushFilter(_ *primitiveBuilder, _ sqlparser.Expr, whereType string, _ builder) error {
262262
return errors.New("unsupported: filtering on results of aggregates")
263263
}
264264

@@ -364,7 +364,7 @@ func (oa *orderedAggregate) SetGroupBy(groupBy sqlparser.GroupBy) error {
364364
// 'select a, b, count(*) from t group by a, b order by b'
365365
// The following construct is not allowed:
366366
// 'select a, count(*) from t group by a order by count(*)'
367-
func (oa *orderedAggregate) PushOrderBy(pb *planBuilder, orderBy sqlparser.OrderBy) error {
367+
func (oa *orderedAggregate) PushOrderBy(pb *primitiveBuilder, orderBy sqlparser.OrderBy) error {
368368
// Treat order by null as nil order by.
369369
if len(orderBy) == 1 {
370370
if _, ok := orderBy[0].Expr.(*sqlparser.NullVal); ok {

go/vt/vtgate/planbuilder/postprocess.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type groupByHandler interface {
3939

4040
// pushGroupBy processes the group by clause. It resolves all symbols,
4141
// and ensures that there are no subqueries.
42-
func (pb *planBuilder) pushGroupBy(sel *sqlparser.Select, grouper groupByHandler) error {
42+
func (pb *primitiveBuilder) pushGroupBy(sel *sqlparser.Select, grouper groupByHandler) error {
4343
if sel.Distinct != "" {
4444
// We can be here only if the builder could handle a group by.
4545
if err := grouper.MakeDistinct(); err != nil {
@@ -62,7 +62,7 @@ func (pb *planBuilder) pushGroupBy(sel *sqlparser.Select, grouper groupByHandler
6262
// In the case of a join, it's only possible to push down if the
6363
// order by references columns of the left-most route. Otherwise, the
6464
// function returns an unsupported error.
65-
func (pb *planBuilder) pushOrderBy(orderBy sqlparser.OrderBy) error {
65+
func (pb *primitiveBuilder) pushOrderBy(orderBy sqlparser.OrderBy) error {
6666
if oa, ok := pb.bldr.(*orderedAggregate); ok {
6767
return oa.PushOrderBy(pb, orderBy)
6868
}
@@ -130,7 +130,7 @@ func (pb *planBuilder) pushOrderBy(orderBy sqlparser.OrderBy) error {
130130
return nil
131131
}
132132

133-
func (pb *planBuilder) pushLimit(limit *sqlparser.Limit) error {
133+
func (pb *primitiveBuilder) pushLimit(limit *sqlparser.Limit) error {
134134
if limit == nil {
135135
return nil
136136
}

go/vt/vtgate/planbuilder/planbuilder.go renamed to go/vt/vtgate/planbuilder/primitive_builder.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ limitations under the License.
1616

1717
package planbuilder
1818

19-
// planBuilder is the top level type for building plans.
19+
// primitiveBuilder is the top level type for building plans.
2020
// It contains the current builder tree, the symtab and
2121
// the jointab. It can create transient planBuilders due
2222
// to the recursive nature of SQL.
23-
type planBuilder struct {
23+
type primitiveBuilder struct {
2424
vschema ContextVSchema
2525
jt *jointab
2626
bldr builder
2727
st *symtab
2828
}
2929

30-
func newPlanBuilder(vschema ContextVSchema, jt *jointab) *planBuilder {
31-
return &planBuilder{
30+
func newPrimitiveBuilder(vschema ContextVSchema, jt *jointab) *primitiveBuilder {
31+
return &primitiveBuilder{
3232
vschema: vschema,
3333
jt: jt,
3434
}

0 commit comments

Comments
 (0)