Skip to content

ESQL: Fix incorrectly optimized fork with nullify unmapped_fields (#143030)#144386

Merged
elasticsearchmachine merged 3 commits intoelastic:9.3from
astefan:backport/9.3/pr-143030
Mar 18, 2026
Merged

ESQL: Fix incorrectly optimized fork with nullify unmapped_fields (#143030)#144386
elasticsearchmachine merged 3 commits intoelastic:9.3from
astefan:backport/9.3/pr-143030

Conversation

@astefan
Copy link
Copy Markdown
Contributor

@astefan astefan commented Mar 17, 2026

Backports #143030

(cherry picked from commit 5fb7136)

…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)
@astefan astefan added >bug backport external-contributor Pull request authored by a developer outside the Elasticsearch team :Analytics/ES|QL AKA ESQL labels Mar 17, 2026
@astefan astefan added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Mar 17, 2026
@elasticsearchmachine elasticsearchmachine merged commit 6831d0b into elastic:9.3 Mar 18, 2026
36 checks passed
@astefan astefan deleted the backport/9.3/pr-143030 branch March 18, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) 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.

3 participants