Skip to content

Fix row policies usage for Merge table + child table - #102860

Open
yariks5s wants to merge 6 commits into
masterfrom
yarik/fix-row-policies-in-merge-table
Open

yariks5s wants to merge 6 commits into
masterfrom
yarik/fix-row-policies-in-merge-table

Conversation

@yariks5s

@yariks5s yariks5s commented Apr 15, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixes NOT_FOUND_COLUMN_IN_BLOCK exception while applying row policies on the same column with the Merge table and the child table. Closes #102650

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@clickhouse-gh

clickhouse-gh Bot commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e06adcd]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_tsan, parallel, 1/2) FAIL
00175_obfuscator_schema_inference FAIL cidb
00096_obfuscator_save_load FAIL cidb
Unit tests (asan_ubsan) FAIL
AST fuzzer (amd_debug, targeted) ERROR

AI Review

Summary

This PR fixes row-policy handling when a Merge table and its child table both have SELECT row policies. The current code combines the parent and child FilterDAGInfo filters before the child read, keeps the temporary combined filter column until the child plan boundary, then removes it before adapting the child stream back to the Merge table header. I did not find a new actionable correctness, safety, or performance issue in the current diff.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Apr 15, 2026
Comment thread src/Storages/StorageMerge.cpp Resolved
@yariks5s
yariks5s marked this pull request as draft April 15, 2026 22:17
Comment thread src/Storages/StorageMerge.cpp Resolved
@yariks5s
yariks5s marked this pull request as ready for review April 17, 2026 15:49
@clickhouse-gh

clickhouse-gh Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.40% 84.40% +0.00%
Functions 92.40% 92.40% +0.00%
Branches 77.00% 77.00% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 58/70 (82.86%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 13 line(s) · Uncovered code

Full report · Diff report

@abashkeev abashkeev added the comp-storage-merge Merge table engine (logical union over tables) and related mechanics. label Sep 4, 2026
nihalzp pushed a commit to nihalzp/ClickHouse that referenced this pull request Nov 4, 2026
… PREWHERE and WHERE

`ReadFromMerge` applied the row policy of a local child as a `FilterStep` above
the child's read. The query's PREWHERE is forwarded into that read, and the
query's WHERE is pushed below the Merge, merged with the policy filter by the
child plan's optimization and moved into the read's PREWHERE as one unordered
conjunction. Either way the query's condition was evaluated on the rows the
policy hides: a condition that throws on a value (`toUInt64(payload) > 10`,
`throwIf`) printed hidden values and works as an oracle over hidden rows. A
direct read of the same table is not affected, because the planner gives the
read the policy as `SelectQueryInfo::row_level_filter`, which the reads
evaluate as a separate step before every PREWHERE step. ClickHouse#125765 fixed the
children that process the query themselves; a local child read at
`FetchColumns` still got the late filter.

Now the child's read gets the policy as its row-level filter whenever the
planner's own push-down rule says the storage can evaluate it there, and the
late `FilterStep` is not planted:

- The rule (`supportsPrewhere`, not remote, every column inside the PREWHERE
  contract) was written out twice, in the planner and in the old interpreter.
  It is now `canPushDownRowPolicyFilter`, used by both and by `Merge`.
- `RowPolicyData::makeRowLevelFilter` returns the policy as a `FilterDAGInfo`,
  or nothing when the rule fails or a column is not physical. When the Merge
  table has a policy of its own (forwarded to every child as
  `row_level_filter`), both are AND-ed into one filter that keeps every input
  column, as ClickHouse#102860 proposes; this also removes the
  `NOT_FOUND_COLUMN_IN_BLOCK` of ClickHouse#102650.
- The policy's IN-subquery sets are still built by a step above the read
  (`addCreatingSetsStep`); a Buffer child's in-memory read needs it.
- `ALIAS` columns in the policy are expanded before analysis, since a read
  cannot produce them.

When the read cannot evaluate the policy (e.g. a `Memory` child's policy over
a `DEFAULT` column) the previous path is kept. A direct read of such a table
keeps the policy as a WHERE filter and orders it the same way; that is the
planner's behaviour and is not changed here.

Behaviour changes, both matching a direct read: a Merge child's plan shows a
`Row level filter` instead of a `Filter` step, and
`apply_row_policy_after_final = 0` now applies a Merge child's policy before
FINAL.

Test: 05453_merge_child_row_policy_before_prewhere, eight arms (MergeTree
PREWHERE and WHERE, Memory, FINAL, IN subquery over Buffer, ALIAS, policies on
both tables, nested Merge) plus a control showing the condition throws on the
hidden value while it is visible.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-storage-merge Merge table engine (logical union over tables) and related mechanics. pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NOT_FOUND_COLUMN_IN_BLOCK with row policies on both Merge table and child table

3 participants