Repository navigation
Keep a key sample in the bucket Top-K conversion for the output-bytes estimate - #123807
Conversation
… estimate The bucket Top-K conversion (`query_plan_aggregation_bucket_top_k`) emits only the best rows of each two-level bucket. For the runtime dataflow statistics of automatic parallel replicas it already reports the untruncated key bytes, but it kept no key sample, so the statistics took the keys' compression ratio from the emitted chunk. Ten rows compress far worse than the bucket's keys (ratio ~1.5 instead of ~2.7 on `test.hits` `SearchPhrase`), so the estimate came out about twice as high as the same aggregation without Top-K. `03634_autopr_output_bytes_estimation` query_12 takes Top-K only when its tables go two-level, which depends on the read split, and its estimate then straddled the 2.5x tolerance (2.51x on master ed7e72d). Keep the meter's bounded sample (at most 1024 keys / 1 MiB of the bucket) and hand it to the statistics, as the HAVING pre-filter conversion already does. With the change the Top-K estimate equals the non-Top-K one within 1% on the same data. New test 05321 compares the estimate with and without the Top-K conversion on a deterministic two-level fixture. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Name what the bucket Top-K meter samples: the bucket's keys, not the kept rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings) plus my own review of the same head.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261004-021600 |
|
Workflow [PR], commit [f7b09ca] Summary: ✅
AI ReviewSummaryThe PR retains a sample of untruncated grouping keys during bucket Top-K conversion so automatic parallel replicas estimate key compression from representative data. The regression test compares estimates with Top-K enabled and disabled and checks that both execution paths ran. No unresolved findings at Missing context / blind spots
Final Verdict✅ Approve — no further changes requested by this review. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261004-020003 |
Build profile diff (arm_release)No arm_release build profile data for commit f7b09ca - the build was skipped, reused from cache, or predates profile upload. |
…tput-bytes Co-Authored-By: Claude Opus 5.5 <[email protected]>
The distributed-plan stateless jobs load tests/config/users.d/distributed_plan.xml, which sets serialize_query_plan = 1. Since master 9ba7a19 / 76c606e, tryPushBucketTopKIntoAggregation does not enable the bucket Top-K selection for a serialized or distributed plan, so in that suite both measured queries took the ordinary conversion and the liveness line read `bucket_top_k_on 0 1`. Pin the setting as 04911 and 05183 do. Measured with the distributed-plan profile: the unpinned test fails 3/3 on the liveness line; the pinned test passes 3/3 + 20/20 randomized with the fix, and fails 3/3 + 10/10 randomized at the estimate line without it (ratio 1.85). Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - f7b09caEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261027-030010 |
c8c7411
Related: #104510
Related: #123781
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The output-bytes estimate of automatic parallel replicas no longer depends on whether the final aggregation keeps only each bucket's top rows (
query_plan_aggregation_bucket_top_k).Description
03634_autopr_output_bytes_estimationfailed on master withquery_12at 2.51x of its golden (tolerance 2.5x):https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=ed7e72d6797b8e678518f5a2a26faff7f2bd695e&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29
The bucket Top-K conversion emits only the best rows of each two-level bucket. For the dataflow statistics it already
reports the untruncated key bytes, but it kept no key sample, so the statistics took the keys' compression ratio from
the 10-row chunk. Ten keys compress much worse than the whole bucket (ratio ~1.5 instead of ~2.7 on
test.hitsSearchPhrase), so the estimate came out ~1.8x higher than the same aggregation without Top-K.query_12takes Top-Konly when its tables go two-level, which depends on the read split, so CI landed on both sides of the tolerance.
The conversion now keeps the meter's bounded sample (at most 1024 keys / 1 MiB per bucket) and passes it to the
statistics, as the HAVING pre-filter conversion already does. The open #123531 rewrites this function and adds a
second Top-K conversion that also passes
keep_sample = false.Validation, debug build, server with 32 streams like the CI job,
query_12estimate:05321compares the estimate with and without Top-K: fails 5/5 before (2.37x), passes 50/50 randomizedafter. Removing either of its two pins makes it fail in a configuration CI can produce.
03634is unchanged and passes 45/45 in three modes, includingenable_adaptive_aggregator = 0(the pin of Disable the adaptive aggregator in03634_autopr_output_bytes_estimation#123781),which does not avoid Top-K at 32 streams (2.27-2.42x before).
query_34now estimates 0.66x of a golden recordedbefore bucket Top-K existed, inside the tolerance, so I did not re-measure it.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123807]
Version info
26.11.1.1478-master(included in26.11and later)