elena-rostova-dev opened a new pull request, #26729: URL: https://github.com/apache/datafusion/pull/26729
## Which issue does this PR close? Closes #26690. ## Rationale for this change When an `ORDER BY ... LIMIT` query executes over a subquery with `OFFSET` (e.g. `SELECT * FROM (SELECT * FROM t OFFSET 5) ORDER BY a LIMIT 10`) on pre-sorted, multi-partition data, `replace_with_order_preserving_variants` converts the underlying `CoalescePartitionsExec` to `SortPreservingMergeExec` using the parent sort's `fetch` without accounting for the intervening `GlobalLimitExec`'s `skip`. Consequently, `SortPreservingMergeExec` limits row emission to `fetch` (10 rows). The downstream `GlobalLimitExec` then skips 5 of those 10 rows, producing only 5 rows instead of 10 rows. ## What changes are included in this PR? - Added `input_fetch` and `min_fetch` in `replace_with_order_preserving_variants.rs` to adjust the pushed-down `fetch` by `plan.skip()` when descending through a `GlobalLimitExec` (saturating on overflow, matching `sort_pushdown.rs`). - Added physical optimizer unit regression test `test_plan_with_order_preserving_variants_accounts_for_limit_skip` verifying that `fetch` pushed down through a `GlobalLimitExec` accounts for `skip`. ## Are these changes tested? Yes, physical optimizer unit regression test added to `replace_with_order_preserving_variants.rs`. ## Are there any user-facing changes? No breaking changes. Fixes a bug where queries with `LIMIT` over an `OFFSET` subquery on pre-sorted data returned fewer rows than requested. -- 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]
