本文整理汇总了Golang中github.com/pingcap/tidb/expression.BinaryOperation.IsIdentCompareVal方法的典型用法代码示例。如果您正苦于以下问题:Golang BinaryOperation.IsIdentCompareVal方法的具体用法?Golang BinaryOperation.IsIdentCompareVal怎么用?Golang BinaryOperation.IsIdentCompareVal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/expression.BinaryOperation
的用法示例。
在下文中一共展示了BinaryOperation.IsIdentCompareVal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: filterBinOp
func (r *TableDefaultPlan) filterBinOp(ctx context.Context, x *expression.BinaryOperation) (plan.Plan, bool, error) {
ok, name, rval, err := x.IsIdentCompareVal()
if err != nil {
return r, false, errors.Trace(err)
}
if !ok {
return r, false, nil
}
if rval == nil {
// if nil, any <, <=, >, >=, =, != operator will do nothing
// any value compared null returns null
// TODO: if we support <=> later, we must handle null
return &NullPlan{r.GetFields()}, true, nil
}
_, tn, cn := field.SplitQualifiedName(name)
t := r.T
if tn != "" && tn != t.TableName().L {
return r, false, nil
}
c := column.FindCol(t.Cols(), cn)
if c == nil {
return nil, false, errors.Errorf("No such column: %s", cn)
}
var seekVal interface{}
if seekVal, err = types.Convert(rval, &c.FieldType); err != nil {
return nil, false, errors.Trace(err)
}
spans := toSpans(x.Op, rval, seekVal)
if c.IsPKHandleColumn(r.T.Meta()) {
if r.rangeScan {
spans = filterSpans(r.spans, spans)
}
return &TableDefaultPlan{
T: r.T,
Fields: r.Fields,
rangeScan: true,
spans: spans,
}, true, nil
} else if r.rangeScan {
// Already filtered on PK handle column, should not switch to index plan.
return r, false, nil
}
ix := t.FindIndexByColName(cn)
if ix == nil { // Column cn has no index.
return r, false, nil
}
return &indexPlan{
src: t,
col: c,
unique: ix.Unique,
idxName: ix.Name.O,
idx: ix.X,
spans: spans,
}, true, nil
}
示例2: filterBinOp
func (r *TableDefaultPlan) filterBinOp(ctx context.Context, x *expression.BinaryOperation) (plan.Plan, bool, error) {
ok, name, rval, err := x.IsIdentCompareVal()
if err != nil {
return r, false, err
}
if !ok {
return r, false, nil
}
if rval == nil {
// if nil, any <, <=, >, >=, =, != operator will do nothing
// any value compared null returns null
// TODO: if we support <=> later, we must handle null
return &NullPlan{r.GetFields()}, true, nil
}
_, tn, cn := field.SplitQualifiedName(name)
t := r.T
if tn != "" && tn != t.TableName().L {
return r, false, nil
}
c := column.FindCol(t.Cols(), cn)
if c == nil {
return nil, false, errors.Errorf("No such column: %s", cn)
}
ix := t.FindIndexByColName(cn)
if ix == nil { // Column cn has no index.
return r, false, nil
}
var seekVal interface{}
if seekVal, err = types.Convert(rval, &c.FieldType); err != nil {
return nil, false, err
}
return &indexPlan{
src: t,
col: c,
idxName: ix.Name.O,
idx: ix.X,
spans: toSpans(x.Op, rval, seekVal),
}, true, nil
}