Repository navigation
Apply a row policy on a Memory table to a read shipped as a serialized query plan - #122503
Conversation
…zed query plan Since #116248 `Memory` supports PREWHERE, so the planner pushes a row policy into `SelectQueryInfo::row_level_filter`. A logical plan reads through a placeholder `ReadFromTableStep`, which does not carry that filter, so the node executing a serialized plan rebuilt the read without the policy and returned the rows it excludes. Before #116248 the policy was an explicit filter step of the plan. Keep it one in a logical plan for storages whose PREWHERE support depends on the columns, ahead of the PREWHERE filter step. The `MergeTree` family (a `nullopt` PREWHERE contract) is left as is; it is handled by #114955 by re-planning on the executing node. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=e7aebccc74b28ac3f7829f11dc1ffdd8ff49b83f&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29 https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=beb4d3dad37bf154e5b710f2b5c57ff3725f8b48&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29 https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=199f114be9fc953c781745db345deffbc2c0031a&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Workflow [PR], commit [ae46270] Summary: ✅
AI ReviewSummaryThis PR keeps row policies on column-constrained PREWHERE storages as explicit plan filters when building a logical plan, which fixes the Findings❌ Blockers
Final VerdictChanges requested. LLVM Coverage ReportMeasured on commit ae46270.
Changed lines: Changed C/C++ lines covered: 4/4 (100.00%) · Uncovered code |
| /// that node cannot tell whether the policy was pushed down, so keep the policy as an | ||
| /// explicit filter step of the plan, ahead of the PREWHERE filter step, so that the | ||
| /// user's conditions never see the excluded rows. | ||
| if (select_query_options.build_logical_plan && storage->supportedPrewhereColumns().has_value()) |
There was a problem hiding this comment.
StorageMerge::supportedPrewhereColumns() returns a concrete set, so this branch also fires for Merge tables. That breaks the “handle it here” assumption for serialized plans: on the worker, resolveStorages rebuilds a Merge read by running InterpreterSelectQueryAnalyzer again (resolveStorages.cpp:211-259), and StorageMerge then reapplies row policies to its children (StorageMerge.cpp:1290-1299). The explicit FilterStep added here would therefore evaluate the same policy a second time on top of the rebuilt read. That is observable because row-policy expressions are not required to be deterministic (RowPolicy.cpp only rejects arrayJoin): USING rand() % 2 = 0 becomes roughly 25% instead of 50%, and even deterministic IN (subquery) policies now build their sets twice. This needs a narrower gate than supportedPrewhereColumns().has_value() (at least excluding StorageMerge / any other storage whose worker path already re-plans and re-resolves row policies).
…to the read The shipped read recorded `FilterStep` only when the planner set `row_policy_filter_not_pushed`, so a policy that reaches the plan as a filter step on any other path was recorded as `NotInPlan` and the executing node applied it a second time. ClickHouse#122503 adds such a path: under a logical plan it ships a `Memory` policy as a filter step without that flag. With its change applied on top of this branch, the nondeterministic `memory nd` and `memory materialized nd` arms of 04908_row_policy_serialized_query_plan read TWICE instead of ONCE; with this change they read ONCE and its own 05259 test still passes. Record `FilterStep` whenever a policy was built for the read and not pushed into it. On this branch that is the same condition as the flag, so behaviour here does not change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…wo test comments The remote-replica-first arm arms `slowdown_parallel_replicas_local_plan_read`, and since 67965ab the style check requires `no-parallel` and `no-fasttest` on every stateless test that arms a server fail point. Since ClickHouse#122503, a serialized plan keeps a `Memory` or `Buffer` row policy as a filter step whenever the storage reports its PREWHERE columns, so the policy is shipped in the plan rather than applied inside the executing node's read. The two comments in 04908_row_policy_serialized_query_plan now say so; the asserted values do not change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…alized query plan `StorageFromMergeTreeProjection` supports PREWHERE and keeps the default (nullopt) `supportedPrewhereColumns()` contract, so the planner pushed a `_table_function.mergeTreeProjection` row policy into `SelectQueryInfo::row_level_filter`. Under a logical plan the read is a placeholder `ReadFromTableFunctionStep`, which serializes only the table function AST and FINAL/SAMPLE flags, and the executing server reads this storage directly (`readRequiresAnalyzedQuery()` is false), so with `serialize_query_plan = 1` a `cluster()` read returned the rows the policy excludes (reproduces on 26.8.10.6 and master). Keep such a policy as the explicit filter step at the front of `where_filters` under `build_logical_plan`, the placement ClickHouse#122503 uses for storages with a column-set PREWHERE contract. `mergeTreeProjection` is the only table function storage that reached the pushed branch (remote and non-PREWHERE table functions already take the `else` filter step). The shipped step needs no receiver change, so an older executing server is fixed too; no setting, protocol or step version changes. The receiver re-plan hook (`readRequiresAnalyzedQuery() = true`) was rejected: a correct re-plan there would apply `additional_table_filters` twice and check `max_columns_to_read` on the widened header, which needs root-read exemptions that do not exist on master. Related: ClickHouse#112891 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Caused by: #116248
Related: #114955
Related: #112891
Since #116248
Memorysupports PREWHERE, so the planner pushes a row policy on aMemorytable intoSelectQueryInfo::row_level_filter. A logical plan (a serialized query plan or a parallel replicas plan) reads through a placeholderReadFromTableStep, which does not carry that filter, so the node executing a serialized plan rebuilt the read without the policy and returned the rows it excludes. Before #116248 the policy was an explicit filter step of the shipped plan.This keeps the policy as an explicit filter step of a logical plan for storages whose PREWHERE support depends on the columns (a non-
nulloptsupportedPrewhereColumns:Memory,Buffer,File, ...), ahead of the PREWHERE filter step, so user conditions never see the excluded rows. TheMergeTreefamily (anulloptcontract, whereapply_row_policy_after_finaland per-node policy resolution matter) is left as is: #114955 handles it by re-planning on the executing node, and it excludes exactly the storages handled here, so the two do not apply the policy twice.This fixes the master failures of
03812_row_policy_after_changing_initial_user_rolesand03812_row_policy_after_replacing_initial_userinStateless tests (amd_asan_ubsan, distributed plan, parallel)withprefer_localhost_replica = 0, which started at the merge of #116248:The new test
05259_row_policy_serialized_query_plan_memoryfails on the master binary and passes with the change.Changelog category (leave one):
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122503]
Version info
26.10.1.833-master(included in26.10and later)