Skip to content

Perf CI: key the learned per-query thresholds by the query text - #121278

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:perf-ci-threshold-key-by-query-text
Sep 21, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:perf-ci-threshold-key-by-query-text

Conversation

@groeneai

@groeneai groeneai commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

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):

Key the learned per-query thresholds of Performance Comparison by the query text, so a query whose text changed is no longer judged by the bare 0.15 floor.

Description

A query whose learned per-query bar goes missing is judged by the bare 0.15 floor, so a noisy
micro benchmark is reported slower on unrelated pull requests and on master, at different
indices each run.

The CIDB query that learns the bars groups by (test, query_index) and returns
any(query_display_name); both compare.sh consumers join its output on all three columns.
query_index is positional, so after a test's query text changes the one-month window holds two
names for one index, any() returns one, and the other text's join misses; with no
join_use_nulls that miss yields 0 and the bar collapses to the floor unnoticed.
36a37341953ff narrowed the grain without touching the consumers.

The fix restores query_display_name to the GROUP BY, so each text keeps the bar learned from
its own timings. Column order, the floors, the multiplier and the count() > 100 cut-off are
untouched. double_check_perf.py carries a deliberate copy and gets the same fix.

Measured today: none of the 5596 groups with a bar loses it (rows emitted 5596 to 5644); 50
groups in 12 tests carry two names; rows read identical at 15.02e9; over 8 interleaved passes the
median paired time is -0.67 s, peak memory 1514 to 1289 MiB, and 3 of 8 exceed the 10 s fetch
timeout in both arms. In the report below, all 4 indices published at 0.15 are ambiguous and all
5 with a learned bar are single-name.

Unchanged: a new query text gets the floor until it has over 100 rows in the window. Narrowed, 2 of
5596 groups: grace_hash_join #3 and #7, where a 14-row variant against 1977 now gets the floor
instead of a bar pooled over two texts.

Does not overlap #121189 (restores the fetch) or #121090 (narrows the dashboard gate).

Related: #116234
Shape this fixes: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=c67f0b1829486bfa55e30e0ff050cfdcbb493e73&name_0=MasterCI&name_1=Performance%20Comparison%20%28arm_release%2C%20master_head%2C%201%2F6%29


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

Version info

  • Merged into: 26.10.1.382-master (included in 26.10 and later)

The CIDB query that learns the per-query performance thresholds aggregated
GROUP BY test, query_index and returned any(query_display_name), while both
consumers of the resulting historical-thresholds.tsv join it on all three
columns: report_thresholds (compare.sh:1238-1243), which publishes
changed_threshold/unstable_threshold, and flagged_queries in confirm_changes
(compare.sh:921-926), which decides which queries enter the confirmation rerun.

query_display_name is the query text while query_index is positional, so
editing a test's substitution values changes the text at an unchanged index.
The historical window then holds two display names for one
(test, query_index), any() returns one of them per run, and the other text's
join misses. join_use_nulls is not in CHPC_REPORT_LOCAL_QUERY_SETTINGS
(compare.sh:46), so the miss yields 0 and ceil(greatest(0.15, 0, 0), 2)
silently collapses to the 0.15 floor. A noisy micro benchmark judged by that
floor is then reported slower on unrelated pull requests and on master, at a
different set of query indices each run.

This restores the producer's grain to the three columns the consumers already
join on. 36a3734 narrowed it from

    group by test, query_index, query_display_name

to

    GROUP BY test, query_index

in the same edit that shrank the window from three months to one; the
consumers were not touched, and the original grain still survives in the
commented-out calibration query 20 lines below.

double_check_perf.py carries a deliberate copy of the same query (its comment
says so, and its consumer already keys a dict on all three fields), so it gets
the same two-line fix.

Measured on play.clickhouse.com, 2026-09-21, window
today() - 1M - 1W .. today() - 1W:

  * 5596 (test, query_index) groups hold a bar and none loses it; rows emitted
    5596 to 5644, rows read identical at 15.02e9.
  * 50 groups across 12 tests currently carry two display names, 18 of them in
    timeseries_to_grid_aggregation_functions, whose window substitution changed
    in 46d27f5.
  * Over 8 interleaved pairs the median paired server time is -0.67 s (faster
    in 5 of 8) and median peak memory drops 1514 to 1289 MiB, so exposure to
    the 10 s fetch timeout is unchanged at 3 of 8 in both arms.
  * On master c67f0b1, whose fetch succeeded, all four carrier-test indices
    published at the bare floor are ambiguous and all five that kept a learned
    bar are single-name, 9 of 9.

Two pre-existing behaviours are unchanged: a brand-new query text gets the
floor until it has more than 100 rows in the window, and grace_hash_join ClickHouse#3
and ClickHouse#7 have a 14-row variant against 1977 that now gets the floor rather than
a bar pooled over two different query texts.

Related: ClickHouse#116234

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 21, 2026
@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; 1 gate finding plus 3 from my own
cold read; 1 full pass, no fix round needed).

