From 3b19de6eb69fa9d7056f0c03c71d004e5fb62595 Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Tue, 6 Aug 2024 18:27:39 +0800 Subject: [PATCH] infoschema,executor: change TableByID to skip refill infoschema v2 cache (#55101) ref pingcap/tidb#50959 --- pkg/executor/infoschema_reader.go | 21 +++++++------------ pkg/infoschema/infoschema_v2.go | 2 +- .../test/infoschemav2test/v2_test.go | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/pkg/executor/infoschema_reader.go b/pkg/executor/infoschema_reader.go index 999b2a7ae2208..3016d1c2d2c25 100644 --- a/pkg/executor/infoschema_reader.go +++ b/pkg/executor/infoschema_reader.go @@ -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 { @@ -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, @@ -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) { @@ -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) } diff --git a/pkg/infoschema/infoschema_v2.go b/pkg/infoschema/infoschema_v2.go index e8a0f45fa995a..c26b5787d3405 100644 --- a/pkg/infoschema/infoschema_v2.go +++ b/pkg/infoschema/infoschema_v2.go @@ -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) { diff --git a/pkg/infoschema/test/infoschemav2test/v2_test.go b/pkg/infoschema/test/infoschemav2test/v2_test.go index b8bf008304752..452509c551ff8 100644 --- a/pkg/infoschema/test/infoschemav2test/v2_test.go +++ b/pkg/infoschema/test/infoschemav2test/v2_test.go @@ -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) {