Skip to content

Refactoring of row policy usage - #118668

Merged
yariks5s merged 21 commits into
masterfrom
yarik/row-policy-underlying-storages
Sep 22, 2026
Merged

yariks5s merged 21 commits into
masterfrom
yarik/row-policy-underlying-storages

Conversation

@yariks5s

@yariks5s yariks5s commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...


Workflow [PR]
Sync PR [sync-upstream/pr/118668]

Version info

  • Merged into: 26.10.1.414-master (included in 26.10 and later)

@mintlify

mintlify Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
ClickHouse-docs 🟢 Ready View Preview Sep 16, 2026, 3:00 PM

@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [87b2eac]

Summary: ✅


AI Review

Summary

This PR centralizes effective row-policy resolution through getEffectiveRowPolicyFilter, makes Alias inherit the row policies of its target table (including through lazy proxies), and wires that helper into Merge, trivial-count, and mergeTree* auxiliary read paths. It is not ready to approve yet: one touched table-function entrypoint still discloses source-table metadata before SELECT is checked, and Merge still accepts a late-applied child row policy path that the direct storage reads already fail closed.

Findings

❌ Blockers

  • [src/TableFunctions/TableFunctionMergeTreeTextIndex.cpp:136] mergeTreeTextIndex still derives protected metadata before its SELECT and row-policy guard runs. resolveIndex only checks SHOW TABLES, then reads the source metadata, resolves source_index_name, and can throw the index-type or engine-specific BAD_ARGUMENTS before StorageMergeTreeTextIndex::checkAccess executes. A user who can see db.t but cannot SELECT it can therefore learn whether the table is MergeTree and whether a named index exists or is text via DESCRIBE mergeTreeTextIndex(...) or the first execute. Suggested fix: move the SELECT plus row-policy check immediately after getTable(...), before getInMemoryMetadataPtr, getByName(source_index_name), index_desc.type, and the MergeTreeData cast.

⚠️ Majors

  • [src/Storages/StorageMerge.cpp:1199] [dismissed by author -- https://github.com/Refactoring of row policy usage #118668#discussion_r3960847476] ReadFromMerge still has no fail-closed check for a child row policy when the child processes above FetchColumns. Direct Distributed and wrapper reads already throw ILLEGAL_PREWHERE in that shape, but a Merge child still gets the policy appended after the child plan, so queries over Distributed (or an Alias over Distributed) can still throw after the remote read or silently return too few rows under ORDER BY ... LIMIT instead of being rejected up front. Suggested fix: mirror the top-level row_policy_filter_not_pushed && till_stage > FetchColumns guard for any Merge child with row_policy_data_opt, or otherwise refuse child stages above FetchColumns whenever a child policy is present.
Tests
  • ⚠️ Add one negative DESCRIBE mergeTreeTextIndex(...) case and one execution/read case for a user who has SHOW TABLES but not SELECT on the source table. That is the smallest proof that the new guard runs before metadata and error text are derived, not only at read time.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: move the mergeTreeTextIndex SELECT and row-policy guard ahead of metadata and engine/index derivation, and fail closed for Merge children whose row policy would otherwise run above the child read.

LLVM Coverage Report

Measured on commit 87b2eac.

Metric Baseline Current Δ
Lines 88.50% 88.50% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 80.70% 80.70% +0.00%

Changed lines: Changed C/C++ lines covered: 109/117 (93.16%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 7, 2026
Comment thread src/Storages/StorageMaterializedView.h Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. label Sep 7, 2026
Comment thread src/Storages/StorageMerge.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 87b2eacff with master f51fa728a (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

298 object files changed (+180.14 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/getEffectiveRowPolicyFilter.cpp.o new 25.04 KiB +25.04 KiB

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

689 translation units recompiled, 5429 s compile time in total, 688 of them have a recent master baseline.

Job report

@yariks5s yariks5s added the pr-autogenerated-docs PR that regenerates docs artifacts from source; exempt from the autogenerated-region edit guard label Sep 8, 2026
Comment thread src/Planner/PlannerJoinTree.cpp Resolved
Comment thread src/Storages/StorageMerge.cpp Resolved
Comment thread src/Storages/StorageMerge.cpp Resolved
@nihalzp nihalzp self-assigned this Sep 18, 2026
@yariks5s
yariks5s added this pull request to the merge queue Sep 22, 2026
Merged via the queue into master with commit 06ecf69 Sep 22, 2026
178 checks passed
@yariks5s
yariks5s deleted the yarik/row-policy-underlying-storages branch September 22, 2026 11:26
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 22, 2026
alexey-milovidov added a commit to AlyHKafoury/ClickHouse that referenced this pull request Sep 22, 2026
…lay-databases

Conflicts: `QueryAnalyzer.cpp`, `InterpreterSelectQuery.cpp`, `PlannerJoinTree.cpp` — master (ClickHouse#118668) moved the
row-policy resolution into the shared `getRowPolicyFilterForStorage` / `getEffectiveRowPolicyFilter` helpers in
`Storages/getEffectiveRowPolicyFilter.h`, replacing the per-call-site code where this branch combined the policies of
the `Overlay` facade name with the source's. Resolved by adding `as_written_id` overloads of the two shared helpers
that combine the other name's policies when the written id resolves through a read-only facade (plain source table:
the facade's policies; parameterized view: the carried source view's policies), and by switching the three call sites
to them; the branch's local planner copy of `getEffectiveRowPolicyFilter` is dropped in favour of the shared one.
`DatabaseOverlay::getSourceTableIdForReadonlyFacade` gained an `IStorage const &` overload for the helper.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. pr-autogenerated-docs PR that regenerates docs artifacts from source; exempt from the autogenerated-region edit guard pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants