本文整理匯總了Golang中github.com/pingcap/tidb/mysql.HasPriKeyFlag函數的典型用法代碼示例。如果您正苦於以下問題:Golang HasPriKeyFlag函數的具體用法?Golang HasPriKeyFlag怎麽用?Golang HasPriKeyFlag使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了HasPriKeyFlag函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: detachConditions
// detachConditions distinguishs between access conditions and filter conditions from conditions.
func detachConditions(conditions []expression.Expression, table *model.TableInfo,
idx *model.IndexInfo, colOffset int) ([]expression.Expression, []expression.Expression) {
var pkName model.CIStr
var accessConditions, filterConditions []expression.Expression
if table.PKIsHandle {
for _, colInfo := range table.Columns {
if mysql.HasPriKeyFlag(colInfo.Flag) {
pkName = colInfo.Name
break
}
}
}
for _, con := range conditions {
if pkName.L != "" {
checker := conditionChecker{
tableName: table.Name,
pkName: pkName,
idx: idx,
columnOffset: colOffset}
if checker.newCheck(con) {
accessConditions = append(accessConditions, con)
continue
}
}
filterConditions = append(filterConditions, con)
}
return accessConditions, filterConditions
}
示例2: buildTableScanPlan
func (b *planBuilder) buildTableScanPlan(path *joinPath) Plan {
tn := path.table
p := &TableScan{
Table: tn.TableInfo,
TableName: tn,
}
// Equal condition contains a column from previous joined table.
p.RefAccess = len(path.eqConds) > 0
p.SetFields(tn.GetResultFields())
p.TableAsName = getTableAsName(p.Fields())
var pkName model.CIStr
if p.Table.PKIsHandle {
for _, colInfo := range p.Table.Columns {
if mysql.HasPriKeyFlag(colInfo.Flag) {
pkName = colInfo.Name
}
}
}
for _, con := range path.conditions {
if pkName.L != "" {
checker := conditionChecker{tableName: tn.TableInfo.Name, pkName: pkName}
if checker.check(con) {
p.AccessConditions = append(p.AccessConditions, con)
} else {
p.FilterConditions = append(p.FilterConditions, con)
}
} else {
p.FilterConditions = append(p.FilterConditions, con)
}
}
return p
}
示例3: detachTableScanConditions
// detachTableScanConditions distinguishes between access conditions and filter conditions from conditions.
func detachTableScanConditions(conditions []expression.Expression, table *model.TableInfo) ([]expression.Expression, []expression.Expression) {
var pkName model.CIStr
if table.PKIsHandle {
for _, colInfo := range table.Columns {
if mysql.HasPriKeyFlag(colInfo.Flag) {
pkName = colInfo.Name
break
}
}
}
if pkName.L == "" {
return nil, conditions
}
var accessConditions, filterConditions []expression.Expression
checker := conditionChecker{
tableName: table.Name,
pkName: pkName}
for _, cond := range conditions {
cond = pushDownNot(cond, false)
if !checker.newCheck(cond) {
filterConditions = append(filterConditions, cond)
continue
}
accessConditions = append(accessConditions, cond)
// TODO: it will lead to repeated compution cost.
if checker.shouldReserve {
filterConditions = append(filterConditions, cond)
checker.shouldReserve = false
}
}
return accessConditions, filterConditions
}
示例4: fetchShowIndex
func (e *ShowExec) fetchShowIndex() error {
tb, err := e.getTable()
if err != nil {
return errors.Trace(err)
}
if tb.Meta().PKIsHandle {
var pkCol *table.Column
for _, col := range tb.Cols() {
if mysql.HasPriKeyFlag(col.Flag) {
pkCol = col
break
}
}
data := types.MakeDatums(
tb.Meta().Name.O, // Table
0, // Non_unique
"PRIMARY", // Key_name
1, // Seq_in_index
pkCol.Name.O, // Column_name
"utf8_bin", // Colation
0, // Cardinality
nil, // Sub_part
nil, // Packed
"", // Null
"BTREE", // Index_type
"", // Comment
"", // Index_comment
)
e.rows = append(e.rows, &Row{Data: data})
}
for _, idx := range tb.Indices() {
for i, col := range idx.Meta().Columns {
nonUniq := 1
if idx.Meta().Unique {
nonUniq = 0
}
var subPart interface{}
if col.Length != types.UnspecifiedLength {
subPart = col.Length
}
data := types.MakeDatums(
tb.Meta().Name.O, // Table
nonUniq, // Non_unique
idx.Meta().Name.O, // Key_name
i+1, // Seq_in_index
col.Name.O, // Column_name
"utf8_bin", // Colation
0, // Cardinality
subPart, // Sub_part
nil, // Packed
"YES", // Null
idx.Meta().Tp.String(), // Index_type
"", // Comment
idx.Meta().Comment, // Index_comment
)
e.rows = append(e.rows, &Row{Data: data})
}
}
return nil
}
示例5: buildTableScanPlan
func (b *planBuilder) buildTableScanPlan(tn *ast.TableName, conditions []ast.ExprNode) Plan {
p := &TableScan{
Table: tn.TableInfo,
}
p.SetFields(tn.GetResultFields())
var pkName model.CIStr
if p.Table.PKIsHandle {
for _, colInfo := range p.Table.Columns {
if mysql.HasPriKeyFlag(colInfo.Flag) {
pkName = colInfo.Name
}
}
}
for _, con := range conditions {
if pkName.L != "" {
checker := conditionChecker{tableName: tn.TableInfo.Name, pkName: pkName}
if checker.check(con) {
p.AccessConditions = append(p.AccessConditions, con)
} else {
p.FilterConditions = append(p.FilterConditions, con)
}
} else {
p.FilterConditions = append(p.FilterConditions, con)
}
}
return p
}
示例6: 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})
}
}
}
示例7: matchOrder
// matchOrder checks if the plan has the same ordering as items.
func matchOrder(p Plan, items []*ast.ByItem) bool {
switch x := p.(type) {
case *Aggregate:
return false
case *IndexScan:
if len(items) > len(x.Index.Columns) {
return false
}
for i, item := range items {
if item.Desc {
return false
}
var rf *ast.ResultField
switch y := item.Expr.(type) {
case *ast.ColumnNameExpr:
rf = y.Refer
case *ast.PositionExpr:
rf = y.Refer
default:
return false
}
if rf.Table.Name.L != x.Table.Name.L || rf.Column.Name.L != x.Index.Columns[i].Name.L {
return false
}
}
return true
case *TableScan:
if len(items) != 1 || !x.Table.PKIsHandle {
return false
}
if items[0].Desc {
return false
}
var refer *ast.ResultField
switch x := items[0].Expr.(type) {
case *ast.ColumnNameExpr:
refer = x.Refer
case *ast.PositionExpr:
refer = x.Refer
default:
return false
}
if mysql.HasPriKeyFlag(refer.Column.Flag) {
return true
}
return false
case *JoinOuter:
return false
case *JoinInner:
return false
case *Sort:
// Sort plan should not be checked here as there should only be one sort plan in a plan tree.
return false
case WithSrcPlan:
return matchOrder(x.Src(), items)
}
return true
}
示例8: equivHasIndex
func equivHasIndex(rf *ast.ResultField) bool {
if rf.Table.PKIsHandle && mysql.HasPriKeyFlag(rf.Column.Flag) {
return true
}
for _, idx := range rf.Table.Indices {
if len(idx.Columns) == 1 && idx.Columns[0].Name.L == rf.Column.Name.L {
return true
}
}
return false
}
示例9: ColumnsToProto
// ColumnsToProto converts a slice of model.ColumnInfo to a slice of tipb.ColumnInfo.
func ColumnsToProto(columns []*model.ColumnInfo, pkIsHandle bool) []*tipb.ColumnInfo {
cols := make([]*tipb.ColumnInfo, 0, len(columns))
for _, c := range columns {
col := columnToProto(c)
if pkIsHandle && mysql.HasPriKeyFlag(c.Flag) {
col.PkHandle = true
} else {
col.PkHandle = false
}
cols = append(cols, col)
}
return cols
}
示例10: sortBypass
func (r *refiner) sortBypass(p *Sort) {
if r.indexScan != nil {
idx := r.indexScan.Index
if len(p.ByItems) > len(idx.Columns) {
return
}
var desc bool
for i, val := range p.ByItems {
if val.Desc {
desc = true
}
cn, ok := val.Expr.(*ast.ColumnNameExpr)
if !ok {
return
}
if r.indexScan.Table.Name.L != cn.Refer.Table.Name.L {
return
}
indexColumn := idx.Columns[i]
if indexColumn.Name.L != cn.Refer.Column.Name.L {
return
}
}
if desc {
// TODO: support desc when index reverse iterator is supported.
r.indexScan.Desc = true
return
}
p.Bypass = true
} else if r.tableScan != nil {
if len(p.ByItems) != 1 {
return
}
byItem := p.ByItems[0]
if byItem.Desc {
// TODO: support desc when table reverse iterator is supported.
return
}
cn, ok := byItem.Expr.(*ast.ColumnNameExpr)
if !ok {
return
}
if !mysql.HasPriKeyFlag(cn.Refer.Column.Flag) {
return
}
if !cn.Refer.Table.PKIsHandle {
return
}
p.Bypass = true
}
}
示例11: indexRowToTableRow
func (e *XSelectIndexExec) indexRowToTableRow(handle int64, indexRow []types.Datum) []types.Datum {
tableRow := make([]types.Datum, len(e.indexPlan.Columns))
for i, tblCol := range e.indexPlan.Columns {
if mysql.HasPriKeyFlag(tblCol.Flag) && e.indexPlan.Table.PKIsHandle {
tableRow[i] = types.NewIntDatum(handle)
continue
}
for j, idxCol := range e.indexPlan.Index.Columns {
if tblCol.Name.L == idxCol.Name.L {
tableRow[i] = indexRow[j]
break
}
}
}
return tableRow
}
示例12: TableToProto
// TableToProto converts a model.TableInfo to a tipb.TableInfo.
func TableToProto(t *model.TableInfo) *tipb.TableInfo {
pt := &tipb.TableInfo{
TableId: proto.Int64(t.ID),
}
cols := make([]*tipb.ColumnInfo, 0, len(t.Columns))
for _, c := range t.Columns {
col := columnToProto(c)
if t.PKIsHandle && mysql.HasPriKeyFlag(c.Flag) {
col.PkHandle = proto.Bool(true)
} else {
col.PkHandle = proto.Bool(false)
}
cols = append(cols, col)
}
pt.Columns = cols
return pt
}
示例13: isCoveringIndex
func isCoveringIndex(columns []*model.ColumnInfo, indexColumns []*model.IndexColumn, pkIsHandle bool) bool {
for _, colInfo := range columns {
if pkIsHandle && mysql.HasPriKeyFlag(colInfo.Flag) {
continue
}
isIndexColumn := false
for _, indexCol := range indexColumns {
if colInfo.Name.L == indexCol.Name.L && indexCol.Length == types.UnspecifiedLength {
isIndexColumn = true
break
}
}
if !isIndexColumn {
return false
}
}
return true
}
示例14: NewColDesc
// NewColDesc returns a new ColDesc for a column.
func NewColDesc(col *Column) *ColDesc {
// TODO: if we have no primary key and a unique index which's columns are all not null
// we will set these columns' flag as PriKeyFlag
// see https://dev.mysql.com/doc/refman/5.7/en/show-columns.html
// create table
name := col.Name
nullFlag := "YES"
if mysql.HasNotNullFlag(col.Flag) {
nullFlag = "NO"
}
keyFlag := ""
if mysql.HasPriKeyFlag(col.Flag) {
keyFlag = "PRI"
} else if mysql.HasUniKeyFlag(col.Flag) {
keyFlag = "UNI"
} else if mysql.HasMultipleKeyFlag(col.Flag) {
keyFlag = "MUL"
}
var defaultValue interface{}
if !mysql.HasNoDefaultValueFlag(col.Flag) {
defaultValue = col.DefaultValue
}
extra := ""
if mysql.HasAutoIncrementFlag(col.Flag) {
extra = "auto_increment"
} else if mysql.HasOnUpdateNowFlag(col.Flag) {
extra = "on update CURRENT_TIMESTAMP"
}
return &ColDesc{
Field: name.O,
Type: col.GetTypeDesc(),
Collation: col.Collate,
Null: nullFlag,
Key: keyFlag,
DefaultValue: defaultValue,
Extra: extra,
Privileges: defaultPrivileges,
Comment: "",
}
}
示例15: detachIndexFilterConditions
func detachIndexFilterConditions(conditions []expression.Expression, indexColumns []*model.IndexColumn, table *model.TableInfo) ([]expression.Expression, []expression.Expression) {
var pKName model.CIStr
if table.PKIsHandle {
for _, colInfo := range table.Columns {
if mysql.HasPriKeyFlag(colInfo.Flag) {
pKName = colInfo.Name
break
}
}
}
var indexConditions, tableConditions []expression.Expression
for _, cond := range conditions {
if checkIndexCondition(cond, indexColumns, pKName) {
indexConditions = append(indexConditions, cond)
} else {
tableConditions = append(tableConditions, cond)
}
}
return indexConditions, tableConditions
}