Skip to content

Re-measure the query_28 expected value in 03634_autopr_output_bytes_estimation - #111981

Merged
alexey-milovidov merged 7 commits into
masterfrom
fix-03634-autopr-query28-calibration
Jul 31, 2026
Merged

alexey-milovidov merged 7 commits into
masterfrom
fix-03634-autopr-query28-calibration

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 26, 2026 •

Copy link
Copy Markdown
Member

03634_autopr_output_bytes_estimation compares the RuntimeDataflowStatisticsOutputBytes profile event against a recorded value per query and reports every query whose estimate differs from the recorded one by more than 2.5x. For query_28 the recorded value is stale: the estimate is a stable ~58 MB while the array said 23722663, a ratio of ~2.45. That left the check no margin at all below the 2.5 bound, so the test failed as soon as a run landed slightly above the average. The reported failure is query_28 59335657 23722663, a ratio of 2.5012.

The estimate is not noisy. In the failing job the query ran nine times - the failure plus the eight reruns of the randomized-settings diagnosis, spanning two independent randomizations - and produced 57843408..59335657 bytes, a spread of 1.3%. Reading the estimates back out of the server log for every query in the failing run shows the other ten match their recorded values within 1.00..1.41x, so this single entry is the only one that is off:

query estimate recorded ratio
query_1 3 3 1.00
query_10 150754 195461 1.30
query_12 5968124 5962954 1.00
query_15 1101822 1100491 1.00
query_20 2 2 1.00
query_21 16885 16885 1.00
query_22 41741 42323 1.01
query_23 10508 9434 1.11
query_28 59335657 23722663 2.50
query_34 204175795 203701090 1.00
query_43 58536078 82404720 1.41

Where the stale value came from - measured, not conjectured

The review rightly insisted that re-recording a golden without knowing why it moved risks hiding a regression. It has now been measured, by running query_28 with this test's exact pinned settings against the hits_v1 dataset using pre-built CI binaries of historical commits:

