Skip to content

Cherry pick #121398 to 26.3: Skip the direct join when the right table has a row policy - #123207

Merged
robot-ch-test-poll3 merged 11 commits into
backport/26.3/121398from
cherrypick/26.3/121398
Oct 1, 2026
Merged

robot-ch-test-poll3 merged 11 commits into
backport/26.3/121398from
cherrypick/26.3/121398

Conversation

@robot-clickhouse-ci-2

Copy link
Copy Markdown
Contributor

Original pull-request #121398

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

vdimir and others added 10 commits September 21, 2026 16:42
…the legacy analyzer

`JoinedTables::makeTableJoin` installed a `StorageJoin`, dictionary or key-value storage on
`TableJoin` based on the storage type alone. `ExpressionAnalyzer::tryCreateJoin` then dropped the
right-side plan, and with it the `FilterStep` carrying the table's row policy, so a user holding only
`SELECT` on an `EmbeddedRocksDB` or `KeeperMap` table read every row the policy hides through a direct
join, and could enumerate the whole key space by joining against `numbers(N)`.

Skip the special storage when a `SELECT` row policy applies to the joined table, so it is joined as an
ordinary stream through its plan, which keeps the filter. A `Join` table is a prebuilt hash table read
as is and cannot be filtered, so joining it under a row policy throws instead.

The legacy analyzer cannot be enabled on master anymore, so this cannot be tested here; the change
exists to be backported to releases that still accept `enable_analyzer = 0`.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…able_filters

In the new analyzer a `JoinStepLogicalLookup` replaces the right-side plan with a lookup into a
`StorageJoin`, dictionary or key-value storage, discarding the `FilterStep`s the plan applied to the
table. The `used_row_policies` guard already excluded the row policy case, but a filter from
`additional_table_filters` on the right table was silently dropped by the direct join.

Record on `TableExpressionData` that an additional filter applies to the table and skip the storage
lookup in that case too, so the join reads the table as a stream through its plan.

A `Join` table is a prebuilt hash table read as is by JOIN and `joinGet`, so its rows cannot be
filtered at all: `CREATE ROW POLICY` on such a table is rejected, and joining a `Join` table that
still has a row policy throws instead of silently falling back.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
`joinGet` and `joinGetOrNull` read the hash table of a `Join` table as is, exactly like a JOIN with
it, so a row policy on the table was silently ignored on this path while the JOIN now throws.
Throw the same exception from `FunctionJoinGet::prepare`, next to the `SELECT` privilege check.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Both the `Join` engine page and `CREATE ROW POLICY` now say that a policy
on a `Join` table is rejected, and that a policy which still applies to
one, such as a database-wide `ON db.*` policy, makes `JOIN` and `joinGet`
fail with `NOT_IMPLEMENTED`.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The right side of a `JoinNode` is always a leaf table expression whose
data `collectTableExpressionData` has registered, and
`buildQueryPlanForTableExpression` has already fetched it with
`getTableExpressionDataOrThrow` by the time the join is planned, so the
null check was dead code.

Review comment: #121398 (comment)

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The setting is applied by the user to their own query, not an access
control boundary, so dropping the filter in a direct join is an ordinary
correctness bug and does not belong in a backported RBAC fix. It will be
handled separately on master, where the legacy analyzer is unreachable.

Review comment: #121398 (comment)

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…CESS_DENIED`

The check in `CREATE ROW POLICY` protected nothing: `ON db.*`, a policy
created before the table, and a table created after the policy all
bypassed it, while it broke `ALTER ROW POLICY` on an existing policy and
ran per node under `ON CLUSTER`. The query-time rejection in `JOIN` and
`joinGet` is the actual boundary, and persisted policies never went
through the interpreter anyway. The error code follows the `mergeTreeIndex`
fix in #115304.

Related: ClickHouse/clickhouse-private#70504

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Skip the direct join when the right table has a row policy
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 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 pr-critical-bugfix labels Oct 1, 2026
@vdimir vdimir closed this Oct 1, 2026
@vdimir vdimir reopened this Oct 1, 2026
Keep only the legacy analyzer part of #121398: a right table with a row
policy is joined through its query plan instead of its special storage,
so the `FilterStep` carrying the policy is kept. The `ACCESS_DENIED`
for `JOIN` and `joinGet` on a `Join` table and its docs are not backported.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@robot-ch-test-poll3

Copy link
Copy Markdown
Contributor

Dear @Ergus, @vdimir, this PR is opened while #121398 was marked as backported. The pr-backports-created is removed, so the original PR can be processed again.

If the cherry-pick is not needed anymore, then just close this PR.

@robot-ch-test-poll3
robot-ch-test-poll3 merged commit a056017 into backport/26.3/121398 Oct 1, 2026
1 check passed
@robot-ch-test-poll3
robot-ch-test-poll3 deleted the cherrypick/26.3/121398 branch October 1, 2026 14:24
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! pr-critical-bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants