diff --git a/infoschema/infoschema.go b/infoschema/infoschema.go index d024afde40d7d..040dbd239eef6 100644 --- a/infoschema/infoschema.go +++ b/infoschema/infoschema.go @@ -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) } diff --git a/planner/core/preprocess.go b/planner/core/preprocess.go index d059139bd7159..7673f57011bbe 100644 --- a/planner/core/preprocess.go +++ b/planner/core/preprocess.go @@ -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