Skip to content

Commit

Permalink
infoschema, planner: lock the new table id in tryLockMDLAndUpdateSche…
Browse files Browse the repository at this point in the history
…maIfNecessary (#39366)

close #39363
  • Loading branch information
wjhuang2016 authored Nov 25, 2022
1 parent ebc4e43 commit 88ad3f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 6 additions & 0 deletions infoschema/infoschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,12 @@ func (ts *SessionExtendedInfoSchema) SchemaByTable(tableInfo *model.TableInfo) (
}
}

if ts.MdlTables != nil {
if tbl, ok := ts.MdlTables.SchemaByTable(tableInfo); ok {
return tbl, true
}
}

return ts.InfoSchema.SchemaByTable(tableInfo)
}

Expand Down
7 changes: 3 additions & 4 deletions planner/core/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -1825,15 +1825,14 @@ func tryLockMDLAndUpdateSchemaIfNecessary(sctx sessionctx.Context, dbName model.
}
domainSchema := domain.GetDomain(sctx).InfoSchema()
domainSchemaVer := domainSchema.SchemaMetaVersion()
if !skipLock {
sctx.GetSessionVars().GetRelatedTableForMDL().Store(tableInfo.ID, domainSchemaVer)
}

var err error
tbl, err = domainSchema.TableByName(dbName, tableInfo.Name)
if err != nil {
return nil, err
}
if !skipLock {
sctx.GetSessionVars().GetRelatedTableForMDL().Store(tbl.Meta().ID, domainSchemaVer)
}
// Check the table change, if adding new public index or modify a column, we need to handle them.
if !sctx.GetSessionVars().IsPessimisticReadConsistency() {
var copyTableInfo *model.TableInfo
Expand Down

0 comments on commit 88ad3f4

Please sign in to comment.