|
18 | 18 | import org.elasticsearch.xpack.esql.plan.logical.Project; |
19 | 19 | import org.elasticsearch.xpack.esql.plan.logical.RegexExtract; |
20 | 20 | import org.elasticsearch.xpack.esql.plan.logical.UnaryPlan; |
| 21 | +import org.elasticsearch.xpack.esql.plan.logical.inference.Rerank; |
21 | 22 | import org.elasticsearch.xpack.esql.plan.logical.join.Join; |
22 | 23 | import org.elasticsearch.xpack.esql.plan.logical.join.JoinTypes; |
23 | 24 |
|
@@ -52,11 +53,14 @@ public LogicalPlan rule(Limit limit, LogicalOptimizerContext ctx) { |
52 | 53 | mvx = new MvExpand(mvx.source(), mvx.child(), mvx.target(), mvx.expanded(), limitVal); |
53 | 54 | } |
54 | 55 | return mvx.replaceChild(limit.replaceChild(mvx.child())); |
55 | | - } |
56 | | - // check if there's a 'visible' descendant limit lower than the current one |
57 | | - // and if so, align the current limit since it adds no value |
58 | | - // this applies for cases such as | limit 1 | sort field | limit 10 |
59 | | - else { |
| 56 | + } else if (unary instanceof Rerank) { |
| 57 | + Limit descendantLimit = descendantLimit(unary); |
| 58 | + if (descendantLimit == null) { |
| 59 | + var rerankerDefaultLimit = ctx.configuration().resultTruncationDefaultSize(); |
| 60 | + var rerankerLimit = new Limit(limit.source(), Literal.of(limit.limit(), rerankerDefaultLimit), unary.child()); |
| 61 | + return limit.replaceChild(unary.replaceChild(rerankerLimit)); |
| 62 | + } |
| 63 | + } else { |
60 | 64 | Limit descendantLimit = descendantLimit(unary); |
61 | 65 | if (descendantLimit != null) { |
62 | 66 | var l1 = (int) limit.limit().fold(ctx.foldCtx()); |
|
0 commit comments