Skip to content

ESQL: optimise ProjectAwayColumns handling of AttributeSet/Map #126610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public PhysicalPlan apply(PhysicalPlan plan) {
Holder<Boolean> keepTraversing = new Holder<>(TRUE);
// Invariant: if we add a projection with these attributes after the current plan node, the plan remains valid
// and the overall output will not change.
Holder<AttributeSet> requiredAttributes = new Holder<>(plan.outputSet());
AttributeSet.Builder requiredAttrBuilder = plan.outputSet().asBuilder();

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

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