Repository navigation
Upgrade check: drop the row policies that cannot be applied to a table they cover - #126169
Conversation
The stress phase runs many tests in one shared database per worker, and a test that is stopped before its last statement leaves its row policies behind. A database-level one (`02703_row_policy_for_database.sh`: `ON * USING x=1 TO ALL` on `test_1`) filters every table of that database, so after the upgrade the eager dictionary of `04365_dictionary_lazy_load` over `test_1.src`, which has no column `x`, fails to load in the background with `UNKNOWN_IDENTIFIER` and the log scan fails the job (seen on ClickHouse#126078). The old server fails the same way, so it is leftover test state, not an upgrade incompatibility. 15 row policies were alive when the old server stopped in that run, two of them created by the AST fuzzer. Drop every row policy not defined in `users.xml` before the upgrade and fail the job when one survives, as is done for leftover mutations (ClickHouse#120978). Neutralizing them instead does not work: the test config sets `throw_on_unmatched_row_policies`, so a table whose policies apply to nobody throws for every reader. The statements are generated server-side from `system.row_policies.name`, so no name passes through the shell. The drop takes away the policies that happened to cross the upgrade, so one is created deliberately (`k < 3` on a 10-row table) and the new server has to apply it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings) plus my own cold review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-11:20261016-004100 |
|
Workflow [PR], commit [bcff35c] Summary: ✅ AI ReviewSummaryThe PR removes leftover row policies whose filters cannot be analyzed against their covered tables before upgrading, while preserving other policies for upgrade coverage. The current Missing context / blind spots
Final VerdictStatus: ✅ Approve. No further code changes requested. |
|
We want to test upgrading a server with installed row policies. This is the purpose of the upgrade check. The change now defeats the point. Can we drop only the incorrect row policies? Or, better, prevent their creation? (Otherwise, it is a usability problem - a user can create an invalid row policy, and the server will not be able to restart.) |
|
Agreed, the policies should stay. I'll do both:
On the impact: the server does restart (checked on master). What breaks is every read of a table the policy cannot be applied to, from the moment the policy is created: the old server in this run already failed 245 queries on it, and an eager dictionary over such a table stays |
Drop only the row policies left by the stress phase whose filter does not resolve against a table they cover, and keep the rest across the upgrade, so the upgraded server still has to load and apply them (review on ClickHouse#126169). A filter is checked with `EXPLAIN QUERY TREE SELECT 1 FROM <table> WHERE <filter>` for every table it covers (every table of the database for `ON db.*`). Row policies are applied by the planner, not by the analyzer, so this checks the one filter without the other policies of the table. The deliberate fixture policy is removed: it only compensated for dropping all policies. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Point 1 is done in c4adf1a: only the policies whose filter fails that check are dropped, all the others stay across the upgrade, and the deliberate fixture policy is gone. Locally, of 12 seeded policies the 5 that cannot be applied were dropped and 7 were kept; after a restart there were no errors. The |
…be failures The filter of a row policy may name a table without a database, and such a name resolves in the current database of the reader. The probe ran in `default`, so a working policy like `k IN (SELECT k FROM allowed)` of a test in `test_1` failed with `UNKNOWN_TABLE` and was dropped. Select the policy's database before `EXPLAIN QUERY TREE`. Any failure of the probe also fell through to `DROP`, including a failure of the query that only generates it, a timeout and a lost connection. Drop a policy only when the server rejects its probe (`Received exception from server`); otherwise keep it and write a FAIL row with the client errors. Both reported by the AI review of ClickHouse#126169. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Both AI review findings are fixed in 3ac1062: the probe now runs in the policy's database, and a policy is dropped only when the server rejects its probe (any other failure keeps it and writes a FAIL row). |
|
@alexey-milovidov, one design question about the When the table is read, the filter is analyzed in each reader's context.
In both, a filter that reads another table or a dictionary (a subquery, I would do A. |
`Received exception from server` also covers resource limits, server-side timeouts and cancellation, which say nothing about the filter. With a memory exception forced in the validation client (26.9.19.9), every checked policy was dropped, the valid ones included, and no FAIL row was written. Drop a policy only when the server rejects its probe with one of the codes an unresolvable filter produces on `EXPLAIN QUERY TREE`, measured on 26.9.19.9: ILLEGAL_TYPE_OF_ARGUMENT (43), UNKNOWN_FUNCTION (46), UNKNOWN_IDENTIFIER (47), ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER (59), UNKNOWN_TABLE (60) and NO_COMMON_TYPE (386, e.g. `has([1, 2], x)` over a `String` column). A failed `USE` gives UNKNOWN_DATABASE or an operational code, so it never matches. Any other error keeps the policy and is reported in the existing FAIL row, with the client output. The `Code: N. DB::Exception: Received from` line is the same in the 26.3, 26.6, 26.8, 26.9 and master clients. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A scalar subquery of a filter is evaluated by `EXPLAIN QUERY TREE` and reads
its table with that table's row policies, so a working policy such as
`k > (SELECT max(k) FROM allowed)` failed its check, and was dropped, when
`allowed` carried a broken policy (`x = 1` over a table without `x`). The
filters without a subquery are now checked first, and a broken policy is
dropped as soon as its check fails, so the later checks no longer see it.
The check also recognizes more errors that the analysis of a broken filter
gives on 26.9 (each also fails every read of the table): 53 (`k IN (SELECT
tuple(1, 2))`), 42 (`equals(k)`), 184 (`count() > 0`), 36 (`dictGet` over a
missing dictionary, an unknown time zone), 69 (`toDecimal32(k, 100)`), 6
(`toUInt8('abc')`) and 125 (a scalar subquery returning two rows). These
policies were kept with a FAIL row before.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`EXPLAIN QUERY TREE` executes the scalar subqueries of the filter, and their reads apply the row policies of the tables they read as the `default` user. So a valid policy was dropped when a broken policy covered its subquery's table, and a valid user-scoped policy failed the check with ACCESS_DENIED when no policy on that table covered `default`. `DESCRIBE TABLE view(...)` analyzes the query with `only_analyze`: scalar subqueries get type-only placeholders and the planner applies no row policies, so each filter is checked on its own. Subqueries in table function arguments still run; no row policy in the suite has one. Measured on 26.3.33.24 and 26.9.19.9: every filter it rejects also fails a normal read, and it also rejects plan-level type errors (`s = 1` on a String column). A scalar subquery that returns several rows (125) is no longer detected, so the ordering of filters with subqueries and code 125 are removed. The stress phase fuzzes `CREATE ROW POLICY` filters (`ast_fuzzer_any_query`), so add the other analyzer errors a fuzzed filter gives, each measured on 26.9 to fail both the check and a normal read: 20, 38, 41, 44, 81, 153, 190, 407, 675. Reader-dependent errors (ACCESS_DENIED, an unknown custom setting) still keep the policy and write the FAIL row. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@groeneai, yes, A is ok. |
alexey-milovidov
left a comment
There was a problem hiding this comment.
Ok. The check is quite heavy and ad-hoc, but good enough for its place.
|
Thanks, I'm implementing A and will link the PR here when it opens. |
|
The |
Related: #126078
Related: #120978
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Upgrade check: before the server is upgraded, drop the row policies left by the stress phase whose filter cannot be applied to a table they cover, so they can no longer break a background read on the upgraded server. The other row policies stay and are carried across the upgrade.
Description
Upgrade check (amd_release)failed on #126078 withError message in clickhouse-server.log: after the upgrade,ExternalDictionariesLoaderlogged... Unknown expression or function identifier `x`. In scope x = 1. (UNKNOWN_IDENTIFIER): report.Root cause. The stress phase runs many tests in one database (
--database=test_1).02703_row_policy_for_database.shcreatedCREATE ROW POLICY ... ON * USING x=1 TO ALL, and its client stopped before theDROP ROW POLICY. That database-level policy filters every table oftest_1, includingsrcof04365_dictionary_lazy_load, which has no columnx. The upgraded server loads that test's eager dictionary at startup, and its source query fails. The old server failed the same way (245 query errors in the stress log): leftover test state, not an upgrade incompatibility.Change. Before the upgrade, each row policy not from
users.xmlis checked withDESCRIBE TABLE view(SELECT 1 FROM <table> WHERE <filter>)in the policy's database, for every table it covers (all tables of the database forON db.*). This only analyzes the filter: apart from those in table function arguments, its subqueries do not run, so another policy cannot fail the check. A policy is dropped only when the server fails to analyze its filter (unknown column, table or function, wrong type or arity, invalid constant), the others stay across the upgrade. Any other check failure and a failedDROPare FAIL rows.Validation. Locally, the leaked policy reproduces the CI error after a restart. With the step, on 26.9, the policies that cannot be applied (21 error codes; database-level, restrictive,
memory) are dropped, the others kept (ALL EXCEPT, quoted names, user-scoped, subqueries over a table with a broken policy); a memory limit in the check keeps them all. After a restart: 0 errors, the dictionary loads, the kept policies still filter. Each FAIL row was forced once.Workflow [PR]
Sync PR [sync-upstream/pr/126169]
Version info
26.11.1.181-master(included in26.11and later)