Skip to content

ESQL: bug in ReplaceAliasingEvalWithProject: optimized incorrectly due to missing references #137019

Description

@alex-spies

Once more! Straight from the generative tests (already shrunk):

row vKBRQmBiqSe = 1
| eval  HqAogEZW = RAZdNDZEWAnqxF,  kfkZrDpdlGhS = vKBRQmBiqSe, vKBRQmBiqSe = 4191264652016276724
| enrich languages_policy on HqAogEZW
| rename language_name as message

Activity

  1. self-assigned this
    on Oct 23, 2025
  2. added theissue type on Oct 23, 2025
  3. elasticsearchmachine commented on Oct 23, 2025

    @elasticsearchmachine
    Collaborator

    Pinging @elastic/es-analytical-engine (Team:Analytics)

  4. alex-spies commented on Oct 23, 2025

    @alex-spies
    ContributorAuthor

    The culprit is ReplaceAliasingEvalWithProject:

    [2025-10-23T12:37:26,535][TRACE][o.e.x.e.o.L.changes      ] [runTask-0] Rule logical.ReplaceAliasingEvalWithProject applied with change
    Limit[1000[INTEGER],false,false]                                                                                             = Limit[1000[INTEGER],false,false]
    \_EsqlProject[[HqAogEZW{r}#4894, kfkZrDpdlGhS{r}#4897, vKBRQmBiqSe{r}#4899, language_name{r}#4906 AS message#4903]]          = \_EsqlProject[[HqAogEZW{r}#4894, kfkZrDpdlGhS{r}#4897, vKBRQmBiqSe{r}#4899, language_name{r}#4906 AS message#4903]]
      \_Enrich[ANY,languages_policy[KEYWORD],HqAogEZW{r}#4894,{"match":{"indices":[],"match_field":"language_code","enrich_field =   \_Enrich[ANY,languages_policy[KEYWORD],HqAogEZW{r}#4894,{"match":{"indices":[],"match_field":"language_code","enrich_field
    s":["language_name"]}},{=.enrich-languages_policy-1761214271791},[language_name{r}#4906]]                                    = s":["language_name"]}},{=.enrich-languages_policy-1761214271791},[language_name{r}#4906]]
        \_Eval[[RAZdNDZEWAnqxF[KEYWORD] AS HqAogEZW#4894, vKBRQmBiqSe{r}#4892 AS kfkZrDpdlGhS#4897, 4191264652016276724[LONG]    !     \_Project[[HqAogEZW{r}#4894, vKBRQmBiqSe{r}#4892 AS kfkZrDpdlGhS#4897, vKBRQmBiqSe{r}#4899]]
     AS vKBRQmBiqSe#4899]]                                                                                                       !       \_Eval[[RAZdNDZEWAnqxF[KEYWORD] AS HqAogEZW#4894, 4191264652016276724[LONG] AS vKBRQmBiqSe#4899]]
          \_Row[[1[INTEGER] AS vKBRQmBiqSe#4892]]                                                                                !         \_Row[[1[INTEGER] AS vKBRQmBiqSe#4892]]
    
    
  5. alex-spies commented on Oct 23, 2025

    @alex-spies
    ContributorAuthor

    Smaller reproducer:

    row vKBRQmBiqSe = 1
    | eval  HqAogEZW = "RAZdNDZEWAnqxF",  kfkZrDpdlGhS = vKBRQmBiqSe, vKBRQmBiqSe = 4191264652016276724
    | rename HqAogEZW as message
    
    [2025-10-23T12:51:27,023][TRACE][o.e.x.e.o.L.changes      ] [runTask-0] Rule logical.ReplaceAliasingEvalWithProject applied with change
    Limit[1000[INTEGER],false,false]                                                                                        = Limit[1000[INTEGER],false,false]
    \_EsqlProject[[HqAogEZW{r}#4919 AS message#4927, kfkZrDpdlGhS{r}#4922, vKBRQmBiqSe{r}#4924]]                            = \_EsqlProject[[HqAogEZW{r}#4919 AS message#4927, kfkZrDpdlGhS{r}#4922, vKBRQmBiqSe{r}#4924]]
      \_Eval[[RAZdNDZEWAnqxF[KEYWORD] AS HqAogEZW#4919, vKBRQmBiqSe{r}#4917 AS kfkZrDpdlGhS#4922, 4191264652016276724[LONG] !   \_Project[[HqAogEZW{r}#4919, vKBRQmBiqSe{r}#4917 AS kfkZrDpdlGhS#4922, vKBRQmBiqSe{r}#4924]]
     AS vKBRQmBiqSe#4924]]                                                                                                  !     \_Eval[[RAZdNDZEWAnqxF[KEYWORD] AS HqAogEZW#4919, 4191264652016276724[LONG] AS vKBRQmBiqSe#4924]]
        \_Row[[1[INTEGER] AS vKBRQmBiqSe#4917]]                                                                             !       \_Row[[1[INTEGER] AS vKBRQmBiqSe#4917]]
    
    
  6. alex-spies commented on Oct 23, 2025

    @alex-spies
    ContributorAuthor

    Another, related problem in ReplaceAliasingEvalWithProject:

    row x = 1 | eval y = x, z = y, x = 2, y = 3 | keep *
    
    [2025-10-23T13:29:33,582][TRACE][o.e.x.e.o.L.changes      ] [runTask-0] Rule logical.ReplaceAliasingEvalWithProject applied with change
    Limit[1000[INTEGER],false,false]                                                 = Limit[1000[INTEGER],false,false]
    \_EsqlProject[[z{r}#8, x{r}#10, y{r}#12]]                                        = \_EsqlProject[[z{r}#8, x{r}#10, y{r}#12]]
      \_Eval[[x{r}#2 AS y#5, y{r}#5 AS z#8, 2[INTEGER] AS x#10, 3[INTEGER] AS y#12]] !   \_Project[[y{r}#5 AS z#8, x{r}#10, y{r}#12]]
        \_Row[[1[INTEGER] AS x#2]]                                                   !     \_Eval[[2[INTEGER] AS x#10, 3[INTEGER] AS y#12]]
                                                                                     !       \_Row[[1[INTEGER] AS x#2]]
    
    

    The common theme is that the EVAL shadows attributes in the chain of aliases that we try to move into a subsequent Project.

  7. changed the title [-]ESQL: optimized incorrectly due to missing references[/-] [+]ESQL: bug in ReplaceAliasingEvalWithProject: optimized incorrectly due to missing references[/+] on Oct 23, 2025
  8. added 2 commits that reference this issue on Oct 28, 2025
    386b156
    b2897e1
  9. added a commit that references this issue on Oct 28, 2025
    437952c
  10. added 2 commits that reference this issue on Oct 29, 2025
    6da06d7
    45061f9
  11. added 2 commits that reference this issue on Oct 29, 2025
    bd71a29
    5a24930
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions