Skip to content

Cherry pick #130148 to 26.10: Do not consult the query condition cache under a masking policy - #133169

Merged
robot-clickhouse merged 3 commits into
backport/26.10/130148from
cherrypick/26.10/130148
Nov 24, 2026
Merged

robot-clickhouse merged 3 commits into
backport/26.10/130148from
cherrypick/26.10/130148

Conversation

@robot-ch-test-poll2

Copy link
Copy Markdown
Contributor

Original pull-request #130148

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 2 commits November 8, 2026 13:06
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]>
…-policy-gate

Do not consult the query condition cache under a masking policy
@robot-ch-test-poll2 robot-ch-test-poll2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels Nov 20, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

The only conflict is in the early return of filterPartsByQueryConditionCache (MergeTreeDataSelectExecutor.cpp). On master its condition list ends with hasPendingAlterOrMetadataMutations(...) from #119337, which is not on 26.10: its v26.10-must-backport label was removed, and there is no 26.10 backport of it, so this cherry-pick will not resolve itself. I kept the 26.10 side and appended the masking policy condition of #130148; its 4 new lines are identical to master. Against backport/26.10/130148 the merge changes only that file, +5/-1, like #130148. -X ours does not work here: it leaves a call to hasPendingAlterOrMetadataMutations, which 26.10 does not declare.

A syntax-only compile of the resolved file against the 26.10 sources with clang-22 is clean (not a full build). There is no public behavioral test: outside Cloud, hasEnabledMaskingPolicies is always false, as on master.

I cannot push to cherrypick/26.10/130148. The merge is on my fork, and its first parent is this PR's head 1b8054738bd2, so applying it is a fast-forward:

git fetch https://github.com/groeneai/ClickHouse.git groeneai/resolve-26.10-cherrypick-130148
git push origin FETCH_HEAD:cherrypick/26.10/130148

@robot-ch-test-poll3

Copy link
Copy Markdown
Contributor

Dear @azat, @groeneai, this cherry-pick PR has not been updated for 3d0h10m13s. Please resolve the conflicts to backport #130148, or close this PR if the backport is no longer needed. This PR will be automatically closed after 7 days of inactivity.

@robot-clickhouse
robot-clickhouse merged commit 1c8fb45 into backport/26.10/130148 Nov 24, 2026
2 checks passed
@robot-clickhouse
robot-clickhouse deleted the cherrypick/26.10/130148 branch November 24, 2026 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants