diff --git a/go/vt/vtgate/vindexes/vschema.go b/go/vt/vtgate/vindexes/vschema.go index 3852bbfcde3..a9580bdcfb2 100644 --- a/go/vt/vtgate/vindexes/vschema.go +++ b/go/vt/vtgate/vindexes/vschema.go @@ -58,6 +58,7 @@ const ( TypeTable = "" TypeSequence = "sequence" TypeReference = "reference" + TypeView = "view" ) // VSchema represents the denormalized version of SrvVSchema, @@ -440,7 +441,7 @@ func (vschema *VSchema) AddView(ksname, viewName, query string, parser *sqlparse } ks.Views[viewName] = selectStmt t := &Table{ - Type: "View", + Type: TypeView, Name: sqlparser.NewIdentifierCS(viewName), Keyspace: ks.Keyspace, ColumnListAuthoritative: true, diff --git a/go/vt/vtgate/vschema_manager.go b/go/vt/vtgate/vschema_manager.go index 62ea2cd3455..9ae7164eb99 100644 --- a/go/vt/vtgate/vschema_manager.go +++ b/go/vt/vtgate/vschema_manager.go @@ -200,21 +200,34 @@ func (vm *VSchemaManager) buildAndEnhanceVSchema(v *vschemapb.SrvVSchema) *vinde func (vm *VSchemaManager) updateFromSchema(vschema *vindexes.VSchema) { for ksName, ks := range vschema.Keyspaces { - vm.updateTableInfo(vschema, ks, ksName) vm.updateViewInfo(ks, ksName) + vm.updateTableInfo(vschema, ks, ksName) vm.updateUDFsInfo(ks, ksName) } } func (vm *VSchemaManager) updateViewInfo(ks *vindexes.KeyspaceSchema, ksName string) { views := vm.schema.Views(ksName) - if views != nil { - ks.Views = make(map[string]sqlparser.SelectStatement, len(views)) - for name, def := range views { - ks.Views[name] = sqlparser.Clone(def) + if views == nil { + return + } + ks.Views = make(map[string]sqlparser.SelectStatement, 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, + } } } } + func (vm *VSchemaManager) updateTableInfo(vschema *vindexes.VSchema, ks *vindexes.KeyspaceSchema, ksName string) { m := vm.schema.Tables(ksName) // Before we add the foreign key definitions in the tables, we need to make sure that all the tables