binary date query_28 estimate
master a3312f32194 2026-04-01 57.3 MB
master c720f10f0da 2026-06-10 57.8 MB
master e1648b6cff3 (just before the merge of #110573) 2026-07-26 57.0 MB
#93271 final head cd73b80e0c9 (before the HashMethodPackedString simplification) 2026-07-10 58.4 MB
current master (with #110573) 2026-07-31 58.2 MB
failing CI job, nine runs 2026-07-26 57.8..59.3 MB

So master has produced ~57..58 MB for this query continuously since at least 2026-04-01, and #110573 itself does not change the estimate. Nothing regressed in the aggregation or statistics path - there is no later change to find, because the estimate never moved in the first place.

What actually happened: the 23722663 golden was calibrated on 2025-12-31 (commit Fix tests on the branch of #93271, the original of #110573) and was carried unchanged for seven months. Meanwhile master had recalibrated this test on its own - since at least 2026-02-15 master's array said 31064320 for query_28, which kept the check green against the actual ~58 MB (ratio 1.85). When #110573 merged on 2026-07-26 it replaced the whole array with the December values, overwriting master's fresher calibration, and the test went red within an hour on the first master run. The other ten December entries happen to still be within the 2.5x tolerance; query_28 sits at 2.45..2.50x.

A side finding: with group_by_two_level_threshold=1 the current estimate is 58170420 vs 58237072 at the pinned defaults - the two-level threshold no longer affects this value at all, so the pin added in 8746386893 (based on the December expectation) guards nothing for query_28 today, though it remains harmless and still reduces randomization noise.

Why ~58 MB, and the relation to #111985

The ~2.45x gap between the estimate and the recorded value is the estimator defect described below: Aggregator::estimateSizeOfCompressedState serializes the sampled states into the NullWriteBuffer instead of into the CompressedWriteBuffer wrapped around it, so it reports the uncompressed serialized size of the states rather than their size on the wire, and for query_28 - the only query here whose output is dominated by variable-size aggregate states (MIN(Referer) over a two-level hash table with many groups) - that overshoots the transferred bytes by ~2.45x.

This pull request is therefore the fallback, not the preferred fix. #111985 fixes the estimator itself, and with that fix this test passes with the golden left at 23722663. The two changes are mutually exclusive: if #111985 lands, this one should be closed; only if it does not should the golden be re-based as done here.

This change records the median of the nine observations, 58136394, which puts every observed run within 1.02x and restores the intended margin.

Details of the defect: Aggregator::estimateSizeOfCompressedState builds a CompressedWriteBuffer wbuf(wb) but serializes the sampled states into the underlying NullWriteBuffer wb instead of into wbuf, then reads wb.count(). wbuf is never written to, so the function returns the uncompressed serialized size despite its name and its We only interested in the size of compressed state comment. That has been the behaviour since the function was introduced, so every recorded value in this test already accounts for it, and correcting it would need all of them re-measured. It is left alone here and fixed in #111985 instead.

Related: #111985
Related: #110573

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=5baed0f5a10c333cd220b9646d6ef4647425079d&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Version info

  • Merged into: 26.8.1.553 (included in 26.8 and later)

…s_estimation`

The test compares the `RuntimeDataflowStatisticsOutputBytes` profile event
against a recorded value per query and fails when the two differ by more than
2.5x. For `query_28` the recorded value had gone stale: the estimate is a stable
~58 MB while the array still said `23722663`, a ratio of ~2.45. That left the
check no margin at all, so the test failed as soon as a run landed slightly
above the average - the reported failure is `query_28 59335657 23722663`, a
ratio of 2.5012.

The estimate is not noisy. In the failing job the query ran nine times (the
failure plus the eight reruns of the randomized-settings diagnosis, across two
independent randomizations) and produced 57843408..59335657 bytes, a spread of
1.3%. The other ten queries in the test match their recorded values within
1.00..1.41x, so only this one entry is off. `query_28` is the only query whose
output is dominated by variable-size aggregate states - `MIN(Referer)` over a
two-level hash table with many groups - which is why it drifted on its own.

Use the median of the nine observations, `58136394`, which puts every observed
run within 1.02x of the recorded value.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=5baed0f5a10c333cd220b9646d6ef4647425079d&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8f992a4]

Summary: ✅


AI Review

Summary

This PR re-records the query_28 expected RuntimeDataflowStatisticsOutputBytes value in 03634_autopr_output_bytes_estimation to match the stable ~58 MB that current master has been producing under the test's pinned settings. I re-checked the current diff against the full discussion history, the updated rationale closes the earlier concern that this was re-baselining the old early-two-level-conversion artifact, and the current PR CI run is fully green; I did not find a remaining correctness or evidence issue in the current change.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 26, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Follow-up: I found the reason query_28 alone drifted, and it is a real defect rather than a stale measurement.

Aggregator::estimateSizeOfCompressedState builds a CompressedWriteBuffer over a NullWriteBuffer but serializes the sampled states into the NullWriteBuffer directly, so nothing is ever compressed and the function returns the serialized size instead of the compressed one. query_28 is the only query in this test whose output is dominated by compressible aggregate states (MIN(Referer) over a two-level hash table with many groups), which is why it was the only entry that looked wrong - the others are dominated by aggregation keys or output columns, which were already measured compressed.

Fixed in #111985. The estimate there is expected to drop back to roughly the 23722663 this array already records.

These two PRs touch the same line and are mutually exclusive. This one is the interim unblock for the master CI failure; if #111985 lands first, close this one as unnecessary, and if this one lands first, #111985 has to set query_28 back to the post-fix measurement.

alexey-milovidov and others added 2 commits July 27, 2026 16:15
… early-conversion one

The review objected that `58136394` is the value that the
`group_by_two_level_threshold*` pins in this test were added to exclude, so
making it the golden would stop the test from catching a regression back onto
the early-two-level-conversion path.

The server log of the failing job refutes that for current master. All nine
`query_28` runs in that job execute the same pinned `SET`s, and the first of
them - with a cold hash-table size-hint cache - started with the single-level
`key_string` method, logged `Converting aggregation data to two-level` when it
crossed the pinned default `group_by_two_level_threshold` of 100000, and still
reported `RuntimeDataflowStatisticsOutputBytes` of 58092765:

| run | first `Aggregation method` | output bytes |
| --- | --- | --- |
| 07:23:46 | `key_string` (then converted) | 58092765 |
| 07:52:40 | `key_string_two_level` | 59335657 |
| 08:37:33 | `key_string_two_level` | 57843408 |
| 08:37:43 | `key_string_two_level` | 58136394 |
| 08:37:52 | `key_string_two_level` | 58222877 |
| 08:38:01 | `key_string_two_level` | 58671197 |
| 08:38:10 | `key_string_two_level` | 58398433 |
| 08:38:19 | `key_string_two_level` | 58074861 |
| 08:38:28 | `key_string_two_level` | 57992381 |

The later runs are initialized as two-level straight away because
`initDataVariantsWithSizeHint` finds a cached size hint above the threshold, not
because of the thresholds themselves - so the pin is still doing its job, and
the pinned-default path itself now lands at ~58 MB. Record that reasoning next
to the array.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Correction to my earlier follow-up above: the estimateSizeOfCompressedState defect (serializing into the NullWriteBuffer instead of the CompressedWriteBuffer) does not explain why query_28 drifted. It has behaved that way since the function was introduced, so it was equally in effect when 23722663 was calibrated in June and when ~58 MB was measured now. #111985 is therefore an independent fix, not the root cause of this failure; it will move this entry again, and the post-fix value has to be measured rather than assumed to equal the old 23722663.

What I did verify (details in #111981 (comment)): the ~58 MB is the value the pinned-default path produces - the first of the nine runs started single-level and converted only at the pinned default threshold, and still reported 58092765 - so the rebaseline is not adopting the early-conversion artifact that the pins exclude. The two PRs still touch the same line and remain mutually exclusive.

alexey-milovidov and others added 3 commits July 30, 2026 05:56
The previous justification cited a `query_28` run that came from the sibling
`03634_autopr_input_bytes_estimation.sql` (identifiable by its unpinned
`group_by_two_level_threshold=883857` / `max_block_size=94183`), so it said
nothing about the pinned-default path of this test. The reviewer is right about
that.

What the ~58 MB actually is: `Aggregator::estimateSizeOfCompressedState`
serializes the sampled states into the `NullWriteBuffer` instead of into the
`CompressedWriteBuffer` wrapped around it, so the reported figure is the
uncompressed serialized size of the states, not their size on the wire. That
is the reason the estimate overshoots the transferred bytes by ~2.45x here.
Recorded in the test comment, including the note that the value has to be
re-measured (back to about `23722663`) once the estimator is fixed.
…mment

Measured with pre-built CI binaries against the `hits_v1` dataset under the
test's pinned settings: master produced ~57..58 MB for `query_28` continuously
since at least 2026-04-01 (2026-04-01: 57.3 MB, 2026-06-10: 57.8 MB,
2026-07-26 just before the merge of #110573: 57.0 MB, current master: 58.2 MB),
so nothing regressed in the aggregation or statistics path around the failure.
The recorded 23722663 was calibrated on 2025-12-31 on the branch of #93271 and
carried unchanged into #110573, whose merge also overwrote the value master had
been green with since February, 31064320 (ratio ~1.85 against the actual ~58 MB,
which is why master stayed green until the merge). The final head of #93271
(before the `HashMethodPackedString` simplification) measures 58.4 MB as well,
so the pull request itself does not change the estimate. With
`group_by_two_level_threshold=1` the current estimate is 58170420 vs 58237072
at the pinned defaults, i.e. the threshold no longer affects this value.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=5baed0f5a10c333cd220b9646d6ef4647425079d&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 31, 2026
@alexey-milovidov alexey-milovidov self-assigned this Jul 31, 2026
Merged via the queue into master with commit 3f6399b Jul 31, 2026
178 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-03634-autopr-query28-calibration branch July 31, 2026 20:33
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 31, 2026
alexey-milovidov added a commit that referenced this pull request Aug 1, 2026
…e compressed estimate

#111981 re-measured `query_28` to 58136394, the uncompressed serialized size the estimator
reported while it serialized the sampled states into the `NullWriteBuffer`; that change and
this fix touch the same value and were explicitly mutually exclusive. With the estimator
measuring the compressed size, the estimate returns to the compressed figure the test had
been calibrated against before: both CI runs of this pull request
(4cef641 and 6d554ce, before #111981 merged) passed this test with 23722663.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111985&sha=6d554cecfe7ebd6ab6819102f316beb2ebf0436e&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29

Co-Authored-By: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants