Repository navigation
fix: don't drop a limit above a leaf in LimitPushdown - #27892
Merged
Merged
Conversation
Contributor
Author
|
cc @xudong963 @adriangb |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the fix addressing lost limits above custom leaf execution plans.
No open issues 🎉
What changed in this PR
Fixes #27891 by preventing LimitPushdown from discarding limits above custom leaf execution plans. Built-in leaf behavior remains unchanged.
Changes:
- Treats childless plans declaring
MoveToInputorCopyToChildrenas stopping points, allowing the leaf to accept a fetch or retain the limit above it. - Adds regression tests for fetch pushdown, OFFSET preservation, and leaves that cannot accept a fetch.
| File | Description |
|---|---|
datafusion/physical-optimizer/src/limit_pushdown.rs |
Adds a leaf guard to prevent limits from being lost. |
datafusion/core/tests/physical_optimizer/limit_pushdown.rs |
Adds a configurable test leaf and three regression tests. |
Review effort: Balanced
adriangb
approved these changes
Dec 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
LimitPushdownpasses a limit to the children of a node whoselimit_behaviorisMoveToInputorCopyToChildren. A leaf has no children, so the limit is dropped and the query returns too many rows. The defaultlimit_behaviorgives a leaf one of these when it still returnstruefrom the deprecatedsupports_limit_pushdown.What changes are included in this PR?
LimitPushdowntreats such a leaf asStops: the leaf takes the limit as its fetch, or the limit stays above it.Are these changes tested?
Yes, 3 tests in
limit_pushdown.rswith a leaf that declaresMoveToInputorCopyToChildren: one that takes a fetch, the same with an OFFSET, and one that can't take a fetch. All three fail without the fix: the plan is the bare leaf.Are there any user-facing changes?
A custom leaf that passes limits now gets the limit instead of losing it. Built-in leaves don't pass limits, so their plans don't change.