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

planner: don't lock schema if an error happens #41896

Merged
merged 2 commits into from Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions ddl/metadatalocktest/mdl_test.go
Expand Up @@ -332,6 +332,7 @@ func TestMDLRRUpdateSchema(t *testing.T) {
tk.MustExec("begin")
tkDDL.MustExec("alter table test.t modify column a char(10);")
tk.MustGetErrCode("select * from t", mysql.ErrInfoSchemaChanged)
tk.MustGetErrCode("select * from t", mysql.ErrInfoSchemaChanged)
tk.MustExec("commit")
tk.MustQuery("select * from t").Check(testkit.Rows("1 <nil>"))

Expand Down
6 changes: 6 additions & 0 deletions planner/core/preprocess.go
Expand Up @@ -1833,6 +1833,9 @@ func tryLockMDLAndUpdateSchemaIfNecessary(sctx sessionctx.Context, dbName model.
var err error
tbl, err = domainSchema.TableByName(dbName, tableInfo.Name)
if err != nil {
if !skipLock {
sctx.GetSessionVars().GetRelatedTableForMDL().Delete(tableInfo.ID)
}
return nil, err
}
if !skipLock {
Expand Down Expand Up @@ -1879,6 +1882,9 @@ func tryLockMDLAndUpdateSchemaIfNecessary(sctx sessionctx.Context, dbName model.
}
}
if found {
if !skipLock {
sctx.GetSessionVars().GetRelatedTableForMDL().Delete(tableInfo.ID)
}
return nil, domain.ErrInfoSchemaChanged.GenWithStack("public column %s has changed", col.Name)
}
}
Expand Down