Skip to content

fix: don't drop a limit above a leaf in LimitPushdown - #27892

Merged
adriangb merged 1 commit into
apache:mainfrom
zhuqi-lucas:qizhu/limit-pushdown-leaf
Dec 1, 2026
Merged

adriangb merged 1 commit into
apache:mainfrom
zhuqi-lucas:qizhu/limit-pushdown-leaf

Conversation

@zhuqi-lucas

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

LimitPushdown passes a limit to the children of a node whose limit_behavior is MoveToInput or CopyToChildren. A leaf has no children, so the limit is dropped and the query returns too many rows. The default limit_behavior gives a leaf one of these when it still returns true from the deprecated supports_limit_pushdown.

What changes are included in this PR?

LimitPushdown treats such a leaf as Stops: the leaf takes the limit as its fetch, or the limit stays above it.

Are these changes tested?

Yes, 3 tests in limit_pushdown.rs with a leaf that declares MoveToInput or CopyToChildren: 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.

Copilot AI balanced review requested due to automatic review settings December 1, 2026 07:12
@github-actions github-actions Bot added optimizer Optimizer rules core Core DataFusion crate labels Dec 1, 2026
@zhuqi-lucas

Copy link
Copy Markdown
Contributor Author

cc @xudong963 @adriangb
The fix for the comments here:

#27816 (comment)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 MoveToInput or CopyToChildren as 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
adriangb added this pull request to the merge queue Dec 1, 2026
Merged via the queue into apache:main with commit c75bc57 Dec 1, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate optimizer Optimizer rules v57.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LimitPushdown drops the limit above a leaf that returns true from supports_limit_pushdown

3 participants