Skip to content

Commit

Permalink
infoschema: remove some redundant methods from InfoSchema (#50916)
Browse files Browse the repository at this point in the history
ref #50959
  • Loading branch information
tiancaiamao authored Feb 4, 2024
1 parent a24f1e9 commit c6d7270
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 35 deletions.
2 changes: 1 addition & 1 deletion pkg/ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7081,7 +7081,7 @@ func ExtractTblInfos(is infoschema.InfoSchema, oldIdent, newIdent ast.Ident, isA
return nil, 0, nil
}
//View can be renamed only in the same schema. Compatible with mysql
if is.TableIsView(oldIdent.Schema, oldIdent.Name) {
if infoschema.TableIsView(is, oldIdent.Schema, oldIdent.Name) {
if oldIdent.Schema != newIdent.Schema {
return nil, 0, infoschema.ErrForbidSchemaChange.GenWithStackByArgs(oldIdent.Schema, newIdent.Schema)
}
Expand Down
10 changes: 0 additions & 10 deletions pkg/ddl/schematracker/info_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,6 @@ func (i InfoStoreAdaptor) TableExists(schema, table model.CIStr) bool {
return tableInfo != nil
}

// TableIsView implements the InfoSchema interface.
// nolint:unused
func (i InfoStoreAdaptor) TableIsView(schema, table model.CIStr) bool {
tableInfo, _ := i.inner.TableByName(schema, table)
if tableInfo == nil {
return false
}
return tableInfo.IsView()
}

// TableByName implements the InfoSchema interface.
// nolint:unused
func (i InfoStoreAdaptor) TableByName(schema, table model.CIStr) (t table.Table, err error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/plan_replayer_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (tne *tableNameExtractor) handleIsView(t *ast.TableName) (bool, error) {
schema = tne.curDB
}
table := t.Name
isView := tne.is.TableIsView(schema, table)
isView := infoschema.TableIsView(tne.is, schema, table)
if !isView {
return false, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func moveInfoSchemaToFront(dbs []string) {
}

func (e *ShowExec) fetchShowDatabases() error {
dbs := e.is.AllSchemaNames()
dbs := infoschema.AllSchemaNames(e.is)
checker := privilege.GetPrivilegeManager(e.Ctx())
slices.Sort(dbs)
var (
Expand Down
33 changes: 15 additions & 18 deletions pkg/infoschema/infoschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,10 @@ type InfoSchema interface {
ResourceGroupByName(name model.CIStr) (*model.ResourceGroupInfo, bool)
TableByID(id int64) (table.Table, bool)
AllocByID(id int64) (autoid.Allocators, bool)
AllSchemaNames() []string
AllSchemas() []*model.DBInfo
Clone() (result []*model.DBInfo)
SchemaTables(schema model.CIStr) []table.Table
SchemaMetaVersion() int64
// TableIsView indicates whether the schema.table is a view.
TableIsView(schema, table model.CIStr) bool
// TableIsSequence indicates whether the schema.table is a sequence.
TableIsSequence(schema, table model.CIStr) bool
FindTableByPartitionID(partitionID int64) (table.Table, *model.DBInfo, *model.PartitionDefinition)
// PlacementBundleByPhysicalTableID is used to get a rule bundle.
PlacementBundleByPhysicalTableID(id int64) (*placement.Bundle, bool)
Expand Down Expand Up @@ -208,20 +203,20 @@ func (is *infoSchema) TableByName(schema, table model.CIStr) (t table.Table, err
return nil, ErrTableNotExists.GenWithStackByArgs(schema, table)
}

func (is *infoSchema) TableIsView(schema, table model.CIStr) bool {
if tbNames, ok := is.schemaMap[schema.L]; ok {
if t, ok := tbNames.tables[table.L]; ok {
return t.Meta().IsView()
}
// TableIsView indicates whether the schema.table is a view.
func TableIsView(is InfoSchema, schema, table model.CIStr) bool {
tbl, err := is.TableByName(schema, table)
if err == nil {
return tbl.Meta().IsView()
}
return false
}

func (is *infoSchema) TableIsSequence(schema, table model.CIStr) bool {
if tbNames, ok := is.schemaMap[schema.L]; ok {
if t, ok := tbNames.tables[table.L]; ok {
return t.Meta().IsSequence()
}
// TableIsSequence indicates whether the schema.table is a sequence.
func TableIsSequence(is InfoSchema, schema, table model.CIStr) bool {
tbl, err := is.TableByName(schema, table)
if err == nil {
return tbl.Meta().IsSequence()
}
return false
}
Expand Down Expand Up @@ -296,9 +291,11 @@ func (is *infoSchema) AllocByID(id int64) (autoid.Allocators, bool) {
return tbl.Allocators(nil), true
}

func (is *infoSchema) AllSchemaNames() (names []string) {
for _, v := range is.schemaMap {
names = append(names, v.dbInfo.Name.O)
// AllSchemaNames returns all the schemas' names.
func AllSchemaNames(is InfoSchema) (names []string) {
schemas := is.AllSchemas()
for _, v := range schemas {
names = append(names, v.Name.O)
}
return
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/infoschema/infoschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestBasic(t *testing.T) {

is := builder.Build()

schemaNames := is.AllSchemaNames()
schemaNames := infoschema.AllSchemaNames(is)
require.Len(t, schemaNames, 4)
require.True(t, testutil.CompareUnorderedStringSlice(schemaNames, []string{util.InformationSchemaName.O, util.MetricSchemaName.O, util.PerformanceSchemaName.O, "Test"}))

Expand Down Expand Up @@ -161,8 +161,8 @@ func TestBasic(t *testing.T) {

require.True(t, is.TableExists(dbName, tbName))
require.False(t, is.TableExists(dbName, noexist))
require.False(t, is.TableIsView(dbName, tbName))
require.False(t, is.TableIsSequence(dbName, tbName))
require.False(t, infoschema.TableIsView(is, dbName, tbName))
require.False(t, infoschema.TableIsSequence(is, dbName, tbName))

tb, ok := is.TableByID(tbID)
require.True(t, ok)
Expand Down
2 changes: 1 addition & 1 deletion pkg/statistics/handle/autoanalyze/autoanalyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func RandomPickOneTableAndTryAutoAnalyze(
start, end time.Time,
) bool {
is := sctx.GetDomainInfoSchema().(infoschema.InfoSchema)
dbs := is.AllSchemaNames()
dbs := infoschema.AllSchemaNames(is)
// Shuffle the database and table slice to randomize the order of analyzing tables.
rd := rand.New(rand.NewSource(time.Now().UnixNano())) // #nosec G404
rd.Shuffle(len(dbs), func(i, j int) {
Expand Down

0 comments on commit c6d7270

Please sign in to comment.