Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions docs/changelog/124611.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 124611
summary: Reuse child `outputSet` inside the plan where possible
area: ES|QL
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.elasticsearch.xpack.esql.plan.logical;

import org.elasticsearch.xpack.esql.core.expression.Attribute;
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
import org.elasticsearch.xpack.esql.core.tree.Source;

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

private final LogicalPlan child;
private AttributeSet lazyOutputSet;

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

public AttributeSet outputSet() {
if (lazyOutputSet == null) {
List<Attribute> output = output();
lazyOutputSet = (output == child.output() ? child.outputSet() : new AttributeSet(output));
}
return lazyOutputSet;
}

@Override
public int hashCode() {
return Objects.hashCode(child());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.xpack.esql.core.expression.Attribute;
import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
import org.elasticsearch.xpack.esql.core.tree.Source;
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;

import java.io.IOException;
import java.util.List;
import java.util.Objects;

public class FilterExec extends UnaryExec {
Expand Down Expand Up @@ -63,11 +61,6 @@ public Expression condition() {
return condition;
}

@Override
public List<Attribute> output() {
return child().output();
}

@Override
public int hashCode() {
return Objects.hash(condition, child());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package org.elasticsearch.xpack.esql.plan.physical;

import org.elasticsearch.xpack.esql.core.expression.Attribute;
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
import org.elasticsearch.xpack.esql.core.tree.Source;

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

private final PhysicalPlan child;
private AttributeSet lazyOutputSet;

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

@Override
public AttributeSet outputSet() {
if (lazyOutputSet == null) {
List<Attribute> output = output();
lazyOutputSet = (output == child.output() ? child.outputSet() : new AttributeSet(output));
return lazyOutputSet;
}
return lazyOutputSet;
}

@Override
public int hashCode() {
return Objects.hashCode(child());
Expand Down