alamb commented on code in PR #7832:
URL: https://github.com/apache/arrow-datafusion/pull/7832#discussion_r1360892790
##########
datafusion/physical-plan/src/aggregates/mod.rs:
##########
@@ -1021,12 +1021,21 @@ impl ExecutionPlan for AggregateExec {
..Default::default()
}
}
- _ => Statistics {
- // the output row count is surely not larger than its input
row count
- num_rows: self.input.statistics().num_rows,
- is_exact: false,
- ..Default::default()
- },
+ _ => {
+ let input_stats = self.input.statistics();
+ // Input statistics is exact and number of rows not greater
than 1:
+ let is_exact = input_stats.is_exact
+ && (input_stats
+ .num_rows
+ .map(|num_rows| num_rows <= 1)
+ .unwrap_or(false));
+ Statistics {
+ // the output row count is surely not larger than its
input row count
Review Comment:
I don't know if it matters, but the output rows could be larger than the
input rows for `COUNT(*)` queries -- specifically if there are no input rows,
COUNT(*) still produces an output row 🤔
```
❯ create table t(x int) as values (1);
0 rows in set. Query took 0.001 seconds.
❯ select count(*) from t where x > 1000;
+----------+
| COUNT(*) |
+----------+
| 0 |
+----------+
```
##########
datafusion/physical-plan/src/aggregates/mod.rs:
##########
@@ -1021,12 +1021,21 @@ impl ExecutionPlan for AggregateExec {
..Default::default()
}
}
- _ => Statistics {
- // the output row count is surely not larger than its input
row count
- num_rows: self.input.statistics().num_rows,
- is_exact: false,
- ..Default::default()
- },
+ _ => {
+ let input_stats = self.input.statistics();
+ // Input statistics is exact and number of rows not greater
than 1:
+ let is_exact = input_stats.is_exact
+ && (input_stats
+ .num_rows
+ .map(|num_rows| num_rows <= 1)
+ .unwrap_or(false));
+ Statistics {
+ // the output row count is surely not larger than its
input row count
Review Comment:
I don't know if it matters, but the output rows could be larger than the
input rows for `COUNT(*)` queries -- specifically if there are no input rows,
COUNT(*) still produces an output row 🤔
```
❯ create table t(x int) as values (1);
0 rows in set. Query took 0.001 seconds.
❯ select count(*) from t where x > 1000;
+----------+
| COUNT(*) |
+----------+
| 0 |
+----------+
```
--
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]