Skip to content

[9.3] ESQL: Fix incorrectly optimized fork with nullify unmapped_fields (#143030)#144205

Closed
kanoshiou wants to merge 1 commit intoelastic:9.3from
kanoshiou:backport/9.3/pr-143030
Closed

[9.3] ESQL: Fix incorrectly optimized fork with nullify unmapped_fields (#143030)#144205
kanoshiou wants to merge 1 commit intoelastic:9.3from
kanoshiou:backport/9.3/pr-143030

Conversation

@kanoshiou
Copy link
Copy Markdown
Contributor

Backport

This will backport the following commits from main to 9.3:

Questions ?

Please refer to the Backport tool documentation

…astic#143030)

This PR fixes a bug where `Fork.withSubPlans()` incorrectly reassigned
new `NameId`s to its output attributes, breaking references in the upper
plan. This issue specifically manifests when using `FORK` alongside the
`SET unmapped_fields="nullify"` mode.

By design, a `FORK` assigns new `NameId`s to its output attributes via
`refreshOutput()` to decouple them from the internal branches. This
isolation is necessary to prevent unintended side effects during plan
optimizations, such as aggressive constant folding leaking across
branches.

However, the previous implementation unconditionally re-minted these
`NameId`s every time `withSubPlans()` was called. Because of this, any
node sitting above the `FORK` (like `EVAL` or `STATS`) that already held
a reference to the initial `NameId`s would suddenly point to a
nonexistent ID. Downstream analysis rules would then fail to resolve
these orphaned references, causing the plan execution to fail with an
*"optimized incorrectly due to missing references"* error.

Fixes elastic#142762

(cherry picked from commit 5fb7136)

# Conflicts:
#	muted-tests.yml
#	x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/GenerativeRestTest.java
#	x-pack/plugin/esql/qa/testFixtures/src/main/resources/unmapped-nullify.csv-spec
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/rules/ResolveUnmapped.java
#	x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/AnalyzerUnmappedTests.java
@elasticsearchmachine elasticsearchmachine added external-contributor Pull request authored by a developer outside the Elasticsearch team needs:triage Requires assignment of a team area label v9.3.3 labels Mar 13, 2026
@astefan astefan added >bug :Analytics/ES|QL AKA ESQL backport and removed needs:triage Requires assignment of a team area label labels Mar 13, 2026
@astefan
Copy link
Copy Markdown
Contributor

astefan commented Mar 13, 2026

buildkite test this

@astefan astefan self-assigned this Mar 13, 2026
@kanoshiou
Copy link
Copy Markdown
Contributor Author

My apologies,@astefan. I am currently in the hospital and trying to manage this cherry-pick remotely from my phone is proving too difficult. My local tests are failing, and I’m unable to properly track this backport under these conditions. I'm sorry for can't be able to backport this patch this as promised.😢

@astefan
Copy link
Copy Markdown
Contributor

astefan commented Mar 13, 2026

No worries @kanoshiou. Thank you for the update. I'll take a look myself. Take care!

@astefan
Copy link
Copy Markdown
Contributor

astefan commented Mar 13, 2026

Actually, the backport would be slightly easier if we wait for #144210 to be merged as well

@alex-spies
Copy link
Copy Markdown
Contributor

Update: contrary to what I previously said on the original PR, we had to change plans and urgently backport #143399 after all. I'm sorry for the noise, @kanoshiou and @astefan !

I am currently in the hospital

Oh no, get well soon, @kanoshiou !

@astefan
Copy link
Copy Markdown
Contributor

astefan commented Mar 18, 2026

Backported with #144386

@astefan astefan closed this Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL backport >bug external-contributor Pull request authored by a developer outside the Elasticsearch team v9.3.3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants