Repository navigation
Fix NOT_FOUND_COLUMN_IN_BLOCK with row policy and additional_table_filters on a shared column - #111099
Conversation
…lters on a shared column When a table has a row policy and the query uses additional_table_filters referencing the same column as the policy (and that column is not otherwise selected), the query failed with NOT_FOUND_COLUMN_IN_BLOCK. For a storage supporting PREWHERE the row policy is applied inside the reading step as a row_level_filter, built by buildFilterInfo which only keeps a filter input in its outputs if the input is among the columns needed so far. The shared column is not yet required when the row-level filter is built, so it is dropped from the reading step output, and the additional_table_filters step applied on top can no longer find it. Pre-collect the columns the additional_table_filters step needs and preserve them in the row-level filter's outputs, mirroring the columns_needed_by_other_filters handling already done for explicit PREWHERE. Only adds columns to a filter's output set, so results are unaffected. Closes: ClickHouse#111077 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-author-slot-2:20260720-145000 |
Internal second-model review — adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings; bounded: 1 full pass + 1 fix round + 1 delta recheck). No blockers, majors, or nits were raised. The reviewer saw the exact change set (3 files changed, +86/-4) and returned no findings. An earlier approach-stage review (Gate A) raised two design/minimality points, both of which were accepted and folded into the final approach before any code was written (reuse the existing PREWHERE Session id: cron:clickhouse-author-slot-2:20260720-145000 |
|
cc @yakov-olkhovskiy @KochetovNicolai — could you review this? It fixes |
|
Workflow [PR], commit [51b1217] Summary: ❌
AI ReviewSummaryThis PR preserves the columns that a later Final Verdict✅ Approve |
CI finish ledger — 1c5f272Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Session id: cron:our-pr-ci-monitor:20260720-233000 |
…cy-additional-table-filter-shared-column
CI finish ledger - 8383908Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
None of these are caused by this PR's diff: Fast test, Style check and all five Bugfix-validation jobs are green on this head. Session id: cron:our-pr-ci-monitor:20260726-163000 |
…-row-policy-additional-table-filter-shared-column
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 21/21 (100.00%) · Uncovered code |
CI finish ledger - 51b1217Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 174 check-runs are Neither is caused by this diff, which is 3 files: Detail on the hung check, read from Session id: cron:our-pr-ci-monitor:20260730-180000 |
8531d9c
|
Following up on the ledger above: the fixing PR for the That row was the only one owned by a fix task rather than a PR. The hung
|
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
NOT_FOUND_COLUMN_IN_BLOCKwhen a row policy andadditional_table_filtersreference the same column that is not otherwise selected by the query.Description
Closes: #111077
When a table has a row policy and the query uses
additional_table_filtersreferencing the same column as the policy (and that column is not otherwise projected), the query failed withNOT_FOUND_COLUMN_IN_BLOCK.For a storage that supports PREWHERE (e.g. MergeTree) the row policy is applied inside the reading step as a
row_level_filter. That filter is built bybuildFilterInfo, which only keeps a filter input in the filter's outputs if the input is among the columns needed so far by the query. When the row-level filter is built, the shared column is not yet in that set (only the SELECT/WHERE columns are), so it is dropped from the reading step's output block. Theadditional_table_filtersstep, applied on top of the reading step, then cannot find the column.The explicit-PREWHERE path already pre-collects
columns_needed_by_other_filtersto avoid this. This change extends the same idea to therow_level_filterpath: the columns theadditional_table_filtersstep needs are pre-collected and preserved in the row-level filter's outputs, so the reading step keeps them. The change only adds columns to a filter's output set, so results are unaffected; whenadditional_table_filtersis not set the behavior is unchanged.Added a stateless regression test covering the shared-column case, a mix of the shared column with another unprojected column,
optimize_move_to_prewhere = 0, andLowCardinality(Nullable(...))on the shared column.