From 16359011d9ebf4c4d1927d326183644d3e43cc57 Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Wed, 31 Jul 2024 16:53:41 +0800 Subject: [PATCH 1/6] infoschema,executor: change TableByID to skip refill infoschema v2 cache --- pkg/executor/infoschema_reader.go | 16 ++++++---------- pkg/infoschema/infoschema_v2.go | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/pkg/executor/infoschema_reader.go b/pkg/executor/infoschema_reader.go index 2262c118db8f5..f661b128d9f86 100644 --- a/pkg/executor/infoschema_reader.go +++ b/pkg/executor/infoschema_reader.go @@ -235,13 +235,13 @@ func (e *memtableRetriever) retrieve(ctx context.Context, sctx sessionctx.Contex return adjustColumns(ret, e.columns, e.table), nil } -func getAutoIncrementID(ctx context.Context, sctx sessionctx.Context, schema model.CIStr, tblInfo *model.TableInfo) (int64, error) { +func getAutoIncrementID(sctx sessionctx.Context, schema model.CIStr, tblInfo *model.TableInfo) int64 { is := sctx.GetInfoSchema().(infoschema.InfoSchema) - tbl, err := is.TableByName(ctx, schema, tblInfo.Name) - if err != nil { - return 0, err + 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 { @@ -607,14 +607,10 @@ func (e *memtableRetriever) setDataFromTables(ctx context.Context, sctx sessionc } 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, sctx, schema, table) - if err != nil { - return err - } + autoIncID = getAutoIncrementID(sctx, schema, table) } tableType := "BASE TABLE" if util.IsSystemView(schema.L) { diff --git a/pkg/infoschema/infoschema_v2.go b/pkg/infoschema/infoschema_v2.go index 3c590cc6f6774..26e436bb2a855 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) { From 1078eb7f334fcc224d80682be8227b89d7205179 Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Wed, 31 Jul 2024 17:36:23 +0800 Subject: [PATCH 2/6] make lint happy --- pkg/executor/infoschema_reader.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/executor/infoschema_reader.go b/pkg/executor/infoschema_reader.go index f661b128d9f86..5b2cfed5d04cb 100644 --- a/pkg/executor/infoschema_reader.go +++ b/pkg/executor/infoschema_reader.go @@ -235,7 +235,7 @@ func (e *memtableRetriever) retrieve(ctx context.Context, sctx sessionctx.Contex return adjustColumns(ret, e.columns, e.table), nil } -func getAutoIncrementID(sctx sessionctx.Context, schema model.CIStr, tblInfo *model.TableInfo) int64 { +func getAutoIncrementID(sctx sessionctx.Context, tblInfo *model.TableInfo) int64 { is := sctx.GetInfoSchema().(infoschema.InfoSchema) tbl, ok := is.TableByID(tblInfo.ID) if !ok { @@ -610,7 +610,7 @@ func (e *memtableRetriever) setDataFromTables(ctx context.Context, sctx sessionc var autoIncID any hasAutoIncID, _ := infoschema.HasAutoIncrementColumn(table) if hasAutoIncID { - autoIncID = getAutoIncrementID(sctx, schema, table) + autoIncID = getAutoIncrementID(sctx, table) } tableType := "BASE TABLE" if util.IsSystemView(schema.L) { From 6365478c0018db69542786aa44ffe24d174d8978 Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Thu, 1 Aug 2024 12:09:07 +0800 Subject: [PATCH 3/6] make lint happy --- pkg/executor/infoschema_reader.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/executor/infoschema_reader.go b/pkg/executor/infoschema_reader.go index 95a282d2cc244..424ea72b5033a 100644 --- a/pkg/executor/infoschema_reader.go +++ b/pkg/executor/infoschema_reader.go @@ -256,7 +256,6 @@ func (e *memtableRetriever) retrieve(ctx context.Context, sctx sessionctx.Contex } func getAutoIncrementID( - ctx context.Context, is infoschema.InfoSchema, sctx sessionctx.Context, tblInfo *model.TableInfo, @@ -721,7 +720,7 @@ func (e *memtableRetriever) setDataFromOneTable( var autoIncID any hasAutoIncID, _ := infoschema.HasAutoIncrementColumn(table) if hasAutoIncID { - autoIncID = getAutoIncrementID(ctx, e.is, sctx, table) + autoIncID = getAutoIncrementID(e.is, sctx, table) } tableType := "BASE TABLE" if util.IsSystemView(schema.L) { From db26d077052dd728b7df18892e0434987e7fa387 Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Thu, 1 Aug 2024 12:26:02 +0800 Subject: [PATCH 4/6] make lint happy --- pkg/executor/infoschema_reader.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/executor/infoschema_reader.go b/pkg/executor/infoschema_reader.go index 424ea72b5033a..75633c20f208a 100644 --- a/pkg/executor/infoschema_reader.go +++ b/pkg/executor/infoschema_reader.go @@ -690,7 +690,6 @@ func getMatchTableInfos( } func (e *memtableRetriever) setDataFromOneTable( - ctx context.Context, sctx sessionctx.Context, loc *time.Location, checker privilege.Manager, @@ -839,7 +838,7 @@ func (e *memtableRetriever) setDataFromTables(ctx context.Context, sctx sessionc return errors.Trace(err) } for _, table := range tables { - rows, err = e.setDataFromOneTable(ctx, sctx, loc, checker, schema, table, rows, useStatsCache) + rows, err = e.setDataFromOneTable(sctx, loc, checker, schema, table, rows, useStatsCache) if err != nil { return errors.Trace(err) } From 61cc3bff8b71492a331766d4bf8fef35792f9ae1 Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Thu, 1 Aug 2024 16:02:08 +0800 Subject: [PATCH 5/6] fix-ci --- pkg/infoschema/test/infoschemav2test/v2_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/infoschema/test/infoschemav2test/v2_test.go b/pkg/infoschema/test/infoschemav2test/v2_test.go index 5d89d22134271..d789981e0bece 100644 --- a/pkg/infoschema/test/infoschemav2test/v2_test.go +++ b/pkg/infoschema/test/infoschemav2test/v2_test.go @@ -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) { From b9fc64f4d22ddfe20724e96a6e7df870d451c531 Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Tue, 6 Aug 2024 15:24:18 +0800 Subject: [PATCH 6/6] fix build --- pkg/executor/infoschema_reader.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/executor/infoschema_reader.go b/pkg/executor/infoschema_reader.go index 24cd24b33809f..3016d1c2d2c25 100644 --- a/pkg/executor/infoschema_reader.go +++ b/pkg/executor/infoschema_reader.go @@ -730,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) }