Skip to content

refactor: move EnforceDistribution per-child flags into ChildPolicy - #26716

Merged
alamb merged 1 commit into
apache:mainfrom
Aaryan-Dadu:refactor/26299-child-policy
Nov 13, 2026
Merged

alamb merged 1 commit into
apache:mainfrom
Aaryan-Dadu:refactor/26299-child-policy

Conversation

@Aaryan-Dadu

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Step 1 from the issue. The per-child closure in ensure_distribution_with_stats works out several flags inline (allow_subset_satisfy_partitioning, add_roundrobin, needs_repartition, ...). They depend on each other and can only be tested through full plan tests right now. This moves them into one place so they can be unit tested. No behaviour change.

What changes are included in this PR?

  • ChildPolicyConfig: the settings that are the same for every child.
  • ChildPolicy::new: works out the flags for one child. The partial aggregate check (including the partial_aggregate_input_keeps_groups_local case from feat: reuse range partitioning for date_trunc aggregation #26449) is passed as a closure, so it still only runs when it did before.
  • ChildPolicy::needs_hash_repartition: the repartition decision from the hash arm.
  • The closure now uses these. The rest of the function is unchanged.

What is the testing strategy for this PR?

New unit tests in enforce_distribution.rs for the flags. The existing physical_optimizer tests and sqllogictests pass without changes.

Are there any user-facing changes?

No

Copilot AI balanced review requested due to automatic review settings October 24, 2026 15:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@github-actions github-actions Bot added the optimizer Optimizer rules label Oct 24, 2026
@Aaryan-Dadu

Copy link
Copy Markdown
Contributor Author

@andygrove gentle ping, could you take a look when you get a chance? CI also needs approval to run.

@kosiew kosiew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Aaryan-Dadu, thanks for this refactor. Extracting the interacting distribution-policy decisions makes them easier to understand and test independently. The approach is appropriate for the issue's scope, and the focused tests cover the important threshold and preservation interactions.

The extraction stays at the existing decision boundary without introducing a competing implementation or changing public contracts. Static comparison confirms that the predicates, lazy aggregate checks, and repartitioning decisions retain their behavior. Source repartitioning, range scaling, co-partitioning enforcement, and ordering restoration remain consistent with the previous implementation.

I'm approving because the change improves local maintainability without altering optimizer behavior. The targeted unit and integration suites passed. I've left two optional suggestions concerning legacy partitioning coverage and documentation of the partition-count snapshot boundary; neither is blocking.

!policy(&config, TARGET, hash_on(&["a"])).allow_subset_satisfy_partitioning
);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Optional coverage suggestion: could we test the grouping-ID policy with both KeyPartitioned and deprecated HashPartitioned? ChildPolicy::new supports both, but hash_on only constructs KeyPartitioned. A small table-driven test would help protect the legacy case during migration.

maintains,
RepartitionRequirementStatus {
|(child_idx, mut child, required_input_ordering, maintains, status)| {
let policy = ChildPolicy::new(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Optional documentation suggestion: could we clarify that the policy intentionally captures the partition count before source repartitioning, while hash eligibility uses the updated count afterward? A short comment would make this snapshot boundary easier to understand without changing the existing behavior.

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks nice -- thank you @Aaryan-Dadu and @kosiew

FYI @jayzhan211 and @zhuqi-lucas

@kosiew

kosiew commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

🚀
@Aaryan-Dadu
Thank you for your contribution.

@kosiew
kosiew added this pull request to the merge queue Nov 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 13, 2026
@alamb
alamb added this pull request to the merge queue Nov 13, 2026
Merged via the queue into apache:main with commit 4c7b307 Nov 13, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules v57.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants