Skip to content

[Exploration] DataFusion engine E0b: output batching of the TimeRange join #1505

Backlog

Description

@milindsrivastava1997

Example

rate(m[5m]) over a range query with 240 steps joins each sample with the table of evaluation times (D13 TimeRange row). Sidra found DataFusion's cross join emits one output batch per left row.

Question and hypothesis

Does a nested-loop or cross join of N rows with a 240-row evaluation-times table, filtered by T−s−w < t ≤ T−s, emit tiny batches in DataFusion 54.1? Hypothesis: yes for CrossJoinExec; NestedLoopJoinExec with the filter may not. (D13 risk)

Success signal

Batch-size histogram and time for 1M samples × 240 evaluation times, for CrossJoinExec+FilterExec and NestedLoopJoinExec with a join filter.

Scope or time boundary

One day.

Cheapest discriminating experiment

A throwaway benchmark of the two variants.

Expected artifact

A comment on this issue with the numbers and a recommendation for E3: plain join, join + CoalesceBatches, sidra's patch (sidra/patches/), or a small custom operator.

Production shortcuts and limitations

None; findings only.

Exit decision: adopt, investigate, or stop

Adopt the recommendation in E3.

Activity

  1. milindsrivastava1997 commented on Dec 2, 2026

    @milindsrivastava1997
    CollaboratorAuthor

    E0b result: no tiny output batches; put the evaluation-times table on the left

    Answer: no variant emits tiny output batches in DataFusion 54.1. Tiny batches appear only inside CrossJoinExec, and only when the samples are the left (build) side. With the 240-row evaluation-times table on the left, every variant emits full 8192-row batches.

    Setup. About 1M samples: 3,846 series × 260 samples, a sample every 15 s. Joined with 240 evaluation times (step 15 s), keeping T − 5m < t ≤ T (s = 0); 18.46M rows survive.

    • Plans built directly (D6), one partition, batch_size 8192, release mode.
    • Times are the median of 3 runs and exclude data generation. 16-core machine, process capped at 8 GB.
    • All datafusion-* crates at 54.1.0, matching the workspace Cargo.lock.
    • Throwaway code, not committed.

    Output batch sizes. Every join+filter variant emits 2,254 batches: 2,253 of 8192 rows and one shorter batch for the remainder (or 2,111 + 160 at 4096–8191 rows for CrossJoinExec+FilterExec on time-ordered input). Two reasons:

    • FilterExec in 54.x coalesces its own output to 8192 rows (LimitedBatchCoalescer).
    • NestedLoopJoinExec buffers its output in a BatchCoalescer.

    So (c) CoalesceBatches changes nothing, and CoalesceBatchesExec is deprecated since 52.

    The cross join's own output (no filter, 240M rows):

    left (build) side batches batch sizes time
    evaluation times (240) 29,520 8192 (plus 240 batches of 256–1023 rows) 38 ms
    samples (1M) 999,960 240 each 870 ms

    Time, ms (series-ordered input / time-ordered input):

    left side variant upstream 54.1 sidra's patch
    evaluation times (a) cross + filter 534 / 364 810 / 629
    evaluation times (b) nested loop + join filter 507 / 337 512 / 340
    samples (a) cross + filter 3,703 / 3,641 1,397 / 1,377
    samples (b) nested loop + join filter 1,629 / 1,622 1,630 / 1,635

    Rows (c), each with CoalesceBatches added, are within ±3% of (a) and (b) and are left out.

    Sidra's patch fixes the 240-row batches when the samples are on the left (3.7 s → 1.4 s). With the evaluation times on the left it is slower: the cross join alone goes from 38 to 311 ms, and cross + filter from 534 to 810 ms. The patch builds each output batch with take, which is slower than repeating one left value. It does not affect the nested loop join.

    Recommendation for E3 (#1509): plain join

    Use NestedLoopJoinExec (inner) with the window condition as its join filter, and the evaluation-times table as the left input.

    • It is the fastest variant: 0.34–0.51 s for 1M × 240.
    • Its output is already 8192-row batches.
    • It does not depend on which side DataFusion streams.
    • No CoalesceBatches, no sidra patch, no custom operator for batching.

    E3 must keep the evaluation times on the left. If E3 runs DataFusion's physical optimizer, check that its JoinSelection rule does not swap the two sides (not tested here; D6 builds plans directly).

    Possible later work, not measured: the join tests all 240M candidate pairs to keep 18.5M (8%). An operator that reads time-sorted samples and walks the evaluation times could skip most of that work. That is a speed optimization, not a batching fix. D7 already fuses range functions with TimeRange, so it would matter only for other consumers of TimeRange.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions