Skip to content

Commit 7bc1dbc

Browse files
committed
Move attributeSet reuse inside UnaryPlan(Exec)
1 parent da09472 commit 7bc1dbc

File tree

8 files changed

+18
-69
lines changed

8 files changed

+18
-69
lines changed

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@
1010
import org.elasticsearch.common.io.stream.StreamInput;
1111
import org.elasticsearch.common.io.stream.StreamOutput;
1212
import org.elasticsearch.xpack.esql.capabilities.TelemetryAware;
13-
import org.elasticsearch.xpack.esql.core.expression.Attribute;
14-
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
1513
import org.elasticsearch.xpack.esql.core.expression.Expression;
1614
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
1715
import org.elasticsearch.xpack.esql.core.tree.Source;
1816
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;
1917

2018
import java.io.IOException;
21-
import java.util.List;
2219
import java.util.Objects;
2320

2421
public class Limit extends UnaryPlan implements TelemetryAware {
@@ -78,16 +75,6 @@ public String getWriteableName() {
7875
return ENTRY.name;
7976
}
8077

81-
@Override
82-
public List<Attribute> output() {
83-
return child().output();
84-
}
85-
86-
@Override
87-
public AttributeSet outputSet() {
88-
return child().outputSet();
89-
}
90-
9178
@Override
9279
protected NodeInfo<Limit> info() {
9380
return NodeInfo.create(this, Limit::new, limit, child(), duplicated);

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import org.elasticsearch.xpack.esql.capabilities.TelemetryAware;
1515
import org.elasticsearch.xpack.esql.common.Failures;
1616
import org.elasticsearch.xpack.esql.core.capabilities.Resolvables;
17-
import org.elasticsearch.xpack.esql.core.expression.Attribute;
18-
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
1917
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
2018
import org.elasticsearch.xpack.esql.core.tree.Source;
2119
import org.elasticsearch.xpack.esql.core.type.DataType;
@@ -63,16 +61,6 @@ public String getWriteableName() {
6361
return ENTRY.name;
6462
}
6563

66-
@Override
67-
public List<Attribute> output() {
68-
return child().output();
69-
}
70-
71-
@Override
72-
public AttributeSet outputSet() {
73-
return child().outputSet();
74-
}
75-
7664
@Override
7765
protected NodeInfo<OrderBy> info() {
7866
return NodeInfo.create(this, OrderBy::new, child(), order);

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import org.elasticsearch.common.io.stream.StreamInput;
1212
import org.elasticsearch.common.io.stream.StreamOutput;
1313
import org.elasticsearch.xpack.esql.core.capabilities.Resolvables;
14-
import org.elasticsearch.xpack.esql.core.expression.Attribute;
15-
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
1614
import org.elasticsearch.xpack.esql.core.expression.Expression;
1715
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
1816
import org.elasticsearch.xpack.esql.core.tree.Source;
@@ -57,16 +55,6 @@ public String getWriteableName() {
5755
return ENTRY.name;
5856
}
5957

60-
@Override
61-
public List<Attribute> output() {
62-
return child().output();
63-
}
64-
65-
@Override
66-
public AttributeSet outputSet() {
67-
return child().outputSet();
68-
}
69-
7058
@Override
7159
public boolean expressionsResolved() {
7260
return limit.resolved() && Resolvables.resolved(order);

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
public abstract class UnaryPlan extends LogicalPlan {
2222

2323
private final LogicalPlan child;
24+
private AttributeSet lazyOutputSet;
2425

2526
protected UnaryPlan(Source source, LogicalPlan child) {
2627
super(source, Collections.singletonList(child));
@@ -43,9 +44,12 @@ public List<Attribute> output() {
4344
return child.output();
4445
}
4546

46-
@Override
4747
public AttributeSet outputSet() {
48-
return child().outputSet();
48+
if (lazyOutputSet == null) {
49+
List<Attribute> output = output();
50+
lazyOutputSet = (output == child.output() ? child.outputSet() : new AttributeSet(output));
51+
}
52+
return lazyOutputSet;
4953
}
5054

5155
@Override

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.elasticsearch.common.io.stream.StreamInput;
1111
import org.elasticsearch.common.io.stream.StreamOutput;
1212
import org.elasticsearch.xpack.esql.core.expression.Attribute;
13-
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
1413
import org.elasticsearch.xpack.esql.core.expression.Expression;
1514
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
1615
import org.elasticsearch.xpack.esql.core.tree.Source;
@@ -69,11 +68,6 @@ public List<Attribute> output() {
6968
return child().output();
7069
}
7170

72-
@Override
73-
public AttributeSet outputSet() {
74-
return child().outputSet();
75-
}
76-
7771
@Override
7872
public int hashCode() {
7973
return Objects.hash(condition, child());

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@
1010
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1111
import org.elasticsearch.common.io.stream.StreamInput;
1212
import org.elasticsearch.common.io.stream.StreamOutput;
13-
import org.elasticsearch.xpack.esql.core.expression.Attribute;
14-
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
1513
import org.elasticsearch.xpack.esql.core.expression.Expression;
1614
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
1715
import org.elasticsearch.xpack.esql.core.tree.Source;
1816
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;
1917

2018
import java.io.IOException;
21-
import java.util.List;
2219
import java.util.Objects;
2320

2421
public class LimitExec extends UnaryExec {
@@ -51,16 +48,6 @@ public String getWriteableName() {
5148
return ENTRY.name;
5249
}
5350

54-
@Override
55-
public List<Attribute> output() {
56-
return child().output();
57-
}
58-
59-
@Override
60-
public AttributeSet outputSet() {
61-
return child().outputSet();
62-
}
63-
6451
@Override
6552
protected NodeInfo<? extends LimitExec> info() {
6653
return NodeInfo.create(this, LimitExec::new, child(), limit);

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.elasticsearch.common.io.stream.StreamInput;
1212
import org.elasticsearch.common.io.stream.StreamOutput;
1313
import org.elasticsearch.xpack.esql.core.expression.Attribute;
14-
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
1514
import org.elasticsearch.xpack.esql.core.expression.Expression;
1615
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
1716
import org.elasticsearch.xpack.esql.core.tree.Source;
@@ -70,16 +69,6 @@ public String getWriteableName() {
7069
return ENTRY.name;
7170
}
7271

73-
@Override
74-
public List<Attribute> output() {
75-
return child().output();
76-
}
77-
78-
@Override
79-
public AttributeSet outputSet() {
80-
return child().outputSet();
81-
}
82-
8372
@Override
8473
protected NodeInfo<TopNExec> info() {
8574
return NodeInfo.create(this, TopNExec::new, child(), order, limit, estimatedRowSize);

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

Lines changed: 12 additions & 0 deletions
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)