Skip to content

doc: Add documentation for pushing limit into plan#20271

Merged
xudong963 merged 2 commits intoapache:mainfrom
2010YOUY01:doc-limit-absorb
Mar 11, 2026
Merged

doc: Add documentation for pushing limit into plan#20271
xudong963 merged 2 commits intoapache:mainfrom
2010YOUY01:doc-limit-absorb

Conversation

@2010YOUY01
Copy link
Contributor

Which issue does this PR close?

  • Closes #.

Rationale for this change

Besides pushing LimitExec down the query plan, there is another optimization that allows plan nodes to absorb a limit, so it can potentially stop early.

I’ve noticed that this form of limit absorption has not been implemented by many operators. This suggests the optimization is non-obvious, so I’d like to improve the documentation for it.

A recent PR that implements this optimization is:

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added optimizer Optimizer rules physical-plan Changes to the physical-plan crate labels Feb 10, 2026
Copy link
Contributor

@jonathanc-n jonathanc-n left a comment

Choose a reason for hiding this comment

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

Just some comments

//! [`LimitPushdown`] pushes `LIMIT` down through `ExecutionPlan`s to reduce
//! data transfer as much as possible.
//!
//! # Plan Limit Absorption
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can mention that with the use of LimitedBatchCoalescer this can allow for passing the limit down and allowing output immediately when the limit is reached.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, updated!

//! --- DataSourceExec()
//! --- DataSourceExec()
//! ```
//! Under this model, `NestedLoopJoinExec` would keep working until it can emit
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we want to give an example with an embedded limit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, thanks.

@xudong963 xudong963 added this pull request to the merge queue Mar 11, 2026
Merged via the queue into apache:main with commit 2589fa8 Mar 11, 2026
32 checks passed
de-bgunter pushed a commit to de-bgunter/datafusion that referenced this pull request Mar 24, 2026
## Which issue does this PR close?

<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes apache#123` indicates that this PR will close issue apache#123.
-->

- Closes #.

## Rationale for this change

<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
Besides pushing `LimitExec` down the query plan, there is another
optimization that allows plan nodes to *absorb* a limit, so it can
potentially stop early.

I’ve noticed that this form of limit absorption has not been implemented
by many operators. This suggests the optimization is non-obvious, so I’d
like to improve the documentation for it.

A recent PR that implements this optimization is:
- apache#20228

## What changes are included in this PR?

<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->

## Are these changes tested?

<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code

If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->

## Are there any user-facing changes?

<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->

<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules physical-plan Changes to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants