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

Significant CPU usage for tryLockMDLAndUpdateSchemaIfNecessary for insert statement on table over 1k columns #54779

Closed
dbsid opened this issue Jul 20, 2024 · 2 comments · Fixed by #54963
Labels
type/enhancement The issue or PR belongs to an enhancement.

Comments

@dbsid
Copy link
Contributor

dbsid commented Jul 20, 2024

Enhancement

Even with plan cache hits, high cpu on tryLockMDLAndUpdateSchemaIfNecessary is observed, the table has over 1 thousands columns. seems the loops on tbl.Meta().Columns caused high cpu usage, need to see if anyway to optimize the cpu usage when the number of column on the table is high.

image

image

			// Check the column change.
			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 {
					if !skipLock {
						sctx.GetSessionVars().GetRelatedTableForMDL().Delete(tableInfo.ID)
					}
					return nil, domain.ErrInfoSchemaChanged.GenWithStack("public column %s has changed", col.Name)
				}
			}
		}
@dbsid dbsid added the type/enhancement The issue or PR belongs to an enhancement. label Jul 20, 2024
@wjhuang2016
Copy link
Member

I guess there is no DDL in your scenario, right?
We can simplify checking the table change by comparing Revision in tableInfo

@bb7133
Copy link
Member

bb7133 commented Jul 25, 2024

Could you please share the profiling file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants