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

[Feature](Nereids) Support materialized index selection. #13416

Merged
merged 7 commits into from
Oct 25, 2022

Conversation

wangshuo128
Copy link
Contributor

@wangshuo128 wangshuo128 commented Oct 17, 2022

Proposed changes

This PR unified the selection of rollup index and materialized view index into uniform logic, which is called selecting materialized index.

Main steps:

Find candidate indexes

  1. When aggregate is present, it's handled in SelectMaterializedIndexWithAggregate. The base index and indexes that could use pre-aggregation should be used. The pre-aggregation status is determined by aggregation function, grouping expression, and pushdown predicates.
  2. When aggregate is not on top of scan node, it's handled in SelectMaterializedIndexWithoutAggregate. The base index and indexes that have all the key columns could be used.

Filter and order the candidate indexes

  1. filter indexes that contain all the required output scan columns.
  2. filter indexes that could match prefix index most.
  3. order the result index by row count, column count, and index id.

Problem summary

Describe your changes.

Checklist(Required)

  1. Does it affect the original behavior:
    • Yes
    • No
    • I don't know
  2. Has unit tests been added:
    • Yes
    • No
    • No Need
  3. Has document been added or modified:
    • Yes
    • No
    • No Need
  4. Does it need to update dependencies:
    • Yes
    • No
  5. Are there any changes that cannot be rolled back:
    • Yes (If Yes, please explain WHY)
    • No

Further comments

If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...

@@ -543,7 +398,7 @@ public CheckContext(LogicalOlapScan scan) {
)
));
Copy link
Contributor

Choose a reason for hiding this comment

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

Map<Boolean, Map<String, Column>> nameToColumnGroupingByIsKey
    = scan.getTable().getSchemaByIndexId(indexId)
        .collect(Collectors.groupingBy(
                Column::isKey,
                Collectors.toMap(Column::getName, Function.identity())
        ));

Copy link
Contributor

Choose a reason for hiding this comment

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

rename checkHasNoValueTypeColumn method to disablePreAggIfContainsAnyValueColumn

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -313,22 +312,13 @@ public PlanFragment visitPhysicalOlapScan(PhysicalOlapScan olapScan, PlanTransla
tupleDescriptor.setRef(tableRef);
olapScanNode.setSelectedPartitionIds(olapScan.getSelectedPartitionIds());
Copy link
Contributor

Choose a reason for hiding this comment

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

olapScanNode should be immutable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

olapScanNode is the plan node in old planner. OlapScanNode.setXXX is to set the result of nereids planner to OlapScanNode in old planner.

924060929
924060929 previously approved these changes Oct 24, 2022
@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Oct 24, 2022
@github-actions
Copy link
Contributor

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Contributor

PR approved by anyone and no changes requested.

@924060929
Copy link
Contributor

924060929 commented Oct 24, 2022

we should flat filter candidate indexes to refine code later.

*/
public boolean shouldSelectRollup() {
public boolean shouldSelectIndex() {
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to remove this function and use isIndexSelected instead?

Copy link
Contributor Author

@wangshuo128 wangshuo128 Oct 25, 2022

Choose a reason for hiding this comment

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

This was to do two things:

  1. judge indexSelected is true or false
  2. make sure the keys type of the OLAP table is DUP_KEYS, UNIQUE_KEYS, or AGG_KEYS, but it should not be PRIMARY_KEYS. Even if it seems PRIMARY_KEYS is not used, it's safe to ensure the scope to apply materialized view selection rules is right.

I would keep the getter method of the status of indexSelected in LogicalOlapScan and move the condition of applying materialized view selection to the rule itself.

@morrySnow morrySnow linked an issue Oct 25, 2022 that may be closed by this pull request
15 tasks
@github-actions github-actions bot removed the approved Indicates a PR has been approved by one committer. label Oct 25, 2022
@morrySnow morrySnow merged commit d6c3470 into apache:master Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/nereids area/planner Issues or PRs related to the query planner reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Support rollup and materialized view in nereids planner.
3 participants