Repository navigation
Conversation
…orting key DELETE and UPDATE failed with The size of reverse_flags (1) does not match the size of KeyDescription 3 on any MergeTree table whose sorting key has a descending column and which has enable_block_number_column and enable_block_offset_column enabled. In a release build the statement is rejected with an internal error instead of executing; in a debug or sanitizer build the exception aborts the server. Found by BuzzHouse on several unrelated pull requests, with plain DML such as `DELETE FROM d18.t278 WHERE (NULL)` and no experimental setting involved. patch_parts_version defaults to v2, so the affected branch is the default one. KeyDescription requires a key expression list to be either entirely wrapped in ASTStorageOrderByElement or not wrapped at all; the contract is spelled out at ParserCreateQuery.cpp:567-569, established by buildKeyColumns and enforced by the size check in getKeyFromAST. getPatchPartMetadataV2 broke it by mixing the two shapes: it appended the children of sorting_key.getOriginalExpressionList(), which re-wraps every child once the key has a reversed column, and then appended bare ASTIdentifiers for _block_number and _block_offset. buildKeyColumns records a direction flag only for a wrapped child, and its additional_columns loop cannot make up for the two missing flags because both names are already present in column_names by then. So reverse_flags ended up two entries shorter than the column list. A one-column reversed key produces exactly the reported 1 versus 3. Append the two trailing system columns in the shape inherited from the list, so getKeyFromAST always receives a uniform list and the flags line up positionally with the columns. This repairs the single producer that violated the contract rather than relaxing the check, which stays armed for any future malformed producer: letting a short vector through would silently mean "ascending" for the tail, and several consumers index reverse_flags positionally. Fixing the caller also follows 6fb087c, which met the same mixed-wrapper condition and repaired the caller while leaving KeyDescription untouched. The wrapped-ness of the inherited list is read off the list itself rather than inferred from reverse_flags, because the list is what buildKeyColumns inspects. For a table with no reversed column the list comes back bare and the emitted AST is byte-identical to before, so the default path does not move. Compatibility was measured, not assumed. The formatted text of getOriginalExpressionList() feeds the patch partition hash, the persisted and equality-compared sorting_key_desc, and replica metadata comparison; all of those read formatted text and none hashes the AST, and every added wrapper is ascending, which renders no DESC. The key text in system.tables and the patch partition ids are byte-identical across the change, and a patch part written by the previous binary is still read and merged correctly by the fixed one and vice versa.
…test clickhouse-test randomizes patch_parts_version between 'v1' and 'v2' and injects the draw into a CREATE only when the setting is absent from its SETTINGS clause. Seven of the eight tables here left it out, so on a 'v1' draw the whole file went through getPatchPartMetadataV1 -- a uniformly bare key list that never reads the table sorting key -- and every expected result still matched. Roughly half of CI runs therefore could not fail, and would have passed with the source fix reverted. Pinning 'v2' per CREATE keeps the rest of the MergeTree randomization in place, which a no-random-merge-tree-settings tag would switch off. The eighth table stays on 'v1' as the arm proving that path is unaffected. Results are unchanged, so the reference file is untouched. Measured on a binary with the source fix reverted: the unpinned test passed on a 'v1' draw and failed on 'v2'; the pinned test fails on either draw, 10 of 10 restarted runs. Co-Authored-By: Claude Fable 5 <[email protected]>
Internal second-model reviewTwo rounds of independent cold review plus a second-model pass. Verdicts below. 2 accepted and fixedThe regression test could have passed with the fix reverted. Seven of the eight Fixed by pinning The changelog category claimed a released version was affected. Verified two ways. The PR that 1 accurate mechanism, no actionA Stripping 2 nits I raised and refuted myself
The seven new pins are not inert: the client injects a randomized MergeTree setting only when the |
|
Workflow [PR], commit [ef7b6f4] Summary: ❌
AI ReviewSummaryThis PR fixes Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 13/13 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 14 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger: ef7b6f4Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Attribution for the logical error: the abort is raised from Session id: cron:our-pr-ci-monitor:20260822-140000 |
|
The feature was reverted. |
Related: #103182
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes an unreleased defect from #103182 (
masteronly):DELETEandUPDATEon aMergeTreetable whose sorting key has a descending column, withenable_block_number_columnandenable_block_offset_columnenabled, raisedThe size of reverse_flags (N) does not match the size of KeyDescription M. No stable release is affected, so no changelog entry and no backport are owed.Description
DELETE FROM t WHERE ...andUPDATE t SET ...failed with an internal error instead of executing, for any table combining a reversed sorting key (ORDER BY c0 DESC) withenable_block_number_column = 1, enable_block_offset_column = 1. Found by BuzzHouse on unrelated PRs (DELETE FROM d18.t278 WHERE (NULL); report). Ordinary DML, no experimental setting, andpatch_parts_versiondefaults tov2, so this is the default path onmaster.v2patch parts arrived in #103182, which is in no release branch.Root cause:
KeyDescriptionrequires a key expression list to be either entirely wrapped inASTStorageOrderByElementor not wrapped at all (the contract is stated atParserCreateQuery.cpp:567-569).getPatchPartMetadataV2built the patch part's sorting key by mixing both shapes: it appended the table key children returned bygetOriginalExpressionList(), which re-wraps every child when the key has a reversed column, and then appended bare identifiers for_block_numberand_block_offset.buildKeyColumnsrecords a direction flag only for wrapped children, soreverse_flagsended up two entries short and the consistency check ingetKeyFromASTthrew.The fix appends those two trailing columns in the shape inherited from the list, so
getKeyFromASTalways receives a uniform list and the flags line up positionally.KeyDescription.cppis untouched and its check stays armed. For a table with no reversed column the emitted AST is unchanged.Validated with a deterministic reproducer in both directions, and by confirming the formatted key text and the patch partition ids stay byte-identical across the change. Ascending-key patch parts, the only shape a pre-fix binary can write, were exchanged both ways between the two binaries and merged, which exercises the equality check on the persisted
sorting_key_desc. A descending key has no pre-fix counterpart: writing such a patch is the statement that failed.Workflow [PR]
Sync PR [sync-upstream/pr/115900]