Beispiel #1
0
func initMemoryTables(h *memSchemaHandle) error {
	// Init Information_Schema
	var (
		err error
		tbl table.Table
	)
	dbID := autoid.GenLocalSchemaID()
	isTables := make([]*model.TableInfo, 0, len(tableNameToColumns))
	for name, cols := range tableNameToColumns {
		meta := buildTableMeta(name, cols)
		isTables = append(isTables, meta)
		meta.ID = autoid.GenLocalSchemaID()
		for _, c := range meta.Columns {
			c.ID = autoid.GenLocalSchemaID()
		}
		alloc := autoid.NewMemoryAllocator(dbID)
		tbl, err = createMemoryTable(meta, alloc)
		if err != nil {
			return errors.Trace(err)
		}
		h.nameToTable[meta.Name.L] = tbl
	}
	h.schemataTbl = h.nameToTable[strings.ToLower(tableSchemata)]
	h.tablesTbl = h.nameToTable[strings.ToLower(tableTables)]
	h.columnsTbl = h.nameToTable[strings.ToLower(tableColumns)]
	h.statisticsTbl = h.nameToTable[strings.ToLower(tableStatistics)]
	h.charsetTbl = h.nameToTable[strings.ToLower(tableCharacterSets)]
	h.collationsTbl = h.nameToTable[strings.ToLower(tableCollations)]

	// CharacterSets/Collations contain static data. Init them now.
	err = insertData(h.charsetTbl, dataForCharacterSets())
	if err != nil {
		return errors.Trace(err)
	}
	err = insertData(h.collationsTbl, dataForColltions())
	if err != nil {
		return errors.Trace(err)
	}
	// create db
	h.isDB = &model.DBInfo{
		ID:      dbID,
		Name:    model.NewCIStr(Name),
		Charset: mysql.DefaultCharset,
		Collate: mysql.DefaultCollationName,
		Tables:  isTables,
	}
	return nil
}
Beispiel #2
0
func initInfoSchemaDB() {
	dbID := autoid.GenLocalSchemaID()
	infoSchemaTables := make([]*model.TableInfo, 0, len(tableNameToColumns))
	for name, cols := range tableNameToColumns {
		tableInfo := buildTableMeta(name, cols)
		infoSchemaTables = append(infoSchemaTables, tableInfo)
		tableInfo.ID = autoid.GenLocalSchemaID()
		for _, c := range tableInfo.Columns {
			c.ID = autoid.GenLocalSchemaID()
		}
	}
	infoSchemaDB = &model.DBInfo{
		ID:      dbID,
		Name:    model.NewCIStr(Name),
		Charset: mysql.DefaultCharset,
		Collate: mysql.DefaultCollationName,
		Tables:  infoSchemaTables,
	}
}
Beispiel #3
0
func (ps *perfSchema) buildTables() error {
	tbls := make([]*model.TableInfo, 0, len(ps.tables))
	dbID := autoid.GenLocalSchemaID()

	for name, meta := range ps.tables {
		tbls = append(tbls, meta)
		meta.ID = autoid.GenLocalSchemaID()
		for _, c := range meta.Columns {
			c.ID = autoid.GenLocalSchemaID()
		}
		alloc := autoid.NewMemoryAllocator(dbID)

		var tbl table.Table
		switch name {
		case TableStmtsCurrent, TablePreparedStmtsInstances, TableTransCurrent, TableStagesCurrent:
			tbl = createBoundedTable(meta, alloc, currentElemMax)
		case TableStmtsHistory, TableStmtsHistoryLong, TableTransHistory, TableTransHistoryLong, TableStagesHistory, TableStagesHistoryLong:
			tbl = createBoundedTable(meta, alloc, historyElemMax)
		default:
			var err error
			tbl, err = createMemoryTable(meta, alloc)
			if err != nil {
				return errors.Trace(err)
			}
		}
		ps.mTables[name] = tbl
	}
	ps.dbInfo = &model.DBInfo{
		ID:      dbID,
		Name:    model.NewCIStr(Name),
		Charset: mysql.DefaultCharset,
		Collate: mysql.DefaultCollationName,
		Tables:  tbls,
	}
	return nil
}