From 92194c1e09bfa546c25aebb39d512434b8dcad95 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Wed, 28 Feb 2024 23:37:52 +0100 Subject: [PATCH 1/2] ProjectOperator should not retain block references --- .../compute/operator/ProjectOperator.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/ProjectOperator.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/ProjectOperator.java index 2e61150061e1a..d318639625034 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/ProjectOperator.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/ProjectOperator.java @@ -30,7 +30,7 @@ public String describe() { } private final int[] projection; - private Block[] blocks; + private final Block[] blocks; /** * Creates an operator that applies the given projection, encoded as an integer list where @@ -41,6 +41,7 @@ public String describe() { */ public ProjectOperator(List projection) { this.projection = projection.stream().mapToInt(Integer::intValue).toArray(); + this.blocks = new Block[projection.size()]; } @Override @@ -49,11 +50,6 @@ protected Page process(Page page) { if (blockCount == 0) { return page; } - if (blocks == null) { - blocks = new Block[projection.length]; - } - - Arrays.fill(blocks, null); int b = 0; for (int source : projection) { if (source >= blockCount) { @@ -69,7 +65,9 @@ protected Page process(Page page) { page.releaseBlocks(); // Use positionCount explicitly to avoid re-computing - also, if the projection is empty, there may be // no more blocks left to determine the positionCount from. - return new Page(positionCount, blocks); + Page output = new Page(positionCount, blocks); + Arrays.fill(blocks, null); + return output; } @Override From d908097eefca1c38e9123f6c6b987e185f4ae30e Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Wed, 28 Feb 2024 23:48:31 +0100 Subject: [PATCH 2/2] Update docs/changelog/105848.yaml --- docs/changelog/105848.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/changelog/105848.yaml diff --git a/docs/changelog/105848.yaml b/docs/changelog/105848.yaml new file mode 100644 index 0000000000000..18291066177f6 --- /dev/null +++ b/docs/changelog/105848.yaml @@ -0,0 +1,5 @@ +pr: 105848 +summary: '`ProjectOperator` should not retain references to released blocks' +area: ES|QL +type: bug +issues: []