本文整理汇总了Golang中github.com/youtube/vitess/go/vt/schema.Index类的典型用法代码示例。如果您正苦于以下问题:Golang Index类的具体用法?Golang Index怎么用?Golang Index使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Index类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getPKValues
func getPKValues(conditions []*sqlparser.ComparisonExpr, pkIndex *schema.Index) []interface{} {
pkValues := make([]interface{}, len(pkIndex.Columns))
inClauseSeen := false
for _, condition := range conditions {
if condition.Operator == sqlparser.InStr {
if inClauseSeen {
return nil
}
inClauseSeen = true
}
index := pkIndex.FindColumn(condition.Left.(*sqlparser.ColName).Name.Original())
if index == -1 {
return nil
}
if pkValues[index] != nil {
return nil
}
var err error
pkValues[index], err = sqlparser.AsInterface(condition.Right)
if err != nil {
return nil
}
}
for _, v := range pkValues {
if v == nil {
return nil
}
}
return pkValues
}
示例2: fetchIndexes
func (ti *TableInfo) fetchIndexes(conn *DBConn) error {
indexes, err := conn.Exec(context.Background(), fmt.Sprintf("show index from `%s`", ti.Name), 10000, false)
if err != nil {
return err
}
var currentIndex *schema.Index
currentName := ""
for _, row := range indexes.Rows {
indexName := row[2].String()
if currentName != indexName {
currentIndex = ti.AddIndex(indexName)
currentName = indexName
}
var cardinality uint64
if !row[6].IsNull() {
cardinality, err = strconv.ParseUint(row[6].String(), 0, 64)
if err != nil {
log.Warningf("%s", err)
}
}
currentIndex.AddColumn(row[4].String(), cardinality)
}
if len(ti.Indexes) == 0 {
return nil
}
pkIndex := ti.Indexes[0]
if pkIndex.Name != "PRIMARY" {
return nil
}
ti.PKColumns = make([]int, len(pkIndex.Columns))
for i, pkCol := range pkIndex.Columns {
ti.PKColumns[i] = ti.FindColumn(pkCol)
}
// Primary key contains all table columns
for _, col := range ti.Columns {
pkIndex.DataColumns = append(pkIndex.DataColumns, col.Name)
}
// Secondary indices contain all primary key columns
for i := 1; i < len(ti.Indexes); i++ {
for _, c := range ti.Indexes[i].Columns {
ti.Indexes[i].DataColumns = append(ti.Indexes[i].DataColumns, c)
}
for _, c := range pkIndex.Columns {
// pk columns may already be part of the index. So,
// check before adding.
if ti.Indexes[i].FindDataColumn(c) != -1 {
continue
}
ti.Indexes[i].DataColumns = append(ti.Indexes[i].DataColumns, c)
}
}
return nil
}
示例3: fetchIndexes
func (ti *TableInfo) fetchIndexes(conn PoolConnection) bool {
indexes, err := conn.ExecuteFetch(fmt.Sprintf("show index from %s", ti.Name), 10000, false)
if err != nil {
log.Warningf("%s", err.Error())
return false
}
var currentIndex *schema.Index
currentName := ""
for _, row := range indexes.Rows {
indexName := row[2].String()
if currentName != indexName {
currentIndex = ti.AddIndex(indexName)
currentName = indexName
}
var cardinality uint64
if !row[6].IsNull() {
cardinality, err = strconv.ParseUint(row[6].String(), 0, 64)
if err != nil {
log.Warningf("%s", err)
}
}
currentIndex.AddColumn(row[4].String(), cardinality)
}
if len(ti.Indexes) == 0 {
return true
}
pkIndex := ti.Indexes[0]
if pkIndex.Name != "PRIMARY" {
return true
}
ti.PKColumns = make([]int, len(pkIndex.Columns))
for i, pkCol := range pkIndex.Columns {
ti.PKColumns[i] = ti.FindColumn(pkCol)
}
// Primary key contains all table columns
for _, col := range ti.Columns {
pkIndex.DataColumns = append(pkIndex.DataColumns, col.Name)
}
// Secondary indices contain all primary key columns
for i := 1; i < len(ti.Indexes); i++ {
ti.Indexes[i].DataColumns = pkIndex.Columns
}
return true
}
示例4: execAnalyzeUpdateExpressions
func (node *Node) execAnalyzeUpdateExpressions(pkIndex *schema.Index) (pkValues []interface{}, ok bool) {
for i := 0; i < node.Len(); i++ {
columnName := string(node.At(i).At(0).Value)
index := pkIndex.FindColumn(columnName)
if index == -1 {
continue
}
value := node.At(i).At(1).execAnalyzeValue()
if value == nil {
log.Warningf("expression is too complex %v", node.At(i).At(0))
return nil, false
}
if pkValues == nil {
pkValues = make([]interface{}, len(pkIndex.Columns))
}
pkValues[index] = asInterface(value)
}
return pkValues, true
}
示例5: analyzeUpdateExpressions
func analyzeUpdateExpressions(exprs sqlparser.UpdateExprs, pkIndex *schema.Index) (pkValues []interface{}, err error) {
for _, expr := range exprs {
index := pkIndex.FindColumn(expr.Name.Original())
if index == -1 {
continue
}
if !sqlparser.IsValue(expr.Expr) {
return nil, ErrTooComplex
}
if pkValues == nil {
pkValues = make([]interface{}, len(pkIndex.Columns))
}
var err error
pkValues[index], err = sqlparser.AsInterface(expr.Expr)
if err != nil {
return nil, err
}
}
return pkValues, nil
}
示例6: analyzeUpdateExpressions
func analyzeUpdateExpressions(exprs sqlparser.UpdateExprs, pkIndex *schema.Index) (pkValues []interface{}, err error) {
for _, expr := range exprs {
index := pkIndex.FindColumn(sqlparser.GetColName(expr.Name))
if index == -1 {
continue
}
if !sqlparser.IsValue(expr.Expr) {
log.Warningf("expression is too complex %v", expr)
return nil, TooComplex
}
if pkValues == nil {
pkValues = make([]interface{}, len(pkIndex.Columns))
}
var err error
pkValues[index], err = sqlparser.AsInterface(expr.Expr)
if err != nil {
return nil, err
}
}
return pkValues, nil
}