# Sev Finding Verdict Evidence / action
1 ❌ Thresholds still are not keyed by the complete query text: perf.py trims the display name to 1000 characters, so two revisions of one index that share that prefix stay in one historical group (tests/performance/scripts/perf.py:897-904) DISAGREE The trim is real, the consequence is not this one. A collision means both revisions carry the same name, so the three-key join hits and the bar is pooled, never the 0.15 floor this PR is about, and with the third key constant inside the group the two-key and three-key aggregations are identical by construction, so nothing regresses. Not observed either: in c67f0b18's own all-query-metrics.tsv only 5 of 602 indices carry a trimmed name, in 4 test files, and none of those files has had a <query> line edited inside the window (clickbench's single commit 88a1d8a27d62d changes the <test> attribute only; tpcds.xml's last query edit is 581b3a3dbbe10, 2026-05-19). Flooring is uncorrelated with trimming: 454 of the 597 untrimmed indices are floored too. Finally the proposed remedy is unsafe here, because query_display_name is the persisted CIDB column: digesting it would match nothing against the rows already stored in the five-week window and would floor every query in every test for five weeks
2 ⚠️ The PR should ship a committed regression test, since a stateless test can host python assertions against live code DISAGREE That precedent (05099_clickhouse_test_keeper_retry_matching.sh) targets tests/clickhouse-test, the test runner inside tests/, and calls a pure function. No stateless test on master reads anything under ci/ as code, ci/tests/ has had no runner since 5e8bf203b1409 and 4c737a6b4637a removed the suite and its job, and a string assertion on this constant is the "pins the internals of CI scripts rather than their observable behavior" shape those removals cite. The behavioural form would have to lift compare.sh's join at runtime from the server test suite. The oracle therefore stays out of tree and the five-week production A/B is in the description
3 💡 "Kept, not introduced" mislabels the grace_hash_join residual, which the same sentence describes as a change AGREE Corrected in the description before publication: it now reads "Narrowed, 2 of 5596 groups". No code change
4 💡 The description called the window "five-week"; the SQL defines a one-month span ending a week ago AGREE Corrected in the description before publication. No code change

Noted, not blocking: the 1000-character trim does leave the identity column a partial
discriminator for very long queries. It is a property of the pre-existing column rather than of
this change, it is not occurring in the current suite, and redefining that column is a separate
decision for the perf CI owners, so I am not raising it.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-48:20260921-053700

@clickhouse-gh clickhouse-gh Bot closed this Sep 21, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 21, 2026
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Sep 21, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. A clickhouse local round trip over a fixture with two display names at one (test, query_index), driving the real producer constant (exposed as a view named query_metrics_v2, so the shipped SQL text runs unmodified) and the verbatim report_thresholds and flagged_queries statements from compare.sh. Fully deterministic.
b Root cause explained? Yes. The producer aggregates GROUP BY test, query_index and returns any(query_display_name); both consumers join on all three columns. query_index is positional, so after a query's text changes the window holds two names for one index, any() returns one, and the other text's join misses. join_use_nulls is unset, so the miss yields 0 and ceil(greatest(0.15, 0, 0), 2) gives the 0.15 floor.
c Fix matches root cause? Yes. The producer's grain is restored to the three columns the consumers already join on. No floor, multiplier, cut-off, column order or consumer is touched, and no symptom is guarded.
d Test intent preserved / new tests added? Test intent is strengthened: the affected bars get stricter, not looser. No committed test file: nothing in the tree runs ci/tests/ (no ci_tests job, no runner, no workflow reference), and the observable is a threshold learned from five weeks of production data. The regression evidence is the production A/B in the description.
e Both directions demonstrated? Yes. Before: the index gets one historical row, so one text is judged by (0.15, 0.25) and the other inherits a bar pooled over both texts, (1.13, 1.24) instead of its own (0.39, 0.43). After: each text gets its own bar. On the second consumer the same measured diff of 0.40 is flagged for the confirmation rerun before the fix and correctly not flagged after it, while still being flagged when the current text is the quieter one.
f Fix is general across code paths? Yes. All four in-tree readers of this grain were enumerated: the two compare.sh joins and the second-order queries and all_query_metrics_tsv joins already use three keys and simply gain matching rows. The one sibling producer with the same defect, a deliberate copy in double_check_perf.py, is fixed in the same commit.
g Fix generalizes across inputs? Yes, over the input space this SQL has. Exercised: unambiguous index (byte-identical output), ambiguous index with either text current, a variant below the count() > 100 cut-off, and a multi-line display name, which is the shape most real ones have and the one that must survive the TSV escaping round trip.
h Backward compatible? Yes. No setting, no SettingsChangesHistory.cpp, no format change, no user-visible behaviour. The output file keeps its five columns in the same order, with the display name last, which both file(...) schema declarations require.
i Invariants and contracts preserved? Yes. The invariant is that the learned-threshold rows are keyed by (test, query_index, query_display_name) end to end, and that a join miss silently means the floor. This restores the producer side of it. Output column order and count are asserted unchanged, and the row count per group only ever grows, so no consumer can lose a row it had.

Session id: cron:clickhouse-impl-slot-5:20260921-043200

@clickhouse-gh

clickhouse-gh Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a31e508]

Summary: ✅


AI Review

Summary

This PR restores query_display_name to the grouping key of the historical-threshold query in both the production perf job and the double_check_perf.py reproduction tool. That matches the existing three-column joins in compare.sh, so renamed queries stop silently falling back to the bare 0.15 threshold while the exported schema stays unchanged. I did not find any unresolved correctness, compatibility, or metadata issues in the current patch.

Final Verdict
  • Status: ✅ Approve

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). groeneai-origin-request PR origin: a maintainer pinged or directed groeneai manual approve Manual approve required to run CI 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