Skip to content

Commit

Permalink
infoschema,executor: change TableByID to skip refill infoschema v2 ca…
Browse files Browse the repository at this point in the history
…che (#55101)

ref #50959
  • Loading branch information
tiancaiamao authored Aug 6, 2024
1 parent 5458324 commit 3b19de6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
21 changes: 7 additions & 14 deletions pkg/executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,15 @@ func (e *memtableRetriever) retrieve(ctx context.Context, sctx sessionctx.Contex
}

func getAutoIncrementID(
ctx context.Context,
is infoschema.InfoSchema,
sctx sessionctx.Context,
schema model.CIStr,
tblInfo *model.TableInfo,
) (int64, error) {
tbl, err := is.TableByName(ctx, schema, tblInfo.Name)
if err != nil {
return 0, err
) int64 {
tbl, ok := is.TableByID(tblInfo.ID)
if !ok {
return 0
}
return tbl.Allocators(sctx.GetTableCtx()).Get(autoid.AutoIncrementType).Base() + 1, nil
return tbl.Allocators(sctx.GetTableCtx()).Get(autoid.AutoIncrementType).Base() + 1
}

func hasPriv(ctx sessionctx.Context, priv mysql.PrivilegeType) bool {
Expand Down Expand Up @@ -583,7 +581,6 @@ func (e *memtableRetriever) updateStatsCacheIfNeed() bool {
}

func (e *memtableRetriever) setDataFromOneTable(
ctx context.Context,
sctx sessionctx.Context,
loc *time.Location,
checker privilege.Manager,
Expand All @@ -610,14 +607,10 @@ func (e *memtableRetriever) setDataFromOneTable(
} else if table.TableCacheStatusType == model.TableCacheStatusEnable {
createOptions = "cached=on"
}
var err error
var autoIncID any
hasAutoIncID, _ := infoschema.HasAutoIncrementColumn(table)
if hasAutoIncID {
autoIncID, err = getAutoIncrementID(ctx, e.is, sctx, schema, table)
if err != nil {
return rows, err
}
autoIncID = getAutoIncrementID(e.is, sctx, table)
}
tableType := "BASE TABLE"
if util.IsSystemView(schema.L) {
Expand Down Expand Up @@ -737,7 +730,7 @@ func (e *memtableRetriever) setDataFromTables(ctx context.Context, sctx sessionc
return errors.Trace(err)
}
for i, table := range tables {
rows, err = e.setDataFromOneTable(ctx, sctx, loc, checker, schemas[i], table, rows, useStatsCache)
rows, err = e.setDataFromOneTable(sctx, loc, checker, schemas[i], table, rows, useStatsCache)
if err != nil {
return errors.Trace(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/infoschema/infoschema_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ func (is *infoschemaV2) CloneAndUpdateTS(startTS uint64) *infoschemaV2 {
}

func (is *infoschemaV2) TableByID(id int64) (val table.Table, ok bool) {
return is.tableByID(id, false)
return is.tableByID(id, true)
}

func (is *infoschemaV2) tableByID(id int64, noRefill bool) (val table.Table, ok bool) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/infoschema/test/infoschemav2test/v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func TestTrace(t *testing.T) {

// Evict the table cache and check the trace information can catch this calling.
raw.EvictTable("test", "t_trace")
tk.MustQuery("trace select * from information_schema.tables").CheckContain("infoschema.loadTableInfo")
tk.MustQuery("trace select * from information_schema.tables where table_schema='test' and table_name='t_trace'").CheckContain("infoschema.loadTableInfo")
}

func BenchmarkTableByName(t *testing.B) {
Expand Down

0 comments on commit 3b19de6

Please sign in to comment.