예제 #1
0
파일: evaluator.go 프로젝트: xudongQiu/tidb
// Evaluate SubqueryExpr.
// Get the value from v.SubQuery and set it to v.
func (e *Evaluator) subqueryExpr(v *ast.SubqueryExpr) bool {
	if v.SubqueryExec != nil {
		v.SetValue(v.SubqueryExec.GetValue())
	}
	v.Evaluated = true
	return true
}
예제 #2
0
// EvalSubquery evaluates a subquery.
func EvalSubquery(ctx context.Context, v *ast.SubqueryExpr) error {
	if v.SubqueryExec != nil {
		rowCount := 2
		if v.MultiRows {
			rowCount = -1
		} else if v.Exists {
			rowCount = 1
		}
		rows, err := v.SubqueryExec.EvalRows(ctx, rowCount)
		if err != nil {
			return errors.Trace(err)
		}
		if v.MultiRows || v.Exists {
			v.GetDatum().SetRow(rows)
			v.Evaluated = true
			return nil
		}
		switch len(rows) {
		case 0:
			v.SetNull()
		case 1:
			v.SetDatum(rows[0])
		default:
			return errors.New("Subquery returns more than 1 row")
		}
	}
	v.Evaluated = true
	return nil
}