Skip to content

Commit a93f840

Browse files
committed
Logical plan optimization for the completion command.
1 parent 17c6e10 commit a93f840

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.elasticsearch.xpack.esql.optimizer.rules.logical.PushDownAndCombineFilters;
3939
import org.elasticsearch.xpack.esql.optimizer.rules.logical.PushDownAndCombineLimits;
4040
import org.elasticsearch.xpack.esql.optimizer.rules.logical.PushDownAndCombineOrderBy;
41+
import org.elasticsearch.xpack.esql.optimizer.rules.logical.PushDownCompletion;
4142
import org.elasticsearch.xpack.esql.optimizer.rules.logical.PushDownEnrich;
4243
import org.elasticsearch.xpack.esql.optimizer.rules.logical.PushDownEval;
4344
import org.elasticsearch.xpack.esql.optimizer.rules.logical.PushDownRegexExtract;
@@ -190,6 +191,7 @@ protected static Batch<LogicalPlan> operators() {
190191
new PruneLiteralsInOrderBy(),
191192
new PushDownAndCombineLimits(),
192193
new PushDownAndCombineFilters(),
194+
new PushDownCompletion(),
193195
new PushDownEval(),
194196
new PushDownRegexExtract(),
195197
new PushDownEnrich(),

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/PushDownAndCombineLimits.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.xpack.esql.plan.logical.Project;
1818
import org.elasticsearch.xpack.esql.plan.logical.RegexExtract;
1919
import org.elasticsearch.xpack.esql.plan.logical.UnaryPlan;
20+
import org.elasticsearch.xpack.esql.plan.logical.inference.Completion;
2021
import org.elasticsearch.xpack.esql.plan.logical.join.Join;
2122
import org.elasticsearch.xpack.esql.plan.logical.join.JoinTypes;
2223

@@ -38,7 +39,11 @@ public LogicalPlan rule(Limit limit, LogicalOptimizerContext ctx) {
3839
// We want to preserve the duplicated() value of the smaller limit, so we'll use replaceChild.
3940
return parentLimitValue < childLimitValue ? limit.replaceChild(childLimit.child()) : childLimit;
4041
} else if (limit.child() instanceof UnaryPlan unary) {
41-
if (unary instanceof Eval || unary instanceof Project || unary instanceof RegexExtract || unary instanceof Enrich) {
42+
if (unary instanceof Eval
43+
|| unary instanceof Project
44+
|| unary instanceof RegexExtract
45+
|| unary instanceof Enrich
46+
|| unary instanceof Completion) {
4247
return unary.replaceChild(limit.replaceChild(unary.child()));
4348
} else if (unary instanceof MvExpand) {
4449
// MV_EXPAND can increase the number of rows, so we cannot just push the limit down
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.optimizer.rules.logical;
9+
10+
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
11+
import org.elasticsearch.xpack.esql.plan.logical.inference.Completion;
12+
13+
public final class PushDownCompletion extends OptimizerRules.OptimizerRule<Completion> {
14+
@Override
15+
protected LogicalPlan rule(Completion p) {
16+
return PushDownUtils.pushGeneratingPlanPastProjectAndOrderBy(p);
17+
}
18+
}

0 commit comments

Comments
 (0)