本文整理汇总了Golang中github.com/pingcap/tidb/table.TableFromMeta函数的典型用法代码示例。如果您正苦于以下问题:Golang TableFromMeta函数的具体用法?Golang TableFromMeta怎么用?Golang TableFromMeta使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TableFromMeta函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Set
// Set sets DBInfo to information schema.
func (h *Handle) Set(newInfo []*model.DBInfo) {
info := &infoSchema{
schemaNameToID: map[string]int64{},
tableNameToID: map[tableName]int64{},
columnNameToID: map[columnName]int64{},
schemas: map[int64]*model.DBInfo{},
tables: map[int64]table.Table{},
columns: map[int64]*model.ColumnInfo{},
indices: map[indexName]*model.IndexInfo{},
columnIndices: map[int64][]*model.IndexInfo{},
}
for _, di := range newInfo {
info.schemas[di.ID] = di
info.schemaNameToID[di.Name.L] = di.ID
for _, t := range di.Tables {
alloc := autoid.NewAllocator(h.store)
info.tables[t.ID] = table.TableFromMeta(di.Name.L, alloc, t)
tname := tableName{di.Name.L, t.Name.L}
info.tableNameToID[tname] = t.ID
for _, c := range t.Columns {
info.columns[c.ID] = c
info.columnNameToID[columnName{tname, c.Name.L}] = c.ID
}
for _, idx := range t.Indices {
info.indices[indexName{tname, idx.Name.L}] = idx
for _, idxCol := range idx.Columns {
columnID := t.Columns[idxCol.Offset].ID
columnIndices := info.columnIndices[columnID]
info.columnIndices[columnID] = append(columnIndices, idx)
}
}
}
}
h.value.Store(info)
}
开发者ID:ninefive,项目名称:tidb,代码行数:36,代码来源:infoschema.go
示例2: dropSchemaData
func (d *ddl) dropSchemaData(dbInfo *model.DBInfo, tables []*model.TableInfo) error {
for _, tblInfo := range tables {
alloc := autoid.NewAllocator(d.store, dbInfo.ID)
t := table.TableFromMeta(alloc, tblInfo)
err := d.dropTableData(t)
if err != nil {
return errors.Trace(err)
}
}
return nil
}
开发者ID:yzl11,项目名称:vessel,代码行数:11,代码来源:schema.go
示例3: testGetTable
func testGetTable(c *C, d *ddl, schemaID int64, tableID int64) table.Table {
var tblInfo *model.TableInfo
kv.RunInNewTxn(d.store, false, func(txn kv.Transaction) error {
t := meta.NewMeta(txn)
var err error
tblInfo, err = t.GetTable(schemaID, tableID)
c.Assert(err, IsNil)
c.Assert(tblInfo, NotNil)
return nil
})
alloc := autoid.NewAllocator(d.store, schemaID)
tbl := table.TableFromMeta(alloc, tblInfo)
return tbl
}
开发者ID:yzl11,项目名称:vessel,代码行数:14,代码来源:table_test.go
示例4: handleAutoIncID
// If create table with auto_increment option, we should rebase tableAutoIncID value.
func (d *ddl) handleAutoIncID(tbInfo *model.TableInfo, schemaID int64) error {
alloc := autoid.NewAllocator(d.store, schemaID)
tbInfo.State = model.StatePublic
tb, err := table.TableFromMeta(alloc, tbInfo)
if err != nil {
return errors.Trace(err)
}
// The operation of the minus 1 to make sure that the current value doesn't be used,
// the next Alloc operation will get this value.
// Its behavior is consistent with MySQL.
if err = tb.RebaseAutoID(tbInfo.AutoIncID-1, false); err != nil {
return errors.Trace(err)
}
return nil
}
开发者ID:pingcap,项目名称:tidb,代码行数:16,代码来源:ddl.go
示例5: handleTableOptions
func (d *ddl) handleTableOptions(options []*ast.TableOption, tbInfo *model.TableInfo, schemaID int64) error {
for _, op := range options {
if op.Tp == ast.TableOptionAutoIncrement {
alloc := autoid.NewAllocator(d.store, schemaID)
tbInfo.State = model.StatePublic
tb, err := table.TableFromMeta(alloc, tbInfo)
if err != nil {
return errors.Trace(err)
}
// The operation of the minus 1 to make sure that the current value doesn't be used,
// the next Alloc operation will get this value.
// Its behavior is consistent with MySQL.
if err = tb.RebaseAutoID(int64(op.UintValue-1), false); err != nil {
return errors.Trace(err)
}
}
}
return nil
}
开发者ID:astaxie,项目名称:tidb,代码行数:20,代码来源:ddl.go
示例6: Set
// Set sets DBInfo to information schema.
func (h *Handle) Set(newInfo []*model.DBInfo, schemaMetaVersion int64) error {
info := &infoSchema{
schemaNameToID: map[string]int64{},
tableNameToID: map[tableName]int64{},
columnNameToID: map[columnName]int64{},
schemas: map[int64]*model.DBInfo{},
tables: map[int64]table.Table{},
columns: map[int64]*model.ColumnInfo{},
indices: map[indexName]*model.IndexInfo{},
columnIndices: map[int64][]*model.IndexInfo{},
schemaMetaVersion: schemaMetaVersion,
}
var err error
for _, di := range newInfo {
info.schemas[di.ID] = di
info.schemaNameToID[di.Name.L] = di.ID
for _, t := range di.Tables {
alloc := autoid.NewAllocator(h.store, di.ID)
info.tables[t.ID], err = table.TableFromMeta(alloc, t)
if err != nil {
return errors.Trace(err)
}
tname := tableName{di.Name.L, t.Name.L}
info.tableNameToID[tname] = t.ID
for _, c := range t.Columns {
info.columns[c.ID] = c
info.columnNameToID[columnName{tname, c.Name.L}] = c.ID
}
for _, idx := range t.Indices {
info.indices[indexName{tname, idx.Name.L}] = idx
for _, idxCol := range idx.Columns {
columnID := t.Columns[idxCol.Offset].ID
columnIndices := info.columnIndices[columnID]
info.columnIndices[columnID] = append(columnIndices, idx)
}
}
}
}
h.value.Store(info)
return nil
}
开发者ID:lovedboy,项目名称:tidb,代码行数:42,代码来源:infoschema.go
示例7: getCurrentTable
func getCurrentTable(d *ddl, schemaID, tableID int64) (table.Table, error) {
var tblInfo *model.TableInfo
err := kv.RunInNewTxn(d.store, false, func(txn kv.Transaction) error {
t := meta.NewMeta(txn)
var err error
tblInfo, err = t.GetTable(schemaID, tableID)
if err != nil {
return errors.Trace(err)
}
return nil
})
if err != nil {
return nil, errors.Trace(err)
}
alloc := autoid.NewAllocator(d.store, schemaID)
tbl, err := table.TableFromMeta(alloc, tblInfo)
if err != nil {
return nil, errors.Trace(err)
}
return tbl, err
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:21,代码来源:column_change_test.go
示例8: InitWithDBInfos
// InitWithDBInfos initializes an empty new InfoSchema with a slice of DBInfo and schema version.
func (b *Builder) InitWithDBInfos(dbInfos []*model.DBInfo, schemaVersion int64) (*Builder, error) {
err := b.initMemorySchemas()
if err != nil {
return nil, errors.Trace(err)
}
info := b.is
info.schemaMetaVersion = schemaVersion
for _, di := range dbInfos {
info.schemas[di.ID] = di
info.schemaNameToID[di.Name.L] = di.ID
for _, t := range di.Tables {
alloc := autoid.NewAllocator(b.handle.store, di.ID)
var tbl table.Table
tbl, err = table.TableFromMeta(alloc, t)
if err != nil {
return nil, errors.Trace(err)
}
info.tables[t.ID] = tbl
tname := makeTableName(di.Name.L, t.Name.L)
info.tableNameToID[string(tname)] = t.ID
}
}
return b, nil
}
开发者ID:jmptrader,项目名称:tidb,代码行数:25,代码来源:builder.go
示例9: getTable
func (d *ddl) getTable(schemaID int64, tblInfo *model.TableInfo) (table.Table, error) {
alloc := autoid.NewAllocator(d.store, schemaID)
tbl, err := table.TableFromMeta(alloc, tblInfo)
return tbl, errors.Trace(err)
}
开发者ID:anywhy,项目名称:tidb,代码行数:5,代码来源:table.go
示例10: getTable
func (d *ddl) getTable(t *meta.Meta, schemaID int64, tblInfo *model.TableInfo) (table.Table, error) {
alloc := autoid.NewAllocator(d.store, schemaID)
tbl := table.TableFromMeta(alloc, tblInfo)
return tbl, nil
}
开发者ID:henrylee2cn,项目名称:tidb,代码行数:5,代码来源:table.go
示例11: Set
// Set sets DBInfo to information schema.
func (h *Handle) Set(newInfo []*model.DBInfo, schemaMetaVersion int64) error {
info := &infoSchema{
schemaNameToID: map[string]int64{},
tableNameToID: map[tableName]int64{},
columnNameToID: map[columnName]int64{},
schemas: map[int64]*model.DBInfo{},
tables: map[int64]table.Table{},
tableAllocators: map[int64]autoid.Allocator{},
columns: map[int64]*model.ColumnInfo{},
indices: map[indexName]*model.IndexInfo{},
columnIndices: map[int64][]*model.IndexInfo{},
schemaMetaVersion: schemaMetaVersion,
}
var err error
var hasOldInfo bool
infoschema := h.Get()
if infoschema != nil {
hasOldInfo = true
}
for _, di := range newInfo {
info.schemas[di.ID] = di
info.schemaNameToID[di.Name.L] = di.ID
for _, t := range di.Tables {
alloc := autoid.NewAllocator(h.store, di.ID)
if hasOldInfo {
val, ok := infoschema.AllocByID(t.ID)
if ok {
alloc = val
}
}
info.tableAllocators[t.ID] = alloc
info.tables[t.ID], err = table.TableFromMeta(alloc, t)
if err != nil {
return errors.Trace(err)
}
tname := tableName{di.Name.L, t.Name.L}
info.tableNameToID[tname] = t.ID
for _, c := range t.Columns {
info.columns[c.ID] = c
info.columnNameToID[columnName{tname, c.Name.L}] = c.ID
}
for _, idx := range t.Indices {
info.indices[indexName{tname, idx.Name.L}] = idx
for _, idxCol := range idx.Columns {
columnID := t.Columns[idxCol.Offset].ID
columnIndices := info.columnIndices[columnID]
info.columnIndices[columnID] = append(columnIndices, idx)
}
}
}
}
// Build Information_Schema
info.schemaNameToID[h.memSchema.isDB.Name.L] = h.memSchema.isDB.ID
info.schemas[h.memSchema.isDB.ID] = h.memSchema.isDB
for _, t := range h.memSchema.isDB.Tables {
tbl, ok := h.memSchema.nameToTable[t.Name.L]
if !ok {
return ErrTableNotExists.Gen("table `%s` is missing.", t.Name)
}
info.tables[t.ID] = tbl
tname := tableName{h.memSchema.isDB.Name.L, t.Name.L}
info.tableNameToID[tname] = t.ID
for _, c := range t.Columns {
info.columns[c.ID] = c
info.columnNameToID[columnName{tname, c.Name.L}] = c.ID
}
}
// Add Performance_Schema
psDB := h.memSchema.perfHandle.GetDBMeta()
info.schemaNameToID[psDB.Name.L] = psDB.ID
info.schemas[psDB.ID] = psDB
for _, t := range psDB.Tables {
tbl, ok := h.memSchema.perfHandle.GetTable(t.Name.O)
if !ok {
return ErrTableNotExists.Gen("table `%s` is missing.", t.Name)
}
info.tables[t.ID] = tbl
tname := tableName{psDB.Name.L, t.Name.L}
info.tableNameToID[tname] = t.ID
for _, c := range t.Columns {
info.columns[c.ID] = c
info.columnNameToID[columnName{tname, c.Name.L}] = c.ID
}
}
// Should refill some tables in Information_Schema.
// schemata/tables/columns/statistics
dbNames := make([]string, 0, len(info.schemas))
dbInfos := make([]*model.DBInfo, 0, len(info.schemas))
for _, v := range info.schemas {
dbNames = append(dbNames, v.Name.L)
dbInfos = append(dbInfos, v)
}
err = refillTable(h.memSchema.schemataTbl, dataForSchemata(dbNames))
if err != nil {
return errors.Trace(err)
}
err = refillTable(h.memSchema.tablesTbl, dataForTables(dbInfos))
if err != nil {
//.........这里部分代码省略.........
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:101,代码来源:infoschema.go
注:本文中的github.com/pingcap/tidb/table.TableFromMeta函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论