asolimando opened a new issue, #27629:
URL: https://github.com/apache/datafusion/issues/27629
### Describe the bug
When one input of an inner join is known to be empty (`Rows=Exact(0)`), the
join's statistics
report `Rows=Inexact(0)` instead of `Rows=Exact(0)`, although the join
cannot produce any row.
Any consumer that acts only on exact counts, for example a rule that removes
provably empty
subtrees, or an exchange that skips empty inputs (as proposed in #27600),
cannot treat the join
as empty.
### To Reproduce
```sql
SET datafusion.explain.show_statistics = true;
SET datafusion.explain.format = 'indent';
SET datafusion.execution.target_partitions = 1;
CREATE TABLE t (a INT) AS VALUES (1), (2), (3);
CREATE TABLE e (a INT) AS SELECT * FROM t WHERE false;
EXPLAIN SELECT * FROM t JOIN e ON t.a = e.a;
```
```
HashJoinExec: mode=CollectLeft, join_type=Inner, on=[(a@0, a@0)], ...,
statistics=[Rows=Inexact(0), ...]
DataSourceExec: partitions=1, partition_sizes=[0],
statistics=[Rows=Exact(0), ...]
DataSourceExec: partitions=1, partition_sizes=[1],
statistics=[Rows=Exact(3), ...]
```
### Expected behavior
`HashJoinExec` reports `Rows=Exact(0)`, since an inner join with an empty
input produces no rows.
### Additional context
`estimate_inner_join_cardinality`
(`datafusion/physical-plan/src/joins/utils.rs`) already returns
`Exact(0)` when an input has `Exact(0)` rows, but `estimate_join_statistics`
wraps every result
as `Precision::Inexact(stats.num_rows)`, so the exact empty case is lost.
A fix could keep `Exact(0)` when the join type guarantees an empty output:
inner and semi joins
with either input `Exact(0)`, outer and anti joins only when their preserved
side is `Exact(0)`.
Other counts stay `Inexact`. This is the same kind of change as #23936 and
#24000, which keep
`Exact(0)` through `FilterExec`.
### Willingness to contribute
I plan to contribute a fix for this bug independently
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]