Repository navigation
Do not lose the rows of a shard that returns no columns - #119542
alexey-milovidov wants to merge 43 commits into
Conversation
When the SELECT list of a query over several shards consists of window functions
only, the rows coming from the remote shards were silently dropped:
SELECT count() OVER () FROM remote('127.0.0.{1,2}', system.one);
-- 1 <-- one row with value 1; expected two rows, both 2
SELECT count() OVER () FROM remote('127.0.0.{1,2}', system.one) SETTINGS prefer_localhost_replica = 0;
-- (no rows) <-- every shard is remote: everything is lost
The window function is evaluated on the initiator and takes no arguments, so the
shards have nothing to return: the rows of their part of the result carry no
values at all. `Block::rows` takes the number of rows from the first column, so a
block with no columns always reports zero rows, and the count of such a block was
lost twice over - when the shard's `Chunk` was turned into a `Block` for sending,
and again when the received block was turned back into a `Chunk`. `NativeWriter`
therefore declared zero rows, the initiator dropped the block as empty, and the
window step saw only the local shard's rows. Adding any column to the SELECT list
restored the full row set, and both analyzers were affected.
Keep the row count of a column-less block in `BlockInfo`, fill it in at the two
`Chunk`-to-`Block` conversions, and take the number of rows from it where there
are no columns to count. It is not one of the serialized `BlockInfo` fields: on
the wire the value is the row count of the block, which the `Native` format
writes independently of the columns.
Sending it is gated on a new protocol revision,
`DBMS_MIN_REVISION_WITH_COLUMN_LESS_BLOCK_ROW_COUNT`, because an older receiver
rejects a column-less block that declares rows. In a mixed-version cluster the
block is written as before, and a `Native` file - written at revision 0 - still
treats a declared row count with no columns as corrupted data.
Closes: #119373
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
Workflow [PR], commit [27d8775] Summary: ✅
AI ReviewSummaryThe PR preserves the row count of a Consumer paths covered for the new block form:
Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units2010 translation units recompiled, 10061 s compile time in total, 2010 of them have a recent master baseline. |
|
🕵 |
The analyzer is mandatory since v26.9: the server refuses `enable_analyzer = 0`, which failed the test. Remove the two legacy queries and the `SET enable_analyzer = 1` that only overrode the old-analyzer CI configuration. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… count `adaptBlockStructure` rebuilds the constant columns of the expected header instead of reading them from the received block, and sized them from `Block::rows`, which is zero for a block with no columns. Take the row count from `BlockInfo::num_rows_without_columns` in that case, so a column-less block cannot lose its rows while its structure is adapted, and clear the carried count on the result, which holds its rows in its columns again. A control build with the change disabled shows that the shapes that put a constant next to the window function (`SELECT 1 AS c1, count() OVER () AS c2 FROM remote(...)`) do not reach this path: the shard computes the constant, so its block carries a column. Their queries are added to `05208_window_function_only_over_shards` as a regression guard for the shape anyway. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The revision table of `docs/reference/interfaces/specs/NativeProtocol.mdx` stopped at `54492`, while this change bumps `DBMS_TCP_PROTOCOL_VERSION` and gates the row count of a column-less block behind `DBMS_MIN_REVISION_WITH_COLUMN_LESS_BLOCK_ROW_COUNT`. Add the `54493` row, so the wire change is described where an external implementer looks for it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…tributed-rows-119373
Addresses review: pins that a zero-column block with `M` rows round-trips through `NativeWriter`/`NativeReader` at revision 54493, is sent with zero rows to a 54492 peer, and that the 54493 layout read below the threshold is rejected with `INCORRECT_DATA`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # docs/resources/develop-contribute/native-protocol/protocol.mdx
#113469 made the shards of `SELECT count() OVER () FROM distributed_table` return a marker column, so the shapes in `05208_window_function_only_over_shards` no longer reproduce on master and the bugfix validation reported "Bug does not reproduce". The marker is added only when nothing but the row count is read from the table. A filter on the shards consumes the column it reads, so their result still has no columns, and master returns no rows for `SELECT count() OVER () FROM remote('127.0.0.{1,2}', numbers(3)) WHERE number > 0` where 4 are correct. This change keeps those rows. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119542&sha=a787285b39048df7ce3804f160939679ca7f20a8&name_0=PR #119542 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…OUNT` Writing a column-less block that carries rows as an empty block to a peer below revision `54493` silently lost the rows of that shard in a mixed-version cluster. Refuse instead, in both directions: - A new shard answering an old initiator throws `NOT_IMPLEMENTED` in `TCPHandler` before it writes the `Data` packet; `NativeWriter` refuses the same block as a safety net rather than declaring zero rows. - A new initiator expecting a result with no columns throws when a `Data` packet arrives and a replica the query was sent to is below the revision. `IConnections::getMinQueriedServerRevision` reports the lowest revision among the replicas that received the query, including later hedges. Also update the examples to a query that still produces a column-less block after #113469, and the spec. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e `Native` format `NativeOutputFormat::consume` and `IOutputFormat::write` rebuilt the block or chunk from the columns only, so a column-less chunk with rows reached `NativeWriter` as an empty block and was written as zero rows instead of failing closed below `DBMS_MIN_REVISION_WITH_COLUMN_LESS_BLOCK_ROW_COUNT`. `NativeInputFormat::read` treated any column-less block as the end of the data. Keep the row count in `BlockInfo::num_rows_without_columns` / the chunk on both paths, and cover the format layer in `gtest_native_column_less_block_row_count`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tributed-rows-119373 Master took protocol revision `54493` for `DBMS_MIN_REVISION_WITH_UNIQ_STATE_VERSION_1`, so `DBMS_MIN_REVISION_WITH_COLUMN_LESS_BLOCK_ROW_COUNT` moves to `54494`, and `DBMS_TCP_PROTOCOL_VERSION` is bumped to `54494`. The native protocol and `Native` format specs are updated accordingly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tributed-rows-119373 Master took protocol revision `54496` for `DBMS_MIN_PROTOCOL_VERSION_WITH_PROFILE_EVENTS_IN_SECONDARY_INSERT`, so `DBMS_MIN_REVISION_WITH_COLUMN_LESS_BLOCK_ROW_COUNT` moves to `54497` and `DBMS_TCP_PROTOCOL_VERSION` is bumped to `54497`. The native protocol specs are updated accordingly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged |
# Conflicts: # src/QueryPipeline/RemoteQueryExecutor.cpp # src/Server/TCPHandler.cpp
…tributed-rows-119373 Master took protocol revision `54497` for `DBMS_MIN_REVISION_WITH_CURRENT_AGGREGATION_VARIANT_SELECTION_METHOD`, so `DBMS_MIN_REVISION_WITH_COLUMN_LESS_BLOCK_ROW_COUNT` and `DBMS_TCP_PROTOCOL_VERSION` move to `54498`, and the native protocol spec is updated accordingly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s no columns A shard may send columns that the result of the query over the shards does not need, e.g. a filter over a constant view: `SELECT count() OVER () FROM remote(..., v) WHERE c0 = 'vv'` received `String(size = 1)` blocks while the header has no columns, and `RemoteSource` threw `Invalid number of columns in chunk pushed to OutputPort`. When the header is known to describe the result, `adaptBlockStructure` now keeps only the number of rows of such a block in `BlockInfo::num_rows_without_columns` and drops its columns. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/QueryPipeline/RemoteQueryExecutor.cpp
The `arm_tidy` builds failed with `modernize-use-nodiscard` on `IConnections::getServerRevisionOfLastPacket`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119542&sha=14369f7fc5a5b7ca48310c62d53daeade9926e5e&name_0=PR&name_1=Build%20%28arm_tidy%2C%201%2F4%29 #119542 Co-Authored-By: Claude Fable 5.2 <[email protected]>
…e clients With `--stage with_mergeable_state`, the client is the consumer of an intermediate result that can have rows and no columns, e.g. `SELECT count() OVER () FROM numbers(3) WHERE number > 0`. `LocalConnection` treated such a block as a timeout of the executor, and `ClientBase::onData` returned early on it, so both `clickhouse-local` and `clickhouse-client` printed nothing. The consumers of such blocks now share two functions in `Core/ColumnLessBlock.h`, `getNumRowsIncludingColumnLess` and `hasNoColumnsAndNoRows`, instead of repeating the check of `BlockInfo::num_rows_without_columns`; `LocalConnection` and `ClientBase::onData` use them, so the rows reach `IOutputFormat::write`. The `Native` output format, written at revision 0, now refuses such a result with `NOT_IMPLEMENTED` instead of writing nothing. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=4 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
… columns A `Block` took its number of rows from its columns, so the rows of a block with no columns were kept aside in `BlockInfo::num_rows_without_columns`, and every consumer of such blocks had to ask for them with the helpers of `Core/ColumnLessBlock.h` instead of `Block::rows` and `Block::empty`. A consumer that did not would lose the rows silently. Now a `Block` keeps the number of its rows itself when it has no columns, and `Block::rows` returns it, so `Chunk(block.getColumns(), block.rows())` and the like are right for such a block with no special care. - The number is set with `Block::setRowsWithoutColumns`, by the `Chunk`-to-`Block` conversions and by `NativeReader`. It is never derived: removing every column of a block leaves a block without rows, as before. - A copy, a move and `swap` keep it. A block that was moved from has no rows, the same as a `Chunk`, and inserting a column resets the number: the block takes its rows from its columns then. - `Block::empty` still means "no columns". `Block::hasNoColumnsAndNoRows` tells the absence of data (the end of the data, a timeout) from a block of rows without columns. `BlockInfo` is the same as on master again, and `Core/ColumnLessBlock.h` is removed. The bytes on the wire do not change. #119542 (comment) Co-Authored-By: Claude Fable 5.2 <[email protected]>
…out columns `clickhouse-benchmark` reads the result until `RemoteQueryExecutor::readBlock` returns a block with no columns. With `--stage`, the intermediate result of a query whose SELECT list consists of window functions only is made of such blocks, and they have rows since the row count of a column-less block is sent: the benchmark stopped at the first of them and cancelled the query instead of reading it to the end. The end of the data is a block with neither columns nor rows. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The test checks on purpose that a `Block` that was moved from has no rows, and `clang-analyzer-cplusplus.Move` reports the calls on the moved-from blocks as errors: the `NOLINTNEXTLINE` comments named only `bugprone-use-after-move` and `hicpp-invalid-access-moved`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119542&sha=2c32b5be0dbac247d6763125a08bc14cf4320f8e&name_0=PR&name_1=Build%20%28arm_tidy%2C%202%2F4%29 #119542 Co-Authored-By: Claude Fable 5.2 <[email protected]>
AI review of a later commit does not approve the PR, see the AI Review comment.
`RemoteQueryExecutor` refuses a result with no columns from a server below `DBMS_MIN_REVISION_WITH_COLUMN_LESS_BLOCK_ROW_COUNT`, and it checked the sender of every `Data` packet, including the header: a block with columns and no rows, which a shard sends when it still computes a column that the result does not need (a filter over a constant view). With hedged requests a replica becomes the sender of the data only with its first block of rows, so the header of an older replica failed the query that a newer replica of the same shard could still answer. The header is not checked any more. The sender is still checked for a block of rows, for the block with neither columns nor rows that ends the data of a replica (the connection is still known then, so the error names the server), and at `EndOfStream`. Checked by hand against a build of `master` that speaks revision 54497, in a query over two shards where the older replica sends its header and then stalls: - hedged, the older replica first and a newer one second: the query used to fail with `NOT_IMPLEMENTED` on the header, and now the newer replica answers it; - only the older replica in the shard: still `NOT_IMPLEMENTED`, for a result with a column that the initiator does not need as well as for a result with no columns at all. #119542 (comment) Co-Authored-By: Claude Fable 5.2 <[email protected]>
When the SELECT list of a query over several shards consists of window functions only, and the shards read a column only to filter on it, the rows coming from the remote shards were silently dropped:
#113469 fixed the shape without a filter (
SELECT count() OVER () FROM distributed_table) in the planner, by making the shards return a marker column when nothing but the row count is read. With a filter the shards consume the column they read, so their result still has no columns, and the rows are still lost on master.The window function is evaluated on the initiator, and it takes no arguments, so the shards have nothing to return: the rows of their part of the result carry no values at all. A
Blocktook its number of rows from its columns, so a block with no columns always reported zero rows, and the count of such a block was lost twice over - when the shard'sChunkwas turned into aBlockfor sending, and again when the received block was turned back into aChunk.NativeWritertherefore declared zero rows, the initiator dropped the block as empty, and the window step saw only the local shard's rows. Adding any column to the SELECT list restored the full row set.The row count of a column-less block now survives that round trip. A
Blockkeeps the number of its rows when it has no columns, andBlock::rowsreturns it, so the consumers of blocks need no special care for such a block. The number is set withBlock::setRowsWithoutColumns: theChunk-to-Blockconversions on the way fill it in, andNativeReadertakes it from the block's row count, which theNativeformat writes independently of the columns.Block::emptystill means "no columns", andBlock::hasNoColumnsAndNoRowstells the absence of data (the end of the data, a timeout) from a block of rows without columns. Sending the row count of such a block is gated on a new protocol revision,DBMS_MIN_REVISION_WITH_COLUMN_LESS_BLOCK_ROW_COUNT: an older receiver rejects a column-less block that declares rows, so aNativefile - written at revision0- still treats a declared row count with no columns as corrupted data.In a mixed-version cluster the query fails with
NOT_IMPLEMENTEDinstead of returning a wrong result: a new shard refuses to send such rows to an older initiator, and a new initiator expecting a result with no columns refuses an older shard. The one exception is an older initiator running withskip_unavailable_shards_mode = 'unavailable_or_exception_before_processing': the new shard fails before sending any data, so that initiator skips the shard, as the mode asks, and logs the error.The specification of the
Nativeformat is updated with the new block variant and the revision that gates it.Closes: #119373
Related: #113469
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix a query over a multi-shard
Distributedtable orremote()silently losing the remote shards' rows when its SELECT list consists of window functions only, such asSELECT count() OVER () FROM distributed_table WHERE x > 0.Workflow [PR]
Sync PR [sync-upstream/pr/119542]