Repository navigation
Preserve input order for order-sensitive insert destinations - #128833
Conversation
|
Workflow [PR], commit [7eb6ee7] Summary: ✅
AI ReviewSummaryReviewed PR #128833 at Findings
Final VerdictStatus: ✅ Approve No additional changes required in this PR. The remaining pre-existing issue has an explicit tracking issue and an accepted deferral; no duplicate inline comment was posted. LLVM Coverage ReportMeasured on commit 7eb6ee7.
Changed lines: Changed C/C++ lines covered: 94/103 (91.26%) · Uncovered code |
`never` is not a value of `deduplicate_insert`, so the client rejected the setting before running the query. Use `disable`.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units725 translation units recompiled, 4673 s compile time in total, 725 of them have a recent master baseline. |
…ias` single-stream `ReplacingMergeTree` keeps the last inserted row among rows with equal versions, so a versioned table depends on insertion order too. Make `MergeTreeData::supportsParallelInsert` return false for every `Replacing` mode and register `ReplacingMergeTree` and `ReplicatedReplacingMergeTree` with `supports_parallel_insert = false`. An `Alias` reports only its target's `supportsParallelInsert`, but each `AliasSink` runs its own nested `INSERT` that also writes the target's dependent views. Add `forwardedInsertHidesSerialDestination` and `insertReachesSerialDestination` to `InsertDependenciesBuilder` to follow `Alias` targets, their dependent materialized views at any depth and aliases reached through them, and keep the insert single-stream when they reach an order-sensitive destination. Use tied versions for `order_versioned` in `05480` and add an alias chain to an unversioned `ReplacingMergeTree`, directly and through a materialized view.
|
@alexbakharew Can you review this PR? |
|
Hi @aschoube, the |
|
@alexbakharew I have added |
|
Hi @aschoube, Tests: could you also add GraphiteMergeTree (the test config already has graphite_rollup) and a data check for KeeperMap, for both plain INSERT and INSERT SELECT? On master both fail with “Node exists”. Also, |
Separate `isInsertOrderSensitive` from physical `supportsParallelInsert` support. Keep `KeeperMap` serial for every input and follow hidden `Alias` and materialized-view destinations before fan-out. Add stream-count, `GraphiteMergeTree`, and `KeeperMap` data regressions, and make zero-count pipeline failures visible.
|
I have separated i.e. single-stream input keeps one sink for order-sensitive destinations; an already-multistream I have added On the previous PR revision, the multistream I have added |
AI review of a later commit does not approve the PR, see the AI Review comment.
…ibuted` A `MergeTree` table with a `UNIQUE KEY` has the `Ordinary` merging mode, so `isInsertOrderSensitive` returned `false` and an input with one stream still got parallel sinks. `unique_key_conflict_action` resolves a conflict by the order in which the blocks are committed, so with four insert threads `ignore` kept the rows of a later block instead of the first one, and `overwrite` could keep the rows of a block that is not the last one. `Distributed` inherited `false` as well. Each `DistributedSink` sends its blocks to the shard in a separate insert, so an `INSERT SELECT` with one stream into a `Distributed` table over `ReplacingMergeTree` kept an older row. Both now report that they depend on the input order. A `SELECT` with several streams keeps parallel sinks, as before. `02981_insert_select_resize_to_max_insert_threads` read an empty table in its parallel replicas case. Such a read has one stream, so the case now needs data in the table to check the resize.
The coverage report of this pull request showed that tests never reached three branches of `insertReachesSerialDestination`: an `Alias` of a materialized view, an `Alias` of a table made from a table function (a `StorageProxy`), and the depth limit of the check. The test counts the sinks of the outer insert for these cases. A table with 15 cascaded materialized views behind an `Alias` keeps parallel sinks; with 16 views the check reaches its depth limit and keeps one sink. https://s3.amazonaws.com/clickhouse-test-reports/PRs/128833/fc807a9725cfcaab9abb7044ec8196310d062546/pr/llvm_coverage/print_uncovered_code/print_uncovered_code.log
`05836_unique_key_preserves_insert_order` fails in `Stateless tests (arm_binary, ParallelReplicas, plan-based, s3 storage, parallel)`. Plan-based parallel replicas cannot read a `UNIQUE KEY` table yet (`SUPPORT_IS_DISABLED`), see ClickHouse#128534. Set `parallel_replicas_plan_based = 0` for the final `SELECT` of the test, as ClickHouse#132872 did for two other tests. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128833&sha=7016cca5a1e22feb060ace1d9ce40eba62adfe09&name_0=PR ClickHouse#128833
…master` Two semantic conflicts with #128833 that the merge of `master` left behind: `insertReachesSerialDestination` failed closed on a dependent view whose target table is dropped. Such a view is pruned from the graph of the nested `INSERT` under `ignore_materialized_views_with_dropped_target_table` or `materialized_views_ignore_errors` and creates no sink there, so an `INSERT` through an `Alias` lost its fan-out, which `04825_insert_quorum_ignored_broken_view_fanout` pins. The probe now prunes it the same way as `dependentViewMayWriteToReplicatedTable` does, resolving the target through the context of the `INSERT`. `05837_distributed_insert_select_preserves_order` expected four `DistributedSink`s for an `INSERT SELECT` from a multi-stream source. This branch intentionally applies the single-stream guards of a plain `INSERT` (`insertDeduplicationNeedsSingleStream`, `serial_hidden_views`) to `INSERT SELECT` as well, and a `Distributed` destination hides the dependent views and the deduplication of the tables on the shards, so that case is single-stream now. The reference and the comment of the test are updated; the ordering half of the test is unchanged. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Parallel insert sinks can commit blocks out of input order, causing order-sensitive engines to keep an older row or collapse the wrong state.
Separate physical parallel-write support from insertion-order sensitivity with
IStorage::isInsertOrderSensitive. Preserve a single input stream forCollapsingMergeTree,CoalescingMergeTree,GraphiteMergeTree,ReplacingMergeTree(including replicated variants), andEmbeddedRocksDB. VersionedReplacingMergeTreeis order-sensitive too when versions tie. ASELECTwith multiple output streams has no input order to retain, so these destinations can still use parallel sinks.Keep
KeeperMapsingle-stream for every input: parallel sinks can concurrently create the same Keeper node and fail withNode exists.InterpreterInsertQuery::addInsertToSelectPipelinechecks the original stream count before resizing.InsertDependenciesBuilderapplies the same policy through materialized views, proxies, and dependent-view graphs hidden behindAliastargets. A hiddenKeeperMaptarget prevents outer fan-out even for multistream input. Existing deduplication and separate-context restrictions remain in place.Cover ordered and multistream sink counts, multi-block input order and final results,
GraphiteMergeTreedata, materialized-view andAliasdestinations, replicated engines, andKeeperMapdata for plainINSERTand multistreamINSERT SELECT. Keep zero-matchgrep -cresults visible in test failures and document the policy inmax_insert_threads.Closes: #126613
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix incorrect results from multi-block
INSERTqueries into order-sensitive table engines whenmax_insert_threadsenables parallel writes. Plain inserts and single-streamINSERT SELECTpreserve input order forCollapsingMergeTree,CoalescingMergeTree,GraphiteMergeTree,ReplacingMergeTree(including replicated variants), andEmbeddedRocksDB, including through materialized views orAliastables. MultistreamSELECTinput can retain parallel sinks;KeeperMapstays single-stream for all inserts.Workflow [PR]
Sync PR [sync-upstream/pr/128833]
Version info
26.12.1.57-master(included in26.12and later)