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

planner/core: simple greedy join reorder based on CBO #8394

Merged
merged 11 commits into from
Dec 7, 2018

Conversation

winoros
Copy link
Member

@winoros winoros commented Nov 22, 2018

What problem does this PR solve?

Let the default join reorder by greedy use CBO.

What is changed and how it works?

Removed old one, add the new greedy algo.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test: TPCH performance checking.

Side effects

No

Related changes

  • Need to be included in the release note. Let default join reorder use CBO.

This change is Reviewable

@winoros
Copy link
Member Author

winoros commented Nov 22, 2018

TPCH
Q5: cannot get result -> 55s
Q8: 46s->11s
Q17 66s->105s
Q18 80s->90s
Q21: 1min24s->24s

Need some investigation on Q17 and Q18.

@ngaut
Copy link
Member

ngaut commented Nov 22, 2018

What's the results of star benchmark?

@winoros
Copy link
Member Author

winoros commented Nov 22, 2018

@ngaut TiDB haven't tested SSB yet. It will takes some time to do it.

@winoros
Copy link
Member Author

winoros commented Nov 22, 2018

Update for TPCH Q17:
Original join order is Join{Join{DataSource[2K rows], DataSource[60M rows]}[6w rows], Agg[2M rows]}[5K rows]

New order is Join{Join{DataSource[2K rows], Agg[2M rows]}[5K rows], DataSource[60M rows]}[5K rows]

You cannot say that the new order(don't care about the actual operator node below) is worse than before.
The problem is that the old one can let agg and inner join execute at the same time. While the new one will let the inner join waiting for agg's execution. And after that, begin to join with the 60M rows' DataSource. So it loses.

This can be optimized i think. But will leave it for future pr to do.

@zz-jason
Copy link
Member

The problem here is we haven't consider the physical cost of the join order, only the number of rows of the intermediate result are considered in this greedy algorithm.

@zz-jason zz-jason added type/enhancement The issue or PR belongs to an enhancement. sig/planner SIG: Planner labels Nov 22, 2018
planner/core/rule_join_reorder_greedy.go Outdated Show resolved Hide resolved
planner/core/rule_join_reorder_greedy.go Show resolved Hide resolved
planner/core/rule_join_reorder_greedy.go Outdated Show resolved Hide resolved
planner/core/rule_join_reorder_greedy.go Show resolved Hide resolved
Copy link
Contributor

@eurekaka eurekaka left a comment

Choose a reason for hiding this comment

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

LGTM

@eurekaka eurekaka added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 23, 2018
planner/core/rule_join_reorder_dp.go Outdated Show resolved Hide resolved
planner/core/rule_join_reorder_dp.go Outdated Show resolved Hide resolved
)

func extractInnerJoinGroup(p *LogicalJoin) ([]LogicalPlan, []*expression.ScalarFunction, []expression.Expression) {
if p.reordered || p.preferJoinType > uint(0) || p.JoinType != InnerJoin || p.StraightJoin {
Copy link
Member

Choose a reason for hiding this comment

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

Why stop extracting inner join groups when p.preferJoinType > uint(0)? IMHO, It's only a hint about join algorithm, not the join order.

Copy link
Member Author

Choose a reason for hiding this comment

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

Emm, we can do this.

Copy link
Member

Choose a reason for hiding this comment

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

OK. Could you please update code to remove this check in this function?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, when do join reorder, we create new join node. And when creating it. We missed the join hint information. We need to change the way we hold it before we remove this check.

planner/core/rule_join_reorder_greedy.go Outdated Show resolved Hide resolved
planner/core/rule_join_reorder_greedy.go Outdated Show resolved Hide resolved
planner/core/rule_join_reorder_greedy.go Show resolved Hide resolved
planner/core/rule_join_reorder_greedy.go Show resolved Hide resolved
planner/core/rule_join_reorder_greedy.go Outdated Show resolved Hide resolved
planner/core/rule_join_reorder_greedy.go Outdated Show resolved Hide resolved
planner/core/rule_join_reorder_greedy.go Outdated Show resolved Hide resolved
@winoros
Copy link
Member Author

winoros commented Nov 30, 2018

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

@zz-jason
Copy link
Member

zz-jason commented Dec 6, 2018

/run-all-tests

planner/core/rule_join_reorder_dp.go Outdated Show resolved Hide resolved
planner/core/rule_join_reorder_dp.go Outdated Show resolved Hide resolved
)

func extractInnerJoinGroup(p *LogicalJoin) ([]LogicalPlan, []*expression.ScalarFunction, []expression.Expression) {
if p.reordered || p.preferJoinType > uint(0) || p.JoinType != InnerJoin || p.StraightJoin {
Copy link
Member

Choose a reason for hiding this comment

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

OK. Could you please update code to remove this check in this function?

planner/core/rule_join_reorder_greedy.go Outdated Show resolved Hide resolved
planner/core/rule_join_reorder_greedy.go Show resolved Hide resolved
planner/core/rule_join_reorder_greedy.go Outdated Show resolved Hide resolved
planner/core/rule_join_reorder_greedy.go Show resolved Hide resolved
planner/core/rule_join_reorder_greedy.go Show resolved Hide resolved
planner/core/rule_join_reorder_greedy.go Outdated Show resolved Hide resolved
planner/core/rule_join_reorder_greedy.go Show resolved Hide resolved
planner/core/rule_join_reorder_greedy.go Outdated Show resolved Hide resolved
planner/core/rule_join_reorder_greedy.go Outdated Show resolved Hide resolved
Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason
Copy link
Member

zz-jason commented Dec 7, 2018

/run-all-tests

@zz-jason zz-jason added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Dec 7, 2018
@zz-jason
Copy link
Member

zz-jason commented Dec 7, 2018

/run-integration-common-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants