asolimando commented on code in PR #27630: URL: https://github.com/apache/datafusion/pull/27630#discussion_r4653255752
########## datafusion/sqllogictest/test_files/explain.slt: ########## @@ -338,6 +338,21 @@ physical_plan 04)------DataSourceExec: partitions=1, partition_sizes=[1], statistics=[Rows=Exact(1), Bytes=Exact(112), [(Col[0]: Null=Exact(0))]] 05)------DataSourceExec: partitions=1, partition_sizes=[1], statistics=[Rows=Exact(5), Bytes=Exact(192), [(Col[0]: Null=Exact(2))]] +# An inner join with an input known to be empty is exactly empty +statement ok +CREATE TABLE empty_join_input(a INT) AS SELECT * FROM null_check_join WHERE false; + +query TT +EXPLAIN SELECT * FROM null_check_statistics t JOIN empty_join_input e ON t.a = e.a; +---- +physical_plan Review Comment: Thanks @Dandandan, no, nothing replaces it today. [`ListingTable::scan`](https://github.com/apache/datafusion/blob/95171adf3c3ebd4835eddddd3bf994fda1df32c8/datafusion/catalog-listing/src/table.rs#L700-L702) (when all files are pruned) and the logical [`PropagateEmptyRelation`](https://github.com/apache/datafusion/blob/95171adf3c3ebd4835eddddd3bf994fda1df32c8/datafusion/optimizer/src/propagate_empty_relation.rs) rule emit an `EmptyExec`, while `FilterExec` (empty input, #24000, or [contradictory equalities](https://github.com/apache/datafusion/blob/95171adf3c3ebd4835eddddd3bf994fda1df32c8/datafusion/physical-plan/src/filter.rs#L1337)) and joins (this PR) only report `Rows=Exact(0)`, and their parents stay in the plan: ``` EXPLAIN SELECT * FROM fp WHERE column1 > 10; -- where fp is a Parquet file with values 1 to 3 FilterExec: column1@0 > 10, statistics=[Rows=Exact(0), ...] EmptyExec, statistics=[Rows=Exact(0), ...] ``` Consumers therefore check both forms, as [`limit_pushdown`](https://github.com/apache/datafusion/blob/95171adf3c3ebd4835eddddd3bf994fda1df32c8/datafusion/physical-optimizer/src/limit_pushdown.rs#L394-L420) does. I agree it should be replaced, and I think we should standardize on `EmptyExec`, with a physical counterpart of Calcite's [`PruneEmptyRules`](https://github.com/apache/calcite/blob/4f8ad6c3133a215621de0cb411c80d34cc8a2778/core/src/main/java/org/apache/calcite/rel/rules/PruneEmptyRules.java): detect empty nodes from metadata (`EMPTY_TABLE_INSTANCE`), then remove the operators above them (`FILTER_INSTANCE`, `JOIN_LEFT_INSTANCE`, ...). Here the detection would read `Exact(0)`, so this PR is a prerequisite for joins. I have a local prototype of the rule, but I think it requires more discussion (for example where it runs relative to `EnsureRequirements`), so I would keep it out of this PR and file an issue to discuss it. But I don't feel strongly either, if you prefer to emit `EmptyExec` here already, I can adapt 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: [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]
