Repository navigation
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 intoOct 1, 2026
Merged
Conversation
…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
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]>
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-picklocally.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:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job