You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "wirybeaver (via GitHub)" <gi...@apache.org> on 2026/05/26 07:00:03 UTC
[PR] fix(physical-plan): make HashJoinExec dynamic filter pushdown idempotent [datafusion]
wirybeaver opened a new pull request, #22523:
URL: https://github.com/apache/datafusion/pull/22523
## Which issue does this PR close?
Related to https://github.com/apache/datafusion-ballista/issues/1359
## Rationale
Ballista's Adaptive Query Execution (AQE) planner re-invokes DataFusion's full `PhysicalOptimizer` chain after every completed stage. `FilterPushdown::new_post_optimization()` is not idempotent on plans containing `HashJoinExec`.
In the `Post` phase, `HashJoinExec::gather_filters_for_pushdown` unconditionally creates a new `DynamicFilterPhysicalExpr` and installs it on the probe-side child via `with_self_filter`. After pass 1 the join already carries a `dynamic_filter: Some(...)`, and the shared `Arc<DynamicFilterPhysicalExpr>` is already wired into the probe-side scan's predicate. On pass 2 a *second* dynamic filter is created and ANDed onto the existing predicate, producing `DynamicFilter AND DynamicFilter`. Each subsequent pass adds another duplicate, compounding indefinitely in AQE replan loops.
## What changes are included in this PR?
- **Guard in `HashJoinExec::gather_filters_for_pushdown`**: skip dynamic-filter creation when `self.dynamic_filter.is_some()`, meaning a previous pass already installed one. The existing `Arc` remains valid and correctly wired into the probe-side scan.
- **Comment** explaining why the guard is needed (AQE replan context).
- **Test** `post_phase_is_idempotent_on_hash_join` in `tests/physical_optimizer/filter_pushdown.rs`: builds a `HashJoinExec`, runs `FilterPushdown::new_post_optimization()` twice, and asserts structural equality via `get_plan_string`.
## Are these changes tested?
Yes. The new test fails without the fix (plan strings diverge due to duplicated dynamic filter predicates) and passes with it.
## Are there any user-facing changes?
No. Dynamic filter pushdown is an internal optimization; the idempotence guard only affects re-optimization scenarios (AQE).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix(physical-plan): make HashJoinExec dynamic filter pushdown idempotent [datafusion]
Posted by "adriangb (via GitHub)" <gi...@apache.org>.
adriangb commented on PR #22523:
URL: https://github.com/apache/datafusion/pull/22523#issuecomment-4583132776
I think it's not too late to ask for something minor like this to be ported to 54 if that helps
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix(physical-plan): make HashJoinExec dynamic filter pushdown idempotent [datafusion]
Posted by "milenkovicm (via GitHub)" <gi...@apache.org>.
milenkovicm commented on PR #22523:
URL: https://github.com/apache/datafusion/pull/22523#issuecomment-4580060586
@adriangb or @gabotechs would be great if you could have a look, you'd know this code much better than me. thanks a lot
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix(physical-plan): make HashJoinExec dynamic filter pushdown idempotent [datafusion]
Posted by "milenkovicm (via GitHub)" <gi...@apache.org>.
milenkovicm commented on code in PR #22523:
URL: https://github.com/apache/datafusion/pull/22523#discussion_r3327018694
##########
datafusion/physical-plan/src/joins/hash_join/exec.rs:
##########
@@ -1635,8 +1640,14 @@ impl ExecutionPlan for HashJoinExec {
ChildFilterDescription::all_unsupported(&parent_filters)
};
- // Add dynamic filters in Post phase if enabled
+ // Add dynamic filters in Post phase if enabled. Skip when this join
+ // already carries a dynamic filter from a previous pass — the shared
+ // `Arc<DynamicFilterPhysicalExpr>` is still wired into the probe-side
+ // scan's predicate, and re-creating it would AND a fresh duplicate
+ // onto every Post-phase invocation (apache/datafusion-ballista#1359
+ // surfaces this in AQE replan loops).
if phase == FilterPushdownPhase::Post
+ && self.dynamic_filter.is_none()
Review Comment:
Unfortunately i dont know much about this peace of code, this might provide correct result but i'm not sure if this is correct way to do it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix(physical-plan): make HashJoinExec dynamic filter pushdown idempotent [datafusion]
Posted by "milenkovicm (via GitHub)" <gi...@apache.org>.
milenkovicm commented on PR #22523:
URL: https://github.com/apache/datafusion/pull/22523#issuecomment-4582006752
@wirybeaver not sure if we can move this optimizers to ballista until df 55 is released
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix(physical-plan): make HashJoinExec dynamic filter pushdown idempotent [datafusion]
Posted by "wirybeaver (via GitHub)" <gi...@apache.org>.
wirybeaver commented on PR #22523:
URL: https://github.com/apache/datafusion/pull/22523#issuecomment-4581957456
> This seems like a reasonable way to do this 👍
>
> Do we have the same situation with SortExec
Dynamic filtering seems to be only applied to HashJoinExec. Let me double check this weekend
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix(physical-plan): make HashJoinExec dynamic filter pushdown idempotent [datafusion]
Posted by "milenkovicm (via GitHub)" <gi...@apache.org>.
milenkovicm commented on PR #22523:
URL: https://github.com/apache/datafusion/pull/22523#issuecomment-4586070327
@wirybeaver would you like to backport this PR to 54 release branch? @adriangb has kindly offered to review it. Details could be found at #21080
If you don't get chance to do it I'll do it tomorrow
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix(physical-plan): make HashJoinExec dynamic filter pushdown idempotent [datafusion]
Posted by "milenkovicm (via GitHub)" <gi...@apache.org>.
milenkovicm commented on PR #22523:
URL: https://github.com/apache/datafusion/pull/22523#issuecomment-4605314999
Ive moved optimizers to ballista until DF55 released, no need to backport for now https://github.com/apache/datafusion-ballista/pull/1806
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix(physical-plan): make HashJoinExec dynamic filter pushdown idempotent [datafusion]
Posted by "adriangb (via GitHub)" <gi...@apache.org>.
adriangb merged PR #22523:
URL: https://github.com/apache/datafusion/pull/22523
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix(physical-plan): make HashJoinExec dynamic filter pushdown idempotent [datafusion]
Posted by "milenkovicm (via GitHub)" <gi...@apache.org>.
milenkovicm commented on PR #22523:
URL: https://github.com/apache/datafusion/pull/22523#issuecomment-4583229452
thats actually good idea
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix(physical-plan): make HashJoinExec dynamic filter pushdown idempotent [datafusion]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #22523:
URL: https://github.com/apache/datafusion/pull/22523#issuecomment-4571696002
<!-- semver-check-comment -->
Thank you for opening this pull request!
Reviewer note: [cargo-semver-checks](https://github.com/obi1kenobi/cargo-semver-checks) reported the current version number is not SemVer-compatible with the changes in this pull request (compared against the base branch).
<details>
<summary>Details</summary>
```
Cloning apache/main
Building datafusion v53.1.0 (current)
Built [ 103.261s] (current)
Parsing datafusion v53.1.0 (current)
Parsed [ 0.038s] (current)
Building datafusion v53.1.0 (baseline)
Built [ 106.552s] (baseline)
Parsing datafusion v53.1.0 (baseline)
Parsed [ 0.038s] (baseline)
Checking datafusion v53.1.0 -> v53.1.0 (no change; assume patch)
Checked [ 0.851s] 222 checks: 222 pass, 30 skip
Summary no semver update required
Finished [ 213.151s] datafusion
Building datafusion-physical-plan v53.1.0 (current)
Built [ 34.178s] (current)
Parsing datafusion-physical-plan v53.1.0 (current)
Parsed [ 0.134s] (current)
Building datafusion-physical-plan v53.1.0 (baseline)
Built [ 37.168s] (baseline)
Parsing datafusion-physical-plan v53.1.0 (baseline)
Parsed [ 0.135s] (baseline)
Checking datafusion-physical-plan v53.1.0 -> v53.1.0 (no change; assume patch)
Checked [ 0.799s] 222 checks: 219 pass, 3 fail, 0 warn, 30 skip
--- failure feature_missing: package feature removed or renamed ---
Description:
A feature has been removed from this package's Cargo.toml. This will break downstream crates which enable that feature.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#cargo-feature-remove
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/feature_missing.ron
Failed in:
feature proto in the package's Cargo.toml
--- failure inherent_method_missing: pub method removed or renamed ---
Description:
A publicly-visible method or associated fn is no longer available under its prior name. It may have been renamed or removed entirely.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/inherent_method_missing.ron
Failed in:
HashExpr::try_from_proto, previously in file /home/runner/work/datafusion/datafusion/target/semver-checks/git-apache_main/0bb8e03b86530af65a4c830ec6e20c30806b5ecb/datafusion/physical-plan/src/joins/hash_join/partitioned_hash_eval.rs:237
--- failure trait_method_missing: pub trait method removed or renamed ---
Description:
A trait method is no longer callable, and may have been renamed or removed entirely.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#trait-item-signature
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/trait_method_missing.ron
Failed in:
method downcast_delegate of trait ExecutionPlan, previously in file /home/runner/work/datafusion/datafusion/target/semver-checks/git-apache_main/0bb8e03b86530af65a4c830ec6e20c30806b5ecb/datafusion/physical-plan/src/execution_plan.rs:138
method downcast_delegate of trait ExecutionPlan, previously in file /home/runner/work/datafusion/datafusion/target/semver-checks/git-apache_main/0bb8e03b86530af65a4c830ec6e20c30806b5ecb/datafusion/physical-plan/src/execution_plan.rs:138
Summary semver requires new major version: 3 major and 0 minor checks failed
Finished [ 74.245s] datafusion-physical-plan
```
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org