本文整理匯總了Golang中github.com/pingcap/tidb/plan/plans.SelectList.CheckReferAmbiguous方法的典型用法代碼示例。如果您正苦於以下問題:Golang SelectList.CheckReferAmbiguous方法的具體用法?Golang SelectList.CheckReferAmbiguous怎麽用?Golang SelectList.CheckReferAmbiguous使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pingcap/tidb/plan/plans.SelectList
的用法示例。
在下文中一共展示了SelectList.CheckReferAmbiguous方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CheckAndUpdateSelectList
// CheckAndUpdateSelectList checks order by fields validity and set hidden fields to selectList.
func (r *OrderByRset) CheckAndUpdateSelectList(selectList *plans.SelectList, tableFields []*field.ResultField) error {
for i, v := range r.By {
if expression.ContainAggregateFunc(v.Expr) {
expr, err := selectList.UpdateAggFields(v.Expr, tableFields)
if err != nil {
return errors.Errorf("%s in 'order clause'", err.Error())
}
r.By[i].Expr = expr
} else {
if _, err := selectList.CheckReferAmbiguous(v.Expr); err != nil {
return errors.Errorf("Column '%s' in order statement is ambiguous", v.Expr)
}
// TODO: check more ambiguous case
// Order by ambiguous rule:
// select c1 as a, c2 as a from t order by a is ambiguous
// select c1 as a, c2 as a from t order by a + 1 is ambiguous
// select c1 as c2, c2 from t order by c2 is ambiguous
// select c1 as c2, c2 from t order by c2 + 1 is ambiguous
// TODO: use vistor to refactor all and combine following plan check.
names := expression.MentionedColumns(v.Expr)
for _, name := range names {
// try to find in select list
// TODO: mysql has confused result for this, see #555.
// now we use select list then order by, later we should make it easier.
if field.ContainFieldName(name, selectList.ResultFields, field.CheckFieldFlag) {
continue
}
if !selectList.CloneHiddenField(name, tableFields) {
return errors.Errorf("Unknown column '%s' in 'order clause'", name)
}
}
}
}
return nil
}