Skip to content

Perf CI: fetch the learned thresholds by the key prefix of query_metrics_v2 - #127387

Merged
egor-click merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/perf-thresholds-by-key-prefix
Oct 22, 2026
Merged

egor-click merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/perf-thresholds-by-key-prefix

Conversation

@groeneai

@groeneai groeneai commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #100759

Changelog category (leave one):

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

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Not required: CI-only change.

Description

Since 2026-10-20 the Select historical data step of Performance Comparison fails with Code: 158 ... Limit for rows (controlled by 'max_rows_to_read' setting) exceeded, max rows: 20.00 billion, current rows: 21.11 billion (first failing job; 22.13B on the next day). The job then writes an empty historical-thresholds.tsv, so every query is judged by the bare floors instead of its learned threshold: flagged queries per master commit went from 3.7/3.1 (amd/arm) to 15.1/12.3. It recovered at midnight and broke again on 2026-10-22 (20.89B).

query_metrics_v2 is ordered by (new_sha, test, query_index, metric), and none of the query's filter columns is a key prefix. Only each part's event_date range can skip data, and merges keep widening it, so the query reads the PR runs of the whole window to aggregate master rows only.

The query now also requires new_sha IN (SELECT new_sha FROM perf_test_times_v1 ...), with the same pr_number = 0 AND workflow_name = 'MasterCI' filter and a window one day wider on each side. The same job writes both tables, and perf_test_times_v1 is ordered by (pr_number, new_sha, ...), so the set costs 2.7M rows (checks is ordered by time only, so a set from it would cost a 5.5B-row estimate). The double-check-perf-tests copy of the query gets the same filter.

Validated on play through prepare_historical_data's own CIDB call: before, Code: 158; after, 6534 rows from 3.23B rows read in 4 s. The aggregated rows are the same (9,875,704 from 1338 SHAs; all 2639 master SHAs from Aug 1 to Oct 15 are in perf_test_times_v1), and on both halves of the current window the output is byte-identical to the original query's. The read is also about 6x smaller against play's hourly read_rows quota, which is shared per client address.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/127387]

Version info

  • Merged into: 26.11.1.551-master (included in 26.11 and later)

…rics_v2`

`GET_HISTORICAL_TRESHOLDS_QUERY` filters `query_metrics_v2` on `event_date`,
`metric`, `pr_number` and `workflow_name`, none of which is a prefix of the
table key `(new_sha, test, query_index, metric)`. Only partition pruning and
the per-part `event_date` min/max can skip data, and merges keep folding new
October parts into older ones, so the primary-key estimate for the six-week
window grew past the 20B `max_rows_to_read` of the `play` user: 21.11B on
2026-10-20, 22.13B on 2026-10-21, 20.89B on 2026-10-22. On `Code: 158`
the job writes an empty `historical-thresholds.tsv`, and every query is
judged by the bare floors.

Select the same master runs by the key prefix, `new_sha IN (SELECT new_sha
FROM perf_test_times_v1 ...)`. The job writes both tables in the same REPORT
stage with the same `pr_number`, `new_sha` and `workflow_name`, so the
subquery repeats the main query's own filter. Its window is one day wider on
each side, because the two uploads of one run can fall on either side of
midnight. `perf_test_times_v1` is ordered by `(pr_number, new_sha, ...)`, so
the set costs 2.7M rows; `checks` is ordered by `check_start_time` only (a
5.5B-row estimate for the range) and would select the runs by check name.

Measured on play on 2026-10-22: 3.23B rows read in about 4 s instead of a
20.89B estimate and `Code: 158`, with the same 9,875,704 aggregated rows from
1338 SHAs. Every one of the 2639 master SHAs with `query_metrics_v2` rows
from Aug 1 to Oct 15 is in `perf_test_times_v1`, and on both halves of the
current window (09-15..09-30 and 10-01..10-15) the output is byte-identical
to the original query's.

The `double-check-perf-tests` copy of the query gets the same filter. For a
run day before 2026-06-01 its window starts before the first
`perf_test_times_v1` row (2026-04-24), so it would see fewer SHAs there; CI
itself only uses `today()`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings). It read both changed queries, their caller prepare_historical_data, both upload paths and the compare.sh readers of historical-thresholds.tsv, and confirmed on play that the primary key prunes to master SHAs and that both halves of the current window give byte-identical output.

Session id: cron:clickhouse-review-slot-10:20261022-112300

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @egor-click, could you review this and add the can be tested label so CI runs? It selects the master runs by the new_sha key prefix of query_metrics_v2, so Select historical data reads 3.23B rows instead of failing on play's 20B max_rows_to_read (Code 158), which has left historical-thresholds.tsv empty since 2026-10-20.

@clickhouse-gh

clickhouse-gh Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a4c8c7b]

Summary: ✅


AI Review

Summary

The PR reduces historical-threshold reads by selecting master SHAs through perf_test_times_v1, with the same filter applied to the local performance reproduction tool. The change preserves the current threshold population while reducing reads below the CI query limit. No actionable findings.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 22, 2026
@egor-click egor-click added the can be tested Allows running workflows for external contributors label Oct 22, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). label Oct 22, 2026
@egor-click
egor-click added this pull request to the merge queue Oct 22, 2026
Merged via the queue into ClickHouse:master with commit e0ae5a4 Oct 22, 2026
352 of 353 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). 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.

3 participants