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, planner: lock the new table id in tryLockMDLAndUpdateSchemaIfNecessary #39366

Merged
merged 4 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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