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

[JoinReorder] Implement a better join reorder algorithm #6226

Merged
merged 1 commit into from
Jul 14, 2021

Conversation

EmmyMiao87
Copy link
Contributor

Proposed changes

The current JoinReorder algorithm mainly sorts according to the star model,
and only considers the query association relationship between the table and the table.
The problems are following:

  1. Only applicable to user data whose data model is a star model, data of other models cannot be sorted.
  2. Regardless of the cost of the table, it is impossible to determine the size of the join table relationship,
    and the real query optimization ability is weak.
  3. It is impossible to avoid possible time-consuming joins such as cross joins by sorting.

The new JoinReorder algorithm mainly introduces a new sorting algorithm for Join
The new ranking algorithm introduces the cost evaluation model to Doris.

The sorting algorithm is mainly based on the following three principles:

  1. The order is: Largest node, Smallest node. . . Second largest node
  2. Cross join is better than Inner join
  3. The right children of Outer join, semi join, and anti join do not move

PlanNode's cost model evaluation mainly relies on two values: cardinality and selectivity.
cardinality: cardinality, can also be simply understood as the number of rows.
selectivity: selectivity, a value between 0 and 1. Predicate generally has selectivity.
The cost model generally calculates the final cardinality of a PlanNode based on the pre-calculated
cardinality of PlanNode and the selectivity of the predicate to which it belongs.

Currently, you can configure "enable_cost_based_join_reorder" to control the opening and closing of JoinReorder.
When the configuration is turned on, the new sorting algorithm will take effect, when it is turned off,
the old sorting algorithm will take effect, and it is turned off by default.

The new sorting algorithm currently has no cost base evaluation for external tables (odbc, es)
and set calculations (intersect, except). When using these queries, it is not recommended to enable cost base join reoder.
When using these queries, it is not recommended to enable cost base join reoder.

At the code architecture level:

  1. The new sorting algorithm occurs in the single-node execution planning stage.
  2. Refactored the init and finalize phases of PlanNode to ensure that PlanNode planning
    and cost evaluation have been completed before the sorting algorithm occurs.

Change-Id: I6a89b20d70ff1d49909900f39337fa31cc8efd1e

Types of changes

What types of changes does your code introduce to Doris?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)
  • Code refactor (Modify the code structure, format the code, etc...)
  • Optimization. Including functional usability improvements and performance improvements.
  • Dependency. Such as changes related to third-party components.
  • Other.

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have created an issue on (Fix New Join Reorder #6225) and described the bug/feature there in detail
  • Compiling and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • If these changes need document changes, I have updated the document
  • Any dependent changes have been merged

The current JoinReorder algorithm mainly sorts according to the star model,
and only considers the query association relationship between the table and the table.
The problems are folllowing:
1. Only applicable to user data whose data model is a star model, data of other models cannot be sorted.
2. Regardless of the cost of the table, it is impossible to determine the size of the join table relationship,
   and the real query optimization ability is weak.
3. It is impossible to avoid possible time-consuming joins such as cross joins by sorting.

The new JoinReorder algorithm mainly introduces a new sorting algorithm for Join
The new ranking algorithm introduces the cost evaluation model to Doris.

The sorting algorithm is mainly based on the following three principles:
1. The order is: Largest node, Smallest node. . . Second largest node
2. Cross join is better than Inner join
3. The right children of Outer join, semi join, and anti join do not move

PlanNode's cost model evaluation mainly relies on two values: cardinality and selectivity.
cardinality: cardinality, can also be simply understood as the number of rows.
selectivity: selectivity, a value between 0 and 1. Predicate generally has selectivity.
The cost model generally calculates the final cardinality of a PlanNode based on the pre-calculated
cardinality of PlanNode and the selectivity of the predicate to which it belongs.

Currently, you can configure "enable_cost_based_join_reorder" to control the opening and closing of JoinReorder.
When the configuration is turned on, the new sorting algorithm will take effect, when it is turned off,
the old sorting algorithm will take effect, and it is turned off by default.

The new sorting algorithm currently has no cost base evaluation for external tables (odbc, es)
and set calculations (intersect, except). When using these queries, it is not recommended to enable cost base join reoder.
When using these queries, it is not recommended to enable cost base join reoder.

At the code architecture level:
1. The new sorting algorithm occurs in the single-node execution planning stage.
2. Refactored the init and finalize phases of PlanNode to ensure that PlanNode planning
   and cost evaluation have been completed before the sorting algorithm occurs.

Fixed apache#6225

Change-Id: I6a89b20d70ff1d49909900f39337fa31cc8efd1e
@EmmyMiao87 EmmyMiao87 added area/planner Issues or PRs related to the query planner kind/feature Categorizes issue or PR as related to a new feature. labels Jul 13, 2021
Copy link
Contributor

@morningman morningman left a comment

Choose a reason for hiding this comment

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

LGTM, merged from baidu inside.

@morningman morningman added the approved Indicates a PR has been approved by one committer. label Jul 13, 2021
@morningman morningman merged commit cbc42db into apache:master Jul 14, 2021
morningman added a commit to morningman/doris that referenced this pull request Jul 17, 2021
In PR apache#6226, we open the debug level of unit test, it cause some
unexpected exception.
morningman added a commit that referenced this pull request Jul 18, 2021
In PR #6226, we open the debug level of unit test, it cause some
unexpected exception.
@morningman morningman mentioned this pull request Oct 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by one committer. area/planner Issues or PRs related to the query planner kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Join Reorder
2 participants