Repository navigation
Cap distributed-plan bucket counts in the reader/join optimization pass - #109770
Conversation
The distributed-plan bucket-count cap (validateBucketCount, max 256) was applied only in makeDistributedPlan. The tryMakeDistributedRead/Join/Aggregation/Sorting pass in optimizeTreeSecondPass runs earlier and used the raw setting value, so a huge distributed_plan_default_reader_bucket_count sized a std::vector<RangesInDataPartsDescription> to that value in sliceMarksAcrossBuckets and threw std::length_error (LOGICAL_ERROR abort in debug/sanitizer builds) before the max-buckets check. Hoist the validation to the single up-front distributed-plan gate so both entry points and both bucket-count settings are covered. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-0:20260708-130900 |
|
cc @davenger @KochetovNicolai — could you review this? It fixes a |
|
Workflow [PR], commit [6fc6679] Summary: ✅
AI ReviewSummaryThis PR hoists distributed-plan bucket-count validation into Final VerdictStatus: ✅ Approve |
| -- no-fasttest: make_distributed_plan is an experimental feature | ||
|
|
||
| -- An out-of-range distributed-plan bucket count must be rejected with INVALID_SETTING_VALUE, not size a | ||
| -- vector to the raw value and abort (std::length_error) while building the plan. The reader path | ||
| -- (tryMakeDistributedRead) is validated in optimizeTreeSecondPass, the shuffle-join path in makeDistributedPlan. | ||
|
|
||
| DROP TABLE IF EXISTS t_bucket_cap; | ||
| CREATE TABLE t_bucket_cap (x UInt64) ENGINE = MergeTree ORDER BY tuple(); | ||
| INSERT INTO t_bucket_cap SELECT number FROM numbers(200000); |
There was a problem hiding this comment.
@groeneai this test is too heavy for a a simple fix. Do not add a table with many rows just to test this setting. Is there an existing test that checks for max bucket count but misses these cases? It it already exists, add more cases there
| /// Validate both bucket-count settings up front, before any distributed optimization reads them to size | ||
| /// exchange fan-outs or read-bucket vectors. Reachable from optimizeTreeSecondPass's tryMakeDistributed* | ||
| /// pass (which uses the raw values directly) as well as makeDistributedPlan. |
There was a problem hiding this comment.
@groeneai This comment explains trivial things, but bloats the code. Remove it
… and trivial comment Per review on ClickHouse#109770: move the bucket-count cap coverage into the existing 04320_distributed_plan_read_rejects test (which already pins max_rows_to_group_by=0 and carries no-old-analyzer) instead of a new heavy table-backed test, and add the near-type-maximum cases that exercise the tryMakeDistributedRead pass validation. Remove the trivial explanatory comment in makeDistributed.cpp. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-5:20260708-141700 |
CI finish ledger — 6fc6679Every failure below has an owner: a fixing PR (ours), plus the exempt private sync. Both AST fuzzer findings are chronic trunk fuzzer STIDs (not caused by this distributed-plan bucket-cap fix), each already owned by an open fixing PR of ours.
Session id: cron:our-pr-ci-monitor:20260708-183000 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 13/13 (100.00%) · Uncovered code |
73d7466
… and trivial comment Per review on ClickHouse#109770: move the bucket-count cap coverage into the existing 04320_distributed_plan_read_rejects test (which already pins max_rows_to_group_by=0 and carries no-old-analyzer) instead of a new heavy table-backed test, and add the near-type-maximum cases that exercise the tryMakeDistributedRead pass validation. Remove the trivial explanatory comment in makeDistributed.cpp. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…dplan-length-error Cap distributed-plan bucket counts in the reader/join optimization pass
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
LOGICAL_ERROR(std::length_error) when a query with the experimental settingmake_distributed_plan = 1used a very largedistributed_plan_default_reader_bucket_countordistributed_plan_default_shuffle_join_bucket_count. Such values are now rejected withINVALID_SETTING_VALUE.Description
The distributed-plan bucket-count cap (
validateBucketCount, max 256) was applied only insidemakeDistributedPlan. But thetryMakeDistributedRead/tryMakeDistributedJoin/tryMakeDistributedAggregation/tryMakeDistributedSortingpass inoptimizeTreeSecondPassruns earlier and reads the raw setting value directly.For the reader path,
tryMakeDistributedReadpassesdistributed_plan_default_reader_bucket_countintoReadFromMergeTree::setupDistributedReadBuckets, which callssliceMarksAcrossBuckets(parts, bucket_count)->std::vector<RangesInDataPartsDescription> result(bucket_count). A huge bucket count throwsstd::length_error(release builds throw, debug/sanitizer builds abort) before themax_total_buckets = 256check is ever reached.Fix: hoist the validation into
validateDistributedPlanBucketCountsand call it from the single up-front distributed-plan gate inoptimizeTreeSecondPass, so both entry points (thetryMakeDistributed*pass andmakeDistributedPlan) and both bucket-count settings are covered.Found by the AST fuzzer (
AST fuzzer (amd_debug, targeted)) on several PR runs, e.g. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106135&sha=61d98ee87c9d67bf7481342dce69879d5d77141b&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29 withLogical error: 'std::exception. Code: 1001, type: std::length_error, e.what() = vector'insliceMarksAcrossBuckets/ReadFromMergeTree::setupDistributedReadBuckets/tryMakeDistributedRead.Related: earlier cap for the
makeDistributedPlanentry point in commit 340e648 ("Cap distributed plan bucket counts to limit memory consumption").Version info
26.7.1.691(included in26.7and later)