Skip to content

Commit

Permalink
*: fix oom in the infoSchema.TableByName (#52220)
Browse files Browse the repository at this point in the history
close #52219
  • Loading branch information
hawkingrei authored Mar 29, 2024
1 parent 7198525 commit b1c0e36
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pkg/infoschema/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ func applyCreateTable(b *Builder, m *meta.Meta, dbInfo *model.DBInfo, tableID in
if tblInfo == nil {
// When we apply an old schema diff, the table may has been dropped already, so we need to fall back to
// full load.
return nil, ErrTableNotExists.GenWithStackByArgs(
return nil, ErrTableNotExists.FastGenByArgs(
fmt.Sprintf("(Schema ID %d)", dbInfo.ID),
fmt.Sprintf("(Table ID %d)", tableID),
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/infoschema/infoschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (is *infoSchema) TableByName(schema, table model.CIStr) (t table.Table, err
return
}
}
return nil, ErrTableNotExists.GenWithStackByArgs(schema, table)
return nil, ErrTableNotExists.FastGenByArgs(schema, table)
}

// TableInfoByName implements InfoSchema.TableInfoByName
Expand Down
8 changes: 4 additions & 4 deletions pkg/infoschema/infoschema_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,14 @@ func (is *infoschemaV2) TableByName(schema, tbl model.CIStr) (t table.Table, err
return
}
}
return nil, ErrTableNotExists.GenWithStackByArgs(schema, tbl)
return nil, ErrTableNotExists.FastGenByArgs(schema, tbl)
}

eq := func(a, b *tableItem) bool { return a.dbName == b.dbName && a.tableName == b.tableName }
itm, ok := search(is.byName, is.infoSchema.schemaMetaVersion, tableItem{dbName: schema.L, tableName: tbl.L, schemaVersion: math.MaxInt64}, eq)
if !ok {
// TODO: in the future, this may happen and we need to check tikv to see whether table exists.
return nil, ErrTableNotExists.GenWithStackByArgs(schema, tbl)
return nil, ErrTableNotExists.FastGenByArgs(schema, tbl)
}

// Get from the cache.
Expand Down Expand Up @@ -569,7 +569,7 @@ func loadTableInfo(r autoid.Requirement, infoData *Data, tblID, dbID int64, ts u

// table removed.
if tblInfo == nil {
return nil, errors.Trace(ErrTableNotExists.GenWithStackByArgs(
return nil, errors.Trace(ErrTableNotExists.FastGenByArgs(
fmt.Sprintf("(Schema ID %d)", dbID),
fmt.Sprintf("(Table ID %d)", tblID),
))
Expand All @@ -590,7 +590,7 @@ func loadTableInfo(r autoid.Requirement, infoData *Data, tblID, dbID int64, ts u
return nil, errors.Trace(err)
}
if res == nil {
return nil, errors.Trace(ErrTableNotExists.GenWithStackByArgs(
return nil, errors.Trace(ErrTableNotExists.FastGenByArgs(
fmt.Sprintf("(Schema ID %d)", dbID),
fmt.Sprintf("(Table ID %d)", tblID),
))
Expand Down
2 changes: 1 addition & 1 deletion pkg/planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5983,7 +5983,7 @@ func (b *PlanBuilder) buildUpdateLists(ctx context.Context, tableList []*ast.Tab
tableInfo := tn.TableInfo
tableVal, found := b.is.TableByID(tableInfo.ID)
if !found {
return nil, nil, false, infoschema.ErrTableNotExists.GenWithStackByArgs(tn.DBInfo.Name.O, tableInfo.Name.O)
return nil, nil, false, infoschema.ErrTableNotExists.FastGenByArgs(tn.DBInfo.Name.O, tableInfo.Name.O)
}
for i, colInfo := range tableVal.Cols() {
if !colInfo.IsGenerated() {
Expand Down
10 changes: 5 additions & 5 deletions pkg/planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,7 @@ func (b *PlanBuilder) buildAdminCheckTable(ctx context.Context, as *ast.AdminStm
tableInfo := as.Tables[0].TableInfo
tbl, ok := b.is.TableByID(tableInfo.ID)
if !ok {
return nil, infoschema.ErrTableNotExists.GenWithStackByArgs(tblName.DBInfo.Name.O, tableInfo.Name.O)
return nil, infoschema.ErrTableNotExists.FastGenByArgs(tblName.DBInfo.Name.O, tableInfo.Name.O)
}
p := &CheckTable{
DBName: tblName.Schema.O,
Expand Down Expand Up @@ -3611,11 +3611,11 @@ func (b *PlanBuilder) resolveGeneratedColumns(ctx context.Context, columns []*ta
func (b *PlanBuilder) buildInsert(ctx context.Context, insert *ast.InsertStmt) (Plan, error) {
ts, ok := insert.Table.TableRefs.Left.(*ast.TableSource)
if !ok {
return nil, infoschema.ErrTableNotExists.GenWithStackByArgs()
return nil, infoschema.ErrTableNotExists.FastGenByArgs()
}
tn, ok := ts.Source.(*ast.TableName)
if !ok {
return nil, infoschema.ErrTableNotExists.GenWithStackByArgs()
return nil, infoschema.ErrTableNotExists.FastGenByArgs()
}
tableInfo := tn.TableInfo
if tableInfo.IsView() {
Expand Down Expand Up @@ -4123,7 +4123,7 @@ func (b *PlanBuilder) buildLoadData(ctx context.Context, ld *ast.LoadDataStmt) (
tableInPlan, ok := b.is.TableByID(tableInfo.ID)
if !ok {
db := b.ctx.GetSessionVars().CurrentDB
return nil, infoschema.ErrTableNotExists.GenWithStackByArgs(db, tableInfo.Name.O)
return nil, infoschema.ErrTableNotExists.FastGenByArgs(db, tableInfo.Name.O)
}
schema, names, err := expression.TableInfo2SchemaAndNames(b.ctx.GetExprCtx(), model.NewCIStr(""), tableInfo)
if err != nil {
Expand Down Expand Up @@ -4223,7 +4223,7 @@ func (b *PlanBuilder) buildImportInto(ctx context.Context, ld *ast.ImportIntoStm
return nil, errors.New("can not execute IMPORT statement when 'tidb_snapshot' is set")
}
db := b.ctx.GetSessionVars().CurrentDB
return nil, infoschema.ErrTableNotExists.GenWithStackByArgs(db, tableInfo.Name.O)
return nil, infoschema.ErrTableNotExists.FastGenByArgs(db, tableInfo.Name.O)
}
schema, names, err := expression.TableInfo2SchemaAndNames(b.ctx.GetExprCtx(), model.NewCIStr(""), tableInfo)
if err != nil {
Expand Down

0 comments on commit b1c0e36

Please sign in to comment.