Skip to content

Cherry pick #116007 to 26.8: Lightweight Updates v2 - #116323

Merged
robot-ch-test-poll3 merged 11 commits into
backport/26.8/116007from
cherrypick/26.8/116007
Aug 25, 2026
Merged

robot-ch-test-poll3 merged 11 commits into
backport/26.8/116007from
cherrypick/26.8/116007

Conversation

@robot-ch-test-poll4

Copy link
Copy Markdown
Contributor

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

alexey-milovidov and others added 10 commits August 23, 2026 20:13
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
@robot-ch-test-poll4 robot-ch-test-poll4 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels Aug 25, 2026
@robot-ch-test-poll3
robot-ch-test-poll3 merged commit fa81bd9 into backport/26.8/116007 Aug 25, 2026
@robot-ch-test-poll3
robot-ch-test-poll3 deleted the cherrypick/26.8/116007 branch August 25, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants