Skip to content

perf: push left filters through ASOF joins - #24801

Draft
Xuanwo wants to merge 4 commits into
apache:mainfrom
Xuanwo:xuanwo/asof-filter-pushdown
Draft

perf: push left filters through ASOF joins#24801
Xuanwo wants to merge 4 commits into
apache:mainfrom
Xuanwo:xuanwo/asof-filter-pushdown

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Aug 30, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

Rationale for this change

An ASOF join emits each left row exactly once and does not change left-side
values. A deterministic predicate that references only the left input can
therefore run before matching. Right-only and mixed predicates must remain
above the join because unmatched right fields are NULL-padded, and volatile
predicates must keep their original evaluation point.

Pushing the safe subset reduces the number of rows entering the ASOF join
without changing query results.

GitHub shows the cumulative stack because fork branches cannot be selected as
upstream PR bases. The isolated diff for this layer is:
Xuanwo/datafusion@xuanwo/asof-logical...xuanwo/asof-filter-pushdown

What changes are included in this PR?

  • Push deterministic left-only conjuncts below logical ASOF joins.
  • Keep right-only, mixed, and volatile predicates above the join.
  • Document the cardinality and NULL-padding assumptions at the optimizer rule.
  • Add focused optimizer snapshots for all four predicate categories.

Are these changes tested?

  • cargo fmt --all
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test --profile ci -p datafusion-optimizer asof_join_ --all-features
  • The extended workspace test command from the contributor guide

Are there any user-facing changes?

No result semantics or public APIs change. Eligible ASOF joins may execute with
fewer left-side rows after logical optimization.

@github-actions github-actions Bot added sql SQL Planner logical-expr Logical plan and expressions optimizer Optimizer rules core Core DataFusion crate substrait Changes to the substrait crate proto Related to proto crate physical-plan Changes to the physical-plan crate labels Aug 30, 2026
@github-actions

Copy link
Copy Markdown

Thank you for opening this pull request!

Reviewer note: 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
     Cloning apache/main
    Building datafusion v55.0.0 (current)
       Built [  57.369s] (current)
     Parsing datafusion v55.0.0 (current)
      Parsed [   0.037s] (current)
    Building datafusion v55.0.0 (baseline)
       Built [  56.759s] (baseline)
     Parsing datafusion v55.0.0 (baseline)
      Parsed [   0.038s] (baseline)
    Checking datafusion v55.0.0 -> v55.0.0 (no change; assume patch)
     Checked [   0.864s] 223 checks: 223 pass, 31 skip
     Summary no semver update required
    Finished [ 117.216s] datafusion
    Building datafusion-expr v55.0.0 (current)
       Built [  28.357s] (current)
     Parsing datafusion-expr v55.0.0 (current)
      Parsed [   0.081s] (current)
    Building datafusion-expr v55.0.0 (baseline)
       Built [  28.744s] (baseline)
     Parsing datafusion-expr v55.0.0 (baseline)
      Parsed [   0.082s] (baseline)
    Checking datafusion-expr v55.0.0 -> v55.0.0 (no change; assume patch)
     Checked [   1.928s] 223 checks: 222 pass, 1 fail, 0 warn, 31 skip

--- failure enum_variant_added: enum variant added on exhaustive enum ---

Description:
A publicly-visible enum without #[non_exhaustive] has a new variant.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#enum-variant-new
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.50.0/src/lints/enum_variant_added.ron

