From d5c293479b106f840c32c9a17bfcb1f33c0a3b8f Mon Sep 17 00:00:00 2001 From: Harshit Gangal Date: Tue, 28 Jan 2025 16:44:57 +0530 Subject: [PATCH] differentiate view from base table in vschema Signed-off-by: Harshit Gangal --- .../schematracker/multi_ks/views_test.go | 10 + go/test/vschemawrapper/vschema_wrapper.go | 4 +- go/vt/schemadiff/semantics.go | 8 +- go/vt/vtgate/engine/fake_vcursor_test.go | 6 +- go/vt/vtgate/engine/insert.go | 2 +- go/vt/vtgate/engine/insert_select.go | 2 +- go/vt/vtgate/engine/primitive.go | 2 +- go/vt/vtgate/engine/route_test.go | 2 +- go/vt/vtgate/executorcontext/vcursor_impl.go | 10 +- go/vt/vtgate/planbuilder/ddl.go | 6 +- go/vt/vtgate/planbuilder/delete.go | 2 +- go/vt/vtgate/planbuilder/insert.go | 4 +- .../planbuilder/operator_transformers.go | 2 +- go/vt/vtgate/planbuilder/operators/delete.go | 10 +- .../planbuilder/operators/dml_planning.go | 6 +- go/vt/vtgate/planbuilder/operators/helpers.go | 2 +- go/vt/vtgate/planbuilder/operators/insert.go | 20 +- go/vt/vtgate/planbuilder/operators/route.go | 8 +- .../planbuilder/operators/route_planning.go | 4 +- .../planbuilder/operators/sharded_routing.go | 2 +- go/vt/vtgate/planbuilder/operators/table.go | 2 +- go/vt/vtgate/planbuilder/operators/update.go | 28 +-- .../planbuilder/operators/update_test.go | 2 +- go/vt/vtgate/planbuilder/operators/upsert.go | 2 +- go/vt/vtgate/planbuilder/operators/vindex.go | 2 +- .../plancontext/planning_context_test.go | 4 +- .../vtgate/planbuilder/plancontext/vschema.go | 4 +- go/vt/vtgate/planbuilder/planner_test.go | 2 +- go/vt/vtgate/planbuilder/update.go | 2 +- go/vt/vtgate/planbuilder/vexplain.go | 2 +- go/vt/vtgate/semantics/FakeSI.go | 4 +- go/vt/vtgate/semantics/analyzer_test.go | 64 +++--- go/vt/vtgate/semantics/cte_table.go | 2 +- go/vt/vtgate/semantics/derived_table.go | 2 +- go/vt/vtgate/semantics/derived_test.go | 6 +- go/vt/vtgate/semantics/early_rewriter_test.go | 18 +- go/vt/vtgate/semantics/foreign_keys_test.go | 20 +- go/vt/vtgate/semantics/info_schema.go | 4 +- go/vt/vtgate/semantics/real_table.go | 4 +- go/vt/vtgate/semantics/semantic_table.go | 12 +- go/vt/vtgate/semantics/semantic_table_test.go | 66 +++--- go/vt/vtgate/semantics/table_collector.go | 10 +- go/vt/vtgate/semantics/vindex_table.go | 2 +- go/vt/vtgate/semantics/vtable.go | 2 +- go/vt/vtgate/vindexes/foreign_keys.go | 12 +- go/vt/vtgate/vindexes/vschema.go | 189 +++++++++++------- go/vt/vtgate/vindexes/vschema_routing_test.go | 16 +- go/vt/vtgate/vindexes/vschema_test.go | 98 ++++----- go/vt/vtgate/vschema_manager.go | 22 +- go/vt/vtgate/vschema_manager_test.go | 86 ++++---- .../tabletserver/vstreamer/local_vschema.go | 2 +- 51 files changed, 424 insertions(+), 379 deletions(-) diff --git a/go/test/endtoend/vtgate/schematracker/multi_ks/views_test.go b/go/test/endtoend/vtgate/schematracker/multi_ks/views_test.go index 0130f64d23d..7aa2ed96a48 100644 --- a/go/test/endtoend/vtgate/schematracker/multi_ks/views_test.go +++ b/go/test/endtoend/vtgate/schematracker/multi_ks/views_test.go @@ -121,6 +121,16 @@ func TestViewQueries(t *testing.T) { require.NoError(t, err) defer conn.Close() + viewExists := func(t *testing.T, ksMap map[string]any) bool { + // wait for the view definition to change + views := ksMap["views"] + viewsMap := views.(map[string]any) + _, ok := viewsMap["cv3"] + return ok + } + + utils.WaitForVschemaCondition(t, clusterInstance.VtgateProcess, shardedKs, viewExists, "view cv3 not found") + // Insert some data insertData(t, conn) diff --git a/go/test/vschemawrapper/vschema_wrapper.go b/go/test/vschemawrapper/vschema_wrapper.go index 5b1c6b033e6..02daa646bf8 100644 --- a/go/test/vschemawrapper/vschema_wrapper.go +++ b/go/test/vschemawrapper/vschema_wrapper.go @@ -253,7 +253,7 @@ func (vw *VSchemaWrapper) Destination() key.Destination { return vw.Dest } -func (vw *VSchemaWrapper) FindTable(tab sqlparser.TableName) (*vindexes.Table, string, topodatapb.TabletType, key.Destination, error) { +func (vw *VSchemaWrapper) FindTable(tab sqlparser.TableName) (*vindexes.BaseTable, string, topodatapb.TabletType, key.Destination, error) { destKeyspace, destTabletType, destTarget, err := topoproto.ParseDestination(tab.Qualifier.String(), topodatapb.TabletType_PRIMARY) if err != nil { return nil, destKeyspace, destTabletType, destTarget, err @@ -284,7 +284,7 @@ func (vw *VSchemaWrapper) FindViewTarget(name sqlparser.TableName) (*vindexes.Ke return nil, nil } -func (vw *VSchemaWrapper) FindTableOrVindex(tab sqlparser.TableName) (*vindexes.Table, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error) { +func (vw *VSchemaWrapper) FindTableOrVindex(tab sqlparser.TableName) (*vindexes.BaseTable, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error) { return vw.Vcursor.FindTableOrVindex(tab) } diff --git a/go/vt/schemadiff/semantics.go b/go/vt/schemadiff/semantics.go index f12f59ef6ae..a2a4b4f954f 100644 --- a/go/vt/schemadiff/semantics.go +++ b/go/vt/schemadiff/semantics.go @@ -38,19 +38,19 @@ var _ semantics.SchemaInformation = (*declarativeSchemaInformation)(nil) // declarativeSchemaInformation is a utility wrapper around FakeSI, and adds a few utility functions // to make it more simple and accessible to schemadiff's logic. type declarativeSchemaInformation struct { - Tables map[string]*vindexes.Table + Tables map[string]*vindexes.BaseTable env *Environment } func newDeclarativeSchemaInformation(env *Environment) *declarativeSchemaInformation { return &declarativeSchemaInformation{ - Tables: make(map[string]*vindexes.Table), + Tables: make(map[string]*vindexes.BaseTable), env: env, } } // FindTableOrVindex implements the SchemaInformation interface -func (si *declarativeSchemaInformation) FindTableOrVindex(tablename sqlparser.TableName) (*vindexes.Table, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error) { +func (si *declarativeSchemaInformation) FindTableOrVindex(tablename sqlparser.TableName) (*vindexes.BaseTable, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error) { table := si.Tables[tablename.Name.String()] return table, nil, "", 0, nil, nil } @@ -86,7 +86,7 @@ func (si *declarativeSchemaInformation) FindMirrorRule(tablename sqlparser.Table // addTable adds a fake table with an empty column list func (si *declarativeSchemaInformation) addTable(tableName string) { - tbl := &vindexes.Table{ + tbl := &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS(tableName), Columns: []vindexes.Column{}, ColumnListAuthoritative: true, diff --git a/go/vt/vtgate/engine/fake_vcursor_test.go b/go/vt/vtgate/engine/fake_vcursor_test.go index 060d2ebcfcb..b277b018faa 100644 --- a/go/vt/vtgate/engine/fake_vcursor_test.go +++ b/go/vt/vtgate/engine/fake_vcursor_test.go @@ -267,7 +267,7 @@ func (t *noopVCursor) InTransactionAndIsDML() bool { panic("implement me") } -func (t *noopVCursor) FindRoutedTable(sqlparser.TableName) (*vindexes.Table, error) { +func (t *noopVCursor) FindRoutedTable(sqlparser.TableName) (*vindexes.BaseTable, error) { panic("implement me") } @@ -480,7 +480,7 @@ func (f *loggingVCursor) GetUDV(key string) *querypb.BindVariable { } type tableRoutes struct { - tbl *vindexes.Table + tbl *vindexes.BaseTable } func (f *loggingVCursor) ExecutePrimitive(ctx context.Context, primitive Primitive, bindVars map[string]*querypb.BindVariable, wantfields bool) (*sqltypes.Result, error) { @@ -845,7 +845,7 @@ func (f *loggingVCursor) SetPriority(string) { panic("implement me") } -func (f *loggingVCursor) FindRoutedTable(tbl sqlparser.TableName) (*vindexes.Table, error) { +func (f *loggingVCursor) FindRoutedTable(tbl sqlparser.TableName) (*vindexes.BaseTable, error) { f.log = append(f.log, fmt.Sprintf("FindTable(%s)", sqlparser.String(tbl))) return f.tableRoutes.tbl, nil } diff --git a/go/vt/vtgate/engine/insert.go b/go/vt/vtgate/engine/insert.go index 5bc206f7465..c51c490ada6 100644 --- a/go/vt/vtgate/engine/insert.go +++ b/go/vt/vtgate/engine/insert.go @@ -77,7 +77,7 @@ func newInsert( ignore bool, keyspace *vindexes.Keyspace, vindexValues [][][]evalengine.Expr, - table *vindexes.Table, + table *vindexes.BaseTable, prefix string, mid sqlparser.Values, suffix sqlparser.OnDup, diff --git a/go/vt/vtgate/engine/insert_select.go b/go/vt/vtgate/engine/insert_select.go index af834858175..1e1ea5b20f9 100644 --- a/go/vt/vtgate/engine/insert_select.go +++ b/go/vt/vtgate/engine/insert_select.go @@ -55,7 +55,7 @@ type ( func newInsertSelect( ignore bool, keyspace *vindexes.Keyspace, - table *vindexes.Table, + table *vindexes.BaseTable, prefix string, suffix sqlparser.OnDup, vv [][]int, diff --git a/go/vt/vtgate/engine/primitive.go b/go/vt/vtgate/engine/primitive.go index 7734dd81a6b..fe991a670b6 100644 --- a/go/vt/vtgate/engine/primitive.go +++ b/go/vt/vtgate/engine/primitive.go @@ -98,7 +98,7 @@ type ( LookupRowLockShardSession() vtgatepb.CommitOrder - FindRoutedTable(tablename sqlparser.TableName) (*vindexes.Table, error) + FindRoutedTable(tablename sqlparser.TableName) (*vindexes.BaseTable, error) // GetDBDDLPlugin gets the configured plugin for DROP/CREATE DATABASE GetDBDDLPluginName() string diff --git a/go/vt/vtgate/engine/route_test.go b/go/vt/vtgate/engine/route_test.go index b2f4020cb59..6b6f65acf42 100644 --- a/go/vt/vtgate/engine/route_test.go +++ b/go/vt/vtgate/engine/route_test.go @@ -178,7 +178,7 @@ func TestInformationSchemaWithTableAndSchemaWithRoutedTables(t *testing.T) { } if tc.routed { vc.tableRoutes = tableRoutes{ - tbl: &vindexes.Table{ + tbl: &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("routedTable"), Keyspace: &vindexes.Keyspace{Name: "routedKeyspace"}, }} diff --git a/go/vt/vtgate/executorcontext/vcursor_impl.go b/go/vt/vtgate/executorcontext/vcursor_impl.go index 4d3f631bac5..19b8f3cbe3a 100644 --- a/go/vt/vtgate/executorcontext/vcursor_impl.go +++ b/go/vt/vtgate/executorcontext/vcursor_impl.go @@ -391,7 +391,7 @@ func (vc *VCursorImpl) StartPrimitiveTrace() func() engine.Stats { // FindTable finds the specified table. If the keyspace what specified in the input, it gets used as qualifier. // Otherwise, the keyspace from the request is used, if one was provided. -func (vc *VCursorImpl) FindTable(name sqlparser.TableName) (*vindexes.Table, string, topodatapb.TabletType, key.Destination, error) { +func (vc *VCursorImpl) FindTable(name sqlparser.TableName) (*vindexes.BaseTable, string, topodatapb.TabletType, key.Destination, error) { destKeyspace, destTabletType, dest, err := vc.parseDestinationTarget(name.Qualifier.String()) if err != nil { return nil, "", destTabletType, nil, err @@ -417,7 +417,7 @@ func (vc *VCursorImpl) FindView(name sqlparser.TableName) sqlparser.TableStateme return vc.vschema.FindView(ks, name.Name.String()) } -func (vc *VCursorImpl) FindRoutedTable(name sqlparser.TableName) (*vindexes.Table, error) { +func (vc *VCursorImpl) FindRoutedTable(name sqlparser.TableName) (*vindexes.BaseTable, error) { destKeyspace, destTabletType, _, err := vc.parseDestinationTarget(name.Qualifier.String()) if err != nil { return nil, err @@ -435,7 +435,7 @@ func (vc *VCursorImpl) FindRoutedTable(name sqlparser.TableName) (*vindexes.Tabl } // FindTableOrVindex finds the specified table or vindex. -func (vc *VCursorImpl) FindTableOrVindex(name sqlparser.TableName) (*vindexes.Table, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error) { +func (vc *VCursorImpl) FindTableOrVindex(name sqlparser.TableName) (*vindexes.BaseTable, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error) { if name.Qualifier.IsEmpty() && name.Name.String() == "dual" { // The magical MySQL dual table should only be resolved // when it is not qualified by a database name. @@ -489,7 +489,7 @@ func ParseDestinationTarget(targetString string, tablet topodatapb.TabletType, v return destKeyspace, destTabletType, dest, err } -func (vc *VCursorImpl) getDualTable() (*vindexes.Table, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error) { +func (vc *VCursorImpl) getDualTable() (*vindexes.BaseTable, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error) { ksName := vc.getActualKeyspace() var ks *vindexes.Keyspace if ksName == "" { @@ -498,7 +498,7 @@ func (vc *VCursorImpl) getDualTable() (*vindexes.Table, vindexes.Vindex, string, } else { ks = vc.vschema.Keyspaces[ksName].Keyspace } - tbl := &vindexes.Table{ + tbl := &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("dual"), Keyspace: ks, Type: vindexes.TypeReference, diff --git a/go/vt/vtgate/planbuilder/ddl.go b/go/vt/vtgate/planbuilder/ddl.go index 2ca924c31ab..1359da1c0a8 100644 --- a/go/vt/vtgate/planbuilder/ddl.go +++ b/go/vt/vtgate/planbuilder/ddl.go @@ -166,7 +166,7 @@ func checkFKError(vschema plancontext.VSchema, ddlStatement sqlparser.DDLStateme } func findTableDestinationAndKeyspace(vschema plancontext.VSchema, ddlStatement sqlparser.DDLStatement) (key.Destination, *vindexes.Keyspace, error) { - var table *vindexes.Table + var table *vindexes.BaseTable var destination key.Destination var keyspace *vindexes.Keyspace var err error @@ -325,7 +325,7 @@ func buildDropTable(vschema plancontext.VSchema, ddlStatement sqlparser.DDLState for i, tab := range ddlStatement.GetFromTables() { var destinationTab key.Destination var keyspaceTab *vindexes.Keyspace - var table *vindexes.Table + var table *vindexes.BaseTable var err error table, _, _, _, destinationTab, err = vschema.FindTableOrVindex(tab) @@ -369,7 +369,7 @@ func buildRenameTable(vschema plancontext.VSchema, renameTable *sqlparser.Rename for _, tabPair := range renameTable.TablePairs { var destinationFrom key.Destination var keyspaceFrom *vindexes.Keyspace - var table *vindexes.Table + var table *vindexes.BaseTable var err error table, _, _, _, destinationFrom, err = vschema.FindTableOrVindex(tabPair.FromTable) diff --git a/go/vt/vtgate/planbuilder/delete.go b/go/vt/vtgate/planbuilder/delete.go index 239e7bae0ae..95c2f68dc62 100644 --- a/go/vt/vtgate/planbuilder/delete.go +++ b/go/vt/vtgate/planbuilder/delete.go @@ -123,7 +123,7 @@ func rewriteSingleTbl(del *sqlparser.Delete) (*sqlparser.Delete, error) { return del, nil } -func deleteUnshardedShortcut(stmt *sqlparser.Delete, ks *vindexes.Keyspace, tables []*vindexes.Table) engine.Primitive { +func deleteUnshardedShortcut(stmt *sqlparser.Delete, ks *vindexes.Keyspace, tables []*vindexes.BaseTable) engine.Primitive { edml := engine.NewDML() edml.Keyspace = ks edml.Opcode = engine.Unsharded diff --git a/go/vt/vtgate/planbuilder/insert.go b/go/vt/vtgate/planbuilder/insert.go index d3ad5afac72..d784fffe7ee 100644 --- a/go/vt/vtgate/planbuilder/insert.go +++ b/go/vt/vtgate/planbuilder/insert.go @@ -83,14 +83,14 @@ func gen4InsertStmtPlanner(version querypb.ExecuteOptions_PlannerVersion, insStm return newPlanResult(plan, operators.TablesUsed(op)...), nil } -func errOutIfPlanCannotBeConstructed(ctx *plancontext.PlanningContext, vTbl *vindexes.Table) error { +func errOutIfPlanCannotBeConstructed(ctx *plancontext.PlanningContext, vTbl *vindexes.BaseTable) error { if !vTbl.Keyspace.Sharded { return nil } return ctx.SemTable.NotUnshardedErr } -func insertUnshardedShortcut(ctx *plancontext.PlanningContext, stmt *sqlparser.Insert, ks *vindexes.Keyspace, tables []*vindexes.Table) engine.Primitive { +func insertUnshardedShortcut(ctx *plancontext.PlanningContext, stmt *sqlparser.Insert, ks *vindexes.Keyspace, tables []*vindexes.BaseTable) engine.Primitive { eIns := &engine.Insert{ InsertCommon: engine.InsertCommon{ Opcode: engine.InsertUnsharded, diff --git a/go/vt/vtgate/planbuilder/operator_transformers.go b/go/vt/vtgate/planbuilder/operator_transformers.go index b51eac449fc..807912110df 100644 --- a/go/vt/vtgate/planbuilder/operator_transformers.go +++ b/go/vt/vtgate/planbuilder/operator_transformers.go @@ -783,7 +783,7 @@ func buildDeletePrimitive(ctx *plancontext.PlanningContext, rb *operators.Route, return &engine.Delete{DML: edml}, nil } -func createDMLPrimitive(ctx *plancontext.PlanningContext, rb *operators.Route, hints *queryHints, vTbl *vindexes.Table, query string, colVindexes []*vindexes.ColumnVindex, vindexQuery string) *engine.DML { +func createDMLPrimitive(ctx *plancontext.PlanningContext, rb *operators.Route, hints *queryHints, vTbl *vindexes.BaseTable, query string, colVindexes []*vindexes.ColumnVindex, vindexQuery string) *engine.DML { rp := newRoutingParams(ctx, rb.Routing.OpCode()) rb.Routing.UpdateRoutingParams(ctx, rp) edml := &engine.DML{ diff --git a/go/vt/vtgate/planbuilder/operators/delete.go b/go/vt/vtgate/planbuilder/operators/delete.go index 015220470e0..23c909e0a04 100644 --- a/go/vt/vtgate/planbuilder/operators/delete.go +++ b/go/vt/vtgate/planbuilder/operators/delete.go @@ -71,7 +71,7 @@ func createOperatorFromDelete(ctx *plancontext.PlanningContext, deleteStmt *sqlp } delClone := sqlparser.Clone(deleteStmt) - var vTbl *vindexes.Table + var vTbl *vindexes.BaseTable op, vTbl = createDeleteOperator(ctx, deleteStmt) if deleteStmt.Comments != nil { @@ -154,7 +154,7 @@ func createDeleteWithInputOp(ctx *plancontext.PlanningContext, del *sqlparser.De } // getFirstVindex returns the first Vindex, if available -func getFirstVindex(vTbl *vindexes.Table) vindexes.Vindex { +func getFirstVindex(vTbl *vindexes.BaseTable) vindexes.Vindex { if len(vTbl.ColumnVindexes) > 0 { return vTbl.ColumnVindexes[0].Vindex } @@ -204,7 +204,7 @@ func createDeleteOpWithTarget(ctx *plancontext.PlanningContext, target semantics } } -func createDeleteOperator(ctx *plancontext.PlanningContext, del *sqlparser.Delete) (Operator, *vindexes.Table) { +func createDeleteOperator(ctx *plancontext.PlanningContext, del *sqlparser.Delete) (Operator, *vindexes.BaseTable) { op := crossJoin(ctx, del.TableExprs) sqc := &SubQueryBuilder{} @@ -310,7 +310,7 @@ func addOrdering(ctx *plancontext.PlanningContext, op Operator, orderBy sqlparse return newOrdering(op, order) } -func updateQueryGraphWithSource(ctx *plancontext.PlanningContext, input Operator, tblID semantics.TableSet, vTbl *vindexes.Table) *vindexes.Table { +func updateQueryGraphWithSource(ctx *plancontext.PlanningContext, input Operator, tblID semantics.TableSet, vTbl *vindexes.BaseTable) *vindexes.BaseTable { sourceTable, _, _, _, _, err := ctx.VSchema.FindTableOrVindex(vTbl.Source.TableName) if err != nil { panic(err) @@ -339,7 +339,7 @@ func updateQueryGraphWithSource(ctx *plancontext.PlanningContext, input Operator return vTbl } -func createFkCascadeOpForDelete(ctx *plancontext.PlanningContext, parentOp Operator, delStmt *sqlparser.Delete, childFks []vindexes.ChildFKInfo, deletedTbl *vindexes.Table) Operator { +func createFkCascadeOpForDelete(ctx *plancontext.PlanningContext, parentOp Operator, delStmt *sqlparser.Delete, childFks []vindexes.ChildFKInfo, deletedTbl *vindexes.BaseTable) Operator { var fkChildren []*FkChild var selectExprs []sqlparser.SelectExpr tblName := delStmt.Targets[0] diff --git a/go/vt/vtgate/planbuilder/operators/dml_planning.go b/go/vt/vtgate/planbuilder/operators/dml_planning.go index 866c308956c..bf8fce7287e 100644 --- a/go/vt/vtgate/planbuilder/operators/dml_planning.go +++ b/go/vt/vtgate/planbuilder/operators/dml_planning.go @@ -35,14 +35,14 @@ type DMLCommon struct { type TargetTable struct { ID semantics.TableSet - VTable *vindexes.Table + VTable *vindexes.BaseTable Name sqlparser.TableName } // dmlOp stores intermediary value for Update/Delete Operator with the vindexes. Table for ordering. type dmlOp struct { op Operator - vTbl *vindexes.Table + vTbl *vindexes.BaseTable cols []*sqlparser.ColName updList updList } @@ -87,7 +87,7 @@ func shortDesc(target TargetTable, ovq *sqlparser.Select) string { // getVindexInformation returns the vindex and VindexPlusPredicates for the DML, // If it cannot find a unique vindex match, it returns an error. -func getVindexInformation(id semantics.TableSet, table *vindexes.Table) *vindexes.ColumnVindex { +func getVindexInformation(id semantics.TableSet, table *vindexes.BaseTable) *vindexes.ColumnVindex { // Check that we have a primary vindex which is valid if len(table.ColumnVindexes) == 0 || !table.ColumnVindexes[0].IsUnique() { panic(vterrors.VT09001(table.Name)) diff --git a/go/vt/vtgate/planbuilder/operators/helpers.go b/go/vt/vtgate/planbuilder/operators/helpers.go index 36b10c96ae1..52c50d15053 100644 --- a/go/vt/vtgate/planbuilder/operators/helpers.go +++ b/go/vt/vtgate/planbuilder/operators/helpers.go @@ -138,7 +138,7 @@ func QualifiedTableNames(ks *vindexes.Keyspace, ts []sqlparser.TableName) []stri return collect() } -func QualifiedTables(ks *vindexes.Keyspace, vts []*vindexes.Table) []string { +func QualifiedTables(ks *vindexes.Keyspace, vts []*vindexes.BaseTable) []string { add, collect := collectSortedUniqueStrings() for _, vt := range vts { add(QualifiedIdentifier(ks, vt.Name)) diff --git a/go/vt/vtgate/planbuilder/operators/insert.go b/go/vt/vtgate/planbuilder/operators/insert.go index ae125dea19c..f6d86d49ca2 100644 --- a/go/vt/vtgate/planbuilder/operators/insert.go +++ b/go/vt/vtgate/planbuilder/operators/insert.go @@ -31,7 +31,7 @@ import ( // Insert represents an insert operation on a table. type Insert struct { // VTable represents the target table for the insert operation. - VTable *vindexes.Table + VTable *vindexes.BaseTable // AST represents the insert statement from the SQL syntax. AST *sqlparser.Insert @@ -146,7 +146,7 @@ func createOperatorFromInsert(ctx *plancontext.PlanningContext, ins *sqlparser.I return &Sequential{Sources: []Operator{delOp, insOp}} } -func checkAndCreateInsertOperator(ctx *plancontext.PlanningContext, ins *sqlparser.Insert, vTbl *vindexes.Table, routing Routing) Operator { +func checkAndCreateInsertOperator(ctx *plancontext.PlanningContext, ins *sqlparser.Insert, vTbl *vindexes.BaseTable, routing Routing) Operator { insOp := createInsertOperator(ctx, ins, vTbl, routing) // Find the foreign key mode and for unmanaged foreign-key-mode, we don't need to do anything. @@ -200,7 +200,7 @@ func getWhereCondExpr(compExprs []*sqlparser.ComparisonExpr) sqlparser.Expr { return outputExpr } -func pkCompExpression(vTbl *vindexes.Table, ins *sqlparser.Insert, rows sqlparser.Values) *sqlparser.ComparisonExpr { +func pkCompExpression(vTbl *vindexes.BaseTable, ins *sqlparser.Insert, rows sqlparser.Values) *sqlparser.ComparisonExpr { if len(vTbl.PrimaryKey) == 0 { return nil } @@ -227,7 +227,7 @@ type pComp struct { col sqlparser.IdentifierCI } -func findPKIndexes(vTbl *vindexes.Table, ins *sqlparser.Insert) (pIndexes []pComp, pColTuple sqlparser.ValTuple) { +func findPKIndexes(vTbl *vindexes.BaseTable, ins *sqlparser.Insert) (pIndexes []pComp, pColTuple sqlparser.ValTuple) { for _, pCol := range vTbl.PrimaryKey { var def sqlparser.Expr idx := ins.Columns.FindColumn(pCol) @@ -244,7 +244,7 @@ func findPKIndexes(vTbl *vindexes.Table, ins *sqlparser.Insert) (pIndexes []pCom return } -func findDefault(vTbl *vindexes.Table, pCol sqlparser.IdentifierCI) sqlparser.Expr { +func findDefault(vTbl *vindexes.BaseTable, pCol sqlparser.IdentifierCI) sqlparser.Expr { for _, column := range vTbl.Columns { if column.Name.Equal(pCol) { return column.Default @@ -258,7 +258,7 @@ type uComp struct { def sqlparser.Expr } -func uniqKeyCompExpressions(vTbl *vindexes.Table, ins *sqlparser.Insert, rows sqlparser.Values) (comps []*sqlparser.ComparisonExpr) { +func uniqKeyCompExpressions(vTbl *vindexes.BaseTable, ins *sqlparser.Insert, rows sqlparser.Values) (comps []*sqlparser.ComparisonExpr) { noOfUniqKeys := len(vTbl.UniqueKeys) if noOfUniqKeys == 0 { return nil @@ -322,7 +322,7 @@ func uniqKeyCompExpressions(vTbl *vindexes.Table, ins *sqlparser.Insert, rows sq return compExprs } -func createUniqueKeyComp(ins *sqlparser.Insert, expr sqlparser.Expr, vTbl *vindexes.Table) ([]uComp, bool) { +func createUniqueKeyComp(ins *sqlparser.Insert, expr sqlparser.Expr, vTbl *vindexes.BaseTable) ([]uComp, bool) { col, isCol := expr.(*sqlparser.ColName) if isCol { var def sqlparser.Expr @@ -357,7 +357,7 @@ func createUniqueKeyComp(ins *sqlparser.Insert, expr sqlparser.Expr, vTbl *vinde return offsets, false } -func createInsertOperator(ctx *plancontext.PlanningContext, insStmt *sqlparser.Insert, vTbl *vindexes.Table, routing Routing) (op Operator) { +func createInsertOperator(ctx *plancontext.PlanningContext, insStmt *sqlparser.Insert, vTbl *vindexes.BaseTable, routing Routing) (op Operator) { if _, target := routing.(*TargetedRouting); target { panic(vterrors.VT09017("INSERT with a target destination is not allowed")) } @@ -595,7 +595,7 @@ func findColumn(ins *sqlparser.Insert, col sqlparser.IdentifierCI) int { return -1 } -func populateInsertColumnlist(ins *sqlparser.Insert, table *vindexes.Table) *sqlparser.Insert { +func populateInsertColumnlist(ins *sqlparser.Insert, table *vindexes.BaseTable) *sqlparser.Insert { cols := make(sqlparser.Columns, 0, len(table.Columns)) for _, c := range table.Columns { cols = append(cols, c.Name) @@ -606,7 +606,7 @@ func populateInsertColumnlist(ins *sqlparser.Insert, table *vindexes.Table) *sql // modifyForAutoinc modifies the AST and the plan to generate necessary autoinc values. // For row values cases, bind variable names are generated using baseName. -func modifyForAutoinc(ctx *plancontext.PlanningContext, ins *sqlparser.Insert, vTable *vindexes.Table) *Generate { +func modifyForAutoinc(ctx *plancontext.PlanningContext, ins *sqlparser.Insert, vTable *vindexes.BaseTable) *Generate { if vTable.AutoIncrement == nil { return nil } diff --git a/go/vt/vtgate/planbuilder/operators/route.go b/go/vt/vtgate/planbuilder/operators/route.go index e398fb05607..904d5085718 100644 --- a/go/vt/vtgate/planbuilder/operators/route.go +++ b/go/vt/vtgate/planbuilder/operators/route.go @@ -365,7 +365,7 @@ func findVSchemaTableAndCreateRoute( ) } -func createTargetedRouting(ctx *plancontext.PlanningContext, target key.Destination, tabletType topodatapb.TabletType, vschemaTable *vindexes.Table) Routing { +func createTargetedRouting(ctx *plancontext.PlanningContext, target key.Destination, tabletType topodatapb.TabletType, vschemaTable *vindexes.BaseTable) Routing { switch ctx.Statement.(type) { case *sqlparser.Update: if tabletType != topodatapb.TabletType_PRIMARY { @@ -401,7 +401,7 @@ func createTargetedRouting(ctx *plancontext.PlanningContext, target key.Destinat func createRouteFromVSchemaTable( ctx *plancontext.PlanningContext, queryTable *QueryTable, - vschemaTable *vindexes.Table, + vschemaTable *vindexes.BaseTable, planAlternates bool, targeted Routing, ) *Route { @@ -457,7 +457,7 @@ func createRouteFromVSchemaTable( return plan } -func createRoutingForVTable(ctx *plancontext.PlanningContext, vschemaTable *vindexes.Table, id semantics.TableSet) Routing { +func createRoutingForVTable(ctx *plancontext.PlanningContext, vschemaTable *vindexes.BaseTable, id semantics.TableSet) Routing { switch { case vschemaTable.Type == vindexes.TypeSequence: return &SequenceRouting{keyspace: vschemaTable.Keyspace} @@ -473,7 +473,7 @@ func createRoutingForVTable(ctx *plancontext.PlanningContext, vschemaTable *vind func createAlternateRoutesFromVSchemaTable( ctx *plancontext.PlanningContext, queryTable *QueryTable, - vschemaTable *vindexes.Table, + vschemaTable *vindexes.BaseTable, ) map[*vindexes.Keyspace]*Route { routes := make(map[*vindexes.Keyspace]*Route) diff --git a/go/vt/vtgate/planbuilder/operators/route_planning.go b/go/vt/vtgate/planbuilder/operators/route_planning.go index 90eb16e1562..b5bcf37c127 100644 --- a/go/vt/vtgate/planbuilder/operators/route_planning.go +++ b/go/vt/vtgate/planbuilder/operators/route_planning.go @@ -82,7 +82,7 @@ func buildVindexTableForDML( table *QueryTable, ins *sqlparser.Insert, dmlType string, -) (*vindexes.Table, Routing) { +) (*vindexes.BaseTable, Routing) { vindexTable := tableInfo.GetVindexTable() if tableInfo.GetVindexTable().Type == vindexes.TypeReference && vindexTable.Source != nil { sourceTable, _, _, _, _, err := ctx.VSchema.FindTableOrVindex(vindexTable.Source.TableName) @@ -179,7 +179,7 @@ func createInfSchemaRoute(ctx *plancontext.PlanningContext, table *QueryTable) O } var src Operator = &Table{ QTable: table, - VTable: &vindexes.Table{ + VTable: &vindexes.BaseTable{ Name: table.Table.Name, Keyspace: ks, }, diff --git a/go/vt/vtgate/planbuilder/operators/sharded_routing.go b/go/vt/vtgate/planbuilder/operators/sharded_routing.go index 2c8873dee07..9ad567c71b1 100644 --- a/go/vt/vtgate/planbuilder/operators/sharded_routing.go +++ b/go/vt/vtgate/planbuilder/operators/sharded_routing.go @@ -51,7 +51,7 @@ type ShardedRouting struct { var _ Routing = (*ShardedRouting)(nil) -func newShardedRouting(ctx *plancontext.PlanningContext, vtable *vindexes.Table, id semantics.TableSet) Routing { +func newShardedRouting(ctx *plancontext.PlanningContext, vtable *vindexes.BaseTable, id semantics.TableSet) Routing { routing := &ShardedRouting{ RouteOpCode: engine.Scatter, keyspace: vtable.Keyspace, diff --git a/go/vt/vtgate/planbuilder/operators/table.go b/go/vt/vtgate/planbuilder/operators/table.go index 4391380480c..473459d6864 100644 --- a/go/vt/vtgate/planbuilder/operators/table.go +++ b/go/vt/vtgate/planbuilder/operators/table.go @@ -30,7 +30,7 @@ import ( type ( Table struct { QTable *QueryTable - VTable *vindexes.Table + VTable *vindexes.BaseTable Columns []*sqlparser.ColName nullaryOperator diff --git a/go/vt/vtgate/planbuilder/operators/update.go b/go/vt/vtgate/planbuilder/operators/update.go index 18a81175f7b..0fa0d10d9c7 100644 --- a/go/vt/vtgate/planbuilder/operators/update.go +++ b/go/vt/vtgate/planbuilder/operators/update.go @@ -543,7 +543,7 @@ func addColumns(ctx *plancontext.PlanningContext, columns sqlparser.Columns, exp // For an update query having non-literal updates, we add the updated expression and a comparison expression to the select query. // For example, for a query like `update fk_table set col = id * 100 + 1` // We would add the expression `id * 100 + 1` and the comparison expression `col <=> id * 100 + 1` to the select query. -func addNonLiteralUpdExprToSelect(ctx *plancontext.PlanningContext, updatedTable *vindexes.Table, updExpr *sqlparser.UpdateExpr, exprs []sqlparser.SelectExpr) (engine.NonLiteralUpdateInfo, []sqlparser.SelectExpr) { +func addNonLiteralUpdExprToSelect(ctx *plancontext.PlanningContext, updatedTable *vindexes.BaseTable, updExpr *sqlparser.UpdateExpr, exprs []sqlparser.SelectExpr) (engine.NonLiteralUpdateInfo, []sqlparser.SelectExpr) { // Create the comparison expression. castedExpr := getCastedUpdateExpression(updatedTable, updExpr) compExpr := sqlparser.NewComparisonExpr(sqlparser.NullSafeEqualOp, updExpr.Name, castedExpr, nil) @@ -572,7 +572,7 @@ func addNonLiteralUpdExprToSelect(ctx *plancontext.PlanningContext, updatedTable return info, exprs } -func getCastedUpdateExpression(updatedTable *vindexes.Table, updExpr *sqlparser.UpdateExpr) sqlparser.Expr { +func getCastedUpdateExpression(updatedTable *vindexes.BaseTable, updExpr *sqlparser.UpdateExpr) sqlparser.Expr { castTypeStr := getCastTypeForColumn(updatedTable, updExpr) if castTypeStr == "" { return updExpr.Expr @@ -585,7 +585,7 @@ func getCastedUpdateExpression(updatedTable *vindexes.Table, updExpr *sqlparser. } } -func getCastTypeForColumn(updatedTable *vindexes.Table, updExpr *sqlparser.UpdateExpr) string { +func getCastTypeForColumn(updatedTable *vindexes.BaseTable, updExpr *sqlparser.UpdateExpr) string { var ty querypb.Type for _, column := range updatedTable.Columns { if updExpr.Name.Name.Equal(column.Name) { @@ -616,7 +616,7 @@ func getCastTypeForColumn(updatedTable *vindexes.Table, updExpr *sqlparser.Updat } // createFkChildForUpdate creates the update query operator for the child table based on the foreign key constraints. -func createFkChildForUpdate(ctx *plancontext.PlanningContext, fk vindexes.ChildFKInfo, selectOffsets []int, nonLiteralUpdateInfo []engine.NonLiteralUpdateInfo, updatedTable *vindexes.Table) *FkChild { +func createFkChildForUpdate(ctx *plancontext.PlanningContext, fk vindexes.ChildFKInfo, selectOffsets []int, nonLiteralUpdateInfo []engine.NonLiteralUpdateInfo, updatedTable *vindexes.BaseTable) *FkChild { // Create a ValTuple of child column names var valTuple sqlparser.ValTuple for _, column := range fk.ChildColumns { @@ -660,7 +660,7 @@ func createFkChildForUpdate(ctx *plancontext.PlanningContext, fk vindexes.ChildF // The query looks like this - // // `UPDATE SET WHERE IN ()` -func buildChildUpdOpForCascade(ctx *plancontext.PlanningContext, fk vindexes.ChildFKInfo, childWhereExpr sqlparser.Expr, nonLiteralUpdateInfo []engine.NonLiteralUpdateInfo, updatedTable *vindexes.Table) Operator { +func buildChildUpdOpForCascade(ctx *plancontext.PlanningContext, fk vindexes.ChildFKInfo, childWhereExpr sqlparser.Expr, nonLiteralUpdateInfo []engine.NonLiteralUpdateInfo, updatedTable *vindexes.BaseTable) Operator { // The update expressions are the same as the update expressions in the parent update query // with the column names replaced with the child column names. var childUpdateExprs sqlparser.UpdateExprs @@ -708,7 +708,7 @@ func buildChildUpdOpForSetNull( fk vindexes.ChildFKInfo, childWhereExpr sqlparser.Expr, nonLiteralUpdateInfo []engine.NonLiteralUpdateInfo, - updatedTable *vindexes.Table, + updatedTable *vindexes.BaseTable, ) Operator { // For the SET NULL type constraint, we need to set all the child columns to NULL. var childUpdateExprs sqlparser.UpdateExprs @@ -769,7 +769,7 @@ func createFKVerifyOp( updStmt *sqlparser.Update, parentFks []vindexes.ParentFKInfo, restrictChildFks []vindexes.ChildFKInfo, - updatedTable *vindexes.Table, + updatedTable *vindexes.BaseTable, ) Operator { if len(parentFks) == 0 && len(restrictChildFks) == 0 { return childOp @@ -811,7 +811,7 @@ func createFKVerifyOp( // where Parent.p1 is null and Parent.p2 is null and Child.id = 1 and Child.c2 + 1 is not null // and Child.c2 is not null and not ((Child.c1) <=> (Child.c2 + 1)) // limit 1 -func createFkVerifyOpForParentFKForUpdate(ctx *plancontext.PlanningContext, updatedTable *vindexes.Table, updStmt *sqlparser.Update, pFK vindexes.ParentFKInfo) Operator { +func createFkVerifyOpForParentFKForUpdate(ctx *plancontext.PlanningContext, updatedTable *vindexes.BaseTable, updStmt *sqlparser.Update, pFK vindexes.ParentFKInfo) Operator { childTblExpr := updStmt.TableExprs[0].(*sqlparser.AliasedTableExpr) childTbl, err := childTblExpr.TableName() if err != nil { @@ -903,14 +903,14 @@ func createFkVerifyOpForParentFKForUpdate(ctx *plancontext.PlanningContext, upda getVerifyLock(updatedTable)) } -func getVerifyLock(vTbl *vindexes.Table) sqlparser.Lock { +func getVerifyLock(vTbl *vindexes.BaseTable) sqlparser.Lock { if len(vTbl.UniqueKeys) > 0 { return sqlparser.ForShareLockNoWait } return sqlparser.ForShareLock } -func getUpdateLock(vTbl *vindexes.Table) sqlparser.Lock { +func getUpdateLock(vTbl *vindexes.BaseTable) sqlparser.Lock { if len(vTbl.UniqueKeys) > 0 { return sqlparser.ForUpdateLockNoWait } @@ -925,7 +925,7 @@ func getUpdateLock(vTbl *vindexes.Table) sqlparser.Lock { // verify query: // select 1 from Child join Parent on Parent.p1 = Child.c1 and Parent.p2 = Child.c2 // where Parent.id = 1 and ((Parent.col + 1) IS NULL OR (child.c1) NOT IN ((Parent.col + 1))) limit 1 -func createFkVerifyOpForChildFKForUpdate(ctx *plancontext.PlanningContext, updatedTable *vindexes.Table, updStmt *sqlparser.Update, cFk vindexes.ChildFKInfo) Operator { +func createFkVerifyOpForChildFKForUpdate(ctx *plancontext.PlanningContext, updatedTable *vindexes.BaseTable, updStmt *sqlparser.Update, cFk vindexes.ChildFKInfo) Operator { // ON UPDATE RESTRICT foreign keys that require validation, should only be allowed in the case where we // are verifying all the FKs on vtgate level. if !ctx.VerifyAllFKs { @@ -992,7 +992,7 @@ func createFkVerifyOpForChildFKForUpdate(ctx *plancontext.PlanningContext, updat // `:v1 IS NULL OR :v2 IS NULL OR (cola, colb) NOT IN ((:v1,:v2))` // So, if either of :v1 or :v2 is NULL, then the entire condition is true (which is the same as not having the condition when :v1 or :v2 is NULL) // This expression is used in cascading SET NULLs and in verifying whether an update should be restricted. -func nullSafeNotInComparison(ctx *plancontext.PlanningContext, updatedTable *vindexes.Table, updateExprs sqlparser.UpdateExprs, cFk vindexes.ChildFKInfo, parentTbl sqlparser.TableName, nonLiteralUpdateInfo []engine.NonLiteralUpdateInfo, appendQualifier bool) sqlparser.Expr { +func nullSafeNotInComparison(ctx *plancontext.PlanningContext, updatedTable *vindexes.BaseTable, updateExprs sqlparser.UpdateExprs, cFk vindexes.ChildFKInfo, parentTbl sqlparser.TableName, nonLiteralUpdateInfo []engine.NonLiteralUpdateInfo, appendQualifier bool) sqlparser.Expr { var valTuple sqlparser.ValTuple var updateValues sqlparser.ValTuple for idx, updateExpr := range updateExprs { @@ -1031,7 +1031,7 @@ func nullSafeNotInComparison(ctx *plancontext.PlanningContext, updatedTable *vin func buildChangedVindexesValues( ctx *plancontext.PlanningContext, update *sqlparser.Update, - table *vindexes.Table, + table *vindexes.BaseTable, ksidCols []sqlparser.IdentifierCI, assignments []SetExpr, ) (changedVindexes map[string]*engine.VindexValues, ovq *sqlparser.Select, subQueriesArgOnChangedVindex []string) { @@ -1076,7 +1076,7 @@ func buildChangedVindexesValues( return changedVindexes, ovq, subQueriesArgOnChangedVindex } -func initialQuery(ksidCols []sqlparser.IdentifierCI, table *vindexes.Table) (sqlparser.SelectExprs, int) { +func initialQuery(ksidCols []sqlparser.IdentifierCI, table *vindexes.BaseTable) (sqlparser.SelectExprs, int) { var selExprs sqlparser.SelectExprs offset := 0 for _, col := range ksidCols { diff --git a/go/vt/vtgate/planbuilder/operators/update_test.go b/go/vt/vtgate/planbuilder/operators/update_test.go index 6cdf7be3f7d..6efe113813c 100644 --- a/go/vt/vtgate/planbuilder/operators/update_test.go +++ b/go/vt/vtgate/planbuilder/operators/update_test.go @@ -125,7 +125,7 @@ func TestGetCastTypeForColumn(t *testing.T) { updExpr := &sqlparser.UpdateExpr{ Name: sqlparser.NewColName("col"), } - updatedTable := &vindexes.Table{ + updatedTable := &vindexes.BaseTable{ Columns: []vindexes.Column{ { Name: sqlparser.NewIdentifierCI("col"), diff --git a/go/vt/vtgate/planbuilder/operators/upsert.go b/go/vt/vtgate/planbuilder/operators/upsert.go index bfe2a1cbc52..90cee8a5607 100644 --- a/go/vt/vtgate/planbuilder/operators/upsert.go +++ b/go/vt/vtgate/planbuilder/operators/upsert.go @@ -74,7 +74,7 @@ func (u *Upsert) GetOrdering(ctx *plancontext.PlanningContext) []OrderBy { return nil } -func createUpsertOperator(ctx *plancontext.PlanningContext, ins *sqlparser.Insert, insOp Operator, rows sqlparser.Values, vTbl *vindexes.Table) Operator { +func createUpsertOperator(ctx *plancontext.PlanningContext, ins *sqlparser.Insert, insOp Operator, rows sqlparser.Values, vTbl *vindexes.BaseTable) Operator { if len(vTbl.UniqueKeys) != 0 { panic(vterrors.VT12001("ON DUPLICATE KEY UPDATE with foreign keys with unique keys")) } diff --git a/go/vt/vtgate/planbuilder/operators/vindex.go b/go/vt/vtgate/planbuilder/operators/vindex.go index 30f13701df6..cb0719b815f 100644 --- a/go/vt/vtgate/planbuilder/operators/vindex.go +++ b/go/vt/vtgate/planbuilder/operators/vindex.go @@ -44,7 +44,7 @@ type ( Alias *sqlparser.AliasedTableExpr Table sqlparser.TableName Predicates []sqlparser.Expr - VTable *vindexes.Table + VTable *vindexes.BaseTable } ) diff --git a/go/vt/vtgate/planbuilder/plancontext/planning_context_test.go b/go/vt/vtgate/planbuilder/plancontext/planning_context_test.go index 2844f7e87dc..b13c2112e3a 100644 --- a/go/vt/vtgate/planbuilder/plancontext/planning_context_test.go +++ b/go/vt/vtgate/planbuilder/plancontext/planning_context_test.go @@ -191,7 +191,7 @@ func (v *vschema) FindViewTarget(name sqlparser.TableName) (*vindexes.Keyspace, panic("implement me") } -func (v *vschema) FindTable(tablename sqlparser.TableName) (*vindexes.Table, string, topodatapb.TabletType, key.Destination, error) { +func (v *vschema) FindTable(tablename sqlparser.TableName) (*vindexes.BaseTable, string, topodatapb.TabletType, key.Destination, error) { // TODO implement me panic("implement me") } @@ -201,7 +201,7 @@ func (v *vschema) FindView(name sqlparser.TableName) sqlparser.TableStatement { panic("implement me") } -func (v *vschema) FindTableOrVindex(tablename sqlparser.TableName) (*vindexes.Table, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error) { +func (v *vschema) FindTableOrVindex(tablename sqlparser.TableName) (*vindexes.BaseTable, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error) { // TODO implement me panic("implement me") } diff --git a/go/vt/vtgate/planbuilder/plancontext/vschema.go b/go/vt/vtgate/planbuilder/plancontext/vschema.go index c810324f369..1b86225382c 100644 --- a/go/vt/vtgate/planbuilder/plancontext/vschema.go +++ b/go/vt/vtgate/planbuilder/plancontext/vschema.go @@ -24,11 +24,11 @@ type PlannerVersion = querypb.ExecuteOptions_PlannerVersion // VSchema defines the interface for this package to fetch // info about tables. type VSchema interface { - FindTable(tablename sqlparser.TableName) (*vindexes.Table, string, topodatapb.TabletType, key.Destination, error) + FindTable(tablename sqlparser.TableName) (*vindexes.BaseTable, string, topodatapb.TabletType, key.Destination, error) FindView(name sqlparser.TableName) sqlparser.TableStatement // FindViewTarget finds the target keyspace for the view table provided. FindViewTarget(name sqlparser.TableName) (*vindexes.Keyspace, error) - FindTableOrVindex(tablename sqlparser.TableName) (*vindexes.Table, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error) + FindTableOrVindex(tablename sqlparser.TableName) (*vindexes.BaseTable, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error) // SelectedKeyspace returns the current keyspace if set, otherwise returns an error SelectedKeyspace() (*vindexes.Keyspace, error) diff --git a/go/vt/vtgate/planbuilder/planner_test.go b/go/vt/vtgate/planbuilder/planner_test.go index c3caf9f3536..bd4c520510c 100644 --- a/go/vt/vtgate/planbuilder/planner_test.go +++ b/go/vt/vtgate/planbuilder/planner_test.go @@ -63,7 +63,7 @@ func TestBindingSubquery(t *testing.T) { require.NoError(t, err) selStmt := parse.(*sqlparser.Select) semTable, err := semantics.Analyze(selStmt, "d", &semantics.FakeSI{ - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "tabl": {Name: sqlparser.NewIdentifierCS("tabl")}, "foo": {Name: sqlparser.NewIdentifierCS("foo")}, }, diff --git a/go/vt/vtgate/planbuilder/update.go b/go/vt/vtgate/planbuilder/update.go index d653df867fb..fb3fd08ecb5 100644 --- a/go/vt/vtgate/planbuilder/update.go +++ b/go/vt/vtgate/planbuilder/update.go @@ -82,7 +82,7 @@ func gen4UpdateStmtPlanner( return newPlanResult(plan, operators.TablesUsed(op)...), nil } -func updateUnshardedShortcut(stmt *sqlparser.Update, ks *vindexes.Keyspace, tables []*vindexes.Table) engine.Primitive { +func updateUnshardedShortcut(stmt *sqlparser.Update, ks *vindexes.Keyspace, tables []*vindexes.BaseTable) engine.Primitive { edml := engine.NewDML() edml.Keyspace = ks edml.Opcode = engine.Unsharded diff --git a/go/vt/vtgate/planbuilder/vexplain.go b/go/vt/vtgate/planbuilder/vexplain.go index a12139c3068..061fa85473d 100644 --- a/go/vt/vtgate/planbuilder/vexplain.go +++ b/go/vt/vtgate/planbuilder/vexplain.go @@ -64,7 +64,7 @@ func explainTabPlan(explain *sqlparser.ExplainTab, vschema plancontext.VSchema) return nil, err } } else { - var tbl *vindexes.Table + var tbl *vindexes.BaseTable var err error tbl, _, _, _, dest, err = vschema.FindTableOrVindex(explain.Table) if err != nil { diff --git a/go/vt/vtgate/semantics/FakeSI.go b/go/vt/vtgate/semantics/FakeSI.go index cb1b9cec094..8e24a029002 100644 --- a/go/vt/vtgate/semantics/FakeSI.go +++ b/go/vt/vtgate/semantics/FakeSI.go @@ -32,7 +32,7 @@ var _ SchemaInformation = (*FakeSI)(nil) // FakeSI is a fake SchemaInformation for testing type FakeSI struct { - Tables map[string]*vindexes.Table + Tables map[string]*vindexes.BaseTable VindexTables map[string]vindexes.Vindex KsForeignKeyMode map[string]vschemapb.Keyspace_ForeignKeyMode KsError map[string]error @@ -40,7 +40,7 @@ type FakeSI struct { } // FindTableOrVindex implements the SchemaInformation interface -func (s *FakeSI) FindTableOrVindex(tablename sqlparser.TableName) (*vindexes.Table, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error) { +func (s *FakeSI) FindTableOrVindex(tablename sqlparser.TableName) (*vindexes.BaseTable, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error) { table, ok := s.Tables[sqlparser.String(tablename)] if ok { return table, nil, "", 0, nil, nil diff --git a/go/vt/vtgate/semantics/analyzer_test.go b/go/vt/vtgate/semantics/analyzer_test.go index 3f7a21cb6ac..c7f24e6c73c 100644 --- a/go/vt/vtgate/semantics/analyzer_test.go +++ b/go/vt/vtgate/semantics/analyzer_test.go @@ -143,7 +143,7 @@ func TestBindingSingleAliasedTableNegative(t *testing.T) { parse, err := sqlparser.NewTestParser().Parse(query) require.NoError(t, err) st, err := Analyze(parse, "", &FakeSI{ - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t": {Name: sqlparser.NewIdentifierCS("t")}, }, }) @@ -294,7 +294,7 @@ func TestBindingMultiTableNegative(t *testing.T) { parse, err := sqlparser.NewTestParser().Parse(query) require.NoError(t, err) _, err = Analyze(parse, "d", &FakeSI{ - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "tabl": {Name: sqlparser.NewIdentifierCS("tabl")}, "foo": {Name: sqlparser.NewIdentifierCS("foo")}, }, @@ -318,7 +318,7 @@ func TestBindingMultiAliasedTableNegative(t *testing.T) { parse, err := sqlparser.NewTestParser().Parse(query) require.NoError(t, err) _, err = Analyze(parse, "d", &FakeSI{ - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "tabl": {Name: sqlparser.NewIdentifierCS("tabl")}, "foo": {Name: sqlparser.NewIdentifierCS("foo")}, }, @@ -383,7 +383,7 @@ func TestMissingTable(t *testing.T) { } func TestUnknownColumnMap2(t *testing.T) { - authoritativeTblA := vindexes.Table{ + authoritativeTblA := vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("a"), Columns: []vindexes.Column{{ Name: sqlparser.NewIdentifierCI("col2"), @@ -391,7 +391,7 @@ func TestUnknownColumnMap2(t *testing.T) { }}, ColumnListAuthoritative: true, } - authoritativeTblB := vindexes.Table{ + authoritativeTblB := vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("b"), Columns: []vindexes.Column{{ Name: sqlparser.NewIdentifierCI("col"), @@ -403,7 +403,7 @@ func TestUnknownColumnMap2(t *testing.T) { nonAuthoritativeTblA.ColumnListAuthoritative = false nonAuthoritativeTblB := authoritativeTblB nonAuthoritativeTblB.ColumnListAuthoritative = false - authoritativeTblAWithConflict := vindexes.Table{ + authoritativeTblAWithConflict := vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("a"), Columns: []vindexes.Column{{ Name: sqlparser.NewIdentifierCI("col"), @@ -411,7 +411,7 @@ func TestUnknownColumnMap2(t *testing.T) { }}, ColumnListAuthoritative: true, } - authoritativeTblBWithInt := vindexes.Table{ + authoritativeTblBWithInt := vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("b"), Columns: []vindexes.Column{{ Name: sqlparser.NewIdentifierCI("col"), @@ -422,40 +422,40 @@ func TestUnknownColumnMap2(t *testing.T) { tests := []struct { name string - schema map[string]*vindexes.Table + schema map[string]*vindexes.BaseTable err bool typ querypb.Type }{{ name: "no info about tables", - schema: map[string]*vindexes.Table{"a": {}, "b": {}}, + schema: map[string]*vindexes.BaseTable{"a": {}, "b": {}}, err: true, }, { name: "non authoritative columns", - schema: map[string]*vindexes.Table{"a": &nonAuthoritativeTblA, "b": &nonAuthoritativeTblA}, + schema: map[string]*vindexes.BaseTable{"a": &nonAuthoritativeTblA, "b": &nonAuthoritativeTblA}, err: true, }, { name: "non authoritative columns - one authoritative and one not", - schema: map[string]*vindexes.Table{"a": &nonAuthoritativeTblA, "b": &authoritativeTblB}, + schema: map[string]*vindexes.BaseTable{"a": &nonAuthoritativeTblA, "b": &authoritativeTblB}, err: false, typ: sqltypes.VarChar, }, { name: "non authoritative columns - one authoritative and one not", - schema: map[string]*vindexes.Table{"a": &authoritativeTblA, "b": &nonAuthoritativeTblB}, + schema: map[string]*vindexes.BaseTable{"a": &authoritativeTblA, "b": &nonAuthoritativeTblB}, err: false, typ: sqltypes.VarChar, }, { name: "authoritative columns", - schema: map[string]*vindexes.Table{"a": &authoritativeTblA, "b": &authoritativeTblB}, + schema: map[string]*vindexes.BaseTable{"a": &authoritativeTblA, "b": &authoritativeTblB}, err: false, typ: sqltypes.VarChar, }, { name: "authoritative columns", - schema: map[string]*vindexes.Table{"a": &authoritativeTblA, "b": &authoritativeTblBWithInt}, + schema: map[string]*vindexes.BaseTable{"a": &authoritativeTblA, "b": &authoritativeTblBWithInt}, err: false, typ: sqltypes.Int64, }, { name: "authoritative columns with overlap", - schema: map[string]*vindexes.Table{"a": &authoritativeTblAWithConflict, "b": &authoritativeTblB}, + schema: map[string]*vindexes.BaseTable{"a": &authoritativeTblAWithConflict, "b": &authoritativeTblB}, err: true, }} @@ -486,10 +486,10 @@ func TestUnknownColumnMap2(t *testing.T) { func TestUnknownPredicate(t *testing.T) { query := "select 1 from a, b where col = 1" - authoritativeTblA := &vindexes.Table{ + authoritativeTblA := &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("a"), } - authoritativeTblB := &vindexes.Table{ + authoritativeTblB := &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("b"), } @@ -497,12 +497,12 @@ func TestUnknownPredicate(t *testing.T) { tests := []struct { name string - schema map[string]*vindexes.Table + schema map[string]*vindexes.BaseTable err bool }{ { name: "no info about tables", - schema: map[string]*vindexes.Table{"a": authoritativeTblA, "b": authoritativeTblB}, + schema: map[string]*vindexes.BaseTable{"a": authoritativeTblA, "b": authoritativeTblB}, err: false, }, } @@ -534,7 +534,7 @@ func TestScoping(t *testing.T) { parse, err := sqlparser.NewTestParser().Parse(query.query) require.NoError(t, err) st, err := Analyze(parse, "user", &FakeSI{ - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t": {Name: sqlparser.NewIdentifierCS("t")}, }, }) @@ -1103,7 +1103,7 @@ func TestScopingWithWITH(t *testing.T) { parse, err := sqlparser.NewTestParser().Parse(query.query) require.NoError(t, err) st, err := Analyze(parse, "user", &FakeSI{ - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t": {Name: sqlparser.NewIdentifierCS("t")}, }, }) @@ -1188,7 +1188,7 @@ func TestScopingWVindexTables(t *testing.T) { require.NoError(t, err) hash, _ := vindexes.CreateVindex("hash", "user_index", nil) st, err := Analyze(parse, "user", &FakeSI{ - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t": {Name: sqlparser.NewIdentifierCS("t")}, }, VindexTables: map[string]vindexes.Vindex{ @@ -1451,7 +1451,7 @@ func TestScopingSubQueryJoinClause(t *testing.T) { require.NoError(t, err) st, err := Analyze(parse, "user", &FakeSI{ - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t": {Name: sqlparser.NewIdentifierCS("t")}, }, }) @@ -1481,7 +1481,7 @@ var ks3 = &vindexes.Keyspace{ // create table t2(uid bigint, name varchar(255)) func fakeSchemaInfo() *FakeSI { si := &FakeSI{ - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t": tableT(), "t1": tableT1(), "t2": tableT2(), @@ -1491,14 +1491,14 @@ func fakeSchemaInfo() *FakeSI { return si } -func tableT() *vindexes.Table { - return &vindexes.Table{ +func tableT() *vindexes.BaseTable { + return &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("t"), Keyspace: unsharded, } } -func tableT1() *vindexes.Table { - return &vindexes.Table{ +func tableT1() *vindexes.BaseTable { + return &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("t1"), Columns: []vindexes.Column{{ Name: sqlparser.NewIdentifierCI("id"), @@ -1511,8 +1511,8 @@ func tableT1() *vindexes.Table { Keyspace: ks2, } } -func tableT2() *vindexes.Table { - return &vindexes.Table{ +func tableT2() *vindexes.BaseTable { + return &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("t2"), Columns: []vindexes.Column{{ Name: sqlparser.NewIdentifierCI("uid"), @@ -1531,8 +1531,8 @@ func tableT2() *vindexes.Table { } } -func tableT3() *vindexes.Table { - return &vindexes.Table{ +func tableT3() *vindexes.BaseTable { + return &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("t3"), Columns: []vindexes.Column{{ Name: sqlparser.NewIdentifierCI("uid"), diff --git a/go/vt/vtgate/semantics/cte_table.go b/go/vt/vtgate/semantics/cte_table.go index 7083fea10d2..30cee8061d1 100644 --- a/go/vt/vtgate/semantics/cte_table.go +++ b/go/vt/vtgate/semantics/cte_table.go @@ -67,7 +67,7 @@ func (cte *CTETable) Name() (sqlparser.TableName, error) { return sqlparser.NewTableName(cte.TableName), nil } -func (cte *CTETable) GetVindexTable() *vindexes.Table { +func (cte *CTETable) GetVindexTable() *vindexes.BaseTable { return nil } diff --git a/go/vt/vtgate/semantics/derived_table.go b/go/vt/vtgate/semantics/derived_table.go index fc7e1cb391c..676679d2fa9 100644 --- a/go/vt/vtgate/semantics/derived_table.go +++ b/go/vt/vtgate/semantics/derived_table.go @@ -150,7 +150,7 @@ func (dt *DerivedTable) canShortCut() shortCut { } // GetVindexTable implements the TableInfo interface -func (dt *DerivedTable) GetVindexTable() *vindexes.Table { +func (dt *DerivedTable) GetVindexTable() *vindexes.BaseTable { return nil } diff --git a/go/vt/vtgate/semantics/derived_test.go b/go/vt/vtgate/semantics/derived_test.go index 8344fd1e261..3788baeae9a 100644 --- a/go/vt/vtgate/semantics/derived_test.go +++ b/go/vt/vtgate/semantics/derived_test.go @@ -113,7 +113,7 @@ func TestScopingWDerivedTables(t *testing.T) { parse, err := sqlparser.NewTestParser().Parse(query.query) require.NoError(t, err) st, err := Analyze(parse, "user", &FakeSI{ - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t": {Name: sqlparser.NewIdentifierCS("t"), Keyspace: ks2}, }, }) @@ -175,7 +175,7 @@ func TestDerivedTablesOrderClause(t *testing.T) { recursiveExpectation: TS0, expectation: TS1, }} - si := &FakeSI{Tables: map[string]*vindexes.Table{"t": {Name: sqlparser.NewIdentifierCS("t")}}} + si := &FakeSI{Tables: map[string]*vindexes.BaseTable{"t": {Name: sqlparser.NewIdentifierCS("t")}}} for _, query := range queries { t.Run(query.query, func(t *testing.T) { parse, err := sqlparser.NewTestParser().Parse(query.query) @@ -215,7 +215,7 @@ func TestScopingWComplexDerivedTables(t *testing.T) { parse, err := sqlparser.NewTestParser().Parse(query.query) require.NoError(t, err) st, err := Analyze(parse, "user", &FakeSI{ - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t": {Name: sqlparser.NewIdentifierCS("t")}, }, }) diff --git a/go/vt/vtgate/semantics/early_rewriter_test.go b/go/vt/vtgate/semantics/early_rewriter_test.go index 1ec7786a46c..29da6ab51ee 100644 --- a/go/vt/vtgate/semantics/early_rewriter_test.go +++ b/go/vt/vtgate/semantics/early_rewriter_test.go @@ -35,7 +35,7 @@ func TestExpandStar(t *testing.T) { Sharded: true, } schemaInfo := &FakeSI{ - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Keyspace: ks, Name: sqlparser.NewIdentifierCS("t1"), @@ -226,7 +226,7 @@ func assertExpandedColumns(t *testing.T, st *SemTable, expandedColumns string) { func TestRewriteJoinUsingColumns(t *testing.T) { schemaInfo := &FakeSI{ - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Columns: []vindexes.Column{{ @@ -309,7 +309,7 @@ func TestRewriteJoinUsingColumns(t *testing.T) { func TestGroupByColumnName(t *testing.T) { schemaInfo := &FakeSI{ - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Columns: []vindexes.Column{{ @@ -393,7 +393,7 @@ func TestGroupByColumnName(t *testing.T) { func TestGroupByLiteral(t *testing.T) { schemaInfo := &FakeSI{ - Tables: map[string]*vindexes.Table{}, + Tables: map[string]*vindexes.BaseTable{}, } cDB := "db" tcases := []struct { @@ -437,7 +437,7 @@ func TestGroupByLiteral(t *testing.T) { func TestOrderByLiteral(t *testing.T) { schemaInfo := &FakeSI{ - Tables: map[string]*vindexes.Table{}, + Tables: map[string]*vindexes.BaseTable{}, } cDB := "db" tcases := []struct { @@ -620,7 +620,7 @@ func TestHavingColumnName(t *testing.T) { func getSchemaWithKnownColumns() *FakeSI { schemaInfo := &FakeSI{ - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Keyspace: &vindexes.Keyspace{Name: "ks", Sharded: true}, Name: sqlparser.NewIdentifierCS("t1"), @@ -753,7 +753,7 @@ func TestOrderByColumnName(t *testing.T) { } func TestSemTableDependenciesAfterExpandStar(t *testing.T) { - schemaInfo := &FakeSI{Tables: map[string]*vindexes.Table{ + schemaInfo := &FakeSI{Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Columns: []vindexes.Column{{ @@ -812,7 +812,7 @@ func TestRewriteNot(t *testing.T) { Sharded: true, } schemaInfo := &FakeSI{ - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Keyspace: ks, Name: sqlparser.NewIdentifierCS("t1"), @@ -866,7 +866,7 @@ func TestOrderByDerivedTable(t *testing.T) { Sharded: true, } schemaInfo := &FakeSI{ - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Keyspace: ks, Name: sqlparser.NewIdentifierCS("t1"), diff --git a/go/vt/vtgate/semantics/foreign_keys_test.go b/go/vt/vtgate/semantics/foreign_keys_test.go index a46c67c9710..e59f06fb435 100644 --- a/go/vt/vtgate/semantics/foreign_keys_test.go +++ b/go/vt/vtgate/semantics/foreign_keys_test.go @@ -27,7 +27,7 @@ import ( "vitess.io/vitess/go/vt/vtgate/vindexes" ) -var parentTbl = &vindexes.Table{ +var parentTbl = &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("parentt"), Keyspace: &vindexes.Keyspace{ Name: "ks", @@ -36,7 +36,7 @@ var parentTbl = &vindexes.Table{ var tbl = map[string]TableInfo{ "t0": &RealTable{ - Table: &vindexes.Table{ + Table: &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("t0"), Keyspace: &vindexes.Keyspace{Name: "ks"}, ChildForeignKeys: []vindexes.ChildFKInfo{ @@ -50,7 +50,7 @@ var tbl = map[string]TableInfo{ }, }, "t1": &RealTable{ - Table: &vindexes.Table{ + Table: &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("t1"), Keyspace: &vindexes.Keyspace{Name: "ks_unmanaged", Sharded: true}, ChildForeignKeys: []vindexes.ChildFKInfo{ @@ -60,19 +60,19 @@ var tbl = map[string]TableInfo{ }, }, "t2": &RealTable{ - Table: &vindexes.Table{ + Table: &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("t2"), Keyspace: &vindexes.Keyspace{Name: "ks"}, }, }, "t3": &RealTable{ - Table: &vindexes.Table{ + Table: &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("t3"), Keyspace: &vindexes.Keyspace{Name: "undefined_ks", Sharded: true}, }, }, "t4": &RealTable{ - Table: &vindexes.Table{ + Table: &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("t4"), Keyspace: &vindexes.Keyspace{Name: "ks"}, ChildForeignKeys: []vindexes.ChildFKInfo{ @@ -92,7 +92,7 @@ var tbl = map[string]TableInfo{ }, }, "t5": &RealTable{ - Table: &vindexes.Table{ + Table: &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("t5"), Keyspace: &vindexes.Keyspace{Name: "ks"}, ChildForeignKeys: []vindexes.ChildFKInfo{ @@ -110,7 +110,7 @@ var tbl = map[string]TableInfo{ }, }, "t6": &RealTable{ - Table: &vindexes.Table{ + Table: &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("t6"), Keyspace: &vindexes.Keyspace{Name: "ks"}, ChildForeignKeys: []vindexes.ChildFKInfo{ @@ -552,7 +552,7 @@ func TestGetInvolvedForeignKeys(t *testing.T) { } } -func ckInfo(cTable *vindexes.Table, pCols []string, cCols []string, refAction sqlparser.ReferenceAction) vindexes.ChildFKInfo { +func ckInfo(cTable *vindexes.BaseTable, pCols []string, cCols []string, refAction sqlparser.ReferenceAction) vindexes.ChildFKInfo { return vindexes.ChildFKInfo{ Table: cTable, ParentColumns: sqlparser.MakeColumns(pCols...), @@ -561,7 +561,7 @@ func ckInfo(cTable *vindexes.Table, pCols []string, cCols []string, refAction sq } } -func pkInfo(parentTable *vindexes.Table, pCols []string, cCols []string) vindexes.ParentFKInfo { +func pkInfo(parentTable *vindexes.BaseTable, pCols []string, cCols []string) vindexes.ParentFKInfo { return vindexes.ParentFKInfo{ Table: parentTable, ParentColumns: sqlparser.MakeColumns(pCols...), diff --git a/go/vt/vtgate/semantics/info_schema.go b/go/vt/vtgate/semantics/info_schema.go index b33a20620e4..c15056ce033 100644 --- a/go/vt/vtgate/semantics/info_schema.go +++ b/go/vt/vtgate/semantics/info_schema.go @@ -1627,7 +1627,7 @@ func loadSchemaInfo(version string) map[string][]vindexes.Column { } // FindTableOrVindex implements the SchemaInformation interface -func (i *infoSchemaWithColumns) FindTableOrVindex(tbl sqlparser.TableName) (*vindexes.Table, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error) { +func (i *infoSchemaWithColumns) FindTableOrVindex(tbl sqlparser.TableName) (*vindexes.BaseTable, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error) { if !strings.EqualFold(tbl.Qualifier.String(), "information_schema") { return i.inner.FindTableOrVindex(tbl) } @@ -1636,7 +1636,7 @@ func (i *infoSchemaWithColumns) FindTableOrVindex(tbl sqlparser.TableName) (*vin if !found { return nil, nil, "", topodatapb.TabletType_UNKNOWN, nil, vindexes.NotFoundError{TableName: tbl.Name.String()} } - vtbl := &vindexes.Table{ + vtbl := &vindexes.BaseTable{ Type: "View", Name: sqlparser.NewIdentifierCS(tbl.Name.String()), Columns: cols, diff --git a/go/vt/vtgate/semantics/real_table.go b/go/vt/vtgate/semantics/real_table.go index 64f3ac5f3f0..55dd25a5064 100644 --- a/go/vt/vtgate/semantics/real_table.go +++ b/go/vt/vtgate/semantics/real_table.go @@ -32,7 +32,7 @@ import ( type RealTable struct { dbName, tableName string ASTNode *sqlparser.AliasedTableExpr - Table *vindexes.Table + Table *vindexes.BaseTable CTE *CTE VindexHint *sqlparser.IndexHint MirrorRule *vindexes.MirrorRule @@ -207,7 +207,7 @@ func (r *RealTable) canShortCut() shortCut { } // GetVindexTable implements the TableInfo interface -func (r *RealTable) GetVindexTable() *vindexes.Table { +func (r *RealTable) GetVindexTable() *vindexes.BaseTable { return r.Table } diff --git a/go/vt/vtgate/semantics/semantic_table.go b/go/vt/vtgate/semantics/semantic_table.go index e3eead71c90..0227ee04137 100644 --- a/go/vt/vtgate/semantics/semantic_table.go +++ b/go/vt/vtgate/semantics/semantic_table.go @@ -39,7 +39,7 @@ type ( Name() (sqlparser.TableName, error) // GetVindexTable returns the vschema version of this TableInfo - GetVindexTable() *vindexes.Table + GetVindexTable() *vindexes.BaseTable // IsInfSchema returns true if this table is information_schema IsInfSchema() bool @@ -165,7 +165,7 @@ type ( // SchemaInformation is used to provide table information from Vschema. SchemaInformation interface { - FindTableOrVindex(tablename sqlparser.TableName) (*vindexes.Table, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error) + FindTableOrVindex(tablename sqlparser.TableName) (*vindexes.BaseTable, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error) ConnCollation() collations.ID Environment() *vtenv.Environment // ForeignKeyMode returns the foreign_key flag value @@ -436,7 +436,7 @@ func (st *SemTable) HasNonLiteralForeignKeyUpdate(updExprs sqlparser.UpdateExprs } // isShardScoped checks if the foreign key constraint is shard-scoped or not. It uses the vindex information to make this call. -func isShardScoped(pTable *vindexes.Table, cTable *vindexes.Table, pCols sqlparser.Columns, cCols sqlparser.Columns) bool { +func isShardScoped(pTable *vindexes.BaseTable, cTable *vindexes.BaseTable, pCols sqlparser.Columns, cCols sqlparser.Columns) bool { if !pTable.Keyspace.Sharded { return true } @@ -762,11 +762,11 @@ func (st *SemTable) ColumnLookup(col *sqlparser.ColName) (int, error) { } // SingleUnshardedKeyspace returns the single keyspace if all tables in the query are in the same, unsharded keyspace -func (st *SemTable) SingleUnshardedKeyspace() (ks *vindexes.Keyspace, tables []*vindexes.Table) { +func (st *SemTable) SingleUnshardedKeyspace() (ks *vindexes.Keyspace, tables []*vindexes.BaseTable) { return singleUnshardedKeyspace(st.Tables) } -func singleUnshardedKeyspace(tableInfos []TableInfo) (ks *vindexes.Keyspace, tables []*vindexes.Table) { +func singleUnshardedKeyspace(tableInfos []TableInfo) (ks *vindexes.Keyspace, tables []*vindexes.BaseTable) { validKS := func(this *vindexes.Keyspace) bool { if this == nil || this.Sharded { return false @@ -783,7 +783,7 @@ func singleUnshardedKeyspace(tableInfos []TableInfo) (ks *vindexes.Keyspace, tab for _, table := range tableInfos { sc := table.canShortCut() - var vtbl *vindexes.Table + var vtbl *vindexes.BaseTable switch sc { case dependsOnKeyspace: diff --git a/go/vt/vtgate/semantics/semantic_table_test.go b/go/vt/vtgate/semantics/semantic_table_test.go index 1f324215326..19f586d6190 100644 --- a/go/vt/vtgate/semantics/semantic_table_test.go +++ b/go/vt/vtgate/semantics/semantic_table_test.go @@ -69,7 +69,7 @@ func fakeSchemaInfoTest() *FakeSI { }} si := &FakeSI{ - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": {Name: sqlparser.NewIdentifierCS("t1"), Columns: cols1, ColumnListAuthoritative: true, Keyspace: ks2}, "t2": {Name: sqlparser.NewIdentifierCS("t2"), Columns: cols2, ColumnListAuthoritative: true, Keyspace: ks3}, }, @@ -141,22 +141,22 @@ func TestIsShardScoped(t *testing.T) { tests := []struct { name string - pTable *vindexes.Table - cTable *vindexes.Table + pTable *vindexes.BaseTable + cTable *vindexes.BaseTable pCols sqlparser.Columns cCols sqlparser.Columns wantedShardScoped bool }{ { name: "unsharded keyspace", - pTable: &vindexes.Table{ + pTable: &vindexes.BaseTable{ Keyspace: &vindexes.Keyspace{Name: "uks", Sharded: false}, }, wantedShardScoped: true, }, { name: "Primary vindexes don't match", - pTable: &vindexes.Table{ + pTable: &vindexes.BaseTable{ Keyspace: &vindexes.Keyspace{Name: "ks", Sharded: true}, ColumnVindexes: []*vindexes.ColumnVindex{ { @@ -164,7 +164,7 @@ func TestIsShardScoped(t *testing.T) { }, }, }, - cTable: &vindexes.Table{ + cTable: &vindexes.BaseTable{ ColumnVindexes: []*vindexes.ColumnVindex{ { Vindex: xxhashVindex, @@ -175,7 +175,7 @@ func TestIsShardScoped(t *testing.T) { }, { name: "Child primary vindex not part of the foreign key", - pTable: &vindexes.Table{ + pTable: &vindexes.BaseTable{ Keyspace: &vindexes.Keyspace{Name: "ks", Sharded: true}, ColumnVindexes: []*vindexes.ColumnVindex{ { @@ -183,7 +183,7 @@ func TestIsShardScoped(t *testing.T) { }, }, }, - cTable: &vindexes.Table{ + cTable: &vindexes.BaseTable{ ColumnVindexes: []*vindexes.ColumnVindex{ { Vindex: hashVindex, @@ -196,7 +196,7 @@ func TestIsShardScoped(t *testing.T) { }, { name: "Parent primary vindex not part of the foreign key", - pTable: &vindexes.Table{ + pTable: &vindexes.BaseTable{ Keyspace: &vindexes.Keyspace{Name: "ks", Sharded: true}, ColumnVindexes: []*vindexes.ColumnVindex{ { @@ -205,7 +205,7 @@ func TestIsShardScoped(t *testing.T) { }, }, }, - cTable: &vindexes.Table{ + cTable: &vindexes.BaseTable{ ColumnVindexes: []*vindexes.ColumnVindex{ { Vindex: hashVindex, @@ -219,7 +219,7 @@ func TestIsShardScoped(t *testing.T) { }, { name: "Indexes order doesn't match", - pTable: &vindexes.Table{ + pTable: &vindexes.BaseTable{ Keyspace: &vindexes.Keyspace{Name: "ks", Sharded: true}, ColumnVindexes: []*vindexes.ColumnVindex{ { @@ -228,7 +228,7 @@ func TestIsShardScoped(t *testing.T) { }, }, }, - cTable: &vindexes.Table{ + cTable: &vindexes.BaseTable{ ColumnVindexes: []*vindexes.ColumnVindex{ { Vindex: hashVindex, @@ -242,7 +242,7 @@ func TestIsShardScoped(t *testing.T) { }, { name: "Is shard scoped", - pTable: &vindexes.Table{ + pTable: &vindexes.BaseTable{ Keyspace: &vindexes.Keyspace{Name: "ks", Sharded: true}, ColumnVindexes: []*vindexes.ColumnVindex{ { @@ -251,7 +251,7 @@ func TestIsShardScoped(t *testing.T) { }, }, }, - cTable: &vindexes.Table{ + cTable: &vindexes.BaseTable{ ColumnVindexes: []*vindexes.ColumnVindex{ { Vindex: hashVindex, @@ -379,15 +379,15 @@ func TestGetParentForeignKeysList(t *testing.T) { // TestRemoveParentForeignKey tests the functionality of RemoveParentForeignKey func TestRemoveParentForeignKey(t *testing.T) { - t1Table := &vindexes.Table{ + t1Table := &vindexes.BaseTable{ Keyspace: &vindexes.Keyspace{Name: "ks"}, Name: sqlparser.NewIdentifierCS("t1"), } - t2Table := &vindexes.Table{ + t2Table := &vindexes.BaseTable{ Keyspace: &vindexes.Keyspace{Name: "ks"}, Name: sqlparser.NewIdentifierCS("t2"), } - t3Table := &vindexes.Table{ + t3Table := &vindexes.BaseTable{ Keyspace: &vindexes.Keyspace{Name: "ks"}, Name: sqlparser.NewIdentifierCS("t3"), } @@ -483,7 +483,7 @@ func TestRemoveParentForeignKey(t *testing.T) { func TestRemoveNonRequiredForeignKeys(t *testing.T) { hashVindex := &vindexes.Hash{} xxhashVindex := &vindexes.XXHash{} - t1Table := &vindexes.Table{ + t1Table := &vindexes.BaseTable{ Keyspace: &vindexes.Keyspace{Name: "ks", Sharded: true}, Name: sqlparser.NewIdentifierCS("t1"), ColumnVindexes: []*vindexes.ColumnVindex{ @@ -493,7 +493,7 @@ func TestRemoveNonRequiredForeignKeys(t *testing.T) { }, }, } - t2Table := &vindexes.Table{ + t2Table := &vindexes.BaseTable{ Keyspace: &vindexes.Keyspace{Name: "ks", Sharded: true}, Name: sqlparser.NewIdentifierCS("t2"), ColumnVindexes: []*vindexes.ColumnVindex{ @@ -503,7 +503,7 @@ func TestRemoveNonRequiredForeignKeys(t *testing.T) { }, }, } - t4Table := &vindexes.Table{ + t4Table := &vindexes.BaseTable{ Keyspace: &vindexes.Keyspace{Name: "ks", Sharded: true}, Name: sqlparser.NewIdentifierCS("t4"), ColumnVindexes: []*vindexes.ColumnVindex{ @@ -513,7 +513,7 @@ func TestRemoveNonRequiredForeignKeys(t *testing.T) { }, }, } - t3Table := &vindexes.Table{ + t3Table := &vindexes.BaseTable{ Keyspace: &vindexes.Keyspace{Name: "ks2"}, Name: sqlparser.NewIdentifierCS("t3"), } @@ -752,7 +752,7 @@ func TestRemoveNonRequiredForeignKeys(t *testing.T) { func TestIsFkDependentColumnUpdated(t *testing.T) { keyspaceName := "ks" - t3Table := &vindexes.Table{ + t3Table := &vindexes.BaseTable{ Keyspace: &vindexes.Keyspace{Name: keyspaceName}, Name: sqlparser.NewIdentifierCS("t3"), } @@ -769,7 +769,7 @@ func TestIsFkDependentColumnUpdated(t *testing.T) { KsForeignKeyMode: map[string]vschemapb.Keyspace_ForeignKeyMode{ keyspaceName: vschemapb.Keyspace_managed, }, - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Keyspace: &vindexes.Keyspace{Name: keyspaceName}, @@ -787,7 +787,7 @@ func TestIsFkDependentColumnUpdated(t *testing.T) { KsForeignKeyMode: map[string]vschemapb.Keyspace_ForeignKeyMode{ keyspaceName: vschemapb.Keyspace_managed, }, - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Keyspace: &vindexes.Keyspace{Name: keyspaceName}, @@ -805,7 +805,7 @@ func TestIsFkDependentColumnUpdated(t *testing.T) { KsForeignKeyMode: map[string]vschemapb.Keyspace_ForeignKeyMode{ keyspaceName: vschemapb.Keyspace_managed, }, - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Keyspace: &vindexes.Keyspace{Name: keyspaceName}, @@ -823,7 +823,7 @@ func TestIsFkDependentColumnUpdated(t *testing.T) { KsForeignKeyMode: map[string]vschemapb.Keyspace_ForeignKeyMode{ keyspaceName: vschemapb.Keyspace_managed, }, - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Keyspace: &vindexes.Keyspace{Name: keyspaceName}, @@ -841,7 +841,7 @@ func TestIsFkDependentColumnUpdated(t *testing.T) { KsForeignKeyMode: map[string]vschemapb.Keyspace_ForeignKeyMode{ keyspaceName: vschemapb.Keyspace_managed, }, - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Keyspace: &vindexes.Keyspace{Name: keyspaceName, Sharded: true}, @@ -869,7 +869,7 @@ func TestIsFkDependentColumnUpdated(t *testing.T) { func TestHasNonLiteralForeignKeyUpdate(t *testing.T) { keyspaceName := "ks" - t3Table := &vindexes.Table{ + t3Table := &vindexes.BaseTable{ Keyspace: &vindexes.Keyspace{Name: keyspaceName}, Name: sqlparser.NewIdentifierCS("t3"), } @@ -886,7 +886,7 @@ func TestHasNonLiteralForeignKeyUpdate(t *testing.T) { KsForeignKeyMode: map[string]vschemapb.Keyspace_ForeignKeyMode{ keyspaceName: vschemapb.Keyspace_managed, }, - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Keyspace: &vindexes.Keyspace{Name: keyspaceName}, @@ -904,7 +904,7 @@ func TestHasNonLiteralForeignKeyUpdate(t *testing.T) { KsForeignKeyMode: map[string]vschemapb.Keyspace_ForeignKeyMode{ keyspaceName: vschemapb.Keyspace_managed, }, - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Keyspace: &vindexes.Keyspace{Name: keyspaceName}, @@ -922,7 +922,7 @@ func TestHasNonLiteralForeignKeyUpdate(t *testing.T) { KsForeignKeyMode: map[string]vschemapb.Keyspace_ForeignKeyMode{ keyspaceName: vschemapb.Keyspace_managed, }, - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Keyspace: &vindexes.Keyspace{Name: keyspaceName}, @@ -940,7 +940,7 @@ func TestHasNonLiteralForeignKeyUpdate(t *testing.T) { KsForeignKeyMode: map[string]vschemapb.Keyspace_ForeignKeyMode{ keyspaceName: vschemapb.Keyspace_managed, }, - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Keyspace: &vindexes.Keyspace{Name: keyspaceName}, @@ -958,7 +958,7 @@ func TestHasNonLiteralForeignKeyUpdate(t *testing.T) { KsForeignKeyMode: map[string]vschemapb.Keyspace_ForeignKeyMode{ keyspaceName: vschemapb.Keyspace_managed, }, - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Keyspace: &vindexes.Keyspace{Name: keyspaceName}, diff --git a/go/vt/vtgate/semantics/table_collector.go b/go/vt/vtgate/semantics/table_collector.go index 329ebcef254..e35165f600d 100644 --- a/go/vt/vtgate/semantics/table_collector.go +++ b/go/vt/vtgate/semantics/table_collector.go @@ -346,7 +346,7 @@ func (etc *earlyTableCollector) getCTE(t sqlparser.TableName) *CTE { } func (etc *earlyTableCollector) getTableInfo(node *sqlparser.AliasedTableExpr, t sqlparser.TableName, sc *scoper) (TableInfo, error) { - var tbl *vindexes.Table + var tbl *vindexes.BaseTable var vindex vindexes.Vindex if cteDef := etc.getCTE(t); cteDef != nil { cte, err := etc.buildRecursiveCTE(node, t, sc, cteDef) @@ -504,7 +504,7 @@ func (tc *tableCollector) addUnionDerivedTable( return scope.addTable(tableInfo) } -func newVindexTable(t sqlparser.IdentifierCS) *vindexes.Table { +func newVindexTable(t sqlparser.IdentifierCS) *vindexes.BaseTable { vindexCols := []vindexes.Column{ {Name: sqlparser.NewIdentifierCI("id"), Type: querypb.Type_VARBINARY}, {Name: sqlparser.NewIdentifierCI("keyspace_id"), Type: querypb.Type_VARBINARY}, @@ -514,7 +514,7 @@ func newVindexTable(t sqlparser.IdentifierCS) *vindexes.Table { {Name: sqlparser.NewIdentifierCI("shard"), Type: querypb.Type_VARBINARY}, } - return &vindexes.Table{ + return &vindexes.BaseTable{ Name: t, Columns: vindexCols, ColumnListAuthoritative: true, @@ -544,7 +544,7 @@ func (tc *tableCollector) tableInfoFor(id TableSet) (TableInfo, error) { func (etc *earlyTableCollector) createTable( t sqlparser.TableName, alias *sqlparser.AliasedTableExpr, - tbl *vindexes.Table, + tbl *vindexes.BaseTable, isInfSchema bool, vindex vindexes.Vindex, ) (TableInfo, error) { @@ -591,7 +591,7 @@ func (etc *earlyTableCollector) createTable( return table, nil } -func checkValidVindexHints(hint *sqlparser.IndexHint, tbl *vindexes.Table) error { +func checkValidVindexHints(hint *sqlparser.IndexHint, tbl *vindexes.BaseTable) error { if hint == nil { return nil } diff --git a/go/vt/vtgate/semantics/vindex_table.go b/go/vt/vtgate/semantics/vindex_table.go index c8ef271af5d..faac55c8116 100644 --- a/go/vt/vtgate/semantics/vindex_table.go +++ b/go/vt/vtgate/semantics/vindex_table.go @@ -47,7 +47,7 @@ func (v *VindexTable) getExprFor(_ string) (sqlparser.Expr, error) { } // GetVindexTable implements the TableInfo interface -func (v *VindexTable) GetVindexTable() *vindexes.Table { +func (v *VindexTable) GetVindexTable() *vindexes.BaseTable { return v.Table.GetVindexTable() } diff --git a/go/vt/vtgate/semantics/vtable.go b/go/vt/vtgate/semantics/vtable.go index 6cd7e34aecc..94dc74cdf34 100644 --- a/go/vt/vtgate/semantics/vtable.go +++ b/go/vt/vtgate/semantics/vtable.go @@ -100,7 +100,7 @@ func (v *vTableInfo) canShortCut() shortCut { } // GetVindexTable implements the TableInfo interface -func (v *vTableInfo) GetVindexTable() *vindexes.Table { +func (v *vTableInfo) GetVindexTable() *vindexes.BaseTable { return nil } diff --git a/go/vt/vtgate/vindexes/foreign_keys.go b/go/vt/vtgate/vindexes/foreign_keys.go index 275a0674998..e9f8c986d10 100644 --- a/go/vt/vtgate/vindexes/foreign_keys.go +++ b/go/vt/vtgate/vindexes/foreign_keys.go @@ -26,7 +26,7 @@ import ( // ParentFKInfo contains the parent foreign key info for the table. type ParentFKInfo struct { - Table *Table + Table *BaseTable ParentColumns sqlparser.Columns ChildColumns sqlparser.Columns } @@ -44,7 +44,7 @@ func (fk *ParentFKInfo) MarshalJSON() ([]byte, error) { }) } -func (fk *ParentFKInfo) String(childTable *Table) string { +func (fk *ParentFKInfo) String(childTable *BaseTable) string { var str strings.Builder str.WriteString(sqlparser.String(childTable.GetTableName())) for _, column := range fk.ChildColumns { @@ -58,7 +58,7 @@ func (fk *ParentFKInfo) String(childTable *Table) string { } // NewParentFkInfo creates a new ParentFKInfo. -func NewParentFkInfo(parentTbl *Table, fkDef *sqlparser.ForeignKeyDefinition) ParentFKInfo { +func NewParentFkInfo(parentTbl *BaseTable, fkDef *sqlparser.ForeignKeyDefinition) ParentFKInfo { return ParentFKInfo{ Table: parentTbl, ChildColumns: fkDef.Source, @@ -68,7 +68,7 @@ func NewParentFkInfo(parentTbl *Table, fkDef *sqlparser.ForeignKeyDefinition) Pa // ChildFKInfo contains the child foreign key info for the table. type ChildFKInfo struct { - Table *Table + Table *BaseTable ChildColumns sqlparser.Columns ParentColumns sqlparser.Columns Match sqlparser.MatchAction @@ -89,7 +89,7 @@ func (fk *ChildFKInfo) MarshalJSON() ([]byte, error) { }) } -func (fk *ChildFKInfo) String(parentTable *Table) string { +func (fk *ChildFKInfo) String(parentTable *BaseTable) string { var str strings.Builder str.WriteString(sqlparser.String(fk.Table.GetTableName())) for _, column := range fk.ChildColumns { @@ -103,7 +103,7 @@ func (fk *ChildFKInfo) String(parentTable *Table) string { } // NewChildFkInfo creates a new ChildFKInfo. -func NewChildFkInfo(childTbl *Table, fkDef *sqlparser.ForeignKeyDefinition) ChildFKInfo { +func NewChildFkInfo(childTbl *BaseTable, fkDef *sqlparser.ForeignKeyDefinition) ChildFKInfo { return ChildFKInfo{ Table: childTbl, ChildColumns: fkDef.Source, diff --git a/go/vt/vtgate/vindexes/vschema.go b/go/vt/vtgate/vindexes/vschema.go index 05081a3c9ba..3f9f94c9361 100644 --- a/go/vt/vtgate/vindexes/vschema.go +++ b/go/vt/vtgate/vindexes/vschema.go @@ -70,7 +70,7 @@ type VSchema struct { // table is uniquely named, the value will be the qualified Table object // with the keyspace where this table exists. If multiple keyspaces have a // table with the same name, the value will be a `nil`. - globalTables map[string]*Table + globalTables map[string]Table uniqueVindexes map[string]Vindex Keyspaces map[string]*KeyspaceSchema `json:"keyspaces"` ShardRoutingRules map[string]string `json:"shard_routing_rules"` @@ -83,8 +83,8 @@ type VSchema struct { // MirrorRule represents one mirror rule. type MirrorRule struct { Error error - Percent float32 `json:"percent,omitempty"` - Table *Table `json:"table,omitempty"` + Percent float32 `json:"percent,omitempty"` + Table *BaseTable `json:"table,omitempty"` } // MarshalJSON returns a JSON representation of MirrorRule. @@ -94,7 +94,7 @@ func (mr *MirrorRule) MarshalJSON() ([]byte, error) { } return json.Marshal(struct { Percent float32 - Table *Table + Table *BaseTable }{ Percent: mr.Percent, Table: mr.Table, @@ -103,7 +103,7 @@ func (mr *MirrorRule) MarshalJSON() ([]byte, error) { // RoutingRule represents one routing rule. type RoutingRule struct { - Tables []*Table + Tables []*BaseTable Error error } @@ -120,8 +120,15 @@ func (rr *RoutingRule) MarshalJSON() ([]byte, error) { return json.Marshal(tables) } -// Table represents a table in VSchema. -type Table struct { +// View represents a view in VSchema. +type View struct { + Name string + Keyspace *Keyspace + Statement sqlparser.TableStatement +} + +// BaseTable represents a table in VSchema. +type BaseTable struct { Type string `json:"type,omitempty"` Name sqlparser.IdentifierCS `json:"name"` Keyspace *Keyspace `json:"-"` @@ -137,7 +144,7 @@ type Table struct { // // This is useful in route-planning for quickly selecting the optimal route // when JOIN-ing a reference table to a sharded table. - ReferencedBy map[string]*Table `json:"-"` + ReferencedBy map[string]*BaseTable `json:"-"` // Source is a keyspace-qualified table name that points to the source of a // reference table. Only applicable for tables with Type set to "reference". Source *Source `json:"source,omitempty"` @@ -153,7 +160,7 @@ type Table struct { } // GetTableName gets the sqlparser.TableName for the vindex Table. -func (t *Table) GetTableName() sqlparser.TableName { +func (t *BaseTable) GetTableName() sqlparser.TableName { return sqlparser.NewTableNameWithQualifier(t.Name.String(), t.Keyspace.Name) } @@ -262,9 +269,9 @@ func (col *Column) ToEvalengineType(collationEnv *collations.Environment) evalen type KeyspaceSchema struct { Keyspace *Keyspace ForeignKeyMode vschemapb.Keyspace_ForeignKeyMode - Tables map[string]*Table + Tables map[string]*BaseTable Vindexes map[string]Vindex - Views map[string]sqlparser.TableStatement + Views map[string]*View Error error MultiTenantSpec *vschemapb.MultiTenantSpec @@ -275,7 +282,7 @@ type KeyspaceSchema struct { type ksJSON struct { Sharded bool `json:"sharded,omitempty"` ForeignKeyMode string `json:"foreignKeyMode,omitempty"` - Tables map[string]*Table `json:"tables,omitempty"` + Tables map[string]*BaseTable `json:"tables,omitempty"` Vindexes map[string]Vindex `json:"vindexes,omitempty"` Views map[string]string `json:"views,omitempty"` Error string `json:"error,omitempty"` @@ -292,14 +299,14 @@ type ksJSON struct { func (ks *KeyspaceSchema) findTable( tablename string, constructUnshardedIfNotFound bool, -) *Table { +) *BaseTable { table := ks.Tables[tablename] if table != nil { return table } if constructUnshardedIfNotFound && !ks.Keyspace.Sharded { - return &Table{Name: sqlparser.NewIdentifierCS(tablename), Keyspace: ks.Keyspace} + return &BaseTable{Name: sqlparser.NewIdentifierCS(tablename), Keyspace: ks.Keyspace} } return nil @@ -321,7 +328,7 @@ func (ks *KeyspaceSchema) MarshalJSON() ([]byte, error) { ksJ.Views = make(map[string]string, len(ks.Views)) } for view, def := range ks.Views { - ksJ.Views[view] = sqlparser.String(def) + ksJ.Views[view] = sqlparser.String(def.Statement) } return json.Marshal(ksJ) @@ -330,7 +337,7 @@ func (ks *KeyspaceSchema) MarshalJSON() ([]byte, error) { // AutoIncrement contains the auto-inc information for a table. type AutoIncrement struct { Column sqlparser.IdentifierCI `json:"column"` - Sequence *Table `json:"sequence"` + Sequence *BaseTable `json:"sequence"` } type Source struct { @@ -348,7 +355,7 @@ func BuildVSchema(source *vschemapb.SrvVSchema, parser *sqlparser.Parser) (vsche vschema = &VSchema{ MirrorRules: make(map[string]*MirrorRule), RoutingRules: make(map[string]*RoutingRule), - globalTables: make(map[string]*Table), + globalTables: make(map[string]Table), uniqueVindexes: make(map[string]Vindex), Keyspaces: make(map[string]*KeyspaceSchema), created: time.Now(), @@ -380,7 +387,7 @@ func BuildKeyspaceSchema(input *vschemapb.Keyspace, keyspace string, parser *sql }, } vschema := &VSchema{ - globalTables: make(map[string]*Table), + globalTables: make(map[string]Table), uniqueVindexes: make(map[string]Vindex), Keyspaces: make(map[string]*KeyspaceSchema), } @@ -403,7 +410,7 @@ func buildKeyspaces(source *vschemapb.SrvVSchema, vschema *VSchema, parser *sqlp Sharded: ks.Sharded, }, ForeignKeyMode: replaceUnspecifiedForeignKeyMode(ks.ForeignKeyMode), - Tables: make(map[string]*Table), + Tables: make(map[string]*BaseTable), Vindexes: make(map[string]Vindex), MultiTenantSpec: ks.MultiTenantSpec, } @@ -436,16 +443,15 @@ func (vschema *VSchema) AddView(ksname, viewName, query string, parser *sqlparse return vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "expected SELECT or UNION query, got %T", ast) } if ks.Views == nil { - ks.Views = make(map[string]sqlparser.TableStatement) + ks.Views = make(map[string]*View) } - ks.Views[viewName] = selectStmt - t := &Table{ - Type: TypeView, - Name: sqlparser.NewIdentifierCS(viewName), - Keyspace: ks.Keyspace, - ColumnListAuthoritative: true, + view := &View{ + Name: viewName, + Keyspace: ks.Keyspace, + Statement: selectStmt, } - vschema.addTableName(t) + ks.Views[viewName] = view + vschema.addToGlobalTables(view) return nil } @@ -478,7 +484,7 @@ func buildGlobalTables(source *vschemapb.SrvVSchema, vschema *VSchema) { // which means that the global tables are already populated with the tables from the sharded keyspaces and from // unsharded keyspaces which have tables specified in associated vschemas. func AddAdditionalGlobalTables(source *vschemapb.SrvVSchema, vschema *VSchema) { - newTables := make(map[string]*Table) + newTables := make(map[string]Table) // Collect valid uniquely named tables from unsharded keyspaces. for ksname, ks := range source.Keyspaces { @@ -499,6 +505,18 @@ func AddAdditionalGlobalTables(source *vschemapb.SrvVSchema, vschema *VSchema) { } } } + for tname, table := range ksvschema.Views { + // Ignore tables already global (i.e. if specified in the vschema of an unsharded keyspace) or ambiguous. + if _, found := vschema.globalTables[tname]; !found { + _, ok := newTables[tname] + if !ok { + table.Keyspace = ksvschema.Keyspace + newTables[tname] = table + } else { + newTables[tname] = nil + } + } + } } // Mark new tables found just once as globally routable, rest as ambiguous. @@ -515,18 +533,17 @@ func buildKeyspaceGlobalTables(vschema *VSchema, ksvschema *KeyspaceSchema) { if gt == nil { // Table name is already marked ambiguous, nothing to do. continue - } else { - // Special handling for reference tables which specify their source. - if t.Type == TypeReference && t.Source != nil { - // If the reference table points to the already stored - // global table, there is no ambiguity. - if t.Source.Qualifier.IsEmpty() || t.Source.Qualifier.String() == gt.Keyspace.Name { - continue - } + } + // Special handling for reference tables which specify their source. + if t.Type == TypeReference && t.Source != nil { + // If the reference table points to the already stored + // global table, there is no ambiguity. + if t.Source.Qualifier.IsEmpty() || t.Source.Qualifier.String() == gt.GetKeyspace().Name { + continue } - // Otherwise, mark this table name ambiguous. - vschema.globalTables[tname] = nil } + // Otherwise, mark this table name ambiguous. + vschema.globalTables[tname] = nil } else { // Reference tables which define a source with the same name may be // globally routable through their source, as long as the source @@ -662,7 +679,7 @@ func buildTables(ks *vschemapb.Keyspace, vschema *VSchema, ksvschema *KeyspaceSc ksvschema.Vindexes[vname] = vindex } for tname, table := range ks.Tables { - t := &Table{ + t := &BaseTable{ Name: sqlparser.NewIdentifierCS(tname), Keyspace: keyspace, ColumnListAuthoritative: table.ColumnListAuthoritative, @@ -887,8 +904,9 @@ func buildTables(ks *vschemapb.Keyspace, vschema *VSchema, ksvschema *KeyspaceSc return nil } -func (vschema *VSchema) addTableName(t *Table) { - tname := t.Name.String() +// addToGlobalTables adds a table to the global tables map if unique otherwise marks it as ambiguous. +func (vschema *VSchema) addToGlobalTables(t Table) { + tname := t.GetName() if _, ok := vschema.globalTables[tname]; ok { vschema.globalTables[tname] = nil } else { @@ -905,7 +923,7 @@ func resolveAutoIncrement(source *vschemapb.SrvVSchema, vschema *VSchema, parser continue } seqks, seqtab, err := parser.ParseTable(table.AutoIncrement.Sequence) - var seq *Table + var seq *BaseTable if err == nil { // Ensure that sequence tables also obey routing rules. seq, err = vschema.FindRoutedTable(seqks, seqtab, topodatapb.TabletType_PRIMARY) @@ -1299,7 +1317,7 @@ func buildMirrorRule(source *vschemapb.SrvVSchema, vschema *VSchema, parser *sql // keyspace in the vschema, and it's unsharded, then all table requests are considered // valid and belonging to that keyspace. // FindTable bypasses routing rules and returns at most one table. -func (vschema *VSchema) FindTable(keyspace, tablename string) (*Table, error) { +func (vschema *VSchema) FindTable(keyspace, tablename string) (*BaseTable, error) { table, err := vschema.findTable( keyspace, tablename, @@ -1333,7 +1351,7 @@ func (vschema *VSchema) FindTable(keyspace, tablename string) (*Table, error) { func (vschema *VSchema) findGlobalTable( tablename string, constructUnshardedIfNotFound bool, -) (*Table, error) { +) (Table, error) { if len(vschema.Keyspaces) == 1 { for _, ks := range vschema.Keyspaces { table := ks.findTable(tablename, constructUnshardedIfNotFound) @@ -1377,9 +1395,16 @@ func (vschema *VSchema) findTable( keyspace, tablename string, constructUnshardedIfNotFound bool, -) (*Table, error) { +) (*BaseTable, error) { if keyspace == "" { - return vschema.findGlobalTable(tablename, constructUnshardedIfNotFound) + tbl, err := vschema.findGlobalTable(tablename, constructUnshardedIfNotFound) + if err != nil || tbl == nil { + return nil, err + } + if tbl.IsBaseTable() { + return tbl.(*BaseTable), nil + } + return nil, vterrors.VT13001(fmt.Sprintf("found view `%s`.`%s`, expecting table", tbl.GetKeyspace().Name, tablename)) } ks, ok := vschema.Keyspaces[keyspace] if !ok { @@ -1426,7 +1451,7 @@ func (vschema *VSchema) findRoutedKeyspace(keyspace string, tabletType topodatap } // FindRoutedTable finds a table checking the routing rules. -func (vschema *VSchema) FindRoutedTable(keyspace, tablename string, tabletType topodatapb.TabletType) (*Table, error) { +func (vschema *VSchema) FindRoutedTable(keyspace, tablename string, tabletType topodatapb.TabletType) (*BaseTable, error) { keyspace = vschema.findRoutedKeyspace(keyspace, tabletType) qualified := tablename if keyspace != "" { @@ -1459,7 +1484,7 @@ func (vschema *VSchema) FindRoutedTable(keyspace, tablename string, tabletType t } // FindTableOrVindex finds a table or a Vindex by name using Find and FindVindex. -func (vschema *VSchema) FindTableOrVindex(keyspace, name string, tabletType topodatapb.TabletType) (*Table, Vindex, error) { +func (vschema *VSchema) FindTableOrVindex(keyspace, name string, tabletType topodatapb.TabletType) (*BaseTable, Vindex, error) { tables, err := vschema.FindRoutedTable(keyspace, name, tabletType) if err != nil { return nil, nil, err @@ -1479,22 +1504,11 @@ func (vschema *VSchema) FindTableOrVindex(keyspace, name string, tabletType topo func (vschema *VSchema) FindView(keyspace, name string) sqlparser.TableStatement { if keyspace == "" { - switch { - case len(vschema.Keyspaces) == 1: - for _, schema := range vschema.Keyspaces { - keyspace = schema.Keyspace.Name - break - } - default: - t, ok := vschema.globalTables[name] - if !ok { - return nil - } - if ok && t == nil { - return nil - } - keyspace = t.Keyspace.Name + t, err := vschema.findGlobalTable(name, false) + if err != nil || t == nil || t.IsBaseTable() { + return nil } + return t.(*View).Statement } ks := vschema.Keyspaces[keyspace] @@ -1502,21 +1516,18 @@ func (vschema *VSchema) FindView(keyspace, name string) sqlparser.TableStatement return nil } - statement, ok := ks.Views[name] + view, ok := ks.Views[name] if !ok { return nil } // We do this to make sure there is no shared state between uses of this AST - statement = sqlparser.Clone(statement) - sqlparser.SafeRewrite(statement, nil, func(cursor *sqlparser.Cursor) bool { + return sqlparser.CopyOnRewrite(view.Statement, nil, func(cursor *sqlparser.CopyOnWriteCursor) { col, ok := cursor.Node().(*sqlparser.ColName) if ok { cursor.Replace(sqlparser.NewColNameWithQualifier(col.Name.String(), col.Qualifier)) } - return true - }) - return statement + }, nil).(sqlparser.TableStatement) } // NotFoundError represents the error where the table name was not found @@ -1679,7 +1690,7 @@ func ChooseVindexForType(typ querypb.Type) (string, error) { } // FindBestColVindex finds the best ColumnVindex for VReplication. -func FindBestColVindex(table *Table) (*ColumnVindex, error) { +func FindBestColVindex(table *BaseTable) (*ColumnVindex, error) { if len(table.ColumnVindexes) == 0 { return nil, vterrors.Errorf( vtrpcpb.Code_INVALID_ARGUMENT, @@ -1743,7 +1754,7 @@ func FindVindexForSharding(tableName string, colVindexes []*ColumnVindex) (*Colu } // String prints the (possibly qualified) table name -func (t *Table) String() string { +func (t *BaseTable) String() string { res := "" if t == nil { return res @@ -1754,14 +1765,14 @@ func (t *Table) String() string { return res + t.Name.String() } -func (t *Table) addReferenceInKeyspace(keyspace string, table *Table) { +func (t *BaseTable) addReferenceInKeyspace(keyspace string, table *BaseTable) { if t.ReferencedBy == nil { - t.ReferencedBy = make(map[string]*Table) + t.ReferencedBy = make(map[string]*BaseTable) } t.ReferencedBy[keyspace] = table } -func (t *Table) getReferenceInKeyspace(keyspace string) *Table { +func (t *BaseTable) getReferenceInKeyspace(keyspace string) *BaseTable { if t.ReferencedBy == nil { return nil } @@ -1771,3 +1782,33 @@ func (t *Table) getReferenceInKeyspace(keyspace string) *Table { } return t } + +type Table interface { + IsBaseTable() bool + GetKeyspace() *Keyspace + GetName() string +} + +func (v *View) IsBaseTable() bool { + return false +} + +func (t *BaseTable) IsBaseTable() bool { + return true +} + +func (v *View) GetKeyspace() *Keyspace { + return v.Keyspace +} + +func (t *BaseTable) GetKeyspace() *Keyspace { + return t.Keyspace +} + +func (v *View) GetName() string { + return v.Name +} + +func (t *BaseTable) GetName() string { + return t.Name.String() +} diff --git a/go/vt/vtgate/vindexes/vschema_routing_test.go b/go/vt/vtgate/vindexes/vschema_routing_test.go index 48ac9239fbb..2b0b1bf7efe 100644 --- a/go/vt/vtgate/vindexes/vschema_routing_test.go +++ b/go/vt/vtgate/vindexes/vschema_routing_test.go @@ -307,7 +307,7 @@ func TestAutoGlobalRoutingBasic(t *testing.T) { // Verify the global tables ks := vschema.Keyspaces["sharded1"] - require.EqualValues(t, vschema.globalTables, map[string]*Table{ + require.EqualValues(t, vschema.globalTables, map[string]Table{ "table5": ks.Tables["table5"], "scommon1": ks.Tables["scommon1"], "scommon2": ks.Tables["scommon2"], @@ -419,7 +419,7 @@ func TestVSchemaRoutingRules(t *testing.T) { vindex1 := &stFU{ name: "stfu1", } - t1 := &Table{ + t1 := &BaseTable{ Name: sqlparser.NewIdentifierCS("t1"), Keyspace: ks1, ColumnVindexes: []*ColumnVindex{{ @@ -434,7 +434,7 @@ func TestVSchemaRoutingRules(t *testing.T) { t1.Ordered = []*ColumnVindex{ t1.ColumnVindexes[0], } - t2 := &Table{ + t2 := &BaseTable{ Name: sqlparser.NewIdentifierCS("t2"), Keyspace: ks2, } @@ -445,10 +445,10 @@ func TestVSchemaRoutingRules(t *testing.T) { Error: errors.New("table rt1 has more than one target: [ks1.t1 ks2.t2]"), }, "rt2": { - Tables: []*Table{t2}, + Tables: []*BaseTable{t2}, }, "escaped": { - Tables: []*Table{t2}, + Tables: []*BaseTable{t2}, }, "dup": { Error: errors.New("duplicate rule for entry dup"), @@ -466,7 +466,7 @@ func TestVSchemaRoutingRules(t *testing.T) { Error: errors.New("table t2 not found"), }, }, - globalTables: map[string]*Table{ + globalTables: map[string]Table{ "t1": t1, "t2": t2, }, @@ -477,7 +477,7 @@ func TestVSchemaRoutingRules(t *testing.T) { "ks1": { Keyspace: ks1, ForeignKeyMode: vschemapb.Keyspace_unmanaged, - Tables: map[string]*Table{ + Tables: map[string]*BaseTable{ "t1": t1, }, Vindexes: map[string]Vindex{ @@ -487,7 +487,7 @@ func TestVSchemaRoutingRules(t *testing.T) { "ks2": { ForeignKeyMode: vschemapb.Keyspace_managed, Keyspace: ks2, - Tables: map[string]*Table{ + Tables: map[string]*BaseTable{ "t2": t2, }, Vindexes: map[string]Vindex{}, diff --git a/go/vt/vtgate/vindexes/vschema_test.go b/go/vt/vtgate/vindexes/vschema_test.go index 70e70745e9b..10da50d4770 100644 --- a/go/vt/vtgate/vindexes/vschema_test.go +++ b/go/vt/vtgate/vindexes/vschema_test.go @@ -899,7 +899,7 @@ func TestVSchemaMirrorRules(t *testing.T) { name: "stfu1", } - ks3t1 := &Table{ + ks3t1 := &BaseTable{ Name: sqlparser.NewIdentifierCS("ks3t1"), Keyspace: ks3, ColumnVindexes: []*ColumnVindex{{ @@ -915,7 +915,7 @@ func TestVSchemaMirrorRules(t *testing.T) { ks3t1.ColumnVindexes[0], } - ks4t1 := &Table{ + ks4t1 := &BaseTable{ Name: sqlparser.NewIdentifierCS("ks4t1"), Keyspace: ks4, ColumnVindexes: []*ColumnVindex{{ @@ -946,7 +946,7 @@ func TestVSchemaMirrorRules(t *testing.T) { Error: errors.New("to table: invalid table name: 'ks2.ks2t2.c', it must be of the qualified form . (dots are not allowed in either name)"), }, "ks1.ks1t3": { - Table: &Table{ + Table: &BaseTable{ Name: sqlparser.NewIdentifierCS("ks2t3"), }, Percent: 50, @@ -955,7 +955,7 @@ func TestVSchemaMirrorRules(t *testing.T) { Error: errors.New("to table: tablet type may not be specified: 'ks2.ks2t4@replica'"), }, "ks1.ks1t5@replica": { - Table: &Table{ + Table: &BaseTable{ Name: sqlparser.NewIdentifierCS("ks2t5"), }, }, @@ -985,19 +985,19 @@ func TestVSchemaMirrorRules(t *testing.T) { "ks1": { Keyspace: ks1, ForeignKeyMode: vschemapb.Keyspace_unmanaged, - Tables: map[string]*Table{}, + Tables: map[string]*BaseTable{}, Vindexes: map[string]Vindex{}, }, "ks2": { ForeignKeyMode: vschemapb.Keyspace_unmanaged, Keyspace: ks2, - Tables: map[string]*Table{}, + Tables: map[string]*BaseTable{}, Vindexes: map[string]Vindex{}, }, "ks3": { ForeignKeyMode: vschemapb.Keyspace_unmanaged, Keyspace: ks3, - Tables: map[string]*Table{ + Tables: map[string]*BaseTable{ "ks3t1": ks3t1, }, Vindexes: map[string]Vindex{ @@ -1007,7 +1007,7 @@ func TestVSchemaMirrorRules(t *testing.T) { "ks4": { ForeignKeyMode: vschemapb.Keyspace_unmanaged, Keyspace: ks4, - Tables: map[string]*Table{ + Tables: map[string]*BaseTable{ "ks4t1": ks4t1, }, Vindexes: map[string]Vindex{ @@ -1224,7 +1224,7 @@ func TestFindVindexForSharding(t *testing.T) { } vindex1 := &stFU{name: "stfu1"} vindex2 := &stLN{name: "stln1"} - t1 := &Table{ + t1 := &BaseTable{ Name: sqlparser.NewIdentifierCS("t1"), Keyspace: ks, ColumnVindexes: []*ColumnVindex{ @@ -1261,7 +1261,7 @@ func TestFindVindexForShardingError(t *testing.T) { } vindex1 := &stLU{name: "stlu1"} vindex2 := &stLN{name: "stln1"} - t1 := &Table{ + t1 := &BaseTable{ Name: sqlparser.NewIdentifierCS("t1"), Keyspace: ks, ColumnVindexes: []*ColumnVindex{ @@ -1301,7 +1301,7 @@ func TestFindVindexForSharding2(t *testing.T) { } vindex1 := &stLU{name: "stlu1"} vindex2 := &stFU{name: "stfu1"} - t1 := &Table{ + t1 := &BaseTable{ Name: sqlparser.NewIdentifierCS("t1"), Keyspace: ks, ColumnVindexes: []*ColumnVindex{ @@ -1356,7 +1356,7 @@ func TestShardedVSchemaMultiColumnVindex(t *testing.T) { Sharded: true, } vindex1 := &stFU{name: "stfu1"} - t1 := &Table{ + t1 := &BaseTable{ Name: sqlparser.NewIdentifierCS("t1"), Keyspace: ks, ColumnVindexes: []*ColumnVindex{ @@ -1376,7 +1376,7 @@ func TestShardedVSchemaMultiColumnVindex(t *testing.T) { want := &VSchema{ MirrorRules: map[string]*MirrorRule{}, RoutingRules: map[string]*RoutingRule{}, - globalTables: map[string]*Table{ + globalTables: map[string]Table{ "t1": t1, }, uniqueVindexes: map[string]Vindex{ @@ -1386,7 +1386,7 @@ func TestShardedVSchemaMultiColumnVindex(t *testing.T) { "sharded": { ForeignKeyMode: vschemapb.Keyspace_disallow, Keyspace: ks, - Tables: map[string]*Table{ + Tables: map[string]*BaseTable{ "t1": t1}, Vindexes: map[string]Vindex{ "stfu1": vindex1}, @@ -1427,7 +1427,7 @@ func TestShardedVSchemaNotOwned(t *testing.T) { } vindex1 := &stLU{name: "stlu1"} vindex2 := &stFU{name: "stfu1"} - t1 := &Table{ + t1 := &BaseTable{ Name: sqlparser.NewIdentifierCS("t1"), Keyspace: ks, ColumnVindexes: []*ColumnVindex{ @@ -1453,7 +1453,7 @@ func TestShardedVSchemaNotOwned(t *testing.T) { want := &VSchema{ MirrorRules: map[string]*MirrorRule{}, RoutingRules: map[string]*RoutingRule{}, - globalTables: map[string]*Table{ + globalTables: map[string]Table{ "t1": t1, }, uniqueVindexes: map[string]Vindex{ @@ -1463,7 +1463,7 @@ func TestShardedVSchemaNotOwned(t *testing.T) { "sharded": { ForeignKeyMode: vschemapb.Keyspace_managed, Keyspace: ks, - Tables: map[string]*Table{ + Tables: map[string]*BaseTable{ "t1": t1, }, Vindexes: map[string]Vindex{ @@ -1550,18 +1550,18 @@ func TestBuildVSchemaDupSeq(t *testing.T) { ksb := &Keyspace{ Name: "ksb"} got := buildVSchema(&good) - t1a := &Table{ + t1a := &BaseTable{ Name: sqlparser.NewIdentifierCS("t1"), Keyspace: ksa, Type: "sequence"} - t1b := &Table{ + t1b := &BaseTable{ Name: sqlparser.NewIdentifierCS("t1"), Keyspace: ksb, Type: "sequence"} want := &VSchema{ MirrorRules: map[string]*MirrorRule{}, RoutingRules: map[string]*RoutingRule{}, - globalTables: map[string]*Table{ + globalTables: map[string]Table{ "t1": nil, }, uniqueVindexes: map[string]Vindex{}, @@ -1569,7 +1569,7 @@ func TestBuildVSchemaDupSeq(t *testing.T) { "ksa": { ForeignKeyMode: vschemapb.Keyspace_managed, Keyspace: ksa, - Tables: map[string]*Table{ + Tables: map[string]*BaseTable{ "t1": t1a, }, Vindexes: map[string]Vindex{}, @@ -1577,7 +1577,7 @@ func TestBuildVSchemaDupSeq(t *testing.T) { "ksb": { ForeignKeyMode: vschemapb.Keyspace_managed, Keyspace: ksb, - Tables: map[string]*Table{ + Tables: map[string]*BaseTable{ "t1": t1b, }, Vindexes: map[string]Vindex{}}}} @@ -1609,21 +1609,21 @@ func TestBuildVSchemaDupTable(t *testing.T) { ksa := &Keyspace{ Name: "ksa", } - t1a := &Table{ + t1a := &BaseTable{ Name: sqlparser.NewIdentifierCS("t1"), Keyspace: ksa, } ksb := &Keyspace{ Name: "ksb", } - t1b := &Table{ + t1b := &BaseTable{ Name: sqlparser.NewIdentifierCS("t1"), Keyspace: ksb, } want := &VSchema{ MirrorRules: map[string]*MirrorRule{}, RoutingRules: map[string]*RoutingRule{}, - globalTables: map[string]*Table{ + globalTables: map[string]Table{ "t1": nil, }, uniqueVindexes: map[string]Vindex{}, @@ -1631,7 +1631,7 @@ func TestBuildVSchemaDupTable(t *testing.T) { "ksa": { ForeignKeyMode: vschemapb.Keyspace_unmanaged, Keyspace: ksa, - Tables: map[string]*Table{ + Tables: map[string]*BaseTable{ "t1": t1a, }, Vindexes: map[string]Vindex{}, @@ -1639,7 +1639,7 @@ func TestBuildVSchemaDupTable(t *testing.T) { "ksb": { ForeignKeyMode: vschemapb.Keyspace_unmanaged, Keyspace: ksb, - Tables: map[string]*Table{ + Tables: map[string]*BaseTable{ "t1": t1b, }, Vindexes: map[string]Vindex{}, @@ -1714,7 +1714,7 @@ func TestBuildVSchemaDupVindex(t *testing.T) { Sharded: true, } vindex1 := &stLU{name: "stlu1"} - t1 := &Table{ + t1 := &BaseTable{ Name: sqlparser.NewIdentifierCS("t1"), Keyspace: ksa, ColumnVindexes: []*ColumnVindex{ @@ -1732,7 +1732,7 @@ func TestBuildVSchemaDupVindex(t *testing.T) { t1.Ordered = []*ColumnVindex{ t1.ColumnVindexes[0], } - t2 := &Table{ + t2 := &BaseTable{ Name: sqlparser.NewIdentifierCS("t1"), Keyspace: ksb, ColumnVindexes: []*ColumnVindex{ @@ -1753,7 +1753,7 @@ func TestBuildVSchemaDupVindex(t *testing.T) { want := &VSchema{ MirrorRules: map[string]*MirrorRule{}, RoutingRules: map[string]*RoutingRule{}, - globalTables: map[string]*Table{ + globalTables: map[string]Table{ "t1": nil, }, uniqueVindexes: map[string]Vindex{ @@ -1763,7 +1763,7 @@ func TestBuildVSchemaDupVindex(t *testing.T) { "ksa": { ForeignKeyMode: vschemapb.Keyspace_unmanaged, Keyspace: ksa, - Tables: map[string]*Table{ + Tables: map[string]*BaseTable{ "t1": t1, }, Vindexes: map[string]Vindex{ @@ -1773,7 +1773,7 @@ func TestBuildVSchemaDupVindex(t *testing.T) { "ksb": { ForeignKeyMode: vschemapb.Keyspace_unmanaged, Keyspace: ksb, - Tables: map[string]*Table{ + Tables: map[string]*BaseTable{ "t1": t2, }, Vindexes: map[string]Vindex{ @@ -2289,13 +2289,13 @@ func TestSequence(t *testing.T) { Name: "sharded", Sharded: true, } - seq := &Table{ + seq := &BaseTable{ Name: sqlparser.NewIdentifierCS("seq"), Keyspace: ksu, Type: "sequence", } vindex1 := &stFU{name: "stfu1"} - t1 := &Table{ + t1 := &BaseTable{ Name: sqlparser.NewIdentifierCS("t1"), Keyspace: kss, ColumnVindexes: []*ColumnVindex{ @@ -2316,7 +2316,7 @@ func TestSequence(t *testing.T) { t1.Ordered = []*ColumnVindex{ t1.ColumnVindexes[0], } - t2 := &Table{ + t2 := &BaseTable{ Name: sqlparser.NewIdentifierCS("t2"), Keyspace: kss, ColumnVindexes: []*ColumnVindex{ @@ -2340,7 +2340,7 @@ func TestSequence(t *testing.T) { want := &VSchema{ MirrorRules: map[string]*MirrorRule{}, RoutingRules: map[string]*RoutingRule{}, - globalTables: map[string]*Table{ + globalTables: map[string]Table{ "seq": seq, "t1": t1, "t2": t2, @@ -2352,7 +2352,7 @@ func TestSequence(t *testing.T) { "unsharded": { ForeignKeyMode: vschemapb.Keyspace_disallow, Keyspace: ksu, - Tables: map[string]*Table{ + Tables: map[string]*BaseTable{ "seq": seq, }, Vindexes: map[string]Vindex{}, @@ -2360,7 +2360,7 @@ func TestSequence(t *testing.T) { "sharded": { ForeignKeyMode: vschemapb.Keyspace_unmanaged, Keyspace: kss, - Tables: map[string]*Table{ + Tables: map[string]*BaseTable{ "t1": t1, "t2": t2, }, @@ -2553,7 +2553,7 @@ func TestFindTable(t *testing.T) { _, err = vschema.FindTable("", "none") require.EqualError(t, err, "table none not found") - ta := &Table{ + ta := &BaseTable{ Name: sqlparser.NewIdentifierCS("ta"), Keyspace: &Keyspace{ Name: "ksa", @@ -2563,12 +2563,12 @@ func TestFindTable(t *testing.T) { require.NoError(t, err) require.Equal(t, ta, got) - t2 := &Table{ + t2 := &BaseTable{ Name: sqlparser.NewIdentifierCS("t2"), Keyspace: &Keyspace{ Name: "ksa", }, - ReferencedBy: map[string]*Table{ + ReferencedBy: map[string]*BaseTable{ "ksb": { Type: "reference", Name: sqlparser.NewIdentifierCS("t2"), @@ -2592,7 +2592,7 @@ func TestFindTable(t *testing.T) { got, _ = vschema.FindTable("ksa", "ta") require.Equal(t, ta, got) - none := &Table{ + none := &BaseTable{ Name: sqlparser.NewIdentifierCS("none"), Keyspace: &Keyspace{ Name: "ksa", @@ -2779,18 +2779,18 @@ func TestBuildKeyspaceSchema(t *testing.T) { ks := &Keyspace{ Name: "ks", } - t1 := &Table{ + t1 := &BaseTable{ Name: sqlparser.NewIdentifierCS("t1"), Keyspace: ks, } - t2 := &Table{ + t2 := &BaseTable{ Name: sqlparser.NewIdentifierCS("t2"), Keyspace: ks, } want := &KeyspaceSchema{ Keyspace: ks, ForeignKeyMode: vschemapb.Keyspace_unmanaged, - Tables: map[string]*Table{ + Tables: map[string]*BaseTable{ "t1": t1, "t2": t2, }, @@ -2929,7 +2929,7 @@ func TestVSchemaJSON(t *testing.T) { Keyspace: &Keyspace{ Name: "k1", }, - Tables: map[string]*Table{ + Tables: map[string]*BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("n1"), Columns: []Column{{ @@ -2952,7 +2952,7 @@ func TestVSchemaJSON(t *testing.T) { Name: "k2", Sharded: true, }, - Tables: map[string]*Table{ + Tables: map[string]*BaseTable{ "t3": { Name: sqlparser.NewIdentifierCS("n3"), ColumnVindexes: []*ColumnVindex{{ @@ -3043,7 +3043,7 @@ func TestFindSingleKeyspace(t *testing.T) { }, } vschema := BuildVSchema(&input, sqlparser.NewTestParser()) - none := &Table{ + none := &BaseTable{ Name: sqlparser.NewIdentifierCS("none"), Keyspace: &Keyspace{ Name: "ksa", @@ -3194,7 +3194,7 @@ func TestSourceTableHasReferencedBy(t *testing.T) { require.NoError(t, err) src, err := vs.FindTable("unsharded", "src") require.NoError(t, err) - require.Equal(t, src.ReferencedBy, map[string]*Table{ + require.Equal(t, src.ReferencedBy, map[string]*BaseTable{ "sharded1": ref1, "sharded2": ref2, }) diff --git a/go/vt/vtgate/vschema_manager.go b/go/vt/vtgate/vschema_manager.go index e73bff4c196..7a1c5ee1d24 100644 --- a/go/vt/vtgate/vschema_manager.go +++ b/go/vt/vtgate/vschema_manager.go @@ -222,20 +222,14 @@ func (vm *VSchemaManager) updateViewInfo(ks *vindexes.KeyspaceSchema, ksName str if views == nil { return } - ks.Views = make(map[string]sqlparser.TableStatement, len(views)) + ks.Views = make(map[string]*vindexes.View, len(views)) for name, def := range views { - ks.Views[name] = sqlparser.Clone(def) - vTbl, ok := ks.Tables[name] - if ok { - vTbl.Type = vindexes.TypeView - } else { - // Adding view to the VSchema as a table. - ks.Tables[name] = &vindexes.Table{ - Type: vindexes.TypeView, - Name: sqlparser.NewIdentifierCS(name), - Keyspace: ks.Keyspace, - } + v := &vindexes.View{ + Name: name, + Keyspace: ks.Keyspace, + Statement: def, } + ks.Views[name] = v } } @@ -353,11 +347,11 @@ func addCrossEdges(g *graph.Graph[string], from []string, to []string) { } } -func setColumns(ks *vindexes.KeyspaceSchema, tblName string, columns []vindexes.Column) *vindexes.Table { +func setColumns(ks *vindexes.KeyspaceSchema, tblName string, columns []vindexes.Column) *vindexes.BaseTable { vTbl := ks.Tables[tblName] if vTbl == nil { // a table that is unknown by the vschema. we add it as a normal table - ks.Tables[tblName] = &vindexes.Table{ + ks.Tables[tblName] = &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS(tblName), Keyspace: ks.Keyspace, Columns: columns, diff --git a/go/vt/vtgate/vschema_manager_test.go b/go/vt/vtgate/vschema_manager_test.go index b4b7a20804f..9f6ca731884 100644 --- a/go/vt/vtgate/vschema_manager_test.go +++ b/go/vt/vtgate/vschema_manager_test.go @@ -27,30 +27,30 @@ func TestVSchemaUpdate(t *testing.T) { Nullable: true, }} ks := &vindexes.Keyspace{Name: "ks"} - tblNoCol := &vindexes.Table{Name: sqlparser.NewIdentifierCS("tbl"), Keyspace: ks, ColumnListAuthoritative: true} - tblCol1 := &vindexes.Table{Name: sqlparser.NewIdentifierCS("tbl"), Keyspace: ks, Columns: cols1, ColumnListAuthoritative: true} - tblCol2 := &vindexes.Table{Name: sqlparser.NewIdentifierCS("tbl"), Keyspace: ks, Columns: cols2, ColumnListAuthoritative: true} - tblCol2NA := &vindexes.Table{Name: sqlparser.NewIdentifierCS("tbl"), Keyspace: ks, Columns: cols2} + tblNoCol := &vindexes.BaseTable{Name: sqlparser.NewIdentifierCS("tbl"), Keyspace: ks, ColumnListAuthoritative: true} + tblCol1 := &vindexes.BaseTable{Name: sqlparser.NewIdentifierCS("tbl"), Keyspace: ks, Columns: cols1, ColumnListAuthoritative: true} + tblCol2 := &vindexes.BaseTable{Name: sqlparser.NewIdentifierCS("tbl"), Keyspace: ks, Columns: cols2, ColumnListAuthoritative: true} + tblCol2NA := &vindexes.BaseTable{Name: sqlparser.NewIdentifierCS("tbl"), Keyspace: ks, Columns: cols2} - vindexTable_multicol_t1 := &vindexes.Table{ + vindexTable_multicol_t1 := &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("multicol_t1"), Keyspace: ks, Columns: cols2, ColumnListAuthoritative: true, } - vindexTable_multicol_t2 := &vindexes.Table{ + vindexTable_multicol_t2 := &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("multicol_t2"), Keyspace: ks, Columns: cols2, ColumnListAuthoritative: true, } - vindexTable_t1 := &vindexes.Table{ + vindexTable_t1 := &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("t1"), Keyspace: ks, Columns: cols1, ColumnListAuthoritative: true, } - vindexTable_t2 := &vindexes.Table{ + vindexTable_t2 := &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("t2"), Keyspace: ks, Columns: cols1, @@ -84,7 +84,7 @@ func TestVSchemaUpdate(t *testing.T) { ParentColumns: sqlparserCols1, }) - idxTbl1 := &vindexes.Table{ + idxTbl1 := &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("idxTbl1"), Keyspace: ks, ColumnListAuthoritative: true, @@ -94,7 +94,7 @@ func TestVSchemaUpdate(t *testing.T) { {sqlparser.NewColName("c"), sqlparser.NewColName("d")}, }, } - idxTbl2 := &vindexes.Table{ + idxTbl2 := &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("idxTbl2"), Keyspace: ks, ColumnListAuthoritative: true, @@ -119,18 +119,18 @@ func TestVSchemaUpdate(t *testing.T) { ColumnListAuthoritative: false, }, }), - expected: makeTestVSchema("ks", false, map[string]*vindexes.Table{"tbl": tblCol2NA}), + expected: makeTestVSchema("ks", false, map[string]*vindexes.BaseTable{"tbl": tblCol2NA}), }, { name: "1 Schematracking- 0 srvVSchema", srvVschema: makeTestSrvVSchema("ks", false, nil), schema: map[string]*vindexes.TableInfo{"tbl": {Columns: cols1}}, - expected: makeTestVSchema("ks", false, map[string]*vindexes.Table{"tbl": tblCol1}), + expected: makeTestVSchema("ks", false, map[string]*vindexes.BaseTable{"tbl": tblCol1}), }, { name: "1 Schematracking - 1 srvVSchema (no columns) not authoritative", srvVschema: makeTestSrvVSchema("ks", false, map[string]*vschemapb.Table{"tbl": {}}), schema: map[string]*vindexes.TableInfo{"tbl": {Columns: cols1}}, // schema will override what srvSchema has. - expected: makeTestVSchema("ks", false, map[string]*vindexes.Table{"tbl": tblCol1}), + expected: makeTestVSchema("ks", false, map[string]*vindexes.BaseTable{"tbl": tblCol1}), }, { name: "1 Schematracking - 1 srvVSchema (have columns) not authoritative", srvVschema: makeTestSrvVSchema("ks", false, map[string]*vschemapb.Table{ @@ -141,7 +141,7 @@ func TestVSchemaUpdate(t *testing.T) { }), schema: map[string]*vindexes.TableInfo{"tbl": {Columns: cols1}}, // schema will override what srvSchema has. - expected: makeTestVSchema("ks", false, map[string]*vindexes.Table{"tbl": tblCol1}), + expected: makeTestVSchema("ks", false, map[string]*vindexes.BaseTable{"tbl": tblCol1}), }, { name: "1 Schematracking - 1 srvVSchema (no columns) authoritative", srvVschema: makeTestSrvVSchema("ks", false, map[string]*vschemapb.Table{"tbl": { @@ -149,7 +149,7 @@ func TestVSchemaUpdate(t *testing.T) { }}), schema: map[string]*vindexes.TableInfo{"tbl": {Columns: cols1}}, // schema will override what srvSchema has. - expected: makeTestVSchema("ks", false, map[string]*vindexes.Table{"tbl": tblNoCol}), + expected: makeTestVSchema("ks", false, map[string]*vindexes.BaseTable{"tbl": tblNoCol}), }, { name: "1 Schematracking - 1 srvVSchema (have columns) authoritative", srvVschema: makeTestSrvVSchema("ks", false, map[string]*vschemapb.Table{ @@ -160,7 +160,7 @@ func TestVSchemaUpdate(t *testing.T) { }), schema: map[string]*vindexes.TableInfo{"tbl": {Columns: cols1}}, // schema tracker will be ignored for authoritative tables. - expected: makeTestVSchema("ks", false, map[string]*vindexes.Table{"tbl": tblCol2}), + expected: makeTestVSchema("ks", false, map[string]*vindexes.BaseTable{"tbl": tblCol2}), }, { name: "srvVschema received as nil", schema: map[string]*vindexes.TableInfo{"tbl": {Columns: cols1}}, @@ -241,7 +241,7 @@ func TestVSchemaUpdate(t *testing.T) { Keyspace: ks, ForeignKeyMode: vschemapb.Keyspace_managed, Vindexes: map[string]vindexes.Vindex{}, - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": vindexTable_t1, "t2": vindexTable_t2, "multicol_t1": vindexTable_multicol_t1, @@ -281,7 +281,7 @@ func TestVSchemaUpdate(t *testing.T) { }, }, srvVschema: makeTestSrvVSchema("ks", false, nil), - expected: makeTestVSchema("ks", false, map[string]*vindexes.Table{"idxTbl1": idxTbl1}), + expected: makeTestVSchema("ks", false, map[string]*vindexes.BaseTable{"idxTbl1": idxTbl1}), }, { name: "indexes in schema using expressions", currentVSchema: &vindexes.VSchema{}, @@ -312,7 +312,7 @@ func TestVSchemaUpdate(t *testing.T) { }, }, srvVschema: makeTestSrvVSchema("ks", false, nil), - expected: makeTestVSchema("ks", false, map[string]*vindexes.Table{"idxTbl2": idxTbl2}), + expected: makeTestVSchema("ks", false, map[string]*vindexes.BaseTable{"idxTbl2": idxTbl2}), }} vm := &VSchemaManager{} @@ -364,11 +364,11 @@ func TestKeyspaceRoutingRules(t *testing.T) { vs := &vindexes.VSchema{ Keyspaces: map[string]*vindexes.KeyspaceSchema{ "ks": { - Tables: map[string]*vindexes.Table{}, + Tables: map[string]*vindexes.BaseTable{}, Keyspace: &vindexes.Keyspace{Name: "ks", Sharded: true}, }, "ks2": { - Tables: map[string]*vindexes.Table{}, + Tables: map[string]*vindexes.BaseTable{}, Keyspace: &vindexes.Keyspace{Name: "ks2", Sharded: true}, }, }, @@ -395,10 +395,10 @@ func TestRebuildVSchema(t *testing.T) { Nullable: true, }} ks := &vindexes.Keyspace{Name: "ks"} - tblNoCol := &vindexes.Table{Name: sqlparser.NewIdentifierCS("tbl"), Keyspace: ks, ColumnListAuthoritative: true} - tblCol1 := &vindexes.Table{Name: sqlparser.NewIdentifierCS("tbl"), Keyspace: ks, Columns: cols1, ColumnListAuthoritative: true} - tblCol2 := &vindexes.Table{Name: sqlparser.NewIdentifierCS("tbl"), Keyspace: ks, Columns: cols2, ColumnListAuthoritative: true} - tblCol2NA := &vindexes.Table{Name: sqlparser.NewIdentifierCS("tbl"), Keyspace: ks, Columns: cols2} + tblNoCol := &vindexes.BaseTable{Name: sqlparser.NewIdentifierCS("tbl"), Keyspace: ks, ColumnListAuthoritative: true} + tblCol1 := &vindexes.BaseTable{Name: sqlparser.NewIdentifierCS("tbl"), Keyspace: ks, Columns: cols1, ColumnListAuthoritative: true} + tblCol2 := &vindexes.BaseTable{Name: sqlparser.NewIdentifierCS("tbl"), Keyspace: ks, Columns: cols2, ColumnListAuthoritative: true} + tblCol2NA := &vindexes.BaseTable{Name: sqlparser.NewIdentifierCS("tbl"), Keyspace: ks, Columns: cols2} tcases := []struct { name string @@ -413,18 +413,18 @@ func TestRebuildVSchema(t *testing.T) { ColumnListAuthoritative: false, }, }), - expected: makeTestVSchema("ks", false, map[string]*vindexes.Table{"tbl": tblCol2NA}), + expected: makeTestVSchema("ks", false, map[string]*vindexes.BaseTable{"tbl": tblCol2NA}), }, { name: "1 Schematracking- 0 srvVSchema", srvVschema: makeTestSrvVSchema("ks", false, nil), schema: map[string]*vindexes.TableInfo{"tbl": {Columns: cols1}}, - expected: makeTestVSchema("ks", false, map[string]*vindexes.Table{"tbl": tblCol1}), + expected: makeTestVSchema("ks", false, map[string]*vindexes.BaseTable{"tbl": tblCol1}), }, { name: "1 Schematracking - 1 srvVSchema (no columns) not authoritative", srvVschema: makeTestSrvVSchema("ks", false, map[string]*vschemapb.Table{"tbl": {}}), schema: map[string]*vindexes.TableInfo{"tbl": {Columns: cols1}}, // schema will override what srvSchema has. - expected: makeTestVSchema("ks", false, map[string]*vindexes.Table{"tbl": tblCol1}), + expected: makeTestVSchema("ks", false, map[string]*vindexes.BaseTable{"tbl": tblCol1}), }, { name: "1 Schematracking - 1 srvVSchema (have columns) not authoritative", srvVschema: makeTestSrvVSchema("ks", false, map[string]*vschemapb.Table{ @@ -435,7 +435,7 @@ func TestRebuildVSchema(t *testing.T) { }), schema: map[string]*vindexes.TableInfo{"tbl": {Columns: cols1}}, // schema will override what srvSchema has. - expected: makeTestVSchema("ks", false, map[string]*vindexes.Table{"tbl": tblCol1}), + expected: makeTestVSchema("ks", false, map[string]*vindexes.BaseTable{"tbl": tblCol1}), }, { name: "1 Schematracking - 1 srvVSchema (no columns) authoritative", srvVschema: makeTestSrvVSchema("ks", false, map[string]*vschemapb.Table{"tbl": { @@ -443,7 +443,7 @@ func TestRebuildVSchema(t *testing.T) { }}), schema: map[string]*vindexes.TableInfo{"tbl": {Columns: cols1}}, // schema will override what srvSchema has. - expected: makeTestVSchema("ks", false, map[string]*vindexes.Table{"tbl": tblNoCol}), + expected: makeTestVSchema("ks", false, map[string]*vindexes.BaseTable{"tbl": tblNoCol}), }, { name: "1 Schematracking - 1 srvVSchema (have columns) authoritative", srvVschema: makeTestSrvVSchema("ks", false, map[string]*vschemapb.Table{ @@ -454,7 +454,7 @@ func TestRebuildVSchema(t *testing.T) { }), schema: map[string]*vindexes.TableInfo{"tbl": {Columns: cols1}}, // schema tracker will be ignored for authoritative tables. - expected: makeTestVSchema("ks", false, map[string]*vindexes.Table{"tbl": tblCol2}), + expected: makeTestVSchema("ks", false, map[string]*vindexes.BaseTable{"tbl": tblCol2}), }, { name: "srvVschema received as nil", schema: map[string]*vindexes.TableInfo{"tbl": {Columns: cols1}}, @@ -506,7 +506,7 @@ func TestVSchemaUDFsUpdate(t *testing.T) { "ks": { Keyspace: ks, ForeignKeyMode: vschemapb.Keyspace_unmanaged, - Tables: map[string]*vindexes.Table{}, + Tables: map[string]*vindexes.BaseTable{}, Vindexes: map[string]vindexes.Vindex{}, AggregateUDFs: []string{"udf1", "udf2"}, }, @@ -532,7 +532,7 @@ func TestMarkErrorIfCyclesInFk(t *testing.T) { Keyspaces: map[string]*vindexes.KeyspaceSchema{ ksName: { ForeignKeyMode: vschemapb.Keyspace_managed, - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Keyspace: keyspace, @@ -563,7 +563,7 @@ func TestMarkErrorIfCyclesInFk(t *testing.T) { Keyspaces: map[string]*vindexes.KeyspaceSchema{ ksName: { ForeignKeyMode: vschemapb.Keyspace_managed, - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Keyspace: keyspace, @@ -594,7 +594,7 @@ func TestMarkErrorIfCyclesInFk(t *testing.T) { Keyspaces: map[string]*vindexes.KeyspaceSchema{ ksName: { ForeignKeyMode: vschemapb.Keyspace_managed, - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Keyspace: keyspace, @@ -623,7 +623,7 @@ func TestMarkErrorIfCyclesInFk(t *testing.T) { Keyspaces: map[string]*vindexes.KeyspaceSchema{ ksName: { ForeignKeyMode: vschemapb.Keyspace_managed, - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Keyspace: keyspace, @@ -651,7 +651,7 @@ func TestMarkErrorIfCyclesInFk(t *testing.T) { Keyspaces: map[string]*vindexes.KeyspaceSchema{ ksName: { ForeignKeyMode: vschemapb.Keyspace_managed, - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Keyspace: keyspace, @@ -679,7 +679,7 @@ func TestMarkErrorIfCyclesInFk(t *testing.T) { Keyspaces: map[string]*vindexes.KeyspaceSchema{ ksName: { ForeignKeyMode: vschemapb.Keyspace_managed, - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Keyspace: keyspace, @@ -726,7 +726,7 @@ func TestMarkErrorIfCyclesInFk(t *testing.T) { Keyspaces: map[string]*vindexes.KeyspaceSchema{ ksName: { ForeignKeyMode: vschemapb.Keyspace_managed, - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": { Name: sqlparser.NewIdentifierCS("t1"), Keyspace: keyspace, @@ -768,13 +768,13 @@ func TestVSchemaUpdateWithFKReferenceToInternalTables(t *testing.T) { }} sqlparserCols1 := sqlparser.MakeColumns("id") - vindexTable_t1 := &vindexes.Table{ + vindexTable_t1 := &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("t1"), Keyspace: ks, Columns: cols1, ColumnListAuthoritative: true, } - vindexTable_t2 := &vindexes.Table{ + vindexTable_t2 := &vindexes.BaseTable{ Name: sqlparser.NewIdentifierCS("t2"), Keyspace: ks, Columns: cols1, @@ -830,7 +830,7 @@ func TestVSchemaUpdateWithFKReferenceToInternalTables(t *testing.T) { Keyspace: ks, ForeignKeyMode: vschemapb.Keyspace_managed, Vindexes: map[string]vindexes.Vindex{}, - Tables: map[string]*vindexes.Table{ + Tables: map[string]*vindexes.BaseTable{ "t1": vindexTable_t1, "t2": vindexTable_t2, }, @@ -854,7 +854,7 @@ func createFkDefinition(childCols []string, parentTableName string, parentCols [ } } -func makeTestVSchema(ks string, sharded bool, tbls map[string]*vindexes.Table) *vindexes.VSchema { +func makeTestVSchema(ks string, sharded bool, tbls map[string]*vindexes.BaseTable) *vindexes.VSchema { keyspaceSchema := &vindexes.KeyspaceSchema{ Keyspace: &vindexes.Keyspace{ Name: ks, diff --git a/go/vt/vttablet/tabletserver/vstreamer/local_vschema.go b/go/vt/vttablet/tabletserver/vstreamer/local_vschema.go index abcdf840e84..e6f8128cc3f 100644 --- a/go/vt/vttablet/tabletserver/vstreamer/local_vschema.go +++ b/go/vt/vttablet/tabletserver/vstreamer/local_vschema.go @@ -65,7 +65,7 @@ func (lvs *localVSchema) FindOrCreateVindex(qualifiedName string) (vindexes.Vind return vindexes.CreateVindex(name, name, map[string]string{}) } -func (lvs *localVSchema) findTable(tablename string) (*vindexes.Table, error) { +func (lvs *localVSchema) findTable(tablename string) (*vindexes.BaseTable, error) { ks, ok := lvs.vschema.Keyspaces[lvs.keyspace] if !ok { return nil, fmt.Errorf("keyspace %s not found in vschema", lvs.keyspace)