Skip to content

Commit

Permalink
refactor: remove TableName from Primitive
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Aug 6, 2024
1 parent 4a89749 commit f22e164
Show file tree
Hide file tree
Showing 85 changed files with 1,558 additions and 4,294 deletions.
9 changes: 0 additions & 9 deletions go/vt/vtgate/engine/concatenate.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,6 @@ func (c *Concatenate) GetKeyspaceName() string {
return res
}

// GetTableName specifies the table that this primitive routes to.
func (c *Concatenate) GetTableName() string {
res := c.Sources[0].GetTableName()
for i := 1; i < len(c.Sources); i++ {
res = formatTwoOptionsNicely(res, c.Sources[i].GetTableName())
}
return res
}

func formatTwoOptionsNicely(a, b string) string {
if a == b {
return a
Expand Down
17 changes: 6 additions & 11 deletions go/vt/vtgate/engine/dbddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ func (c *DBDDL) GetKeyspaceName() string {
return c.name
}

// GetTableName implements the Primitive interface
func (c *DBDDL) GetTableName() string {
return ""
}

// TryExecute implements the Primitive interface
func (c *DBDDL) TryExecute(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable, wantfields bool) (*sqltypes.Result, error) {
name := vcursor.GetDBDDLPluginName()
Expand Down Expand Up @@ -125,9 +120,9 @@ func (c *DBDDL) createDatabase(ctx context.Context, vcursor VCursor, plugin DBDD
break
}
select {
case <-ctx.Done(): //context cancelled
case <-ctx.Done(): // context cancelled
return nil, vterrors.Errorf(vtrpc.Code_DEADLINE_EXCEEDED, "could not validate create database: destination not resolved")
case <-time.After(500 * time.Millisecond): //timeout
case <-time.After(500 * time.Millisecond): // timeout
}
}
var queries []*querypb.BoundQuery
Expand All @@ -146,9 +141,9 @@ func (c *DBDDL) createDatabase(ctx context.Context, vcursor VCursor, plugin DBDD
if err != nil {
noErr = false
select {
case <-ctx.Done(): //context cancelled
case <-ctx.Done(): // context cancelled
return nil, vterrors.Errorf(vtrpc.Code_DEADLINE_EXCEEDED, "could not validate create database: tablets not healthy")
case <-time.After(500 * time.Millisecond): //timeout
case <-time.After(500 * time.Millisecond): // timeout
}
break
}
Expand All @@ -167,9 +162,9 @@ func (c *DBDDL) dropDatabase(ctx context.Context, vcursor VCursor, plugin DBDDLP
}
for vcursor.KeyspaceAvailable(c.name) {
select {
case <-ctx.Done(): //context cancelled
case <-ctx.Done(): // context cancelled
return nil, vterrors.Errorf(vtrpc.Code_DEADLINE_EXCEEDED, "could not validate drop database: keyspace still available in vschema")
case <-time.After(500 * time.Millisecond): //timeout
case <-time.After(500 * time.Millisecond): // timeout
}
}

Expand Down
5 changes: 0 additions & 5 deletions go/vt/vtgate/engine/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ func (ddl *DDL) GetKeyspaceName() string {
return ddl.Keyspace.Name
}

// GetTableName implements the Primitive interface
func (ddl *DDL) GetTableName() string {
return ddl.DDL.GetTable().Name.String()
}

// IsOnlineSchemaDDL returns true if the query is an online schema change DDL
func (ddl *DDL) isOnlineSchemaDDL() bool {
switch ddl.DDL.GetAction() {
Expand Down
1 change: 0 additions & 1 deletion go/vt/vtgate/engine/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ func (del *Delete) deleteVindexEntries(ctx context.Context, vcursor VCursor, bin
func (del *Delete) description() PrimitiveDescription {
other := map[string]any{
"Query": del.Query,
"Table": del.GetTableName(),
"OwnedVindexQuery": del.OwnedVindexQuery,
"MultiShardAutocommit": del.MultiShardAutocommit,
"QueryTimeout": del.QueryTimeout,
Expand Down
5 changes: 0 additions & 5 deletions go/vt/vtgate/engine/distinct.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,6 @@ func (d *Distinct) GetKeyspaceName() string {
return d.Source.GetKeyspaceName()
}

// GetTableName implements the Primitive interface
func (d *Distinct) GetTableName() string {
return d.Source.GetTableName()
}

// GetFields implements the Primitive interface
func (d *Distinct) GetFields(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable) (*sqltypes.Result, error) {
return d.Source.GetFields(ctx, vcursor, bindVars)
Expand Down
16 changes: 0 additions & 16 deletions go/vt/vtgate/engine/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package engine
import (
"context"
"fmt"
"sort"
"strings"

"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/key"
Expand Down Expand Up @@ -107,20 +105,6 @@ func (dml *DML) GetKeyspaceName() string {
return dml.Keyspace.Name
}

// GetTableName specifies the table that this primitive routes to.
func (dml *DML) GetTableName() string {
sort.Strings(dml.TableNames)
var tableNames []string
var previousTbl string
for _, name := range dml.TableNames {
if name != previousTbl {
tableNames = append(tableNames, name)
previousTbl = name
}
}
return strings.Join(tableNames, ", ")
}

func allowOnlyPrimary(rss ...*srvtopo.ResolvedShard) error {
for _, rs := range rss {
if rs != nil && rs.Target.TabletType != topodatapb.TabletType_PRIMARY {
Expand Down
4 changes: 0 additions & 4 deletions go/vt/vtgate/engine/dml_with_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ func (dml *DMLWithInput) GetKeyspaceName() string {
return dml.Input.GetKeyspaceName()
}

func (dml *DMLWithInput) GetTableName() string {
return dml.Input.GetTableName()
}

func (dml *DMLWithInput) Inputs() ([]Primitive, []map[string]any) {
return append([]Primitive{dml.Input}, dml.DMLs...), nil
}
Expand Down
4 changes: 0 additions & 4 deletions go/vt/vtgate/engine/exec_prepared_statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ func (e *ExecStmt) GetKeyspaceName() string {
return e.Input.GetKeyspaceName()
}

func (e *ExecStmt) GetTableName() string {
return e.Input.GetTableName()
}

func (e *ExecStmt) GetFields(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable) (*sqltypes.Result, error) {
return nil, vterrors.VT12001("prepare command on execute statement")
}
Expand Down
4 changes: 0 additions & 4 deletions go/vt/vtgate/engine/fake_primitive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ func (f *fakePrimitive) GetKeyspaceName() string {
return "fakeKs"
}

func (f *fakePrimitive) GetTableName() string {
return "fakeTable"
}

func (f *fakePrimitive) TryExecute(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable, wantfields bool) (*sqltypes.Result, error) {
f.log = append(f.log, fmt.Sprintf("Execute %v %v", printBindVars(bindVars), wantfields))
if f.results == nil {
Expand Down
5 changes: 0 additions & 5 deletions go/vt/vtgate/engine/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ func (f *Filter) GetKeyspaceName() string {
return f.Input.GetKeyspaceName()
}

// GetTableName specifies the table that this primitive routes to.
func (f *Filter) GetTableName() string {
return f.Input.GetTableName()
}

// TryExecute satisfies the Primitive interface.
func (f *Filter) TryExecute(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable, wantfields bool) (*sqltypes.Result, error) {
result, err := vcursor.ExecutePrimitive(ctx, f.Input, bindVars, wantfields)
Expand Down
5 changes: 0 additions & 5 deletions go/vt/vtgate/engine/fk_cascade.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ func (fkc *FkCascade) GetKeyspaceName() string {
return fkc.Parent.GetKeyspaceName()
}

// GetTableName implements the Primitive interface.
func (fkc *FkCascade) GetTableName() string {
return fkc.Parent.GetTableName()
}

// GetFields implements the Primitive interface.
func (fkc *FkCascade) GetFields(_ context.Context, _ VCursor, _ map[string]*querypb.BindVariable) (*sqltypes.Result, error) {
return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "[BUG] GetFields should not be called")
Expand Down
5 changes: 0 additions & 5 deletions go/vt/vtgate/engine/fk_verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ func (f *FkVerify) GetKeyspaceName() string {
return f.Exec.GetKeyspaceName()
}

// GetTableName implements the Primitive interface
func (f *FkVerify) GetTableName() string {
return f.Exec.GetTableName()
}

// GetFields implements the Primitive interface
func (f *FkVerify) GetFields(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable) (*sqltypes.Result, error) {
return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "[BUG] GetFields should not be called")
Expand Down
6 changes: 0 additions & 6 deletions go/vt/vtgate/engine/hash_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,6 @@ func (hj *HashJoin) GetKeyspaceName() string {
return hj.Left.GetKeyspaceName() + "_" + hj.Right.GetKeyspaceName()
}

// GetTableName implements the Primitive interface
func (hj *HashJoin) GetTableName() string {
return hj.Left.GetTableName() + "_" + hj.Right.GetTableName()
}

// GetFields implements the Primitive interface
func (hj *HashJoin) GetFields(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable) (*sqltypes.Result, error) {
joinVars := make(map[string]*querypb.BindVariable)
Expand Down Expand Up @@ -248,7 +243,6 @@ func (hj *HashJoin) Inputs() ([]Primitive, []map[string]any) {
// description implements the Primitive interface
func (hj *HashJoin) description() PrimitiveDescription {
other := map[string]any{
"TableName": hj.GetTableName(),
"JoinColumnIndexes": strings.Trim(strings.Join(strings.Fields(fmt.Sprint(hj.Cols)), ","), "[]"),
"Predicate": sqlparser.String(hj.ASTPred),
"ComparisonType": hj.ComparisonType.String(),
Expand Down
1 change: 0 additions & 1 deletion go/vt/vtgate/engine/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ func (ins *Insert) buildVindexRowsValues(ctx context.Context, vcursor VCursor, b
func (ins *Insert) description() PrimitiveDescription {
other := ins.commonDesc()
other["Query"] = ins.Query
other["TableName"] = ins.GetTableName()

if len(ins.VindexValues) > 0 {
valuesOffsets := map[string]string{}
Expand Down
5 changes: 0 additions & 5 deletions go/vt/vtgate/engine/insert_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ func (ic *InsertCommon) GetKeyspaceName() string {
return ic.Keyspace.Name
}

// GetTableName specifies the table that this primitive routes to.
func (ic *InsertCommon) GetTableName() string {
return ic.TableName
}

// GetFields fetches the field info.
func (ic *InsertCommon) GetFields(context.Context, VCursor, map[string]*querypb.BindVariable) (*sqltypes.Result, error) {
return nil, vterrors.VT13001("unexpected fields call for insert query")
Expand Down
1 change: 0 additions & 1 deletion go/vt/vtgate/engine/insert_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ func (ins *InsertSelect) execInsertSharded(ctx context.Context, vcursor VCursor,

func (ins *InsertSelect) description() PrimitiveDescription {
other := ins.commonDesc()
other["TableName"] = ins.GetTableName()

if len(ins.VindexValueOffset) > 0 {
valuesOffsets := map[string]string{}
Expand Down
6 changes: 0 additions & 6 deletions go/vt/vtgate/engine/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,6 @@ func (jn *Join) GetKeyspaceName() string {
return jn.Left.GetKeyspaceName() + "_" + jn.Right.GetKeyspaceName()
}

// GetTableName specifies the table that this primitive routes to.
func (jn *Join) GetTableName() string {
return jn.Left.GetTableName() + "_" + jn.Right.GetTableName()
}

// NeedsTransaction implements the Primitive interface
func (jn *Join) NeedsTransaction() bool {
return jn.Right.NeedsTransaction() || jn.Left.NeedsTransaction()
Expand All @@ -302,7 +297,6 @@ func combineVars(bv1, bv2 map[string]*querypb.BindVariable) map[string]*querypb.

func (jn *Join) description() PrimitiveDescription {
other := map[string]any{
"TableName": jn.GetTableName(),
"JoinColumnIndexes": jn.joinColsDescription(),
}
if len(jn.Vars) > 0 {
Expand Down
5 changes: 0 additions & 5 deletions go/vt/vtgate/engine/limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ func (l *Limit) GetKeyspaceName() string {
return l.Input.GetKeyspaceName()
}

// GetTableName specifies the table that this primitive routes to.
func (l *Limit) GetTableName() string {
return l.Input.GetTableName()
}

// TryExecute satisfies the Primitive interface.
func (l *Limit) TryExecute(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable, wantfields bool) (*sqltypes.Result, error) {
count, offset, err := l.getCountAndOffset(ctx, vcursor, bindVars)
Expand Down
5 changes: 0 additions & 5 deletions go/vt/vtgate/engine/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ func (l *Lock) GetKeyspaceName() string {
return l.Keyspace.Name
}

// GetTableName is part of the Primitive interface
func (l *Lock) GetTableName() string {
return "dual"
}

// TryExecute is part of the Primitive interface
func (l *Lock) TryExecute(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable, wantfields bool) (*sqltypes.Result, error) {
return l.execLock(ctx, vcursor, bindVars)
Expand Down
5 changes: 0 additions & 5 deletions go/vt/vtgate/engine/memory_sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ func (ms *MemorySort) GetKeyspaceName() string {
return ms.Input.GetKeyspaceName()
}

// GetTableName specifies the table that this primitive routes to.
func (ms *MemorySort) GetTableName() string {
return ms.Input.GetTableName()
}

// TryExecute satisfies the Primitive interface.
func (ms *MemorySort) TryExecute(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable, wantfields bool) (*sqltypes.Result, error) {
count, err := ms.fetchCount(ctx, vcursor, bindVars)
Expand Down
3 changes: 0 additions & 3 deletions go/vt/vtgate/engine/merge_sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ func (ms *MergeSort) RouteType() string { return "MergeSort" }
// GetKeyspaceName satisfies Primitive.
func (ms *MergeSort) GetKeyspaceName() string { return "" }

// GetTableName satisfies Primitive.
func (ms *MergeSort) GetTableName() string { return "" }

// TryExecute is not supported.
func (ms *MergeSort) TryExecute(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable, wantfields bool) (*sqltypes.Result, error) {
return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "[BUG] Execute is not reachable")
Expand Down
5 changes: 0 additions & 5 deletions go/vt/vtgate/engine/mstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ func (m *MStream) GetKeyspaceName() string {
return m.Keyspace.Name
}

// GetTableName implements the Primitive interface
func (m *MStream) GetTableName() string {
return m.TableName
}

// TryExecute implements the Primitive interface
func (m *MStream) TryExecute(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable, wantfields bool) (*sqltypes.Result, error) {
return nil, vterrors.VT13001("TryExecute is not supported for MStream")
Expand Down
5 changes: 0 additions & 5 deletions go/vt/vtgate/engine/online_ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ func (v *OnlineDDL) GetKeyspaceName() string {
return v.Keyspace.Name
}

// GetTableName implements the Primitive interface
func (v *OnlineDDL) GetTableName() string {
return v.DDL.GetTable().Name.String()
}

// TryExecute implements the Primitive interface
func (v *OnlineDDL) TryExecute(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable, wantfields bool) (result *sqltypes.Result, err error) {
result = &sqltypes.Result{
Expand Down
5 changes: 0 additions & 5 deletions go/vt/vtgate/engine/ordered_aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ func (oa *OrderedAggregate) GetKeyspaceName() string {
return oa.Input.GetKeyspaceName()
}

// GetTableName specifies the table that this primitive routes to.
func (oa *OrderedAggregate) GetTableName() string {
return oa.Input.GetTableName()
}

// TryExecute is a Primitive function.
func (oa *OrderedAggregate) TryExecute(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable, _ bool) (*sqltypes.Result, error) {
qr, err := oa.execute(ctx, vcursor, bindVars)
Expand Down
5 changes: 5 additions & 0 deletions go/vt/vtgate/engine/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package engine
import (
"bytes"
"encoding/json"
"strings"
"sync/atomic"
"time"

Expand Down Expand Up @@ -110,3 +111,7 @@ func (p *Plan) MarshalJSON() ([]byte, error) {

return b.Bytes(), nil
}

func (p *Plan) GetTableName() string {
return strings.Join(p.TablesUsed, ",")
}
2 changes: 0 additions & 2 deletions go/vt/vtgate/engine/plan_description_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func TestCreateRoutePlanDescription(t *testing.T) {
TargetDestination: key.DestinationAllShards{},
Other: map[string]any{
"Query": route.Query,
"Table": route.GetTableName(),
"FieldQuery": route.FieldQuery,
"Vindex": route.Vindex.String(),
},
Expand Down Expand Up @@ -98,7 +97,6 @@ func getDescriptionFor(route *Route) PrimitiveDescription {
TargetDestination: key.DestinationAllShards{},
Other: map[string]any{
"Query": route.Query,
"Table": route.GetTableName(),
"FieldQuery": route.FieldQuery,
"Vindex": route.Vindex.String(),
},
Expand Down
1 change: 0 additions & 1 deletion go/vt/vtgate/engine/primitive.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ type (
Primitive interface {
RouteType() string
GetKeyspaceName() string
GetTableName() string
GetFields(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable) (*sqltypes.Result, error)
NeedsTransaction() bool

Expand Down
5 changes: 0 additions & 5 deletions go/vt/vtgate/engine/projection.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ func (p *Projection) GetKeyspaceName() string {
return p.Input.GetKeyspaceName()
}

// GetTableName implements the Primitive interface
func (p *Projection) GetTableName() string {
return p.Input.GetTableName()
}

// TryExecute implements the Primitive interface
func (p *Projection) TryExecute(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable, wantfields bool) (*sqltypes.Result, error) {
result, err := vcursor.ExecutePrimitive(ctx, p.Input, bindVars, wantfields)
Expand Down
Loading

0 comments on commit f22e164

Please sign in to comment.