Skip to content

"Unknown identifier" when executing query with repeating aliases #17319

Closed

Description

@adrian17

How to reproduce

Tested on server versions from 20.4.6 to 20.11.3.3.

Given table:

create temporary table hits (date Date, data Float64) engine=Memory();

The following query (note that data alias exists as column in a table, in a subquery and in the outer query):

SELECT
    subquery1.period AS period,
    if(1=1, 0, subquery1.data1) AS data,
    if(1=1, 0, subquery2.data) AS other_data
FROM 
(
    SELECT date AS period, data AS data1
    FROM hits
) AS subquery1
LEFT JOIN 
(
    SELECT date AS period, data AS data
    FROM hits
) AS subquery2 ON (subquery1.period = subquery2.period)

Fails with message:

Code: 47. DB::Exception: Received from localhost:9000. DB::Exception: Unknown identifier: data there are columns: period, data1, 1, equals(1, 1), 0, if(equals(1, 1), 0, data1): While processing period AS period, if(1 = 1, 0, data1) AS data, if(1 = 1, 0, data) AS other_data.

Interestingly, if you just swap the order of lines in the outer query:

    if(1=1, 0, subquery2.data) AS other_data,
    if(1=1, 0, subquery1.data1) AS data

The query seems to successfully execute.

Activity

  1. added
    bug
    on Nov 23, 2020
  2. den-crane commented on Nov 23, 2020

    @den-crane
    Contributor

    related #14978 #13210

  3. added
    comp-joins
    on Nov 23, 2020
  4. alexey-milovidov commented on Jun 17, 2021

    @alexey-milovidov
    Member

    Reproduced on master.

  5. adrian17 commented on Feb 21, 2024

    @adrian17
    Author

    FYI, this is still reproducible (we have special hacks in queries just to get around this, I was checking if we could possibly remove them).

  6. den-crane commented on Feb 21, 2024

    @den-crane
    Contributor

    @adrian17 it's solved in the experimental_analyzer, eventually experimental_analyzer will be released.

    https://fiddle.clickhouse.com/560e1440-3232-4d4f-b57f-e14f271a723c

  7. added a commit that references this issue on Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcomp-joins

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions