Skip to content

Commit 924205f

Browse files
authored
ESQL: Use less memory in listener (#114358)
Use less memory in the top level listener by fetching the output attributes from the plan before starting rather than after finishing. The plan *can* be very large so let's not hold on to it longer than we have to.
1 parent c27bc08 commit 924205f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

docs/changelog/114358.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 114358
2+
summary: "ESQL: Use less memory in listener"
3+
area: ES|QL
4+
type: enhancement
5+
issues: []

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/ComputeService.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import org.elasticsearch.xpack.esql.action.EsqlExecutionInfo;
6161
import org.elasticsearch.xpack.esql.action.EsqlQueryAction;
6262
import org.elasticsearch.xpack.esql.action.EsqlSearchShardsAction;
63+
import org.elasticsearch.xpack.esql.core.expression.Attribute;
6364
import org.elasticsearch.xpack.esql.enrich.EnrichLookupService;
6465
import org.elasticsearch.xpack.esql.plan.physical.ExchangeSinkExec;
6566
import org.elasticsearch.xpack.esql.plan.physical.ExchangeSourceExec;
@@ -206,13 +207,19 @@ public void execute(
206207
);
207208
long start = configuration.getQueryStartTimeNanos();
208209
String local = RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY;
210+
/*
211+
* Grab the output attributes here, so we can pass them to
212+
* the listener without holding on to a reference to the
213+
* entire plan.
214+
*/
215+
List<Attribute> outputAttributes = physicalPlan.output();
209216
try (
210217
Releasable ignored = exchangeSource.addEmptySink();
211218
// this is the top level ComputeListener called once at the end (e.g., once all clusters have finished for a CCS)
212219
var computeListener = ComputeListener.create(local, transportService, rootTask, execInfo, start, listener.map(r -> {
213220
long tookTimeNanos = System.nanoTime() - configuration.getQueryStartTimeNanos();
214221
execInfo.overallTook(new TimeValue(tookTimeNanos, TimeUnit.NANOSECONDS));
215-
return new Result(physicalPlan.output(), collectedPages, r.getProfiles(), execInfo);
222+
return new Result(outputAttributes, collectedPages, r.getProfiles(), execInfo);
216223
}))
217224
) {
218225
// run compute on the coordinator

0 commit comments

Comments
 (0)