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

Call For Participation: add rules for cascades optimizer #13709

Open
29 of 48 tasks
winoros opened this issue Nov 24, 2019 · 30 comments
Open
29 of 48 tasks

Call For Participation: add rules for cascades optimizer #13709

winoros opened this issue Nov 24, 2019 · 30 comments
Assignees
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.

Comments

@winoros
Copy link
Member

winoros commented Nov 24, 2019

In https://github.com/pingcap/tidb/blob/master/docs/design/2018-08-29-new-planner.md, we proposed a new planner based on cascades.
We create this issue to track the dev progress of the new planner.

If you're interested in this project, feel free to join the discussion by entering the slack channel #sig-planner in the tidbcommunity slack workspace. Or just pick some TODO issues listed in this tracking issue using the following working flow:

  1. Find one issue which you're interested in.
  2. If it's a simple work you can just reply in this issue to let the community know that issue is picked by you. Or you can create a separate issue to describe the rough implementation and discussing with the community.
  3. File new pull requests.

You can find the basic workflow for adding a transformation rule here.

The issues below with [easy] tag are highly recommended for new contributors.

Issues

@winoros winoros added sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement. labels Nov 24, 2019
@francis0407 francis0407 self-assigned this Nov 28, 2019
@francis0407
Copy link
Member

I highly recommend new contributors try rules like 'Limit PushDown' and 'TopN PushDown' above. They are truly easy to implement and can help you get familiar with the cascades framework.

@francis0407 francis0407 added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Nov 28, 2019
@tangwz
Copy link
Contributor

tangwz commented Nov 28, 2019

let me fix Limit PushDown.

@hsqlu
Copy link
Contributor

hsqlu commented Nov 28, 2019

I'd like to take TopN PushDown.

@francis0407
Copy link
Member

That's great. You'd better implement only one transformation rule in one PR. cc @tangwz @hsqlu

@zz-jason zz-jason changed the title Tracking issue for cascades optimizer Call For Participation: add rules for the cascades optimizer Nov 29, 2019
@zz-jason zz-jason changed the title Call For Participation: add rules for the cascades optimizer Call For Participation: add rules for cascades optimizer Nov 29, 2019
@francis0407 francis0407 added the good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. label Nov 29, 2019
@jiangyuzhao
Copy link
Contributor

@francis0407 Do you have some other recommendations for new contributors? Thank you very much!

@francis0407
Copy link
Member

You can try this transformation rule: PushSelDownWindow which pushes the Selection down to the child of Window. The current implementation is here:

func (p *LogicalWindow) PredicatePushDown(predicates []expression.Expression) ([]expression.Expression, LogicalPlan) {
.

The logic of this rule is simple, I think. You only need to implement this rule and add tests in cascades/testdata/transformation_rules_test_in.json/TestPredicatePushDown.

If you encounter any difficulties, you can ask us in slack. @jiangyuzhao

@jiangyuzhao
Copy link
Contributor

@francis0407 OK. Thank you very much. I will try to implement PushSelDownWindow. I'm a new contributor, and I'm not familiar with slack. Do you mean I can send comment below the issue?

@francis0407
Copy link
Member

francis0407 commented Nov 29, 2019

@jiangyuzhao Slack is a powerful software for online communication. You may need to sign up at first. Then check this link: https://pingcap.com/tidbslack/. We can discuss issues about cascades optimizer in the channel sig-planner.

@jiangyuzhao
Copy link
Contributor

@francis0407 Thanks for your explanation~

@gauss1314
Copy link
Contributor

Let me fix PushSelDownUnion from push the selection down to union of Predicate pushdown.

@pingyu
Copy link
Contributor

pingyu commented Dec 1, 2019

Let me fix merge the adjacent projection of Projection elimination

@francis0407
Copy link
Member

Hi guys,
If you are not sure how to implement a rule or how to add unit test for the rule, I think #13106 and #13288 could be good examples.
Note that GetPattern() is not used to define the Pattern anymore, you have to define a function like NewRuleXXXXX to create the rule you have implemented and define the pattern of the rule inside this function.

@francis0407
Copy link
Member

Workflow for Adding a Transformation Rule

Here is the basic workflow for adding a Transformation rule in cascades optimizer. Add Optimization Rules for Cascades Optimizer(in Chinese only) may provide more information.

Implement a Transformation Rule

  1. Define a struct for the rule, like PushSelDownAggregation.
  2. Implement two methods OnMatch() and OnTransform().
  3. Add a function NewRuleXXX to create such a rule, and register it's Pattern inside.

Add unit test for a Transformatino Rule

  1. Add the rule into transformation_rules.go/defaultTransformationMap. The position where it supposed to be depends on the top Operand of its Pattern. For example, if its Pattern is Selection->Projection, it should be in the group of memo.OperandSelection: { ... }.
  2. Add unit test case in transformation_rules_test.go, TestPredicatePushDown is a good example.
  3. Add the rule into the test optimizer's transformation map.
  4. Add test SQL in file testdata/transformation_rules_suite_in.json. Make sure those SQLs will trigger the rule you just implemented.
  5. Run go test with arguments --record, it will generate test results into file testdata/transformation_rules_suite_out.json.
  6. Check if the result shows the rule works.

@edytagarbarz
Copy link
Contributor

Let me fix Stream aggregation

@francis0407
Copy link
Member

Hi, @edytagarbarz
Stream aggregation might not be ready to be implemented now. It requires a bottom-up method to prune physical properties called PreparePossibleProperty(currently in file planner/core/property_cols_prune.go), which I'm still working on.
Could you please try other tasks? I think the implementationRule for LogicalWindow is quite easy to do.
When I finish the PreparePossibleProperty, I will let you know and invite you to fix the Stream agg.

@edytagarbarz
Copy link
Contributor

edytagarbarz commented Dec 3, 2019

@francis0407 definitely!
I'll do implementationRule for LogicalWindow then, thanks!

@jiangyuzhao
Copy link
Contributor

You can try this transformation rule: PushSelDownWindow which pushes the Selection down to the child of Window. The current implementation is here:

func (p *LogicalWindow) PredicatePushDown(predicates []expression.Expression) ([]expression.Expression, LogicalPlan) {

.
The logic of this rule is simple, I think. You only need to implement this rule and add tests in cascades/testdata/transformation_rules_test_in.json/TestPredicatePushDown.

If you encounter any difficulties, you can ask us in slack. @jiangyuzhao

@francis0407 I'm sorry for being busy this week. I will finish the task soon!

@francis0407
Copy link
Member

@jiangyuzhao Don't worry, enjoy the world of open source.

@edytagarbarz
Copy link
Contributor

Let me fix Aggregation elimination implement XfromAggToProj

@gauss1314
Copy link
Contributor

Let me fix Aggregation elimination implement XfromAggToProj

Hi @edytagarbarz , can I do this if you haven't started yet?

@SeaRise
Copy link
Contributor

SeaRise commented Feb 21, 2020

@gauss1314
I am so sorry...I've started to implement XfromAggToProj....

@jackwener
Copy link
Contributor

The task merge the adjacent Window. [easy] is completed by An-DJ.

@jackwener
Copy link
Contributor

Hi, I'm willing to take the Group merging for deduplication. [medium] up.

However, some of the backgrounds are rather scarce. Can you provide some background?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests