Repository navigation
Do not consult the query condition cache under a masking policy - #130148
Conversation
A masking policy reaches a MergeTree read as a synthetic on-the-fly UPDATE that MergeTreeData::getAlterConversionsForPart appends to the part's AlterConversions. It is not part of the mutations snapshot, and it does not change the filter DAG the condition hash is derived from. So the consult gate in filterPartsByQueryConditionCache (which declines only on snapshot state) passes, and a masked read of predicate P reuses entries an unmasked read of P recorded over the raw column values. Those entries can mark granules as non-matching that do match the masked values, so the masked read silently drops rows; in the other direction, the number of granules skipped leaks where raw values match. Decline the consult when the table has an enabled masking policy for the current user, with the same hasEnabledMaskingPolicies idiom the statistics-pruning gate in this file already uses. The write side needs no change: a masked read of a masked column carries on-the-fly mutation steps, so MergeTreeReadTask:: appliesMutationsBeforePrewhere already keeps it from writing entries (the mechanism 03229_query_condition_cache_on_fly_mutations covers), and a read that touches no masked column sees raw values equal to masked ones. Outside the Cloud build hasEnabledMaskingPolicies always returns false, so public behaviour is unchanged. The behavioural test lives in the private repository, where masking policies can be created. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding; 1 full pass), plus one note from my own review.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261108-131400 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261108-124800 |
|
Workflow [PR], commit [7a63718] Summary: ✅
AI ReviewSummaryThe change prevents Missing context / blind spots
Final Verdict✅ Approve — no code changes requested. |
|
cc @azat @kcmannem, could you review this and add the |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 22 s compile time in total, 7 of them have a recent master baseline. |
1b80547
Cherry pick #130148 to 26.10: Do not consult the query condition cache under a masking policy
…nder a masking policy
Backport #130148 to 26.10: Do not consult the query condition cache under a masking policy
Related: https://github.com/ClickHouse/clickhouse-private/pull/83905
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Description
A masking policy is applied to a MergeTree read as an on-the-fly
UPDATEthatgetAlterConversionsForPartadds. It is not in the mutations snapshot and does not change the condition hash, sofilterPartsByQueryConditionCachelet a masked read reuse entries that an unmasked read of the same predicate recorded over the raw values. The masked read could then skip granules that do match the masked values and return fewer rows.The consult now declines when the table has an enabled masking policy for the current user, with the
hasEnabledMaskingPoliciescheck the statistics-pruning gate in this file already uses. Writes need no change: a masked read of a masked column has on-the-fly mutation steps, whichappliesMutationsBeforePrewherealready keeps from writing entries.Outside Cloud builds
hasEnabledMaskingPoliciesis alwaysfalse, so there is no behavior change there; the query condition cache tests pass. The behavioral test is in the private repository, as requested in the review there. No related open issue found.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/130148]
Version info
26.11.1.1670-master(included in26.11and later)26.10.12.11