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:
You can find the basic workflow for adding a transformation rule here.
The issues below with [easy] tag are highly recommended for new contributors.
rule_predicate_push_down.go):attch2Task method of TopN and Limit):rule_eliminate_projection.go):rule_topn_push_down.go):rule_topn_push_down.go):rule_decorrelate.go):rule_max_min_eliminate.go):rule_aggregation_elimination.go):rule_aggregation_push_down.go):rule_join_elimination.go) @SeaRise #14465 PreparePossibleProperty #13910 only_full_group_by checking than TiDB current does and for further optimizations. [hard]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.
let me fix Limit PushDown.
I'd like to take TopN PushDown.
That's great. You'd better implement only one transformation rule in one PR. cc @tangwz @hsqlu
@francis0407 Do you have some other recommendations for new contributors? Thank you very much!
You can try this transformation rule: PushSelDownWindow which pushes the Selection down to the child of Window. The current implementation is here: https://github.com/pingcap/tidb/blob/d438c860a660f00c755094e1d6c9e61c18715edf/planner/core/rule_predicate_push_down.go#L564.
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 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?
@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.
@francis0407 Thanks for your explanation~
Let me fix PushSelDownUnion from push the selection down to union of Predicate pushdown.
Let me fix merge the adjacent projection of Projection elimination
Hi guys,
If you are not sure how to implement a rule or how to add unit test for the rule, I think https://github.com/pingcap/tidb/pull/13106 and https://github.com/pingcap/tidb/pull/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.
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.
PushSelDownAggregation.OnMatch() and OnTransform().NewRuleXXX to create such a rule, and register it's Pattern inside.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: { ... }.transformation_rules_test.go, TestPredicatePushDown is a good example.SQL in file testdata/transformation_rules_suite_in.json. Make sure those SQLs will trigger the rule you just implemented.--record, it will generate test results into file testdata/transformation_rules_suite_out.json.Let me fix Stream aggregation
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.
@francis0407 definitely!
I'll do implementationRule for LogicalWindow then, thanks!
You can try this transformation rule:
PushSelDownWindowwhich pushes the Selection down to the child of Window. The current implementation is here:.
The logic of this rule is simple, I think. You only need to implement this rule and add tests incascades/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!
@jiangyuzhao Don't worry, enjoy the world of open source.
If you are looking for PR examples, check the cascades project.
I'd like to fix eliminate the projection whose output columns are the same with its child from projection elimination.
Let me fix push the top-n down to gather of push operators down to tikv gather.
Let me fix:
push the top-n down to union #14214 implement XformMaxMinToTop1 #14274 merge the adjacent topN #14345 Merge join #14450 let me fix
merge the adjacent selection.let me fix push the limit down to projection
@doggeral If you need some help, you can contact us via slack channel #sig-planner in the tidbcommunity
Let me fix Aggregation elimination implement XfromAggToProj
Let me fix
Aggregation eliminationimplementXfromAggToProj
Hi @edytagarbarz , can I do this if you haven't started yet?
@gauss1314
I am so sorry...I've started to implement XfromAggToProj....