*: having adds SelectList field.
This commit is contained in:
@ -32,6 +32,7 @@ type HavingPlan struct {
|
||||
Src plan.Plan
|
||||
Expr expression.Expression
|
||||
evalArgs map[interface{}]interface{}
|
||||
*SelectList
|
||||
}
|
||||
|
||||
// Explain implements plan.Plan Explain interface.
|
||||
|
||||
@ -30,6 +30,10 @@ var _ = Suite(&testHavingPlan{})
|
||||
func (t *testHavingPlan) TestHaving(c *C) {
|
||||
tblPlan := &testTablePlan{groupByTestData, []string{"id", "name"}, 0}
|
||||
havingPlan := &plans.HavingPlan{
|
||||
SelectList: &plans.SelectList{
|
||||
HiddenFieldOffset: len(tblPlan.GetFields()),
|
||||
ResultFields: tblPlan.GetFields(),
|
||||
},
|
||||
Src: tblPlan,
|
||||
Expr: &expression.BinaryOperation{
|
||||
Op: opcode.GE,
|
||||
|
||||
@ -28,8 +28,9 @@ var (
|
||||
|
||||
// HavingRset is record set for having fields.
|
||||
type HavingRset struct {
|
||||
Src plan.Plan
|
||||
Expr expression.Expression
|
||||
Src plan.Plan
|
||||
Expr expression.Expression
|
||||
SelectList *plans.SelectList
|
||||
}
|
||||
|
||||
// CheckAndUpdateSelectList checks having fields validity and set hidden fields to selectList.
|
||||
@ -90,7 +91,7 @@ func (r *HavingRset) CheckAndUpdateSelectList(selectList *plans.SelectList, grou
|
||||
|
||||
// Plan gets HavingPlan.
|
||||
func (r *HavingRset) Plan(ctx context.Context) (plan.Plan, error) {
|
||||
return &plans.HavingPlan{Src: r.Src, Expr: r.Expr}, nil
|
||||
return &plans.HavingPlan{Src: r.Src, Expr: r.Expr, SelectList: r.SelectList}, nil
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer interface.
|
||||
|
||||
@ -35,12 +35,7 @@ func (s *testHavingRsetSuite) SetUpSuite(c *C) {
|
||||
// expr `id > 1`
|
||||
expr := expression.NewBinaryOperation(opcode.GT, &expression.Ident{CIStr: model.NewCIStr("id")}, expression.Value{Val: 1})
|
||||
|
||||
s.r = &HavingRset{Src: tblPlan, Expr: expr}
|
||||
}
|
||||
|
||||
func (s *testHavingRsetSuite) TestHavingRsetCheckAndUpdateSelectList(c *C) {
|
||||
resultFields := s.r.Src.GetFields()
|
||||
|
||||
resultFields := tblPlan.GetFields()
|
||||
fields := make([]*field.Field, len(resultFields))
|
||||
for i, resultField := range resultFields {
|
||||
name := resultField.Name
|
||||
@ -52,6 +47,13 @@ func (s *testHavingRsetSuite) TestHavingRsetCheckAndUpdateSelectList(c *C) {
|
||||
ResultFields: resultFields,
|
||||
Fields: fields,
|
||||
}
|
||||
s.r = &HavingRset{Src: tblPlan, Expr: expr, SelectList: selectList}
|
||||
}
|
||||
|
||||
func (s *testHavingRsetSuite) TestHavingRsetCheckAndUpdateSelectList(c *C) {
|
||||
resultFields := s.r.Src.GetFields()
|
||||
|
||||
selectList := s.r.SelectList
|
||||
|
||||
groupBy := []expression.Expression{}
|
||||
|
||||
|
||||
@ -207,8 +207,9 @@ func (s *SelectStmt) Plan(ctx context.Context) (plan.Plan, error) {
|
||||
|
||||
if s := s.Having; s != nil {
|
||||
if r, err = (&rsets.HavingRset{
|
||||
Src: r,
|
||||
Expr: s.Expr}).Plan(ctx); err != nil {
|
||||
Src: r,
|
||||
Expr: s.Expr,
|
||||
SelectList: selectList}).Plan(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user