Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions datafusion/physical-plan/src/joins/hash_join/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,10 +655,10 @@ impl HashJoinStream {
self.join_type,
)?;
timer.done();
Copy link
Contributor

Choose a reason for hiding this comment

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

Not related to this PR, but I noticed we don’t need to explicitly end the timer here since it’s an RAII variable. I’ll open a separate PR after this is merged.


self.output_buffer.push_batch(result)?;
self.state = HashJoinStreamState::FetchProbeBatch;

return Ok(StatefulStreamResult::Ready(Some(result)));
return Ok(StatefulStreamResult::Continue);
Copy link
Contributor

@jonathanc-n jonathanc-n Mar 8, 2026

Choose a reason for hiding this comment

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

I think we can slowly transition everything to slowly not need to variants of StatefulStreamResult, maybe an issue can be raised for this. It goes hand in hand with using the limited batch coalescer

Copy link
Contributor

@jonathanc-n jonathanc-n Mar 8, 2026

Choose a reason for hiding this comment

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

@Dandandan We can replicate the pattern you added with LimitedBatchCoalescer and updating metrics in poll_next_impl throughout the codebase

}

// get the matched by join keys indices
Expand Down
43 changes: 43 additions & 0 deletions datafusion/sqllogictest/test_files/joins.slt
Original file line number Diff line number Diff line change
Expand Up @@ -5056,6 +5056,49 @@ LEFT ANTI JOIN t2 ON k1 = k2
WHERE k1 < 0
----

# Also check that the reported number of output rows/batches are correct in the "empty build side"
# optimization.
# Issue: https://github.com/apache/datafusion/issues/20809
query TT
EXPLAIN ANALYZE
WITH t1 (k) AS (
VALUES (1), (2)
), t2 (k) AS (
VALUES (1)
)
SELECT *
FROM t1
LEFT ANTI JOIN (
SELECT *
FROM t2
WHERE k <> 1
) t2 ON t1.k = t2.k;
----
Plan with Metrics
01)HashJoinExec: mode=CollectLeft, join_type=RightAnti, on=[(k@0, k@0)], metrics=[output_rows=2, elapsed_compute=<slt:ignore>, output_bytes=<slt:ignore>, output_batches=1, array_map_created_count=0, build_input_batches=0, build_input_rows=0, input_batches=1, input_rows=2, build_mem_used=<slt:ignore>, build_time=<slt:ignore>, join_time=<slt:ignore>, avg_fanout=N/A (0/0), probe_hit_rate=0% (0/2)]
02)--ProjectionExec: expr=[column1@0 as k], metrics=[output_rows=0, elapsed_compute=<slt:ignore>, output_bytes=<slt:ignore>, output_batches=0, expr_0_eval_time=<slt:ignore>]
03)----FilterExec: column1@0 != 1, metrics=[output_rows=0, elapsed_compute=<slt:ignore>, output_bytes=<slt:ignore>, output_batches=0, selectivity=0% (0/1)]
04)------DataSourceExec: partitions=1, partition_sizes=[1], metrics=[]
05)--ProjectionExec: expr=[column1@0 as k], metrics=[output_rows=2, elapsed_compute=<slt:ignore>, output_bytes=<slt:ignore>, output_batches=1, expr_0_eval_time=<slt:ignore>]
06)----DataSourceExec: partitions=1, partition_sizes=[1], metrics=[]

query I
WITH t1 (k) AS (
VALUES (1), (2)
), t2 (k) AS (
VALUES (1)
)
SELECT *
FROM t1
LEFT ANTI JOIN (
SELECT *
FROM t2
WHERE k <> 1
) t2 ON t1.k = t2.k;
----
1
2

# Mark testing
statement ok
CREATE OR REPLACE TABLE t1(b INT, c INT, d INT);
Expand Down
Loading