ES|QL: Push limit to FORK branches#139443
Merged
ioanatia merged 5 commits intoelastic:mainfrom Dec 15, 2025
Merged
Conversation
3 tasks
ioanatia
commented
Dec 12, 2025
| } | ||
|
|
||
| private static LogicalPlan maybePushDownLimitToForkBranch(Limit limit, LogicalPlan forkBranch, LogicalOptimizerContext ctx) { | ||
| if (forkBranch instanceof UnaryPlan == false) { |
Member
Author
There was a problem hiding this comment.
I am using the descendantLimit helper which needs a UnaryPlan and this is why we have this check here.
When we remove the implicit limit for FORK, we might need to modify this further and not rely on descendantLimit
Collaborator
|
Pinging @elastic/es-search-relevance (Team:Search Relevance) |
pmpailis
approved these changes
Dec 15, 2025
Contributor
pmpailis
left a comment
There was a problem hiding this comment.
LGTM; only a minor comment on an equality check
|
|
||
| for (LogicalPlan forkChild : fork.children()) { | ||
| LogicalPlan newForkChild = maybePushDownLimitToForkBranch(limit, forkChild, ctx); | ||
| changed = changed || newForkChild != limit; |
Contributor
There was a problem hiding this comment.
Shouldn't this be newForkChild != forkChild ?
carlosdelest
approved these changes
Dec 15, 2025
Member
carlosdelest
left a comment
There was a problem hiding this comment.
LGTM 👍
I think we should add a CSV / integration test as well to have an end-to-end test.
ioanatia
commented
Dec 15, 2025
...er/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/GenerativeForkRestTest.java
Show resolved
Hide resolved
parkertimmins
pushed a commit
to parkertimmins/elasticsearch
that referenced
this pull request
Dec 17, 2025
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.
part of #136820
Queries using FORK can be further optimized when a LIMIT is used after FORK:
we have existing optimizations that move the limit past
EVALand add limits beforeMV_EXPAND:in this PR when we detect that a LIMIT follows a FORK, we attempt to duplicate the FORK limit in the branches, and so the final plan becomes something closer to:
This optimization will be useful when we will remove the implicit limit we add right now in the FORK branches.