Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aggregation, plan: split the presentation and evaluation layers of aggregation functions #5635

Merged
merged 8 commits into from Jan 15, 2018

Conversation

zz-jason
Copy link
Member

@zz-jason zz-jason commented Jan 14, 2018

With this patch, I split the Aggregation interface to presentation and evaluation layers.

  1. In presentation layer, we use AggFuncDesc to describe an aggregation function, witch contains all the informations and APIs needed by planner.
  2. In evaluation layer, we use the old Aggregation interface to represent the evaluator of a particular AggFuncDesc object, irrelevant APIs are removed.
  3. We use AggFuncDesc.GetAggFunc() to get the an instance of Aggregation as the corresponding evaluator.

After this PR, we are able to:

  1. In presentation layer, we can do the type inference and construct particular evaluator according to the aggregation function descriptor.
  2. In evaluation layer, we can refactor all the aggregation evaluators on the most efficient way one by one.(the performance gain is about 30% in my test case)

@zz-jason
Copy link
Member Author

/run-all-tests

@shenli
Copy link
Member

shenli commented Jan 14, 2018

Please add a few description for the PR.

@zz-jason
Copy link
Member Author

/run-all-tests tidb-test=pr/446

@ngaut
Copy link
Member

ngaut commented Jan 14, 2018

Cool

// TODO: a.Args[0] = expression.WrapWithCastAsInt(ctx, a.Args[0])
}

func (a *AggFuncDesc) calculateDefaultVale4Count(ctx context.Context, schema *expression.Schema) (types.Datum, bool) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vale -> Value.

}

// GetEvaluator gets an evaluator according to the aggregation function signature.
func (a *AggFuncDesc) GetEvaluator() Aggregation {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just GetAggFunc or GetAggregation?
We can distinguish it from Aggregation by Desc already.

@zz-jason
Copy link
Member Author

@lamxTyler @coocood @XuHuaiyu PTAL

firstRow := aggregation.NewAggFunction(ast.AggFuncFirstRow, []expression.Expression{gbyCol.Clone()}, false)
newAggFuncs = append(newAggFuncs, firstRow)
firstRow := aggregation.NewAggFuncDesc(ast.AggFuncFirstRow, []expression.Expression{gbyCol.Clone()}, false)
firstRow.TypeInfer(agg.ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just combine the TypeInfer and NewFuncDesc for the complete model? Almost every NewFuncDesc is followed by TypeInfer.

@coocood
Copy link
Member

coocood commented Jan 15, 2018

LGTM

@coocood coocood added the status/LGT1 Indicates that a PR has LGTM 1. label Jan 15, 2018
@@ -39,6 +39,10 @@ func (p *LogicalSelection) preparePossibleProperties() (result [][]*expression.C
return p.children[0].preparePossibleProperties()
}

func (p *LogicalProjection) preparePossibleProperties() (result [][]*expression.Column) {
return p.children[0].(LogicalPlan).preparePossibleProperties()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to do type assertion. Also, this is an irrelevant change?

Copy link
Contributor

@alivxxx alivxxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alivxxx alivxxx added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jan 15, 2018
@zz-jason zz-jason merged commit 2550969 into pingcap:master Jan 15, 2018
@zz-jason zz-jason deleted the dev/plan/aggregation branch January 15, 2018 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants