-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
infoschema: change data structure for lookup table by ID. #2006
Conversation
func (b *Builder) copySchemaNames(oldIS *infoSchema) { | ||
for k, v := range oldIS.schemaNameToID { | ||
b.is.schemaNameToID[k] = v | ||
func (b *Builder) copySchemasMap(oldIS *infoSchema) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/schemasMap/schemaMap/
info.schemaNameToID[di.Name.L] = di.ID | ||
schTbls := &schemaTables{ | ||
dbInfo: di, | ||
tables: make(map[string]table.Table), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make with length of di.Tables
info.schemas[infoSchemaDB.ID] = infoSchemaDB | ||
infoSchemaTblNames := &schemaTables{ | ||
dbInfo: infoSchemaDB, | ||
tables: make(map[string]table.Table), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
perfSchemaDB := perfHandle.GetDBMeta() | ||
perfSchemaTblNames := &schemaTables{ | ||
dbInfo: perfSchemaDB, | ||
tables: make(map[string]table.Table), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
// CopySortedTables copies sortedTables for old table and new table for later modification. | ||
func (b *Builder) copySortedTables(oldTableID, newTableID int64) { | ||
buckets := b.is.sortedTablesBuckets | ||
if oldTableID != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please define a constant as invalid table id.
buckets[newTableID%bucketCount] = newSortedTables | ||
} | ||
} | ||
|
||
// updateDBInfo clones a new DBInfo from old DBInfo, and update on the new one. | ||
func (b *Builder) updateDBInfo(roDBInfo *model.DBInfo, oldTableID, newTableID int64) { | ||
newDbInfo := new(model.DBInfo) | ||
*newDbInfo = *roDBInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newDbInfo := *roDBInfo
10ef81c
to
543e474
Compare
for _, tb := range tbList { | ||
tbl := table.MockTableFromMeta(tb) | ||
tableNames.tables[tb.Name.L] = tbl | ||
bucketIdx := tb.ID % bucketCount |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should extract tb.ID % bucketCount to a hash function.
// CopySortedTables copies sortedTables for old table and new table for later modification. | ||
func (b *Builder) copySortedTables(oldTableID, newTableID int64) { | ||
buckets := b.is.sortedTablesBuckets | ||
if oldTableID != invalidTableID { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should extract validation logic to a function.
33a063e
to
887f641
Compare
LGTM |
1 similar comment
LGTM |
Use 512 of table slice to lookup table by ID.
When schema is updated, only 1/512 of memory need to be allocated.