Repository navigation
Report INCORRECT_DATA instead of LOGICAL_ERROR when a part does not match the declared sorting key - #119295
Conversation
… key A part's marks are physically ordered by the sorting key the part was written with. `table_disk` mounts whatever parts are already under the disk root, and nothing records that key, so a table can declare the opposite direction over parts written ascending - two tables over one root is a documented shape. `splitPartsRangesImpl` then sorts each range's RangeStart/RangeEnd events by the primary index value at the range's begin and end mark, compared in the declared order. With the opposite direction every RangeEnd sorts before its own RangeStart, so parts_ranges[0] is a RangeEnd, the pre-seed inserts that range's PartRangeIndex, and the matching RangeStart fails to emplace: LOGICAL_ERROR at :547, or the chassert at :530 one line earlier in builds with assertions. When the violating range is not the global minimum nothing fires at all and the part_index_start_to_range lookups read a default-constructed MarkRange. Check each range against the declared order where the loop already has both values, and report the invalid input instead. The check is placed before the sort rather than at :547 because the chassert fires first in every debug and sanitizer build, which is where most of the CI occurrences are; converting the throw alone would leave those aborting. With the precondition established, :530, :547 and :618 become internal assertions unreachable from a user configuration and stay as they are. `splitIntersectingPartsRangesIntoLayers` is deliberately not guarded: it derives its borders from interior mark values, which an endpoint check does not constrain, and it cannot abort, so its failure mode is wrong results. Requested by PedroTadim in ClickHouse#119159. Co-Authored-By: Claude Opus 5 <[email protected]>
Two tables over one local plain_rewritable root, the writer with four unmerged
ascending parts and the reader declaring the opposite direction. Without the
preceding commit this kills the server on the chassert in splitPartsRangesImpl;
with it the read reports INCORRECT_DATA naming the part.
Three properties the assertions are built around:
The read is `count(), sum(key)`, not `count()`: a bare count is answered by the
trivial-count path and never enters the splitter, which would make the expected
error vacuous.
The fixture asserts `min(marks) > 1` rather than assuming it. The RangeEnd event
exists only while the range's end mark carries an index value, so a part without
its final mark would make the same query return wrong results instead of the
error - the writer pins index_granularity_bytes, and this line is what fails if
that ever stops holding.
The disk names and the disk path carry ${CLICKHOUSE_DATABASE}. The runner
schedules the copies of a repeated test in parallel, and a fixed root makes them
read each other's parts; a shell test is the only way to vary them, since a
query parameter inside disk(...) is rejected as a non-literal.
The correctly declared reader over the same root is the control: without it the
expected error would also pass for an empty root or a broken disk path.
Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review (3 findings raised, 0 blocking; 2 disclosed limitations)Before opening this PR I ran an independent cold review of the resulting code plus a second-model
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20260910-150308 |
|
Workflow [PR], commit [6a86a55] Summary: ✅
AI ReviewSummaryThis PR changes PR Metadata
Findings❌ Blockers
Tests
Final VerdictStatus: Minimum required actions:
LLVM Coverage ReportMeasured on commit 6a86a55.
Changed lines: Changed C/C++ lines covered: 33/33 (100.00%) · Uncovered code |
|
cc @davenger @tiandiwonder, could you review this? A |
| const Values & range_end_value, | ||
| bool in_reverse_order) | ||
| { | ||
| if (compareValues(range_start_value, range_end_value, in_reverse_order) <= 0) |
There was a problem hiding this comment.
This new guard still only covers the literal DESC carrier, because both values come from the stored primary index and the comparison direction comes from sorting_key.reverse_flags. A mounted reader with a same-typed but different key expression, for example ORDER BY -key, still loads the writer's ascending key values in loadIndex, deriveReverseOrder keeps in_reverse_order = false, and this check accepts the range even though the table's declared order is descending. The binary-search paths below then keep splitting by a non-monotone order.
If the contract here is "part does not match the declared sorting key", we either need a stronger validation that the mounted key expression itself matches what the part was written with, or the docs/changelog/test need to be narrowed to the reverse_flags case this helper actually proves.
| auto range_end_value = index_access.getValue(part_index, range.end); | ||
|
|
||
| checkPartRangeMatchesKeyOrder( | ||
| ranges_in_data_parts[part_index].data_part->name, |
There was a problem hiding this comment.
Projection reads reach this helper too: analyzeProjectionCandidate builds RangesInDataPart(projection_part, parent_part, ...), but projection parts keep only the projection name in data_part->name. On that path the new INCORRECT_DATA becomes Part p ..., which is ambiguous across all parent parts that have projection p and does not actually identify the offending mounted part.
RangesInDataPartDescription::getPartOrProjectionName() already formats parent_part.projection; using that here would keep the new diagnostic actionable on projection reads as well.
There was a problem hiding this comment.
This is okay - the diagnostic could be improved.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 25 s compile time in total, 8 of them have a recent master baseline. |
The test forces the splitter to run through `merge_tree_read_split_ranges_into_intersecting_and_non_intersecting_injection_probability`, and that injection is applied only to a read that is not a parallel-replicas read: `spreadMarkRangesAmongStreams` gates it on `read_type != ReadType::ParallelReplicas`. With `enable_parallel_replicas = 1` arriving from the default profile the ranges therefore never reach `splitPartsRangesImpl`, the read that must be rejected returns rows, and the two lines proving `INCORRECT_DATA` fired are missing from the output. Pin the setting off for the two split reads. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119295&sha=ffbdbbf5356b48a2bbad1ce52edad4444051c7da&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29 ClickHouse#119295 Pinning the setting rather than tagging the test `no-parallel-replicas` keeps the `ParallelReplicas` job running it, and the tag would claim more than is true: only the fault injection is skipped on that path, the guard itself is live there. Measured against a server carrying that job's own profile (`enable_parallel_replicas = 1`, `max_parallel_replicas = 10`, a three-replica cluster), a `FINAL` read of the same parts through a `ReplacingMergeTree` over the same disk root throws `INCORRECT_DATA` with `parallel_replicas_local_plan` both 0 and 1. Under that profile the test reproduced the report's diff exactly, and now passes 20 out of 20 randomized runs; it also passes 20 out of 20 under the default profile, and taking the setting back out brings the failure back. Co-Authored-By: Claude Opus 5 <[email protected]>
The splitter reads every primary key column of a part, while column-level grants cover only the columns the query selects, so the values in this message can come from a column the query is not allowed to read. Measured on a user holding just `GRANT SELECT(val)`: `SELECT key FROM t` is refused with `ACCESS_DENIED`, and before this change `SELECT sum(val) FROM t` over parts that disagree with the declared sorting key returned the message carrying both `key` boundary values. The part name and the two mark numbers stay. They are metadata rather than data, and they are what locates the part, so the diagnostic still names what is wrong and where. Co-Authored-By: Claude Opus 5 <[email protected]>
`deriveReverseOrder` reads the reading table's declared direction, so the pair already in the test (ascending parts, descending reader) reaches only the reverse branch of `compareValues`. A guard that returned early for a forward comparison would satisfy every assertion, and that arm is not harmless: built with such a mutant, `SELECT count(), sum(key)` on an ascending reader over descending parts aborts the server on the sibling assertion, `Logical error: 'parts_ranges[0].event == PartsRangesIterator::EventType::RangeStart'` at `splitPartsRangesImpl`, which is the failure this whole change replaces with `INCORRECT_DATA`. Add the mirror on its own disk root: a writer declaring `ORDER BY key DESC` and a reader declaring `ORDER BY key` over its parts. Same two assertions as the existing pair, and the matching reader stays the control for both. Co-Authored-By: Claude Opus 5 <[email protected]>
|
@jkartseva I leave you to decide if this is the best solution for the issue |
CI finish ledger - 91630dfEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260911-160023 |
Since ClickHouse#110665 a custom disk over local object storage must be inside `custom_local_disks_base_directory`, so the relative `disks/05175/...` roots of this test are refused with "Path of the custom local disk must be inside ... directory" and every `CREATE TABLE` in it fails. Use the `${CLICKHOUSE_DISKS_FILES}` prefix that ClickHouse#110665 moved the other `table_disk` tests to (e.g. `04545_read_only_disk_refresh_parts.sh`). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #119159
Related: #116473
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A
MergeTreetable withtable_disk = 1mounts the parts already present at the disk root. If it declares a sorting key those parts were not written with, reading it raisedLOGICAL_ERRORand aborted the server in builds with assertions enabled. It now reportsINCORRECT_DATAand names the offending part.Description
Requested by @ PedroTadim in #119159:
PartsSplitter.cpp:547throwsLOGICAL_ERRORfor a state a user configuration reaches, so it should be a user-facing error. Scope agreed. It reaches CI on master:Stress test (arm_release)on27ee4ee716b4, plus 16 rows of the debug sibling assertion over 13 PRs in 30 days.Nothing records the sorting key a part was written with, and a writer plus a
read_onlyreader over one root is a shape the suite covers (04545_read_only_disk_refresh_parts), so a reader can declareORDER BY key DESCover ascending parts.splitPartsRangesImplthen reads each range's begin and end index value in the declared order, everyRangeEndsorts before its ownRangeStart, and the splitter hits a duplicatePartRangeIndex.I compare the two values where that loop already has both and report
INCORRECT_DATA, before the sort rather than at the throw: thechassertat:530fires first wherever assertions are enabled, and all 16 rows are from such builds.:547/:585keep theirLOGICAL_ERRORs and:530/:618theirchasserts, now unreachable from a user configuration. Say if you prefer the literal:547-only change. It fires only where parts contradict the declared key: a column permutation stays monotone, and a range with no end-mark index value is skipped.Since the first push: the message no longer prints the key values, since the splitter reads every primary key column while
GRANT SELECT(col)covers only the selected ones; and the test now covers the mirrored direction, which aborts at:569instead of just missing it.Residual I am not closing:
splitIntersectingPartsRangesIntoLayersderives borders from interior mark values, which this check does not constrain, so wrong results survive withsplit_parts_ranges_into_intersecting_and_non_intersecting_final = 0or throughquery_plan_join_shard_by_pk_ranges; it cannot abort.Workflow [PR]
Sync PR [sync-upstream/pr/119295]
Version info
26.10.1.1322-master(included in26.10and later)