|
41 | 41 | import org.elasticsearch.xpack.esql.core.expression.predicate.logical.Or; |
42 | 42 | import org.elasticsearch.xpack.esql.core.expression.predicate.nulls.IsNotNull; |
43 | 43 | import org.elasticsearch.xpack.esql.core.expression.predicate.operator.comparison.BinaryComparison; |
| 44 | +import org.elasticsearch.xpack.esql.core.tree.Source; |
44 | 45 | import org.elasticsearch.xpack.esql.core.type.DataType; |
45 | 46 | import org.elasticsearch.xpack.esql.core.type.EsField; |
46 | 47 | import org.elasticsearch.xpack.esql.core.util.Holder; |
|
113 | 114 | import org.elasticsearch.xpack.esql.plan.logical.UnaryPlan; |
114 | 115 | import org.elasticsearch.xpack.esql.plan.logical.join.InlineJoin; |
115 | 116 | import org.elasticsearch.xpack.esql.plan.logical.join.Join; |
| 117 | +import org.elasticsearch.xpack.esql.plan.logical.join.JoinConfig; |
116 | 118 | import org.elasticsearch.xpack.esql.plan.logical.join.JoinTypes; |
| 119 | +import org.elasticsearch.xpack.esql.plan.logical.join.LookupJoin; |
117 | 120 | import org.elasticsearch.xpack.esql.plan.logical.local.EsqlProject; |
118 | 121 | import org.elasticsearch.xpack.esql.plan.logical.local.LocalRelation; |
119 | 122 | import org.elasticsearch.xpack.esql.plan.logical.local.LocalSupplier; |
|
139 | 142 | import static org.elasticsearch.xpack.esql.EsqlTestUtils.TWO; |
140 | 143 | import static org.elasticsearch.xpack.esql.EsqlTestUtils.as; |
141 | 144 | import static org.elasticsearch.xpack.esql.EsqlTestUtils.emptySource; |
| 145 | +import static org.elasticsearch.xpack.esql.EsqlTestUtils.fieldAttribute; |
142 | 146 | import static org.elasticsearch.xpack.esql.EsqlTestUtils.getFieldAttribute; |
143 | 147 | import static org.elasticsearch.xpack.esql.EsqlTestUtils.loadMapping; |
144 | 148 | import static org.elasticsearch.xpack.esql.EsqlTestUtils.localSource; |
@@ -1294,6 +1298,29 @@ public void testCombineLimits() { |
1294 | 1298 | ); |
1295 | 1299 | } |
1296 | 1300 |
|
| 1301 | + public void testPushdownLimitsPastLeftJoin() { |
| 1302 | + var leftChild = emptySource(); |
| 1303 | + var rightChild = new LocalRelation(Source.EMPTY, List.of(fieldAttribute()), LocalSupplier.EMPTY);; |
| 1304 | + assertNotEquals(leftChild, rightChild); |
| 1305 | + |
| 1306 | + var joinConfig = new JoinConfig(JoinTypes.LEFT, List.of(), List.of(), List.of()); |
| 1307 | + var join = switch (randomIntBetween(0, 2)) { |
| 1308 | + case 0 -> new Join(EMPTY, leftChild, rightChild, joinConfig); |
| 1309 | + case 1 -> new LookupJoin(EMPTY, leftChild, rightChild, joinConfig); |
| 1310 | + case 2 -> new InlineJoin(EMPTY, leftChild, rightChild, joinConfig); |
| 1311 | + default -> throw new IllegalArgumentException(); |
| 1312 | + }; |
| 1313 | + |
| 1314 | + var limit = new Limit(EMPTY, L(10), join); |
| 1315 | + |
| 1316 | + var optimizedPlan = new PushDownAndCombineLimits().rule(limit); |
| 1317 | + |
| 1318 | + assertEquals( |
| 1319 | + join.replaceChildren(limit.replaceChild(join.left()), join.right()), |
| 1320 | + optimizedPlan |
| 1321 | + ); |
| 1322 | + } |
| 1323 | + |
1297 | 1324 | public void testMultipleCombineLimits() { |
1298 | 1325 | var numberOfLimits = randomIntBetween(3, 10); |
1299 | 1326 | var minimum = randomIntBetween(10, 99); |
|
0 commit comments