Repository navigation
Fix CREATE ... ON CLUSTER ... AS SELECT over a Distributed table - #109407
Conversation
`CREATE TABLE ... ON CLUSTER ... AS SELECT ... FROM <Distributed> ORDER BY ...` could fail on a cluster with two or more shards with `NOT_FOUND_COLUMN_IN_BLOCK` (`Not found column __table1.<col> in block. There are only columns: <col>`), or with `std::bad_function_call` in 25.8. The `ON CLUSTER` DDL query is executed by the DDL worker, whose query context did not carry a client version - it stayed 0.0.0. When that context reads the `Distributed` table and forwards the sub-query to a remote shard, the shard treats the initiator as a pre-23.3 server and disables the analyzer for compatibility (see `TCPHandler`), while the initiator keeps using the analyzer. The two sides then name columns differently (identifier `__table1.<col>` vs result name `<col>`), so distributed execution fails. Non-cluster distributed reads are not affected because they propagate a real client version. Fill the client version of the DDL query context with this server's version, so distributed sub-queries spawned during DDL execution report a modern initiator and remote shards do not apply the legacy compatibility downgrade. Closes: #90651 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [4f7826f] Summary: ✅
AI ReviewSummaryThis PR stamps the DDL worker query context with this server's own client version so remote shards no longer misclassify Missing context / blind spots
Final Verdict
|
The zero-version guard added to `RemoteQueryExecutor` also surfaced two internal query-context constructors that synthesize an `INITIAL_QUERY` context via `Context::createCopy` and never fill `client_version_*`, so they forwarded a zero version to remote shards: - `AsynchronousInsertQueue::processBatchDeadlines` - the async insert flush context. Reached when the flush spawns a distributed read, e.g. a materialized view triggered by the insert reads from a `Distributed` table. - `StorageMaterializedView::createRefreshContext` - the refreshable materialized view refresh context. Reached when the refresh `SELECT` reads from a `Distributed` table. Both are `setQueryKind(INITIAL_QUERY)` (not `setInitialQuery`), which does not fill the version. This server is the real initiator of these queries and of any distributed sub-query they spawn, so fill the version with this server's own version when it is zero - the same fix already applied to `Session::makeQueryContext`. Otherwise remote shards treat the initiator as a pre-23.3 server and apply legacy compatibility downgrades (see `TCPHandler`), and `RemoteQueryExecutor` now rejects the zero version outright (a logical error that aborts a debug server from the background refresh/flush threads). Adds a regression test covering both paths (verified locally: the guard fires twice without this change and not at all with it). Related: #109407 Related: #90651 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ibuted-client-version
…ery_log The end-to-end test only asserted that CREATE TABLE ... ON CLUSTER ... AS SELECT ... FROM a Distributed table succeeds. Whether an unfixed server actually misbehaves depends on whether allow_experimental_analyzer happens to be marked as explicitly changed on the wire; in the CI harness it always is, so the bug did not reproduce on the master binary and the Bugfix validation job reported "Bug does not reproduce on this arch", failing new_tests_check: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109407&sha=1dc2ba99ad23e6142be0dfa167045fbe3af94d32&name_0=PR&name_1=Finish%20Workflow Add test_ddl_worker_context_carries_client_version: the query executed by the DDL worker (identified by the "/* ddl_entry=... */" prefix it prepends) is recorded in system.query_log with the client version of its query context - client_version_major is 0 without the fix and the server's own version with it, independently of whether the analyzer downgrade fires. Verified against real binaries in the integration harness: the new test fails on the current master binary (26.7.1.802) with client_version_major = 0 and passes with this PR's binary, while the four end-to-end variants pass on both. Also add a GROUP BY variant to the parametrized test. PR: #109407 Co-Authored-By: Claude Fable 5 <[email protected]>
…r test `test_ddl_worker_context_carries_client_version` asserted only `client_version_major > 0`. The compatibility branch the fix avoids is keyed off `client_version < 23.3.0` in `TCPHandler`, so a broken implementation stamping e.g. `1.0.0` or `22.8.0` would pass a major-greater-than-zero check yet still leave the pre-23.3 analyzer downgrade reachable. Assert the full logged `(client_version_major, client_version_minor, client_version_patch)` tuple against the server's own `version`. The fix stamps exactly `VERSION_MAJOR`, `VERSION_MINOR`, `VERSION_PATCH`, whose first three components are what `version` reports, so on a fixed server the logged tuple equals the server version (far above `23.3.0`) and on an unfixed server it is `0.0.0` and the assertion fails - the bug still reproduces on master, keeping the Bugfix validation deterministic. Addresses the AI review on 75ef0a7: #109407 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ibuted-client-version
|
The only red check is I reduced it to a minimal, deterministic reproducer and filed it as #110223. The previous flaky red ( |
…ibuted-client-version
…ibuted-client-version
|
The reds on
The diff versus |
…ibuted-client-version
…ibuted-client-version
|
The |
…ibuted-client-version
|
Merged master (this branch was 335 commits behind) to keep it current; rebuilt locally and confirmed it still compiles cleanly. The sole CI red on the previous head ( |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code |
A distributed query forwarded to a remote shard must carry a known initiator version: the receiving server uses it for version-gated compatibility decisions (e.g. whether to enable the analyzer, see `TCPHandler`). A zero version means the initiating query context was not populated as an initial query - a real client always reports its version, and a server that (re-)initiates a query fills it with its own version. Sending a zero version silently triggers wrong compatibility downgrades on the remote and can break distributed execution (see the issue below). Fail with a logical error instead of sending a zero version, so such context initialization bugs are caught loudly. Related: ClickHouse#109407 Related: ClickHouse#90651 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ery_log The end-to-end test only asserted that CREATE TABLE ... ON CLUSTER ... AS SELECT ... FROM a Distributed table succeeds. Whether an unfixed server actually misbehaves depends on whether allow_experimental_analyzer happens to be marked as explicitly changed on the wire; in the CI harness it always is, so the bug did not reproduce on the master binary and the Bugfix validation job reported "Bug does not reproduce on this arch", failing new_tests_check: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109407&sha=1dc2ba99ad23e6142be0dfa167045fbe3af94d32&name_0=PR&name_1=Finish%20Workflow Add test_ddl_worker_context_carries_client_version: the query executed by the DDL worker (identified by the "/* ddl_entry=... */" prefix it prepends) is recorded in system.query_log with the client version of its query context - client_version_major is 0 without the fix and the server's own version with it, independently of whether the analyzer downgrade fires. Verified against real binaries in the integration harness: the new test fails on the current master binary (26.7.1.802) with client_version_major = 0 and passes with this PR's binary, while the four end-to-end variants pass on both. Also add a GROUP BY variant to the parametrized test. PR: ClickHouse#109407 Co-Authored-By: Claude Fable 5 <[email protected]>
…r test `test_ddl_worker_context_carries_client_version` asserted only `client_version_major > 0`. The compatibility branch the fix avoids is keyed off `client_version < 23.3.0` in `TCPHandler`, so a broken implementation stamping e.g. `1.0.0` or `22.8.0` would pass a major-greater-than-zero check yet still leave the pre-23.3 analyzer downgrade reachable. Assert the full logged `(client_version_major, client_version_minor, client_version_patch)` tuple against the server's own `version`. The fix stamps exactly `VERSION_MAJOR`, `VERSION_MINOR`, `VERSION_PATCH`, whose first three components are what `version` reports, so on a fixed server the logged tuple equals the server version (far above `23.3.0`) and on an unfixed server it is `0.0.0` and the assertion fails - the bug still reproduces on master, keeping the Bugfix validation deterministic. Addresses the AI review on 75ef0a7: ClickHouse#109407 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…stributed-client-version Fix CREATE ... ON CLUSTER ... AS SELECT over a Distributed table
CREATE TABLE ... ON CLUSTER ... AS SELECT ... FROM <Distributed> ORDER BY ...could fail on a cluster with two or more shards withNOT_FOUND_COLUMN_IN_BLOCK(Not found column __table1.<col> in block. There are only columns: <col>: While executing Remote.), or withstd::bad_function_call(STD_EXCEPTION) in 25.8.The
ON CLUSTERDDL query is executed by the DDL worker, whose query context did not carry a client version — it stayed0.0.0. When that context reads theDistributedtable and forwards the sub-query to a remote shard, the shard treats the initiator as a pre-23.3 server and disables the analyzer for compatibility (seeTCPHandler), while the initiator keeps using the analyzer. The two sides then name columns differently (column identifier__table1.<col>vs result name<col>), so distributed execution fails. Non-cluster distributed reads are not affected because they propagate a real client version. The problem could look intermittent because the compatibility downgrade only fired whenallow_experimental_analyzerwas not explicitly marked as changed.The fix fills the client version of the DDL query context with this server's version, so distributed sub-queries spawned during DDL execution report a modern initiator and remote shards do not apply the legacy compatibility downgrade.
Closes: #90651
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed an error (
NOT_FOUND_COLUMN_IN_BLOCK, orstd::bad_function_callin older versions) when runningCREATE TABLE ... ON CLUSTER ... AS SELECTreading aDistributedtable on a cluster with two or more shards.Documentation entry for user-facing changes
Version info
26.7.1.1050(included in26.7and later)