Skip to content

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

Merged
elasticsearchmachine merged 1 commit intoelastic:9.2from
kanoshiou:backport/9.2/pr-139175
Dec 16, 2025
Merged

[9.2] ESQL: Prevent circular alias references in DeduplicateAggs (#139175)#139615
elasticsearchmachine merged 1 commit intoelastic:9.2from
kanoshiou:backport/9.2/pr-139175

Conversation

@kanoshiou
Copy link
Copy Markdown
Contributor

Backport

This will backport the following commits from main to 9.2:

Questions ?

Please refer to the Backport tool documentation

…#139175)

## Summary

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

## Problem

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)
```

## Changes

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)

# Conflicts:
#	x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/generative/GenerativeRestTest.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java
#	x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java
@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label external-contributor Pull request authored by a developer outside the Elasticsearch team v9.2.4 labels Dec 16, 2025
@bpintea bpintea added >bug backport :Analytics/ES|QL AKA ESQL and removed needs:triage Requires assignment of a team area label labels Dec 16, 2025
@bpintea
Copy link
Copy Markdown
Contributor

bpintea commented Dec 16, 2025

buildkite test this

@bpintea bpintea added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Dec 16, 2025
@bpintea bpintea self-assigned this Dec 16, 2025
@elasticsearchmachine elasticsearchmachine merged commit 67e6c5e into elastic:9.2 Dec 16, 2025
37 checks passed
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.2.4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants