Skip to content

[9.2] ESQL: Prevent circular alias references in DeduplicateAggs (#139175)#139614

Closed
bpintea wants to merge 1 commit intoelastic:9.2from
bpintea:port/9.2_139175
Closed

[9.2] ESQL: Prevent circular alias references in DeduplicateAggs (#139175)#139614
bpintea wants to merge 1 commit intoelastic:9.2from
bpintea:port/9.2_139175

Conversation

@bpintea
Copy link
Copy Markdown
Contributor

@bpintea bpintea commented Dec 16, 2025

Fixes circular reference detection in alias chains during DeduplicateAggs optimizations.

The PushDownEnrich optimization can create circular references when pushing Enrich past Project operations, causing ql_illegal_argument_exception: Potential cycle detected errors when DeduplicateAggs.

Example query:

FROM languages_lookup
| RENAME language_name AS message
| ENRICH languages_policy ON language_code
| STATS a = count(to_lower(language_name)), b = count(language_name)

Skip aliases that would create circular references by checking if alias.toAttribute() equals the resolved alias.child().

Closes #138346 Closes #139541

(cherry picked from commit 2289e17)

…#139175)

Fixes circular reference detection in alias chains during
`DeduplicateAggs` optimizations.

The `PushDownEnrich` optimization can create circular references when
pushing `Enrich` past `Project` operations, causing
`ql_illegal_argument_exception: Potential cycle detected` errors when
`DeduplicateAggs`.

Example query:

```esql
FROM languages_lookup
| RENAME language_name AS message
| ENRICH languages_policy ON language_code
| STATS a = count(to_lower(language_name)), b = count(language_name)
```

Skip aliases that would create circular references by checking if
`alias.toAttribute()` equals the resolved `alias.child()`.

Closes elastic#138346 Closes elastic#139541

(cherry picked from commit 2289e17)
@bpintea bpintea added >bug backport :Analytics/ES|QL AKA ESQL v9.2.4 auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) labels Dec 16, 2025
@bpintea
Copy link
Copy Markdown
Contributor Author

bpintea commented Dec 16, 2025

Dup of #139615

@bpintea bpintea closed this Dec 16, 2025
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 v9.2.4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants