当前位置: 首页>>代码示例>>Golang>>正文


Golang infoschema.InfoSchema类代码示例

本文整理汇总了Golang中github.com/pingcap/tidb/infoschema.InfoSchema的典型用法代码示例。如果您正苦于以下问题:Golang InfoSchema类的具体用法?Golang InfoSchema怎么用?Golang InfoSchema使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了InfoSchema类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: fetchStatisticsInTable

func (isp *InfoSchemaPlan) fetchStatisticsInTable(is infoschema.InfoSchema, schema *model.DBInfo, table *model.TableInfo) {
	if table.PKIsHandle {
		for _, col := range table.Columns {
			if mysql.HasPriKeyFlag(col.Flag) {
				record := []interface{}{
					catalogVal,    // TABLE_CATALOG
					schema.Name.O, // TABLE_SCHEMA
					table.Name.O,  // TABLE_NAME
					"0",           // NON_UNIQUE
					schema.Name.O, // INDEX_SCHEMA
					"PRIMARY",     // INDEX_NAME
					1,             // SEQ_IN_INDEX
					col.Name.O,    // COLUMN_NAME
					"A",           // COLLATION
					0,             // CARDINALITY
					nil,           // SUB_PART
					nil,           // PACKED
					"",            // NULLABLE
					"BTREE",       // INDEX_TYPE
					"",            // COMMENT
					"",            // INDEX_COMMENT
				}
				isp.rows = append(isp.rows, &plan.Row{Data: record})
			}
		}
	}
	for _, index := range table.Indices {
		nonUnique := "1"
		if index.Unique {
			nonUnique = "0"
		}
		for i, key := range index.Columns {
			col, _ := is.ColumnByName(schema.Name, table.Name, key.Name)
			nullable := "YES"
			if mysql.HasNotNullFlag(col.Flag) {
				nullable = ""
			}
			record := []interface{}{
				catalogVal,    // TABLE_CATALOG
				schema.Name.O, // TABLE_SCHEMA
				table.Name.O,  // TABLE_NAME
				nonUnique,     // NON_UNIQUE
				schema.Name.O, // INDEX_SCHEMA
				index.Name.O,  // INDEX_NAME
				i + 1,         // SEQ_IN_INDEX
				key.Name.O,    // COLUMN_NAME
				"A",           // COLLATION
				0,             // CARDINALITY
				nil,           // SUB_PART
				nil,           // PACKED
				nullable,      // NULLABLE
				"BTREE",       // INDEX_TYPE
				"",            // COMMENT
				"",            // INDEX_COMMENT
			}
			isp.rows = append(isp.rows, &plan.Row{Data: record})
		}
	}
}
开发者ID:lovedboy,项目名称:tidb,代码行数:59,代码来源:info.go

示例2: GetInfoSchema

// GetInfoSchema gets TxnCtx InfoSchema if snapshot schema is not set,
// Otherwise, snapshot schema is returned.
func GetInfoSchema(ctx context.Context) infoschema.InfoSchema {
	sessVar := ctx.GetSessionVars()
	var is infoschema.InfoSchema
	if snap := sessVar.SnapshotInfoschema; snap != nil {
		is = snap.(infoschema.InfoSchema)
		log.Infof("[%d] use snapshot schema %d", sessVar.ConnectionID, is.SchemaMetaVersion())
	} else {
		is = sessVar.TxnCtx.InfoSchema.(infoschema.InfoSchema)
	}
	return is
}
开发者ID:pingcap,项目名称:tidb,代码行数:13,代码来源:compiler.go

示例3: doStatistics

func (isp *InfoSchemaPlan) doStatistics(is infoschema.InfoSchema, schemas []*model.DBInfo, iterFunc plan.RowIterFunc) error {
	for _, schema := range schemas {
		for _, table := range schema.Tables {
			for _, index := range table.Indices {
				nonUnique := "1"
				if index.Unique {
					nonUnique = "0"
				}
				for i, key := range index.Columns {
					col, _ := is.ColumnByName(schema.Name, table.Name, key.Name)
					nullable := "YES"
					if mysql.HasNotNullFlag(col.Flag) {
						nullable = ""
					}
					record := []interface{}{
						catalogVal,    // TABLE_CATALOG
						schema.Name.O, // TABLE_SCHEMA
						table.Name.O,  // TABLE_NAME
						nonUnique,     // NON_UNIQUE
						schema.Name.O, // INDEX_SCHEMA
						index.Name.O,  // INDEX_NAME
						i + 1,         // SEQ_IN_INDEX
						key.Name.O,    // COLUMN_NAME
						"A",           // COLLATION
						0,             // CARDINALITY
						nil,           // SUB_PART
						nil,           // PACKED
						nullable,      // NULLABLE
						"BTREE",       // INDEX_TYPE
						"",            // COMMENT
						"",            // INDEX_COMMENT
					}
					if more, err := iterFunc(0, record); !more || err != nil {
						return err
					}
				}
			}
		}
	}
	return nil
}
开发者ID:rose1988c,项目名称:tidb,代码行数:41,代码来源:info.go

示例4: Compile

// Compile compiles an ast.StmtNode to an ast.Statement.
// After preprocessed and validated, it will be optimized to a plan,
// then wrappped to an adapter *statement as stmt.Statement.
func (c *Compiler) Compile(ctx context.Context, node ast.StmtNode) (ast.Statement, error) {
	stmtNodeCounter.WithLabelValues(statementLabel(node)).Inc()
	if _, ok := node.(*ast.UpdateStmt); ok {
		sVars := variable.GetSessionVars(ctx)
		sVars.InUpdateStmt = true
		defer func() {
			sVars.InUpdateStmt = false
		}()
	}

	var is infoschema.InfoSchema
	if snap := variable.GetSessionVars(ctx).SnapshotInfoschema; snap != nil {
		is = snap.(infoschema.InfoSchema)
		log.Infof("use snapshot schema %d", is.SchemaMetaVersion())
	} else {
		is = sessionctx.GetDomain(ctx).InfoSchema()
		binloginfo.SetSchemaVersion(ctx, is.SchemaMetaVersion())
	}
	if err := plan.Preprocess(node, is, ctx); err != nil {
		return nil, errors.Trace(err)
	}
	// Validate should be after NameResolve.
	if err := plan.Validate(node, false); err != nil {
		return nil, errors.Trace(err)
	}
	p, err := plan.Optimize(ctx, node, is)
	if err != nil {
		return nil, errors.Trace(err)
	}
	_, isDDL := node.(ast.DDLNode)
	sa := &statement{
		is:    is,
		plan:  p,
		text:  node.Text(),
		isDDL: isDDL,
	}
	return sa, nil
}
开发者ID:jmptrader,项目名称:tidb,代码行数:41,代码来源:compiler.go


注:本文中的github.com/pingcap/tidb/infoschema.InfoSchema类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。