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 #54963

Merged
merged 3 commits into from
Aug 2, 2024
Merged
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 @@ -1872,20 +1872,20 @@ func tryLockMDLAndUpdateSchemaIfNecessary(ctx context.Context, sctx base.PlanCon
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, len(tableInfo.Indices))
Copy link
Collaborator

Choose a reason for hiding this comment

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

A indexID to indexName mapping with type map[int64]int64 maybe more efficient in map searching

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 @@ -1899,19 +1899,19 @@ func tryLockMDLAndUpdateSchemaIfNecessary(ctx context.Context, sctx base.PlanCon
}
}
// Check the column change.
infoColumns := make(map[string]int64, len(tableInfo.Columns))
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