SubhamSinghal opened a new pull request, #21805: URL: https://github.com/apache/datafusion/pull/21805
## Which issue does this PR close?
- Related: [#9469](https://github.com/apache/datafusion/pull/9469)
## Rationale for this change
## What changes are included in this PR?
- **New config option**: `datafusion.optimizer.prefer_partial_sort`
(default `false`) in `OptimizerOptions`
- **Optimizer change**: `replace_with_partial_sort` in `EnforceSorting`
now accepts `ConfigOptions` and allows bounded inputs
when the config is enabled
- **Unit tests**: Two new tests in `enforce_sorting.rs` — bounded input
with config enabled (expects `PartialSortExec`), and
bounded input with no common prefix (stays `SortExec`)
- **SLT tests**: Three scenarios covering different prefix/suffix
combinations:
- prefix=2, suffix=1: sorted on `(a, b)`, ORDER BY `a, b, c`
- prefix=1, suffix=2: sorted on `(a)`, ORDER BY `a, b, c`
- prefix=3, suffix=1: sorted on `(a, b, c)`, ORDER BY `a, b, c, d`
we can enable `datafusion.optimizer.prefer_partial_sort` by default after
adding spill support.
## Are these changes tested?
Yes.
- 2 new unit tests in `enforce_sorting.rs` (bounded with config, no-prefix
with config)
- 1 new SLT test file `partial_sort_bounded.slt` with 3 scenarios covering
correctness, EXPLAIN plans, LIMIT, and config reset
- All existing tests pass unchanged (default is `false`, so no behavior
change)
## Are there any user-facing changes?
Yes — a new configuration option:
```sql
SET datafusion.optimizer.prefer_partial_sort = true;
When enabled, queries with ORDER BY that extend an existing sort prefix
will use PartialSortExec instead of SortExec for
bounded inputs (e.g., Parquet files with declared sort order). This
reduces memory usage and enables streaming output. Default
is false (existing behavior unchanged).
```
--
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]
