galaxytemple opened a new pull request, #28015:
URL: https://github.com/apache/datafusion/pull/28015
## Which issue does this PR close?
- Closes #26809.
- Split out from #27450 per review.
## Rationale for this change
Ungrouped `MIN(col)` / `MAX(col)` queries (e.g., `SELECT MAX(ts) FROM t
WHERE val > 0`) emit a dynamic filter (`AggrDynFilter`, introduced in #18644),
but because `PushdownSort` only matched `SortExec`, Parquet files and row
groups were scanned in listing order rather than statistics order, preventing
the dynamic filter bound from tightening early.
At the same time, unlike `SortExec`, `AggregateExec` cannot be eliminated by
an `Exact` reverse scan — when `enable_exact_reverse_scan` is enabled on an
`ASC` non-null table, reversing individual rows (`reverse_rows = true`) would
buffer whole row groups unnecessarily when `MAX` only needs file and row-group
visiting order.
## What changes are included in this PR?
- Add non-breaking `try_pushdown_sort_inexact` methods (with default
implementations delegating to
`try_pushdown_sort(...).map(SortOrderPushdownResult::into_inexact)`) on
`ExecutionPlan`, `DataSource`, and `FileSource`, forwarded through transparent
plan nodes and `FileScanConfig`:
- `ParquetSource::try_pushdown_sort_inexact` skips the
`enable_exact_reverse_scan` row-reversal path (`reverse_rows`) while preserving
file/row-group statistics reordering and `reverse_row_groups`.
- Add internal `#[doc(hidden)] AggregateExec::dynamic_filter_sort_order` so
`PushdownSort` reuses the single-column `MIN`/`MAX` dynamic filter metadata
initialized in `AggregateExec::init_dynamic_filter` (`[col DESC NULLS LAST]`
for `MAX`, `[col ASC NULLS LAST]` for `MIN`).
- In `PushdownSort`, push this sort hint down via
`try_pushdown_sort_inexact` when aggregate dynamic filter pushdown is enabled
and the input has no `fetch`.
## What is the testing strategy for this PR?
- Snapshot tests in
`datafusion/core/tests/physical_optimizer/pushdown_sort.rs`
(`test_sort_pushdown_ungrouped_max` and `test_sort_pushdown_ungrouped_min`).
- Unit test in `datafusion/datasource-parquet/src/source.rs`
(`try_pushdown_sort_inexact_skips_exact_reverse_when_enabled`) verifying
`reverse_row_groups = true` and `reverse_rows = false` when
`enable_exact_reverse_scan = true`.
- End-to-end `sqllogictest` coverage in `sort_pushdown_exact_reverse.slt`,
`push_down_filter_regression.slt`, and `dynamic_filter_pushdown_config.slt`.
- Local benchmark over 50 Parquet files (10M rows total, 200k rows/file in
ascending `ts` order):
- `SELECT MAX(ts) FROM t WHERE val > 0`: **2.78s → 29ms** (reads
`file_050` first and prunes the remaining 49 files via dynamic filter).
## Are there any user-facing changes?
No breaking API or SQL changes. New non-breaking trait methods with default
implementations:
- `ExecutionPlan::try_pushdown_sort_inexact`
- `DataSource::try_pushdown_sort_inexact`
- `FileSource::try_pushdown_sort_inexact`
(Plus internal `#[doc(hidden)] AggregateExec::dynamic_filter_sort_order`.)
--
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]