Skip to content

UNKNOWN_IDENTIFIER error on simple query with window function and expression in ORDER BY #45535

Closed

Description

@vpanfilov

Hello, we found a bug after updating to latest Clickhouse version (22.12.3.5). Here is a minimal reprodicible example:

SELECT
  *,
  count() OVER () AS c
FROM numbers(10)
ORDER BY toString(number)
Code: 47. DB::Exception: Unknown column: toString(number), there are only columns number. (UNKNOWN_IDENTIFIER) (version 22.12.3.5 (official build))

Or

WITH
  toString(number) as str
SELECT
  *,
  count() OVER () AS c
FROM numbers(10)
ORDER BY str
Code: 47. DB::Exception: Unknown column: str, there are only columns number. (UNKNOWN_IDENTIFIER) (version 22.12.3.5 (official build))

Both queries worked fine in Clickhouse 22.8, but aren't working in 22.9-22.12. Possibly related to #23194.

Workarounds:

  • Move sorting column to SELECT
SELECT
  *,
  count() OVER () AS c,
  toString(number) as str
FROM numbers(10)
ORDER BY str
  • Move initial query to WITH section:
WITH
  test AS (
    SELECT
      *,
      count() OVER () AS c
    FROM numbers(10)
  )
SELECT * FROM test
ORDER BY toString(number)

Activity

  1. added
    potential bug
    on Jan 24, 2023
  2. qoega commented on Jan 24, 2023

    @qoega
    Member

    I is not related to #23194, but it will be fixed by #45461

    SELECT
        *,
        count() OVER () AS c
    FROM numbers(10)
    ORDER BY toString(number) ASC
    SETTINGS allow_experimental_analyzer = 0
    
    Query id: e98fb14f-204f-4245-b95d-1da386f76121
    
    
    0 rows in set. Elapsed: 0.055 sec.
    
    Received exception from server (version 22.13.1):
    Code: 47. DB::Exception: Received from localhost:9000. DB::Exception: Unknown column: toString(number), there are only columns number. (UNKNOWN_IDENTIFIER)
    
    SELECT
        *,
        count() OVER () AS c
    FROM numbers(10)
    ORDER BY toString(number) ASC
    SETTINGS allow_experimental_analyzer = 1
    
    Query id: 96b5927b-b394-42a9-aca4-f3339b06320e
    
    ┌─number─┬──c─┐
    │      0 │ 10 │
    │      1 │ 10 │
    │      2 │ 10 │
    │      3 │ 10 │
    │      4 │ 10 │
    │      5 │ 10 │
    │      6 │ 10 │
    │      7 │ 10 │
    │      8 │ 10 │
    │      9 │ 10 │
    └────────┴────┘
    
    10 rows in set. Elapsed: 0.001 sec.
  3. added
    bug
    comp-window-functions
    and removed
    potential bug
    on Jan 24, 2023
  4. self-assigned this
    on Jan 24, 2023
  5. 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-window-functions

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions