ClickHouse / ClickHouse/ClickHouse
NOT_FOUND_COLUMN_IN_BLOCK with ARRAY JOIN, ALIAS columns, and Row Policy on sorting key
- Dominant language
- C++
- Stars
- 49.9k
- Forks
- 9k
- Avg merge
- 21h 32m
- Merged PRs (30d)
- 515
Description
### 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 : 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.
Contributor guide
Research direction
Start with the linked ClickHouse Fiddle and reproduce the query with enable_analyzer = 0 under the Row Policy. Read InterpreterSelectQuery and ReadFromMergeTree, focusing on how ARRAY JOIN, ALIAS columns, InReverseOrder, and PREWHERE affect the initial header block. Done means the query executes successfully for the affected user without NOT_FOUND_COLUMN_IN_BLOCK and returns the expected rows.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100