Skip to content

Serialize row policy filter on ReadFromTableStep - #107745

Open
devcrafter wants to merge 1 commit into
masterfrom
fix-pr-row-policy-serialization
Open

devcrafter wants to merge 1 commit into
masterfrom
fix-pr-row-policy-serialization

Conversation

@devcrafter

@devcrafter devcrafter commented Jun 17, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

ReadFromTableStep did not carry the row-policy FilterDAGInfo across serialization. With serialize_query_plan = 1 and parallel-replicas / distributed plans, the row policy was set on table_expression_query_info.row_level_filter on the initiator but never propagated to the remote node — so the remote-side storage->read was called without select_query_info.row_level_filter and RLS was bypassed.

Wire it through:

  • ReadFromTableStep gains a FilterDAGInfoPtr row_policy_filter field, ctor argument, getRowPolicyFilter() accessor, and serialize / deserialize / clone plumbing (flag bit 16).
  • PlannerJoinTree.cpp passes table_expression_query_info.row_level_filter to the step.
  • resolveStorages.cpp (replaceReadingFromTable) reads it back via reading_from_table->getRowPolicyFilter() and sets select_query_info.row_level_filter before calling storage->read.

Regression test: 04049_pr_row_policy_and_trivial_count (parallel replicas + plan serialization + row policy + trivial-count).

Add `row_policy_filter` to `ReadFromTableStep` so the row-level filter
attached by the planner survives across plan serialization. Wire it
through `PlannerJoinTree.cpp` (pass `table_expression_query_info.row_level_filter`
into the step) and `resolveStorages.cpp` (re-attach to
`select_query_info.row_level_filter` when reconstructing the read on
the deserialization side).

Without this, queries serialized via `serialize_query_plan = 1` lose
their row policy on the remote node — the row policy is enforced on
the initiator only, breaking RLS for parallel-replicas / distributed
plans.

Regression test: `04049_pr_row_policy_and_trivial_count`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8233470]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_asan_ubsan, distributed plan, parallel, 2/2) FAIL
04099_source_step_with_filter_rp FAIL cidb
Stateless tests (arm_asan_ubsan, targeted) ERROR

AI Review

Summary

This PR propagates the row-policy FilterDAGInfo through ReadFromTableStep so serialize_query_plan parallel-replica reads do not bypass row-level security on the remote side. The functional direction is correct, but the new field extends the existing query-plan serialization payload without a version bump or version gate, so mixed-version distributed execution can misparse the plan stream.

Missing context / blind spots
  • ⚠️ The CI report for commit 8233470cebb93a15a67819484df334bd45a3e2fd currently contains zero test results, so completed CI would still be needed to validate the same-version regression test and build coverage.
Findings
  • ❌ Blockers
    • [src/Processors/QueryPlan/ReadFromTableStep.cpp:62] ReadFromTableStep now writes flag 16 plus a serialized FilterDAGInfo, but DBMS_QUERY_PLAN_SERIALIZATION_VERSION remains 1 and older ReadFromTableStep::deserialize code ignores unknown flag bits without consuming the new payload. A new initiator with serialize_query_plan can therefore send a row-policy plan to an old replica that accepts version 1, returns from ReadFromTableStep::deserialize with unread bytes, and parses the rest of the plan/set stream from the wrong offset instead of failing with a clean unsupported-version exception.
    • Suggested fix: bump and gate the query-plan serialization version for this field, carry the negotiated version through IQueryPlanStep::Serialization and IQueryPlanStep::Deserialization, and either omit the field only when it is safe or fail before sending a plan that requires row_policy_filter to a version-1 receiver.
Tests
  • ⚠️ The new stateless test covers same-version behavior only. Add focused coverage for the serialization boundary, or otherwise prove that a version-1 receiver is never sent a ReadFromTableStep payload containing row_policy_filter.
Final Verdict

Status: ❌ Block

Minimum required action: version-gate the new serialized row_policy_filter field so mixed-version clusters fail cleanly or use a compatible plan representation.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jun 17, 2026
writeIntBinary(use_parallel_replicas, ctx.out);

if (row_policy_filter)
row_policy_filter->serialize(ctx);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extends the version-1 ReadFromTableStep payload, but the outer QueryPlan version stays DBMS_QUERY_PLAN_SERIALIZATION_VERSION = 1 and deserialize does not reject unknown bits here. In a mixed-version cluster, a new initiator can serialize flag 16 plus a FilterDAGInfo; an old replica's ReadFromTableStep::deserialize ignores bit 16 and returns without consuming those bytes, so the rest of the plan/set stream is parsed from the wrong offset instead of producing a clean unsupported-version exception. Please bump/version-gate query-plan serialization for this field, and pass the negotiated plan version into step serialization/deserialization or fail before sending a row-policy plan to a version-1 receiver.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, all the rest seems good

@clickhouse-gh

clickhouse-gh Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.20% 85.20% +0.00%
Functions 92.30% 92.30% +0.00%
Branches 77.50% 77.40% -0.10%

Changed lines: Changed C/C++ lines covered by tests: 35/41 (85.37%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@scanhex12 scanhex12 self-assigned this Jun 18, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Dear @scanhex12, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants