Skip to content

Conversation

@ankitsultana
Copy link
Contributor

@ankitsultana ankitsultana commented Apr 7, 2025

Ongoing work to add support for physical optimizers, this builds on top of these PRs.

Summary

  • LeafStageBoundaryRule: This marks the bottom-most project/filter/scan nodes as leaf stage.
  • LeafStageAggregateRule: When data is partitioned appropriately, then if we have Aggregate > (Leaf-Stage), then it would be possible to make Aggregate a part of the leaf stage. This rule is applied when either the is partitioned by group-by keys hint is present, or when we automatically detect that the data is partitioned on the group-by keys.
  • LeafStageWorkerAssignmentRule: Assigns workers to the leaf stage. Currently, this always checks if we can infer a Hash Dist property in the table scan.
  • DistMapping: Have added a dedicated class for computing mapping from source RelNode to a destination RelNode. The reason for this is to have maximal control. I am open to switching to Calcite's mapping in the future.
  • RelToPRelConverter: Converts the RelNode tree to a PRelNode tree.

Callouts

Leaf Stage Aggregate Rule

Right now the aggregate rules are kinda all over the place. Once I have a working E2E version I think it'll be easy to see if we can merge them into 1 rule. E.g. ideally I would have liked to handle this within the Aggregate Split rule itself, but doing that is tricky because the split happens after Exchange is added, and you could have parallelism change around the leaf stage boundary.

Trait Assignment on PRelNodes

During the PoC my approach was to assign traits to RelNodes. But given many RelNodes can drop traits, and we have built our own Physical* versions anyways, I have now switched to using PRelNodes for trait assignment.

@ankitsultana ankitsultana added multi-stage Related to the multi-stage query engine mse-physical-optimizer labels Apr 7, 2025
@ankitsultana ankitsultana changed the title [multistage] Add Leaf Stage Worker Assignment / Boundary / Agg Rules [WIP] [multistage] Add Leaf Stage Worker Assignment / Boundary / Agg Rules Apr 7, 2025
@codecov-commenter
Copy link

codecov-commenter commented Apr 8, 2025

Codecov Report

Attention: Patch coverage is 27.45995% with 317 lines in your changes missing coverage. Please review.

Project coverage is 62.83%. Comparing base (59551e4) to head (8e4015e).
Report is 2033 commits behind head on master.

Files with missing lines Patch % Lines
...al/v2/opt/rules/LeafStageWorkerAssignmentRule.java 46.79% 99 Missing and 9 partials ⚠️
.../query/planner/physical/v2/RelToPRelConverter.java 0.00% 62 Missing ⚠️
...nner/physical/v2/mapping/DistMappingGenerator.java 0.00% 47 Missing ⚠️
.../physical/v2/opt/rules/LeafStageAggregateRule.java 0.00% 27 Missing ⚠️
...r/physical/v2/opt/rules/LeafStageBoundaryRule.java 0.00% 19 Missing ⚠️
...ache/pinot/calcite/rel/traits/TraitAssignment.java 0.00% 15 Missing ⚠️
...ache/pinot/query/planner/physical/v2/PRelNode.java 0.00% 8 Missing ⚠️
...t/query/planner/physical/v2/opt/RuleExecutors.java 0.00% 7 Missing ⚠️
...y/planner/physical/v2/nodes/PhysicalAggregate.java 0.00% 4 Missing ⚠️
...ery/planner/physical/v2/nodes/PhysicalProject.java 0.00% 4 Missing ⚠️
... and 7 more
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #15481      +/-   ##
============================================
+ Coverage     61.75%   62.83%   +1.07%     
- Complexity      207     1381    +1174     
============================================
  Files          2436     2856     +420     
  Lines        133233   162017   +28784     
  Branches      20636    24851    +4215     
============================================
+ Hits          82274   101797   +19523     
- Misses        44911    52532    +7621     
- Partials       6048     7688    +1640     
Flag Coverage Δ
custom-integration1 100.00% <ø> (+99.99%) ⬆️
integration 100.00% <ø> (+99.99%) ⬆️
integration1 100.00% <ø> (+99.99%) ⬆️
integration2 0.00% <ø> (ø)
java-11 62.80% <27.45%> (+1.09%) ⬆️
java-21 62.81% <27.45%> (+1.18%) ⬆️
skip-bytebuffers-false 62.82% <27.45%> (+1.08%) ⬆️
skip-bytebuffers-true 62.79% <27.45%> (+35.07%) ⬆️
temurin 62.83% <27.45%> (+1.07%) ⬆️
unittests 62.82% <27.45%> (+1.07%) ⬆️
unittests1 55.79% <27.45%> (+8.89%) ⬆️
unittests2 33.57% <0.00%> (+5.84%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ankitsultana ankitsultana changed the title [WIP] [multistage] Add Leaf Stage Worker Assignment / Boundary / Agg Rules [multistage] Add Leaf Stage Worker Assignment / Boundary / Agg Rules Apr 8, 2025
@ankitsultana ankitsultana marked this pull request as ready for review April 8, 2025 20:29
@Jackie-Jiang Jackie-Jiang requested a review from gortiz April 9, 2025 21:20
Copy link
Contributor

@itschrispeck itschrispeck left a comment

Choose a reason for hiding this comment

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

Looks good afaict, though I'd like to take another look after the next couple PRs when I can step through some tests.

Comment on lines +102 to +104
return new PhysicalAggregate(aggRel.getCluster(), aggRel.getTraitSet(), aggRel.getHints(), aggRel.getGroupSet(),
aggRel.getGroupSets(), aggRel.getAggCallList(), nodeIdGenerator.get(), inputs.get(0), null, false,
AggregateNode.AggType.DIRECT, false, List.of(), 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Trying to understand, why is this always direct?

Copy link
Contributor Author

@ankitsultana ankitsultana Apr 11, 2025

Choose a reason for hiding this comment

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

Direct mode aggregate means there's no partial aggregate, and we directly compute the full aggregate.

I am setting it to Direct right now because we are not doing the aggregate split yet. I'll add it in the next PR (or the one after that)

@ankitsultana ankitsultana merged commit 04c8a4f into apache:master Apr 14, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mse-physical-optimizer multi-stage Related to the multi-stage query engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants