Skip to content

Remove the rewrite-off arms of the like_perfect_affix_rewrite performance test - #125531

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/like-perfect-affix-rewrite-perf-noise
Oct 13, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/like-perfect-affix-rewrite-perf-noise

Conversation

@groeneai

@groeneai groeneai commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #122420

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

Test-only change, no changelog entry required.

Description

like_perfect_affix_rewrite #0 (LIKE 'prefix%' with optimize_rewrite_like_perfect_affix=0) failed Performance Comparison (amd_release, master_head, 2/6) on #122420 as a confirmed regression: 0.1311 s to 0.1586 s (+20.9%), +17.2% after a restart. That PR does not touch this path. Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122420&sha=806534a049f136287d382c92f36be70e3d955114&name_0=PR&name_1=Performance%20Comparison%20%28amd_release%2C%20master_head%2C%202%2F6%29

Root cause. With the rewrite off, every row of the fixture matches, so MatchImpl calls the dispatched StringZilla sz_find once per row, 10M times per query. On amd, the cost of that call varies by 5-10% between binaries and between server processes: the red run's extra CPU samples are all in sz_find_skylake. Over 30 days on amd, the old/new ratio of #0 crossed 15%, in both directions, in 29 of 1,193 master-vs-master runs (for example 8a6b5608b0ad at 1.157) and in 26 of 1,316 PR runs (median ratio 1.001); #2 behaves the same. The rewrite-on arms #1/#3 never crossed it on amd (0 of 2,518 runs, p99 ratio 1.109 / 1.081), and on arm the whole test crossed it once in about 7,000 runs.

Change. I delete the two =0 arms. The harness compares the same query index across builds, never one arm against another, so the =1 arms were always the detector: if the rewrite stopped applying, they would get 1.6x to 1.7x slower. The LIKE path with the rewrite off stays measured in regexp_anchored_literal.xml (its two optimize_rewrite_like_perfect_affix = 0 arms: 0 runs above 12% in over 1,050 amd runs each). Correctness is covered by 03594_like_perfect_affix_rewrite_pass. Same shape as #122156.

Cost: the survivors renumber to #0/#1, so their learned thresholds reset to the 0.15 floor, still above their p99.

Validated with perf.py against an official master build: 2 queries, both run, no errors.


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

Version info

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

…ance test

With `optimize_rewrite_like_perfect_affix=0`, every row of the fixture
matches, so `MatchImpl` calls the dispatched StringZilla `sz_find` once per
row, 10M times per query. On amd the cost of that call varies by 5-10%
between binaries and between server processes (the red run's extra CPU
samples are all in `sz_find_skylake`), so over 30 days the old/new ratio of
`#0` crossed 15% in 29 of 1,193 master-vs-master runs and 26 of 1,316 PR
runs (median 1.001), and reddened `Performance Comparison (amd_release,
master_head, 2/6)` on unrelated ClickHouse#122420 (+20.9%, +17.2% after restart).
`ClickHouse#2` behaves the same. The rewrite-on arms never crossed 15% on amd
(0 of 2,518, p99 1.109 / 1.081).

The harness compares the same query index across builds, never one arm
against another, so the `=1` arms are the detector for the rewrite: if it
stopped applying they would get 1.6x to 1.7x slower. The rewrite-off LIKE
path stays measured by the two `optimize_rewrite_like_perfect_affix = 0`
arms of `regexp_anchored_literal.xml` (0 runs above 12% in over 1,050 amd
runs each), and correctness by `03594_like_perfect_affix_rewrite_pass`.
Same shape as ClickHouse#122156.

The survivors renumber to #0/ClickHouse#1, so their learned thresholds reset to the
0.15 floor, which is above their p99.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect labels Oct 12, 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; 0 findings) plus my own cold review (0 blocker, 0 major, 1 nit).

# Sev Finding Verdict Evidence / action
1 💡 The rewrite-on arms' p99 is quoted as 1.109 / 1.081 here and as 1.066 / 1.052 in an earlier measurement Resolved, no change The first is the amd-only p99 over 2,518 runs (30 days), the second the all-arch p99. Both are below the 0.15 floor.

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-8:20261012-215000

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? N/A for the noise itself (per-process variance, about 2% of runs cross 15%, same rate on master-vs-master). Deterministic harness check: perf.py --print-queries lists the two =0 arms on the original (4 queries) and not after the change (2 queries).
b Root cause explained? With the rewrite off, each query makes 10M calls of the dispatched sz_find, one per row; on amd its per-call cost varies 5-10% per binary and per server process, which pushes the old/new ratio past the dashboard bar on master and on unrelated PRs.
c Fix matches root cause? Yes: the noise is confined to the two =0 arms; the =1 arms are quiet on amd (0 of 2,518 runs above 15%). No threshold widened, no fixture reduced.
d Test intent preserved / new tests added? Yes: the =1 arms are the rewrite detector and stay unchanged; the rewrite-off path stays measured in regexp_anchored_literal.xml. Perf-test edit, no new test owed.
e Both directions demonstrated? At the harness level: perf.py --runs 5 on an official master build runs the original (4 queries) and the edited file (2 queries, same timings for the survivors), RC=0, no errors.
f Fix is general across code paths? Sibling amd string-search perf queries checked: the noisy ones are other classes (non-constant needles) at lower rates. None changed here.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (perf-test edit). Both prefix and suffix kinds are handled.
h Backward compatible? (maintainer-approved exception only) Yes: perf test only, no settings or formats.
i Invariants and contracts preserved? Yes: the file parses (xmllint, perf.py), create/fill/drop queries unchanged. The survivors renumber to #0/#1; their learned thresholds reset to the 0.15 floor, above their amd p99 (1.109 / 1.081).

Session id: cron:clickhouse-impl-slot-5:20261012-213700

@clickhouse-gh

clickhouse-gh Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1f31c81]

Summary: ✅


AI Review

Summary

This PR removes the two optimize_rewrite_like_perfect_affix = 0 queries from tests/performance/like_perfect_affix_rewrite.xml so an unstable fallback-path benchmark stops reddening unrelated PRs. I reviewed the PR diff, the current LIKE execution path in src/Functions/MatchImpl.h, the remaining anchored-literal fallback coverage in tests/performance/regexp_anchored_literal.xml, and the prior PR discussion; I did not find a correctness or coverage regression that warrants an inline review comment.

Missing context / blind spots
  • ⚠️ I could not rerun perf.py or .claude/tools/fetch_perf_report.py in this checkout because the environment lacks clickhouse_driver and a clickhouse binary, so the noise diagnosis was validated from the checked-in harness code and the linked report rather than from a fresh local repro.
Final Verdict

✅ No blocker or major findings in the current diff. No inline review comments to post.

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Oct 12, 2026
@alexey-milovidov alexey-milovidov self-assigned this Oct 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 13, 2026
Merged via the queue into ClickHouse:master with commit 2c7b7c2 Oct 13, 2026
177 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 13, 2026
@clickhouse-gh clickhouse-gh Bot added comp-query-analyzer Semantic analysis + logical/physical planning + rewrites (Analyzer and Planner modules). and removed comp-testing Test content only (no production code). labels Nov 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-query-analyzer Semantic analysis + logical/physical planning + rewrites (Analyzer and Planner modules). groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect 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