Skip to content

Commit 129c58f

Browse files
fix: Remove !=0 check from supports_collect_by_thresholds (#20730)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #. ## Rationale for this change Small change to remove the TODO + != 0 check. Since the commit was made two years ago, statistics have been changed to use Precision. Exact(0) and inexact(0) are now valid stats while absent will evaluate to false <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> --------- Co-authored-by: Daniël Heres <danielheres@gmail.com>
1 parent 981b5c3 commit 129c58f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

datafusion/physical-optimizer/src/join_selection.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,18 @@ fn supports_collect_by_thresholds(
8787
threshold_byte_size: usize,
8888
threshold_num_rows: usize,
8989
) -> bool {
90-
// Currently we do not trust the 0 value from stats, due to stats collection might have bug
91-
// TODO check the logic in datasource::get_statistics_with_limit()
9290
let Ok(stats) = plan.partition_statistics(None) else {
9391
return false;
9492
};
9593

94+
// Stats use `Precision<T>` to represent stats, where `Absent` means unknown.
95+
// `Exact(0)` and `Inexact(0)` are both valid stats, and we should not treat
96+
// them as unknown, `Absent` will return None (this is in regards to why
97+
// `!=0` is not checked)
9698
if let Some(byte_size) = stats.total_byte_size.get_value() {
97-
*byte_size != 0 && *byte_size < threshold_byte_size
99+
*byte_size < threshold_byte_size
98100
} else if let Some(num_rows) = stats.num_rows.get_value() {
99-
*num_rows != 0 && *num_rows < threshold_num_rows
101+
*num_rows < threshold_num_rows
100102
} else {
101103
false
102104
}

datafusion/sqllogictest/test_files/cte.slt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ logical_plan
10151015
04)----SubqueryAlias: cte
10161016
05)------TableScan: person projection=[id]
10171017
physical_plan
1018-
01)HashJoinExec: mode=Partitioned, join_type=LeftSemi, on=[(id@0, id@0)]
1018+
01)HashJoinExec: mode=CollectLeft, join_type=LeftSemi, on=[(id@0, id@0)]
10191019
02)--DataSourceExec: partitions=1, partition_sizes=[0]
10201020
03)--DataSourceExec: partitions=1, partition_sizes=[0]
10211021

0 commit comments

Comments
 (0)