Repository navigation
Fix crash in STREAM read over a multi-partition table with a row policy - #111572
Conversation
MergeTreeCommitOrderSequentialSource builds and optimizes a separate read sub-plan per partition, but the row-level filter (row policy) was a FilterDAGInfo shared by shared_ptr through query_info. Plan optimizations (removeUnusedColumns, splitFilter) mutate that ActionsDAG in place, so a later partition optimized a DAG an earlier one had already rewritten and the server aborted with 'Filter column ... not found in DAG outputs' (or segfaulted). Give each partition sub-plan its own deep copy of row_level_filter, mirroring the existing per-partition PREWHERE clone. Found by the AST fuzzer (STID 5572-45f9). Affects only the experimental streaming path (enable_streaming_queries). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-author-slot-4:20260723-065000 |
Internal second-model review — adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 rounds, 5 findings; bounded: 1 full pass + 1 fix round + 1 delta recheck).
Severity: ❌ blocker / Session id: cron:clickhouse-author-slot-4:20260723-065000 |
|
cc @Michicosun @azat — could you review? A |
Michicosun
left a comment
There was a problem hiding this comment.
I will do a combined plan soon with a single optimization point.
|
Agreed, a single optimization point is the better fix at the root. I'll hold while you draft the combined plan, and I'm happy to implement it instead if you'd prefer. Whichever plan lands, could we keep the regression test here ( |
|
Workflow [PR], commit [c06ea0e] Summary: ❌
AI ReviewSummaryThis PR fixes the shared PR Metadata
### Changelog category (leave one):
- Experimental Feature
### Changelog entry (a [user-readable short description](https://github.com/ClickHouse/ClickHouse/blob/master/docs/changelog_entry_guidelines.md) of the changes that goes into CHANGELOG.md):
Fixes a crash when running a `STREAM` read (`enable_streaming_queries = 1`) over a table with more than one partition and a row policy defined on it.Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 11/15 (73.33%) · Uncovered code |
CI finish ledger — 32239a2CI fully finished (Config + Finish Workflow SUCCESS, >3h buffer). Both Fast tests passed -> no PR-caused failure (the fix is a streaming-path row-policy deep-copy, unrelated to any red below). Every failed check has an owner; only
Session id: cron:our-pr-ci-monitor:20260724-063000 |
CI finish ledger - 3852cffEvery failure below has an owner. None are caused by this PR's diff (the streaming per-partition
Session id: cron:our-pr-ci-monitor:20260724-133000 |
CI finish ledger — 43ca40cEvery failure below has an owner. None is caused by this PR's diff (streaming per-partition
Session id: cron:our-pr-ci-monitor:20260724-200000 |
CI finish ledger - 43ca40cCI finished (Finish Workflow green, CH Inc sync green). AST fuzzer (amd_debug, the STID 5572-45f9 target) and all fuzzer/build/stateless-core jobs are green, so the prewhere/planner fix holds. The three red checks below are flaky/trunk, none caused by this PR (diff =
Session id: cron:our-pr-ci-monitor:20260725-000000 |
|
Discharging the ledger line above: the fixing PR for It is a teardown-helper bug, not a Kafka parsing issue, which is why it lands on unrelated PRs. |
kafka_delete_topic, the shared single-topic teardown helper for the whole Kafka integration family, retried a *successful* delete as if it had failed and could never converge, so an otherwise fully passing test was reported FAILED from teardown. UnknownTopicOrPartitionError (error code 3) on a DeleteTopicsRequest means "that topic does not exist", which for a delete is exactly the requested end state. It landed in the helper's generic `except Exception: retry`, so the helper asked the broker 49 more times to delete something already gone, burned ~23 s, and then raised. Read off the failing job's kafka-python client log (2026-07-24, topic Native_stream_err_1784918653): attempt 1's request was sent at 18:44:18.560; at 18:44:48.570 the client gave up on the response after its 30 s request timeout (the shard runs three xdist workers under TSan); the reconnect's metadata refresh at 18:44:49.077 reported ClusterMetadata(brokers: 1, topics: 3, groups: 0), i.e. only the three internal topics, proving the delete had in fact landed broker-side and only its response was lost; every attempt from 18:44:49.078 on returned error_code 3, which kafka/admin/client.py:409 raises on. So this is a classification bug, not a missing retry. More retries provably cannot help: each error-3 response came back in 1-4 ms, and the condition is permanent. Rather than adding a guard, remove the incorrect classification, which makes the teardown operation idempotent - the correct property for a delete. UnknownTopicOrPartitionError is now caught ahead of the generic handler and treated as the absent-topic path. It is not a blind return: it falls through to the helper's existing post-verification loop, which independently confirms the topic is no longer listed and still raises otherwise. The generic retry is untouched, since it is load-bearing for the transient RequestTimedOutError. kafka.errors marks UnknownTopicOrPartitionError retriable, but that describes stale-client-metadata semantics on the produce/fetch paths, where a later metadata refresh can make the topic appear. On the delete path the same code means the opposite, so keying the retry on that flag would preserve the bug. Not a single-test flake: since the retry loop was added (ClickHouse#108635, 2026-06-27) the signature accounts for 4 CI hits across 4 unrelated PRs, 3 test modules and 3 sanitizer flavours, all through this one frame. It also makes a routine operation of tests/casa_del_dolor/catalogs/kafkatest.py, which deletes randomly chosen topic names, stop burning the full 50-attempt loop. The regression test drives the helper with a stub admin client replaying that exact RPC sequence. A broker cannot be made to drop exactly one DeleteTopicsResponse on demand, and the passing path is byte-identical to today's, so a broker-driven test of this interleaving could only be non-deterministic - which is the property this change removes. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111572&sha=43ca40c8c0beb217e3edc66236a546332bb3c000&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%204%2F6%29 Related: ClickHouse#111572 Co-Authored-By: Claude Opus 4.8 <[email protected]>
kafka_delete_topic, the shared single-topic teardown helper for the whole Kafka integration family, retried a *successful* delete as if it had failed and could never converge, so an otherwise fully passing test was reported FAILED from teardown. UnknownTopicOrPartitionError (error code 3) on a DeleteTopicsRequest means "that topic does not exist", which for a delete is exactly the requested end state. It landed in the helper's generic `except Exception: retry`, so the helper asked the broker 49 more times to delete something already gone, burned ~23 s, and then raised. Read off the failing job's kafka-python client log (2026-07-24, topic Native_stream_err_1784918653): attempt 1's request was sent at 18:44:18.560; at 18:44:48.570 the client gave up on the response after its 30 s request timeout (the shard runs three xdist workers under TSan); the reconnect's metadata refresh at 18:44:49.077 reported ClusterMetadata(brokers: 1, topics: 3, groups: 0), i.e. only the three internal topics, proving the delete had in fact landed broker-side and only its response was lost; every attempt from 18:44:49.078 on returned error_code 3, which kafka/admin/client.py:409 raises on. So this is a classification bug, not a missing retry. More retries provably cannot help: each error-3 response came back in 1-4 ms, and the condition is permanent. Rather than adding a guard, remove the incorrect classification, which makes the teardown operation idempotent - the correct property for a delete. UnknownTopicOrPartitionError is now caught ahead of the generic handler and treated as the absent-topic path. It is not a blind return: it falls through to the helper's existing post-verification loop, which independently confirms the topic is no longer listed and still raises otherwise. The generic retry is untouched, since it is load-bearing for the transient RequestTimedOutError. kafka.errors marks UnknownTopicOrPartitionError retriable, but that describes stale-client-metadata semantics on the produce/fetch paths, where a later metadata refresh can make the topic appear. On the delete path the same code means the opposite, so keying the retry on that flag would preserve the bug. Not a single-test flake: since the retry loop was added (ClickHouse#108635, 2026-06-27) the signature accounts for 4 CI hits across 4 unrelated PRs, 3 test modules and 3 sanitizer flavours, all through this one frame. It also makes a routine operation of tests/casa_del_dolor/catalogs/kafkatest.py, which deletes randomly chosen topic names, stop burning the full 50-attempt loop. The regression test drives the helper with a stub admin client replaying that exact RPC sequence. A broker cannot be made to drop exactly one DeleteTopicsResponse on demand, and the passing path is byte-identical to today's, so a broker-driven test of this interleaving could only be non-deterministic - which is the property this change removes. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111572&sha=43ca40c8c0beb217e3edc66236a546332bb3c000&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%204%2F6%29 Related: ClickHouse#111572 Co-Authored-By: Claude Opus 4.8 <[email protected]>
…olicy-shared-dag Master restructured the streaming snapshot reader: buildPartitionReadingPipeline was replaced by buildPartitionReadingPlan, and the per-partition plans are now united into one QueryPlan that is optimized a single time (28f018c, 3ede227). The per-partition row_level_filter deep copy is kept and re-anchored onto that structure. Uniting the plans does not remove the aliasing: every partition still gets its own read step, all of them holding the same FilterDAGInfoPtr, so one optimize() pass over the unified plan still rewrites that shared ActionsDAG once per partition.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 9/15 (60.00%) · Uncovered code |
CI finish ledger - 3c32069Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
All 174 check-runs on this commit are completed and this is the only failing check. Not caused by Session id: cron:our-pr-ci-monitor:20260730-233000 |
CI finish ledger - c06ea0eEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260804-043000 |
3d5cb29
The test loops its STREAM query 30 times with --max_execution_time=20. That limit cannot catch anything the test looks for: the test asserts the query SUCCEEDS (the oracle is throwIf(max(b) >= 5000 OR count() = 0), and the file carries no serverError expectation), and the read is bounded by STREAM LIMIT 400 over 10,010 pre-inserted rows, so it terminates on its own. The limit can therefore only convert a slow-but-correct run into Code: 159 TIMEOUT_EXCEEDED, which happened once on an unrelated PR (ClickHouse#113400). What makes an iteration slow: a STREAM read re-runs full per-partition planning on every snapshot iteration. Measured on this 10-partition table, a single query logs 3 "Building new snapshot", 10 "Loading statistics", 10 "Moved conditions to PREWHERE" and 11 partition-key prunings while reading about 1000 rows. That cost is left alone here, since buildPartitionReadingPlan and buildNextSnapshotReadingPipeline are being rewritten in ClickHouse#106169. The sibling 04619_streaming_queries_shared_snapshot_strip_race.sql keeps its max_execution_time = 2, because there the limit is the oracle ({ serverError TIMEOUT_EXCEEDED }). It is the only other streaming test that sets the setting and is deliberately untouched. The limit also never bought headroom: 30 iterations x 20s is a 600s ceiling, exactly the harness's own --timeout 600. The installed test overlay does not re-impose max_execution_time: the server default is 0, limits.yaml does not set it, and the 60 second limits_fast.yaml is linked only under FAST_TEST==1 && is_fast_build while Fast test passes --no-long and this test is tagged long. Verified live on the installed stateless overlay: system.settings reports max_execution_time 0, changed 0, while limits.yaml's own values read changed 1. limits.yaml does set max_estimated_execution_time: 600, and that path is armed rather than inert, but the guard that reaches it is a conjunction: the estimate is computed only once a query's own elapsed time exceeds timeout_before_checking_execution_speed, which limits.yaml raises to 300s, against a measured server-side 12ms per query (system.query_log, n=30, min 10ms, max 72ms). It cannot substitute for the removed cap. One job adds a further cap on top of that overlay, and it is worth naming because grep -rn max_execution_time tests/docker_scripts/ finds it. The Stress test job runs the same install.sh, then configure_limits in tests/docker_scripts/stress_tests.lib writes max_execution_time 60 into the default profile, and stress_runner.sh calls that before starting the server which runs the functional suite. The Stress test job passes neither --no-long nor --no-parallel-replicas, and both skips are opt-in, so this test does run there. That cap is looser than the one being removed, not tighter: a client setting wins over the profile value, so the test's own --max_execution_time=20 was the effective limit there and it becomes 60s. Measured against that profile: with no client flag system.settings reads 60, with the test's flag it reads 20. Upgrade check never calls configure_limits, and the fuzzer and performance profiles that also set the setting do not run clickhouse-test. Runaway protection stays with the harness, which gives each file --timeout 600 plus an int(600*1.1)+60 = 720s alarm and reports a hang as "Timeout!". The flaky check's 180 second slow-test verdict is gated on "long" not in tags and cannot fire here. This trades a fast false failure for a slower true one. Validation: the modified test passes 50/50 randomized and 50/50 non-randomized runs (--long-test-runs-ratio 1.0 is required, since the long tag otherwise reduces 50 requested runs to 5). Removing the cap does not measurably slow the test. Two runs of the same 21-test streaming suite on the same binary give 7.70s with the cap (suite-base.log) and 7.96s without it (suite-fix2.log). They are separate clickhouse-test invocations 131s apart, so the comparison rests on a load control rather than on co-scheduling: the 20 unmodified tests in those same two runs move +0.50% in total (27.97s to 28.11s, per-test deltas -0.07s to +0.15s), and both logs carry identical 21-test name sets and the same server sha. The +0.26s difference is therefore inside this test's own run-to-run spread of 7.46s to 9.47s across the 50 randomized runs. system.query_log confirms 30 oracle queries per run with zero timeouts, so the pass is not a skipped loop. Reverting the ClickHouse#111572 source fix makes the modified test fail with Code: 10 "Not found column less(b, 5000_UInt16) in block" while executing MergeTreeCommitOrderSequentialSource, so the regression oracle is still armed. The whole streaming family is 21/21 on both arms.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a crash when running a
STREAMread (enable_streaming_queries = 1) over a table with more than one partition and a row policy defined on it. In debug and sanitizer builds it failed with theFilter column ... not found in DAG outputslogical error; in release builds it could segfault.Description
Found by the AST fuzzer (
AST fuzzer (amd_debug), STID 5572-45f9, CI report). This is a pre-existing trunk bug in the experimental streaming-queries feature, unrelated to the PR the fuzzer ran on.Root cause.
MergeTreeCommitOrderSequentialSourcereads each partition through its own query-plan sub-plan and callsplan.optimize()on each one. The row-level filter (row policy) is aFilterDAGInforeached byshared_ptrthrough the sharedquery_info, so every partition'sReadFromMergeTreestep aliases the sameActionsDAG. Plan optimizations that run duringoptimize()(removeUnusedColumns,splitFilter) mutate that DAG in place, so a later partition ends up optimizing a DAG an earlier one already rewrote. The corrupted DAG then aborts withFilter column <name> not found in DAG outputs(or a segfault / assertion, depending on which optimization runs first).The PREWHERE DAG is not affected because the streaming source already clones it per partition; the row-level filter was simply missed.
Fix. Give each partition sub-plan its own deep copy of
row_level_filter(viaActionsDAG::clone()) before building its read, mirroring the existing per-partition PREWHERE clone. The shared DAG is never mutated, so successive partitions each optimize a private copy.The bug only affects the experimental streaming path (
enable_streaming_queriesis off by default); the regular read path is unchanged.