[fix](fe) Fix row policy bypass when leading hint rebuilds the join (#67776) - #68207
Draft
starocean999 wants to merge 1 commit into
Draft
starocean999 wants to merge 1 commit into
starocean999 wants to merge 1 commit into
Conversation
…pache#67776) Problem Summary: Reproduction: A normal user has a restrictive row policy `USING(k = 1)` on table `t1`. Reading the table directly and joining it without a hint only returns the allowed row, but adding a leading hint leaks the protected row: -- returns only k = 1 SELECT t1.k, t1.v, t2.v FROM t1 JOIN t2 ON t1.k = t2.k ORDER BY t1.k; -- returns k = 1 and k = 2, the row policy is bypassed SELECT /*+ leading(t1 t2) */ t1.k, t1.v, t2.v FROM t1 JOIN t2 ON t1.k = t2.k ORDER BY t1.k; `EXPLAIN VERBOSE` shows that the scan of `t1` in the hinted plan has no `k = 1` predicate, while the un-hinted plan has one. It is an access control issue: the hint only changes the join order, so it must never change which rows a user is allowed to read. Root cause: `CheckPolicy` materializes a row policy as a `LogicalFilter` on the relation (and a data mask as a `LogicalProject` above it). The analysis rule `CollectJoinConstraint` only remembered the scan itself, or the `Project(OlapScan)` directly above it, in `LeadingHint.relationIdToScanMap`. `LeadingHint.generateLeadingJoinPlan` rebuilds the whole join from the plans remembered in that map, so every node that was not remembered - the row policy filter, the data mask project, a binder filter, and the pre-aggregation of a random distribution aggregate table - was silently dropped when the join was rebuilt. Fix: `CollectJoinConstraint` now remembers the whole plan below each side of a join instead of only the relation or the project above the relation (`collectLeafPlan()`), so rebuilding the join reuses exactly the original leaves. `LeadingHint.getBitmap()` is generalized accordingly, so that a leaf which is built on one relation (e.g. the `LogicalAggregate` generated for a random distribution aggregate table) is still resolved to its table bitmap. Before the fix, the hinted query returned `(1, 10, 100)` and `(2, 20, 200)`; after the fix it returns only `(1, 10, 100)`, the same as the un-hinted query. As a side effect, `SELECT /*+ leading(...) */ ...` on a random distribution aggregate table no longer loses its pre-aggregation, which previously returned un-merged rows or failed the `CheckAfterRewrite` slot validation.
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
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.
pick #67776