Repository navigation
Cherry pick #116007 to 26.8: Lightweight Updates v2 - #116323
Merged
robot-ch-test-poll3 merged 11 commits intoAug 25, 2026
Merged
Conversation
A lightweight `UPDATE` on a table whose sorting key carries a direction threw
Logical error: The size of reverse_flags (N) does not match the size of KeyDescription N+2
from `InterpreterUpdateQuery::execute` -> `MergeTreeData::updateLightweightImpl` ->
`getPatchPartMetadataV2` -> `KeyDescription::getKeyFromAST`. It was reported against 29
distinct pull requests, by `BuzzHouse`, the `AST fuzzer` and `Stress test`, on both
architectures, and is why the first landing of this work was reverted in #116005.
`getPatchPartMetadataV2` supplied `_block_number` and `_block_offset` twice: inline in the
`ORDER BY` tuple, and again as `additional_columns` of `getKeyFromAST`. Only the second
route maintains `reverse_flags`. In `buildKeyColumns` the `N` cloned children of a
directional sorting key are `ASTStorageOrderByElement`s and contribute `N` entries to both
the expression list and `reverse_flags`; the two inline identifiers are not order-by
elements, so they add two expressions and no flags; and the `additional_columns` loop, which
is what would append the two matching `false` flags, then skips both names because they are
already among the key columns. The key ends up with `N + 2` expressions against `N` flags.
Dropping the two inline `push_back` calls leaves the columns to `additional_columns`, which
appends them to the expression list and appends a `false` flag each when the flags are
non-empty. `expression_list_ast` and `column_names` are byte for byte what they were --
same columns, same order -- so `getEffectivePatchSortingKeySize` and
`getTableSortingKeyExpressionFromPatch`, which read the patch key's expression list and
expect the two system columns at its end, are unaffected. Only `reverse_flags` changes, from
`N` to `N + 2`. An ascending sorting key produces no flags at all and is untouched, which is
why this only ever broke for a directional key.
This also removes a latent out-of-bounds read: `KeyDescription::getOriginalExpressionList`
indexes `reverse_flags[i]` across the whole expression list, which was two entries short.
It was unreachable only because `getKeyFromAST` threw first.
`getEffectivePatchSortingKey` and the v1 path clone key children without passing
`additional_columns`, so their sizes always agree; they are left alone.
Test `05038_lwu_v2_reverse_sorting_key` covers a descending key, a mixed-direction key and
an ascending control. It fails without this change with the logical error above.
`03100_lwu_deletes_3` failed the `Stateless tests (amd_asan_ubsan, flaky check)` job with `Test runs too long (> 180s)` at 209s: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=116007&sha=7d8004e22603dec5906a82841217020bf312c7cc&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29 #116007 The test is a long-standing offender rather than anything new: it also failed this gate five times in the original #103182, and its median in that same job is unchanged by this pull request (44.5s there against 45.1s here), so the `reverse_flags` fix is not implicated. Its sorting key is entirely ascending, which leaves `reverse_flags` empty and the changed code path a no-op for it. Each of the three inserts drops from 100000 rows over 10000 distinct `id`s to 20000 rows over 2000, so every `id` still occurs exactly ten times per partition and all the predicates scale by the same factor of five. The shape of what is exercised is untouched: the same three inserts, three `UPDATE`s and four `DELETE`s, the same overlapping delete ranges, the same delete of rows a previous patch had updated, and the same four patch parts merging into one. `sum(v1)` stays at `42 * 10 * 5`; the row counts and patch row counts scale. Measured against a local build with the exact randomized `MergeTree` settings of the failed run - `merge_max_block_size = 19` above all, which makes the two `OPTIMIZE FINAL` merges linear in row count - the test goes from 1.58s to 0.91s, a 42% cut (min of five runs). Under default settings the saving is only 12%, because the cost is otherwise dominated by fixed per-statement replicated-part overhead; it is the adversarial settings the flaky check randomizes into that make row count matter. Five was preferred to a larger factor because it retains two granules per part at the granularity that run randomized (12441), where a factor of ten would leave one, while capturing nearly all of the saving (42% against 47%). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ting Add an integration test with a server running under the `compatibility` setting in the default profile: lightweight updates write patch parts in v1 format by default, and the explicit `patch_parts_version` table setting takes precedence over `compatibility`. Requested in: #116007 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
Patch-part metadata (columns and patch part index) can be taken only from an active sibling patch part; the partition id stores only a hash of the patch column names. Return false gracefully instead of throwing a logical error in createEmptyPart. #116007 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
…2-lightweight-updates-v2 Lightweight Updates v2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #116007
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job