[9.3] ESQL: Fix incorrectly optimized fork with nullify unmapped_fields (#143030)#144205
[9.3] ESQL: Fix incorrectly optimized fork with nullify unmapped_fields (#143030)#144205kanoshiou wants to merge 1 commit intoelastic:9.3from
Conversation
…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
|
buildkite test this |
|
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.😢 |
|
No worries @kanoshiou. Thank you for the update. I'll take a look myself. Take care! |
|
Actually, the backport would be slightly easier if we wait for #144210 to be merged as well |
|
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 !
Oh no, get well soon, @kanoshiou ! |
|
Backported with #144386 |
Backport
This will backport the following commits from
mainto9.3:Questions ?
Please refer to the Backport tool documentation