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

infoschema: change data structure for lookup table by ID. #2006

Merged
merged 5 commits into from
Nov 18, 2016

Conversation

coocood
Copy link
Member

@coocood coocood commented Nov 15, 2016

Use 512 of table slice to lookup table by ID.
When schema is updated, only 1/512 of memory need to be allocated.

func (b *Builder) copySchemaNames(oldIS *infoSchema) {
for k, v := range oldIS.schemaNameToID {
b.is.schemaNameToID[k] = v
func (b *Builder) copySchemasMap(oldIS *infoSchema) {
Copy link
Member

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),
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 length of di.Tables

info.schemas[infoSchemaDB.ID] = infoSchemaDB
infoSchemaTblNames := &schemaTables{
dbInfo: infoSchemaDB,
tables: make(map[string]table.Table),
Copy link
Member

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),
Copy link
Member

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 {
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

newDbInfo := *roDBInfo

@coocood coocood force-pushed the coocood/split-table-array branch from 10ef81c to 543e474 Compare November 15, 2016 09:38
for _, tb := range tbList {
tbl := table.MockTableFromMeta(tb)
tableNames.tables[tb.Name.L] = tbl
bucketIdx := tb.ID % bucketCount
Copy link
Member

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 {
Copy link
Member

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.

@coocood coocood force-pushed the coocood/split-table-array branch from 33a063e to 887f641 Compare November 15, 2016 10:10
@ngaut
Copy link
Member

ngaut commented Nov 15, 2016

LGTM

1 similar comment
@tiancaiamao
Copy link
Contributor

LGTM

@coocood coocood merged commit abffed3 into master Nov 18, 2016
@coocood coocood deleted the coocood/split-table-array branch November 18, 2016 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants