Skip to content

NOT_FOUND_COLUMN_IN_BLOCK with ARRAY JOIN, ALIAS columns, and Row Policy on sorting key #113102

Description

@runalsh

Company or project name

No response

Describe what's wrong

When executing a query with ARRAY JOIN and enable_analyzer = 0 from a user affected by a Row Policy (which filters by the sorting key column), ClickHouse fails with DB::Exception: Not found column <sorting_key_column>: in block ... (NOT_FOUND_COLUMN_IN_BLOCK).

May be the error occurs because InterpreterSelectQuery in the legacy analyzer fails to propagate the sorting key column into the initial ReadFromMergeTree header block when ARRAY JOIN, ALIAS columns, and InReverseOrder / PREWHERE optimizations are combined.

Does it reproduce on the most recent release?

Yes

How to reproduce

https://fiddle.clickhouse.com/10a4fcd5-d904-49cc-9a5c-d41602cb1f8c

Expected behavior

The query should execute successfully and return matching rows

"event_time","event_id","field_a","joined_item"
"DateTime64(3)","UUID","Nullable(String)","Nullable(String)"
"2026-07-26 12:00:00.000","00000000-0000-0000-0000-000000000001","value_a","value_b"

Error message and/or stacktrace

Code: 10. DB::Exception: Received from localhost:9000. DB::Exception: Not found column event_time: in block event_id UUID UUID(size = 0), attr_keys Array(String) Array(size = 0, UInt64(size = 0), String(size = 0)), field_a_raw String String(size = 0), field_b_raw String String(size = 0). (NOT_FOUND_COLUMN_IN_BLOCK)

Related issues and pull requests

No response

Additional context

Does NOT reproduce when enable_analyzer = 1: The new analyzer processes query plan steps and Row Policies correctly.
Does NOT reproduce for users WITHOUT Row Policy: The query executes fine for default or users not bound to the policy.
Workaround: Wrapping the Row Policy condition in indexHint(...) (e.g., USING indexHint(event_time >= ...)) bypasses the bug because it forces ReadFromMergeTree to include the sorting key column during index analysis.

Metadata

Metadata

Assignees

No one assigned

    Labels

    close in a month if not activeThis will be closed in case of no informationpotential bugTo be reviewed by developers and confirmed/rejected.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions