Repository navigation
Revert "Lightweight Updates v2" - #116005
Merged
Merged
Conversation
Contributor
This was referenced Aug 23, 2026
alexey-milovidov
added a commit
that referenced
this pull request
Aug 23, 2026
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.
Contributor
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
This was referenced Aug 25, 2026
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.
Related: #103182
Related: #111059
Reverts #103182 (
Lightweight Updates v2, merged as70a0c0ff637), which introduced aLOGICAL_ERRORon any lightweightUPDATEof a table whose sorting key has a direction.The failure
InterpreterUpdateQuery::execute->MergeTreeData::updateLightweightImpl->getPatchPartMetadataV2->KeyDescription::getKeyFromAST.Example report: Stress test (arm_debug) (PR #115540, an unrelated Web UI change).
It is not confined to one pull request. Since the first occurrence on 2026-08-21 18:02 it has been reported against 29 distinct pull requests across
BuzzHouse,AST fuzzerandStress test, on both architectures and in several sanitizer builds. There is no tracking issue for it yet.Cause
getPatchPartMetadataV2builds the patch part's sorting key by cloning the table's original sorting-key AST children and then appending two bare identifiers, insrc/Storages/MergeTree/PatchParts/PatchPartsUtils.cpp:_block_numberand_block_offsetare therefore supplied twice: once inline in the tuple and once asadditional_columns. Only the second route maintainsreverse_flags. InbuildKeyColumns(src/Storages/KeyDescription.cpp):Ncloned children areASTStorageOrderByElements, so they contributeNentries to bothreverse_flagsand the expression list;2expression-list entries and noreverse_flagsentries;additional_columnsloop, which is what appends the matchingfalseflags, skips both names because they are already incolumn_namesfrom the tuple.The result is
reverse_flags.size() == Nagainst an expression list ofN + 2, which trips the consistency check inKeyDescription::getKeyFromAST.The check itself and direction-carrying key descriptions (#111059, merged 2026-07-24) both predate the breakage; they were correct together for a month. Before #103182 the patch-part sorting key was built from bare
ASTIdentifiers, soreverse_flagswas always empty and the check's!reverse_flags.empty()guard made it unreachable. This was confirmed by diffing70a0c0ff637^1against70a0c0ff637.An ascending sorting key produces empty
reverse_flagsand short-circuits the guard, which is why the failure is intermittent and has so far only been found by fuzzers.Note
A narrow fix looks possible — dropping the two inline
push_backcalls and lettingadditional_columnsadd the columns, which appends the matchingfalseflags. That is a change to the feature's own code and is better made by its author with a regression test for aORDER BY ... DESCtable under a lightweightUPDATE; this pull request only takes the failure off master in the meantime.Revert mechanics
git revert -m 1 70a0c0ff637. One conflict, intests/queries/0_stateless/04104_lightweight_update_v2_eager_patch_discard.sql: the test was added by #103182 and later adjusted bydddfaccd441, and is removed here along with the rest of the feature. After the revert,src/Storages/MergeTree/PatchParts/SourcePartsSetForPatch.{h,cpp}are restored andPatchPartIndex.{h,cpp}andapplyPatchesLegacy.{h,cpp}are removed; nogetPatchPartMetadataV2reference and no dangling include of a deleted header remains insrc/.The feature is not in any release — the newest is
v26.7.5.10-stable, and #103182 landed in the unreleased 26.8 — so there is no changelog entry to retract.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Workflow [PR]
Sync PR [sync-upstream/pr/116005]
Version info
26.8.1.1956(included in26.8and later)