Skip to content

Commit 4b4c2d3

Browse files
authored
ESQL: Reuse child outputSet inside the plan where possible (#124611) (#125275)
Avoid creating outputSet between nodes that passthrough their input Relates #124395
1 parent 5a6d1cb commit 4b4c2d3

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

docs/changelog/124611.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 124611
2+
summary: Reuse child `outputSet` inside the plan where possible
3+
area: ES|QL
4+
type: enhancement
5+
issues: []

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/UnaryPlan.java

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package org.elasticsearch.xpack.esql.plan.logical;
88

99
import org.elasticsearch.xpack.esql.core.expression.Attribute;
10+
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
1011
import org.elasticsearch.xpack.esql.core.tree.Source;
1112

1213
import java.util.Collections;
@@ -20,6 +21,7 @@
2021
public abstract class UnaryPlan extends LogicalPlan {
2122

2223
private final LogicalPlan child;
24+
private AttributeSet lazyOutputSet;
2325

2426
protected UnaryPlan(Source source, LogicalPlan child) {
2527
super(source, Collections.singletonList(child));
@@ -42,6 +44,14 @@ public List<Attribute> output() {
4244
return child.output();
4345
}
4446

47+
public AttributeSet outputSet() {
48+
if (lazyOutputSet == null) {
49+
List<Attribute> output = output();
50+
lazyOutputSet = (output == child.output() ? child.outputSet() : new AttributeSet(output));
51+
}
52+
return lazyOutputSet;
53+
}
54+
4555
@Override
4656
public int hashCode() {
4757
return Objects.hashCode(child());

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/physical/FilterExec.java

-7
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1010
import org.elasticsearch.common.io.stream.StreamInput;
1111
import org.elasticsearch.common.io.stream.StreamOutput;
12-
import org.elasticsearch.xpack.esql.core.expression.Attribute;
1312
import org.elasticsearch.xpack.esql.core.expression.Expression;
1413
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
1514
import org.elasticsearch.xpack.esql.core.tree.Source;
1615
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;
1716

1817
import java.io.IOException;
19-
import java.util.List;
2018
import java.util.Objects;
2119

2220
public class FilterExec extends UnaryExec {
@@ -63,11 +61,6 @@ public Expression condition() {
6361
return condition;
6462
}
6563

66-
@Override
67-
public List<Attribute> output() {
68-
return child().output();
69-
}
70-
7164
@Override
7265
public int hashCode() {
7366
return Objects.hash(condition, child());

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/physical/UnaryExec.java

+12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package org.elasticsearch.xpack.esql.plan.physical;
99

1010
import org.elasticsearch.xpack.esql.core.expression.Attribute;
11+
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
1112
import org.elasticsearch.xpack.esql.core.tree.Source;
1213

1314
import java.util.Collections;
@@ -17,6 +18,7 @@
1718
public abstract class UnaryExec extends PhysicalPlan {
1819

1920
private final PhysicalPlan child;
21+
private AttributeSet lazyOutputSet;
2022

2123
protected UnaryExec(Source source, PhysicalPlan child) {
2224
super(source, Collections.singletonList(child));
@@ -39,6 +41,16 @@ public List<Attribute> output() {
3941
return child.output();
4042
}
4143

44+
@Override
45+
public AttributeSet outputSet() {
46+
if (lazyOutputSet == null) {
47+
List<Attribute> output = output();
48+
lazyOutputSet = (output == child.output() ? child.outputSet() : new AttributeSet(output));
49+
return lazyOutputSet;
50+
}
51+
return lazyOutputSet;
52+
}
53+
4254
@Override
4355
public int hashCode() {
4456
return Objects.hashCode(child());

0 commit comments

Comments
 (0)