-
Notifications
You must be signed in to change notification settings - Fork 25.6k
ESQL: push down LIMIT past LOOKUP JOIN #118495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
elasticsearchmachine
merged 11 commits into
elastic:main
from
alex-spies:join-limit-pushdown
Dec 13, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ef0e9f6
Add failing test
alex-spies 9d0772b
Enable LIMIT pushdown on LEFT joins in general
alex-spies 809334f
Add LogicalPlanOptimizer test
alex-spies 7a27516
Spotless
alex-spies 846d596
Merge remote-tracking branch 'upstream/main' into join-limit-pushdown
alex-spies eaacda3
Upgrade JOIN_LOOKUP_V4 -> JOIN_LOOKUP_V5
alex-spies a213b8a
Move test just below other languages_lookup tests
alex-spies 07a6ce6
Fix comment
alex-spies ba332c2
Merge remote-tracking branch 'upstream/main' into join-limit-pushdown
alex-spies a4db1dc
Merge branch 'main' into join-limit-pushdown
alex-spies 6bfc807
Fix compilation
alex-spies File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
import org.elasticsearch.xpack.esql.core.expression.predicate.logical.Or; | ||
import org.elasticsearch.xpack.esql.core.expression.predicate.nulls.IsNotNull; | ||
import org.elasticsearch.xpack.esql.core.expression.predicate.operator.comparison.BinaryComparison; | ||
import org.elasticsearch.xpack.esql.core.tree.Source; | ||
import org.elasticsearch.xpack.esql.core.type.DataType; | ||
import org.elasticsearch.xpack.esql.core.type.EsField; | ||
import org.elasticsearch.xpack.esql.core.util.Holder; | ||
|
@@ -112,7 +113,9 @@ | |
import org.elasticsearch.xpack.esql.plan.logical.UnaryPlan; | ||
import org.elasticsearch.xpack.esql.plan.logical.join.InlineJoin; | ||
import org.elasticsearch.xpack.esql.plan.logical.join.Join; | ||
import org.elasticsearch.xpack.esql.plan.logical.join.JoinConfig; | ||
import org.elasticsearch.xpack.esql.plan.logical.join.JoinTypes; | ||
import org.elasticsearch.xpack.esql.plan.logical.join.LookupJoin; | ||
import org.elasticsearch.xpack.esql.plan.logical.local.EsqlProject; | ||
import org.elasticsearch.xpack.esql.plan.logical.local.LocalRelation; | ||
import org.elasticsearch.xpack.esql.plan.logical.local.LocalSupplier; | ||
|
@@ -138,6 +141,7 @@ | |
import static org.elasticsearch.xpack.esql.EsqlTestUtils.TWO; | ||
import static org.elasticsearch.xpack.esql.EsqlTestUtils.as; | ||
import static org.elasticsearch.xpack.esql.EsqlTestUtils.emptySource; | ||
import static org.elasticsearch.xpack.esql.EsqlTestUtils.fieldAttribute; | ||
import static org.elasticsearch.xpack.esql.EsqlTestUtils.getFieldAttribute; | ||
import static org.elasticsearch.xpack.esql.EsqlTestUtils.loadMapping; | ||
import static org.elasticsearch.xpack.esql.EsqlTestUtils.localSource; | ||
|
@@ -1291,6 +1295,26 @@ public void testCombineLimits() { | |
); | ||
} | ||
|
||
public void testPushdownLimitsPastLeftJoin() { | ||
var leftChild = emptySource(); | ||
var rightChild = new LocalRelation(Source.EMPTY, List.of(fieldAttribute()), LocalSupplier.EMPTY); | ||
assertNotEquals(leftChild, rightChild); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotta be very careful here, you never know. |
||
|
||
var joinConfig = new JoinConfig(JoinTypes.LEFT, List.of(), List.of(), List.of()); | ||
var join = switch (randomIntBetween(0, 2)) { | ||
case 0 -> new Join(EMPTY, leftChild, rightChild, joinConfig); | ||
case 1 -> new LookupJoin(EMPTY, leftChild, rightChild, joinConfig); | ||
case 2 -> new InlineJoin(EMPTY, leftChild, rightChild, joinConfig); | ||
default -> throw new IllegalArgumentException(); | ||
}; | ||
|
||
var limit = new Limit(EMPTY, L(10), join); | ||
|
||
var optimizedPlan = new PushDownAndCombineLimits().rule(limit); | ||
|
||
assertEquals(join.replaceChildren(limit.replaceChild(join.left()), join.right()), optimizedPlan); | ||
} | ||
|
||
public void testMultipleCombineLimits() { | ||
var numberOfLimits = randomIntBetween(3, 10); | ||
var minimum = randomIntBetween(10, 99); | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering why the previous restriction to LocalRelation (even if that's what was expected before). Anyways, should be good this way now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That came from when we only had
LOOKUP
(aka 🐔 ) andINLINESTATS
to consider. Both of these ended up with aLocalRelation
on the right, and we didn't want to implement this in all generality because the semantics were not 100% clear.