Skip to content

Commit 7fdf9c1

Browse files
authored
ESQL: optimise ProjectAwayColumns handling of AttrSet/Map (#126610)
Currently, each plan node iterration in ProjectAwayColumns creates 3 AttributeSet/Map_s. This can be dropped to just one by using builders. Related: #124395
1 parent afe97af commit 7fdf9c1

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/physical/ProjectAwayColumns.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public PhysicalPlan apply(PhysicalPlan plan) {
4141
Holder<Boolean> keepTraversing = new Holder<>(TRUE);
4242
// Invariant: if we add a projection with these attributes after the current plan node, the plan remains valid
4343
// and the overall output will not change.
44-
Holder<AttributeSet> requiredAttributes = new Holder<>(plan.outputSet());
44+
AttributeSet.Builder requiredAttrBuilder = plan.outputSet().asBuilder();
4545

4646
// This will require updating should we choose to have non-unary execution plans in the future.
4747
return plan.transformDown(currentPlanNode -> {
@@ -57,7 +57,7 @@ public PhysicalPlan apply(PhysicalPlan plan) {
5757

5858
// no need for projection when dealing with aggs
5959
if (logicalFragment instanceof Aggregate == false) {
60-
List<Attribute> output = new ArrayList<>(requiredAttributes.get());
60+
List<Attribute> output = new ArrayList<>(requiredAttrBuilder.build());
6161
// if all the fields are filtered out, it's only the count that matters
6262
// however until a proper fix (see https://github.com/elastic/elasticsearch/issues/98703)
6363
// add a synthetic field (so it doesn't clash with the user defined one) to return a constant
@@ -79,9 +79,10 @@ public PhysicalPlan apply(PhysicalPlan plan) {
7979
}
8080
}
8181
} else {
82-
AttributeSet childOutput = currentPlanNode.inputSet();
83-
AttributeSet addedAttributes = currentPlanNode.outputSet().subtract(childOutput);
84-
requiredAttributes.set(requiredAttributes.get().subtract(addedAttributes).combine(currentPlanNode.references()));
82+
AttributeSet.Builder addedAttrBuilder = currentPlanNode.outputSet().asBuilder();
83+
addedAttrBuilder.removeIf(currentPlanNode.inputSet()::contains);
84+
requiredAttrBuilder.removeIf(addedAttrBuilder::contains);
85+
requiredAttrBuilder.addAll(currentPlanNode.references());
8586
}
8687
return currentPlanNode;
8788
});

0 commit comments

Comments
 (0)