Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infoschema,executor: change TableByID to skip refill infoschema v2 cache #55101

Merged
merged 8 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -309,7 +309,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