Repository navigation
Keep sparse columns when an async INSERT ... SELECT falls back to a synchronous insert - #129574
Conversation
…ynchronous insert AsyncInsertQueueTransform held a materialized copy of the first block of an INSERT ... SELECT under async_insert (const, sparse and replicated columns converted to full). When a second block arrived, that copy was replayed into the synchronous fallback pipeline, so CountingTransform counted the first block at full size and Squashing, seeing chunks of different structures, materialized every chunk of the squashed block. For a wide table with sparse columns this wrote a full part and used about 6 times more memory. This is what fails 03237_insert_sparse_columns_mem in the AsyncInsert job with min_chunk_bytes_for_parallel_parsing = 171302: the first parsed segment is 4953 rows, small enough to be held, and the second insert reports 10165446 written bytes instead of about 340000. Hold the original chunk and materialize a copy only when the block is diverted to the queue. A block whose materialized size exceeds async_insert_max_data_size now falls back with the original chunks at the end of input, after the existing kill / timeout / cancel guard, which therefore covers both exits of a held block. The replay part of disqualify() is split out as fallBack(). The new test compares the bytes written by the async fallback with a plain synchronous INSERT ... SELECT of the same blocks. Its source table pins index_granularity: a granule of 20000 rows or more is read as one block, which the queue route diverts instead of falling back. Related: ClickHouse#128472 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t assert its route The previous commit moved materializeBlockInplace in getRemaining below the kill / timeout / cancel guard, so an O(block) expansion ran between the last check and the write. Materialize first and keep the guard right before both writes (the divert to the queue and the fallback of a block that is too large after materialization), as it was before. The rejected materialized copy is now released before the fallback runs. The test now also fails when its evidence is missing: it requires both query_log rows and the text_log line showing that the async query took the queue route and fell back there (async_insert_select_as_async_insert = 0 gives 0 for that line). Related: ClickHouse#128472 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 4 findings over 1 full pass, 1 fix round and 1 delta recheck).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261105-182600 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-41:20261105-180700 |
|
cc @Felixoid @jkartseva, could you review this and add the |
|
Workflow [PR], commit [ebc8e52] Summary: ✅
AI ReviewSummaryThe change preserves the original Missing context / blind spots
Final VerdictStatus: ✅ Approve. No changes requested. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 23 s compile time in total, 8 of them have a recent master baseline. |
f0ee6ba
Related: #128472
Related: #111663
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Lower memory usage of an
INSERT ... SELECTwithasync_insert = 1whose result has several blocks: the synchronous insert it falls back to now keeps sparse columns instead of converting the whole insert block to full columns (about 6 times less memory for a wide table with sparse columns).Description
03237_insert_sparse_columns_memfails in the AsyncInsert job withmin_chunk_bytes_for_parallel_parsing = 171302(job): its secondINSERT ... SELECT FROM file(...)reports 10165446 written bytes instead of about 340000.Under
async_insert = 1,AsyncInsertQueueTransformholds the first block of anINSERT ... SELECTin case it is the only one. It held a materialized copy (const, sparse and replicated columns converted to full). When a second block arrives, that copy is replayed into the synchronous fallback, so the first block is counted at full size andSquashingthen materializes every chunk of the squashed block, because their structures differ. With that chunk size the first parsed segment is 4953 rows, small enough to be held.The transform now holds the original chunk and materializes a copy only when the block is diverted to the queue. A block too large after materialization falls back with the original chunks. The kill and timeout guard now runs before both exits.
Validation (debug build, server with
async_insert = 1): the second insert of 03237 writes 10165446 bytes with a 71.88 MiB peak before the fix, and 342374 bytes with a 12.41 MiB peak after it. The new test04633_async_insert_select_fallback_keeps_sparsefails on master and passes with the fix, in 50 randomized runs plain and 50 withasync_insert = 1; the other04633_async_insert*tests pass.Workflow [PR]
Sync PR [sync-upstream/pr/129574]
Version info
26.11.1.2453-master(included in26.11and later)