Repository navigation
Let a merge shrink a table that is over max_table_size_rows - #117229
Conversation
The row limit had no equivalent of the byte limits' shrinking-replacement carve-out, so every partial merge of an over-limit table threw `TABLE_SIZE_LIMIT_EXCEEDED` at commit - even a size-preserving compaction of a few small parts in an untouched partition. The table could then not be compacted at all: the part count grew until `parts_to_throw_insert` made every insert fail, and on `ReplicatedMergeTree` the already-logged `MERGE_PARTS` entry was retried forever, wedging the replication queue. An operation that replaces the covered parts with a part holding no more rows is now allowed, mirroring the byte limits. Growing operations - inserts - are still rejected. Closes: #117101
|
Workflow [PR], commit [cfe2133] Summary: ✅
AI ReviewSummaryThis PR fixes the Findings💡 Nits
Final Verdict✅ The code change itself looks correct. I would merge it after updating the LLVM Coverage ReportMeasured on commit cfe2133.
Changed lines: Changed C/C++ lines covered: 7/7 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 38 s compile time in total, 7 of them have a recent master baseline. |
…rows-shrinking-merge
The previous `ALTER TABLE ... DELETE WHERE p = 0` dropped the whole 5000-row part, so the table fell back under `max_table_size_rows` and the pre-patch check would have accepted it too - the case did not exercise the new carve-out at all. Delete only a part of the big partition first: the table stays at 3100 rows, far above the limit of 1000, and the commit is allowed only because the mutated part holds fewer rows than the part it replaces. The full delete and the follow-up insert are kept, so the test still covers the return under the limit.
|
🕵 Merged On the reds of the previous run — none of them touch this change, which only relaxes
|
|
Investigated. Pre-existing trunk defect, not related to this change. The reason no open issue turns up is that the issue which tracked it is closed: #115057 reported the identical That fix does not cover this abort. Its merge commit Frame 20 is the in-stress AST fuzzer, which is why the report carries no stable query. The surviving route is in the optimizer, downstream of the port count #115352 corrected. if (pipeline.getNumStreams() > 1 && (partition_by_description.empty() || pipeline.getNumThreads() == 1))
Breadth over 30 days, keyed on the message text: 63 rows across 55 distinct carrier PRs. 15 of those rows, across 15 distinct PRs, are after #115352 merged, the latest today at 18:55Z. The 3 true-master rows all predate that merge; there is also one row on release branch A fix is in progress in #109393, but not in a shape I would ask you to merge as it stands: it merges the streams at the |
|
Fix: #117826 Two corrections to my comment above, both from reading the failing tree rather than the stack:
The same line had a second effect worth recording: when both sides were limited to one thread the Reproduced on master with two |
… exercises the over-limit merge Without `max_bytes_to_merge_at_max_space_in_pool = 1` the five small parts of partition 1 could be compacted by a regular background merge before `OPTIMIZE TABLE ... PARTITION 1 FINAL` runs, in which case the part-count check still prints 1 while the new carve-out in `throwIfTableSizeLimitsExceeded` is never taken. Also assert the part count before `OPTIMIZE`, as `04910_max_table_size_merge` does. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 Merged The single red on the previous run was |
…rows-shrinking-merge
… needs the row carve-out The previous mutation case deleted rows from the single 5000-row part of partition 0. `throwIfTableSizeLimitsExceeded` computes the row count outside the replaced parts first (`5100 - 5000 = 100`), which is already under `max_table_size_rows = 1000`, so the old code would have accepted that commit without the new `added_rows <= covered.rows` branch. Add a `DELETE IN PARTITION 1` of the 100-row part first: the rows outside the replaced part stay at 5000, over the limit, so the commit is possible only through the carve-out for a replacement that does not add rows. The partition-0 mutation is kept afterwards. Also renumber the test to `05227` because `05063` collided with tests added on master. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 Merged The only red of the previous run, |
| const UInt64 total_rows = current.rows - std::min(current.rows, covered.rows); | ||
|
|
||
| if (total_rows > max_rows) | ||
| /// An operation that replaces the covered parts with a part that has no more rows than they |
There was a problem hiding this comment.
This changes the user-visible contract of max_table_size_rows, but the structured setting docs still describe only empty parts as the escape hatch (src/Storages/MergeTree/MergeTreeSettings.cpp:1128-1139, which also feeds the autogenerated docs/reference/settings/merge-tree-settings/max.mdx). After this lands, users reading the setting docs will still be told that recovering an over-limit table requires dropping data, even though row-neutral or shrinking merges and mutations are now allowed. Please update the DECLARE doc string rather than the generated .mdx page.
…x_table_size_rows`
Backport #117229 to 26.9: Let a merge shrink a table that is over `max_table_size_rows`
|
@alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
`optimizeParallelFullSortingMergeJoin` converts both pre-join sorts with `convertToScatteredFullSort`, whose contract is one sorted stream per shard with no final merge, so that the two sides present the same number of ports. `JoinStep::updatePipeline` relies on that, because it pairs the shards of the two sides positionally. `SortingStep::fullSort` decided its final merge from `pipeline.getNumThreads`, which is a per-side budget rather than a property of the shared plan: a single-table subquery with a trivial `LIMIT` is planned with one thread, while a `UNION ALL` side is re-budgeted to the sum of its branches. The one-thread side therefore merged its shards back into a single port while the other kept them, the counts diverged, `use_sharding` was dropped, and the single-port fallback `joinPipelinesYShaped` threw `Join is supported only for pipelines with one output port`. On a release build the query fails with `Code: 49`; in debug and sanitizer builds the server aborts. Reachable on the released 26.8. The same line had a second effect: when both sides were limited to one thread the merge fired on both, the counts stayed equal, and the sharded join the optimizer had asked for was silently replaced by a single merge join. Skip the merge when the sort is a fixed-shard-count scatter. This completes 49c7604, which changed the scatter width from the thread count to `scatter_partitions` but left the merge-back condition consulting the thread count. A plain sort and a window-frame partitioned sort are unaffected, since both have `scatter_partitions` equal to zero. Found by the in-stress AST fuzzer on the `Stress test (arm_msan)` run of ClickHouse#117229. Co-Authored-By: Claude Opus 5 <[email protected]>
Closes: #117101
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a table that exceeds
max_table_size_rowsnever being able to come back under the limit: everymerge threw
TABLE_SIZE_LIMIT_EXCEEDED, so the table could not be compacted and its part count grewuntil inserts started failing.
Description
throwIfTableSizeLimitsExceededwas asymmetric. The byte limits have an explicit shrinking-replacement carve-out ("so that a table that has already crossed a limit can be brought back under
it by a size-reducing merge or mutation, and not only by dropping whole parts"), the row limit had
none: it computed
current.rows - covered.rowsand threw whenever that still exceeded the limit, soa merge that covers a handful of small parts in an untouched partition was rejected even though it
does not increase the row count.
Since the background scheduler works by merging subsets of parts, that made an over-limit table
uncompactable — part count grows until
parts_to_throw_insert, and onReplicatedMergeTreethealready-logged
MERGE_PARTSentry is retried forever, wedging the replication queue and hangingSYSTEM SYNC REPLICA.An operation that replaces the covered parts with a part holding no more rows than they had is now
allowed. A patch part carries a mutation of existing rows rather than new table rows, so it never
counts as growth. Inserts, which have no covered parts, are still rejected.
Test
05063_max_table_size_rows_shrinking_merge, which also asserts that an insert into theover-limit table still throws and that a deleting mutation brings the table back under the limit.
Workflow [PR]
Sync PR [sync-upstream/pr/117229]
Version info
26.10.1.115(included in26.10and later)26.9.1.1608