Skip to content

Run the insert_values_with_expressions performance query above 1 s on the first 10000 rows - #131933

Merged
Algunenano merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/perf-insert-values-with-expressions-first-rows
Nov 16, 2026
Merged

Algunenano merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/perf-insert-values-with-expressions-first-rows

Conversation

@groeneai

@groeneai groeneai commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #129258

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

...

Description

Query 0 of insert_values_with_expressions.xml takes 3.47 s on MasterCI amd and 3.89 s on arm. Every row of its 100000-row file calls replaceRegexpAll with its pattern as a literal; the Values template turns that literal into a column, and a non-constant pattern is compiled once per row: 92% of the query. A cache of the compiled patterns was proposed in #122850 and closed as optimizing a corner case.

No existing query number or text changes: 1 query is disabled and 1 copy appended as query 2. The copy is the same query with limit 10000: the reader parses the first 10000 rows as one block and stops. The original with max_block_size = 10000 costs the same (0.996-1.004), so the smaller block is not a regime change. Locally the copy's per-row time is 0.94-0.97 of the original's, and it spends 90-91% of its time in replaceRegexpAll vs 92% for the original. Both hold in two repetitions on different NUMA nodes, also with the L3 capped to 30 MiB; CI's VMs share 105 MB on amd and 36 MB on arm.

The one build pair that moved this query on CI, #109239's static build (x1.05 on amd), moves it by only 0.7-1.4% here and the copy by 0.9-1.3%.

The copy should take about 0.33 s on amd and 0.37 s on arm: about 31 s less query time per master perf job on amd and 35 s on arm. The copy restarts the history of query 0.

Validation: perf.py on the final file runs only queries 1 and 2, also with CI's --max-queries 10, with no run trend.

🤖 Generated with Claude Code


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

Version info

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

… the first 10000 rows

No existing query number or text changes: 1 query is disabled and 1 copy
appended as query 2.

Query 0 reads the 100000-row CI file test_all_expr_matches.values and takes
3.47 s on MasterCI amd and 3.89 s on arm. Every row calls replaceRegexpAll
with its pattern as a literal; the Values template turns that literal into a
column, so the non-constant pattern is compiled once per row (92% of the
query).

The copy is the same query with `limit 10000`. With no WHERE, ORDER BY or
GROUP BY the planner's trivial-LIMIT path reads one block of 10000 rows and
the file source stops there (SelectedRows 10000, FunctionExecute 24).

Local perf.py A/B on the official master build fdc4389, two repetitions
on different NUMA nodes, also with the L3 capped to one 30 MiB way:
- per-row client time of the copy 0.94-0.97 of the original's, user time
  0.93-0.96;
- replaceRegexpAll's share 0.92 of the original vs 0.90-0.91 of the copy;
- the whole file in 10000-row blocks costs 0.996-1.004 of default blocks;
- ClickHouse#109239's static build, the one pair that moved query 0 on CI (x1.05 amd),
  moves it by 0.7-1.4% here and the copy by 0.9-1.3%.

Projected CI medians of the copy: 0.33 s amd, 0.37 s arm; about 31 s less
query time per master perf job on amd and 35 s on arm. The copy restarts
the history of query 0.

Related: ClickHouse#129258

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), plus my own review (0 blocking findings).

# Sev Finding Verdict Evidence / action
1 💡 Query 0 ends its history; the copy (query 2) starts a new one noted The disabled + append shape of the #129258 series; stated in the description.

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

Session id: cron:clickhouse-review-slot-8:20261116-081900

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? The cost is deterministic: query 0 takes 3.23-3.27 s on the official master build in every local perf.py pass (CI median 3.47 s amd), the copy 0.31 s.
b Root cause explained? The Values template turns the replaceRegexpAll pattern literal of every row into a column, so the pattern is compiled once per row: 92% of query 0 (the same file with replaceAll instead takes 8% of the time).
c Fix matches root cause? Test-only: the engine cache was closed in #122850, so the copy keeps measuring the same per-row path on a tenth of the rows. Query 0 is disabled, not changed.
d Test intent preserved / new tests added? Same path: one template evaluation per block (FunctionExecute 24), the same Nullable work per row (2.851 vs 2.848), 90-91% vs 92% of the time in replaceRegexpAll, per-row time 0.94-0.97 of the original. Query 1 untouched.
e Both directions demonstrated? Master's file runs queries 0-1; the final file runs 1-2 and never 0 (also with --max-queries 10). The copy keeps the original's per-row cost and share in two repetitions on different NUMA nodes and with L3 capped to 30 MiB.
f Fix is general across code paths? One query above 1 s in the file; the shrink comes from the planner's general trivial-LIMIT path; a whole-file run in 10000-row blocks costs 0.996-1.004 of the default blocks.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (performance test change); the copy reads the same CI file, schema and file-level setting.
h Backward compatible? (maintainer-approved exception only) No setting, format, dataset, perf.py or CI change; query 2 is a fresh history key, query 0 ends its series.
i Invariants and contracts preserved? Existing query texts and order unchanged, the copy appended after the last query, settings block unchanged; 2 enabled queries, below CI's --max-queries 10.

Session id: cron:clickhouse-impl-slot-4:20261116-070700

@clickhouse-gh

clickhouse-gh Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b575fb3]

Summary: ✅


AI Review

Summary

This PR shortens the insert_values_with_expressions performance test by disabling its 100,000-row query and appending a LIMIT 10000 copy, preserving existing query numbers. The supplied before/after timings and profiles support the runtime reduction and retention of the expression-parsing workload. Review of the current diff, surrounding reader and runner code, and prior discussion found no actionable issues.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci can be tested Allows running workflows for external contributors comp-testing Test content only (no production code). labels Nov 16, 2026

@clickhouse-gh clickhouse-gh Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review approves this commit, see the AI Review comment.

@Algunenano Algunenano self-assigned this Nov 16, 2026
@Algunenano
Algunenano enabled auto-merge November 16, 2026 10:13
@Algunenano
Algunenano added this pull request to the merge queue Nov 16, 2026
Merged via the queue into ClickHouse:master with commit 68d5b2e Nov 16, 2026
570 of 572 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 16, 2026
@clickhouse-gh clickhouse-gh Bot added comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). 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-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). 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