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: Add Revision check in tryLockMDLAndUpdateSchemaIfNecessary #54977

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
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
36 changes: 18 additions & 18 deletions pkg/planner/core/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -1853,20 +1853,20 @@ func tryLockMDLAndUpdateSchemaIfNecessary(sctx PlanContext, dbName model.CIStr,
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() {
if tbl.Meta().Revision != tableInfo.Revision && !sctx.GetSessionVars().IsPessimisticReadConsistency() {
var copyTableInfo *model.TableInfo

infoIndices := make(map[string]int64)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make with capacity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll change this in pull 54963. This pr is just used to build a test image and will be closd later.

for _, idx := range tableInfo.Indices {
infoIndices[idx.Name.L] = idx.ID
}

for i, idx := range tbl.Meta().Indices {
if idx.State != model.StatePublic {
continue
}
found := false
for _, idxx := range tableInfo.Indices {
if idx.Name.L == idxx.Name.L && idx.ID == idxx.ID {
found = true
break
}
}
if !found {
id, found := infoIndices[idx.Name.L]
if !found || id != idx.ID {
if copyTableInfo == nil {
copyTableInfo = tbl.Meta().Clone()
}
Expand All @@ -1880,19 +1880,19 @@ func tryLockMDLAndUpdateSchemaIfNecessary(sctx PlanContext, dbName model.CIStr,
}
}
// Check the column change.
infoColumns := make(map[string]int64)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make with capacity.

for _, col := range tableInfo.Columns {
infoColumns[col.Name.L] = col.ID
}
for _, col := range tbl.Meta().Columns {
if col.State != model.StatePublic {
continue
}
found := false
for _, coll := range tableInfo.Columns {
if col.Name.L == coll.Name.L && col.ID != coll.ID {
logutil.BgLogger().Info("public column changed", zap.String("column", col.Name.L), zap.String("old_col", coll.Name.L), zap.Int64("new id", col.ID), zap.Int64("old id", coll.ID))
found = true
break
}
}
if found {
colid, found := infoColumns[col.Name.L]
if found && colid != col.ID {
logutil.BgLogger().Info("public column changed",
zap.String("column", col.Name.L), zap.String("old_col", col.Name.L),
zap.Int64("new id", col.ID), zap.Int64("old id", col.ID))
if !skipLock {
sctx.GetSessionVars().GetRelatedTableForMDL().Delete(tableInfo.ID)
}
Expand Down