Failed in:
  variant LogicalPlan:AsOfJoin in /home/runner/work/datafusion/datafusion/datafusion/expr/src/logical_plan/plan.rs:301
  variant LogicalPlan:AsOfJoin in /home/runner/work/datafusion/datafusion/datafusion/expr/src/logical_plan/plan.rs:301

     Summary semver requires new major version: 1 major and 0 minor checks failed
    Finished [  60.464s] datafusion-expr
    Building datafusion-optimizer v55.0.0 (current)
       Built [  26.596s] (current)
     Parsing datafusion-optimizer v55.0.0 (current)
      Parsed [   0.033s] (current)
    Building datafusion-optimizer v55.0.0 (baseline)
       Built [  26.526s] (baseline)
     Parsing datafusion-optimizer v55.0.0 (baseline)
      Parsed [   0.034s] (baseline)
    Checking datafusion-optimizer v55.0.0 -> v55.0.0 (no change; assume patch)
     Checked [   0.225s] 223 checks: 223 pass, 31 skip
     Summary no semver update required
    Finished [  54.456s] datafusion-optimizer
    Building datafusion-physical-plan v55.0.0 (current)
       Built [  37.425s] (current)
     Parsing datafusion-physical-plan v55.0.0 (current)
      Parsed [   0.156s] (current)
    Building datafusion-physical-plan v55.0.0 (baseline)
       Built [  37.128s] (baseline)
     Parsing datafusion-physical-plan v55.0.0 (baseline)
      Parsed [   0.158s] (baseline)
    Checking datafusion-physical-plan v55.0.0 -> v55.0.0 (no change; assume patch)
     Checked [   1.058s] 223 checks: 223 pass, 31 skip
     Summary no semver update required
    Finished [  77.527s] datafusion-physical-plan
    Building datafusion-proto v55.0.0 (current)
       Built [  52.623s] (current)
     Parsing datafusion-proto v55.0.0 (current)
      Parsed [   0.018s] (current)
    Building datafusion-proto v55.0.0 (baseline)
       Built [  52.982s] (baseline)
     Parsing datafusion-proto v55.0.0 (baseline)
      Parsed [   0.019s] (baseline)
    Checking datafusion-proto v55.0.0 -> v55.0.0 (no change; assume patch)
     Checked [   0.167s] 223 checks: 223 pass, 31 skip
     Summary no semver update required
    Finished [ 107.219s] datafusion-proto
    Building datafusion-sql v55.0.0 (current)
       Built [  41.434s] (current)
     Parsing datafusion-sql v55.0.0 (current)
      Parsed [   0.033s] (current)
    Building datafusion-sql v55.0.0 (baseline)
       Built [  41.590s] (baseline)
     Parsing datafusion-sql v55.0.0 (baseline)
      Parsed [   0.035s] (baseline)
    Checking datafusion-sql v55.0.0 -> v55.0.0 (no change; assume patch)
     Checked [   0.330s] 223 checks: 223 pass, 31 skip
     Summary no semver update required
    Finished [  84.896s] datafusion-sql
    Building datafusion-substrait v55.0.0 (current)
       Built [ 296.134s] (current)
     Parsing datafusion-substrait v55.0.0 (current)
      Parsed [   0.019s] (current)
    Building datafusion-substrait v55.0.0 (baseline)
       Built [ 296.511s] (baseline)
     Parsing datafusion-substrait v55.0.0 (baseline)
      Parsed [   0.018s] (baseline)
    Checking datafusion-substrait v55.0.0 -> v55.0.0 (no change; assume patch)
     Checked [   0.331s] 223 checks: 223 pass, 31 skip
     Summary no semver update required
    Finished [ 595.250s] datafusion-substrait

@github-actions github-actions Bot added the auto detected api change Auto detected API change label Aug 30, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.95614% with 251 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.48%. Comparing base (c4910e0) to head (3a5e377).
⚠️ Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
datafusion/expr/src/logical_plan/plan.rs 50.25% 81 Missing and 16 partials ⚠️
datafusion/core/src/physical_planner.rs 0.00% 41 Missing ⚠️
datafusion/expr/src/logical_plan/tree_node.rs 9.30% 38 Missing and 1 partial ⚠️
datafusion/optimizer/src/analyzer/type_coercion.rs 0.00% 28 Missing ⚠️
datafusion/expr/src/logical_plan/builder.rs 60.71% 17 Missing and 5 partials ⚠️
datafusion/optimizer/src/push_down_filter.rs 84.41% 5 Missing and 7 partials ⚠️
datafusion/expr/src/logical_plan/display.rs 0.00% 10 Missing ⚠️
datafusion/optimizer/src/optimizer.rs 50.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24801      +/-   ##
==========================================
+ Coverage   81.47%   81.48%   +0.01%     
==========================================
  Files        1122     1123       +1     
  Lines      403629   406555    +2926     
  Branches   403629   406555    +2926     
==========================================
+ Hits       328866   331301    +2435     
- Misses      55510    55856     +346     
- Partials    19253    19398     +145     

☔ View full report in Codecov by Harness.
📢 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto detected api change Auto detected API change core Core DataFusion crate logical-expr Logical plan and expressions optimizer Optimizer rules physical-plan Changes to the physical-plan crate proto Related to proto crate sql SQL Planner substrait Changes to the substrait crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants