Skip to content

Make the datetime_comparison performance test run its comparisons again - #126306

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:datetime-comparison-perf-test-unfold
Oct 16, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:datetime-comparison-perf-test-unfold

Conversation

@groeneai

@groeneai groeneai commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #105987
Related: #124056
Related: #28192

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.

Description

Every query of tests/performance/datetime_comparison.xml has the form WHERE materialize(<constant>) <cmp> <constant>. Since #105987 the planner folds such a filter to a constant, so no comparison runs (FunctionExecute on master went from 30578 to 0 for all 8 queries). Since #124056 the always-true filter step is dropped as well, so each query is now SELECT count() FROM numbers(1000000000).

On arm the speed of that single loop varies by up to ~15% between server starts of one build, so Performance Comparison (arm_release, master_head, 5/6) reports it as a confirmed regression: on #126219 (+17%, again after the confirmation restart) and on two other PRs the same day (1, 2). One side was more than 10% slower in 1.0-1.6% of this test's arm results while it still ran the comparison, and in 4.5-15.1% since #124056.

The change wraps each constant in identity, which is never constant-folded: materialize(identity(X)). The comparison runs for every row again, with the query plan from before #105987 plus one identity call per block. identity goes inside materialize so that the comparison is not JIT-compiled when JIT is enabled (the harness disables it).

Validation on the official amd_release build of master d27018402fae: before the change, no Filter step, FunctionExecute 0 and 0.153-0.156 s for all 8 queries; after it, a Filter step with greater/equals, FilterTransformPassedRows 1e9 and 0.30-0.42 s, slowest for DateTime64/Decimal64/UInt64. On the build just before #105987, the new queries take the same time as the old ones (within 4%).

🤖 Generated with Claude Code


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

Version info

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

Every query of tests/performance/datetime_comparison.xml filters on
materialize(<constant>) <cmp> <constant>. Since ClickHouse#105987 the planner folds such
a filter to a constant (FunctionExecute 30578 -> 0 on master for all 8
queries), and since ClickHouse#124056 the always-true filter step is dropped, so each
query was just count() FROM numbers(1000000000). On arm the speed of that one
loop varies by up to ~15% between server starts of a build, which made the
test report confirmed regressions on unrelated PRs, and it no longer measured
the DateTime/DateTime64 comparisons it exists for (issue ClickHouse#28192).

identity() is not constant-folded, so materialize(identity(X)) keeps the
comparison per row with the pre-ClickHouse#105987 plan plus one identity call per block.
identity goes inside materialize so the comparison is not JIT-compiled when
JIT is enabled.

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

# Sev Finding Verdict Evidence / action
1 ⚠️ Nothing fails if the comparisons get folded away again; add a check that the plans keep their Filter (tests/performance/datetime_comparison.xml) DISAGREE That needs a planner change that folds through identity, which is documented to disable constant folding (src/Functions/identity.cpp). Such a change would also fold the filters in 03324_union_block_structure_mismatch and 04628_split_filter_name_clash_header_leak, which use identity for exactly that purpose, so those tests would fail in that PR. A check of the perf file itself would be a test of a test. Before and after on one binary: FunctionExecute 0 -> 45867, FilterTransformPassedRows 0 -> 1e9.
2 💡 Write identity in backticks in the XML comment AGREE Comment wording only, not blocking.

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

Session id: cron:clickhouse-review-slot-8:20261016-143100

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. On the official amd_release of master d27018402fae, all 8 queries of the current file have no Filter step, FunctionExecute 0, FilterTransformPassedRows 0 and the same 0.153-0.156 s.
b Root cause explained? Yes. #105987 folds materialize(<constant>) <cmp> <constant> filters and #124056 drops the always-true filter step, so each query is count() FROM numbers(1e9); that loop's speed varies by up to ~15% between server starts on arm.
c Fix matches root cause? Yes. The fixture no longer exercised its comparisons; identity is never constant-folded, so the predicate is a per-row comparison again. No threshold, tag or data-size change.
d Test intent preserved / new tests added? Yes. FunctionExecute 45867 (identity, materialize, comparison per block), FilterTransformPassedRows 1e9, timings again depend on the compared type. Test-only change.
e Both directions demonstrated? Yes. Same binary, old file vs new file (numbers above); on the build before #105987 the new queries cost the same as the old ones (within 4%).
f Fix is general across code paths? Yes. All 8 queries are changed and checked one by one; no other performance test query lost its function execution to #105987.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only). All operand types of the file are covered: DateTime against String, UInt32, DateTime and Date, and DateTime64, Decimal64, UInt64 and DateTime equality.
h Backward compatible? (maintainer-approved exception only) Yes. Test-only; both servers of a comparison run the same queries, so the change cannot show as a regression.
i Invariants and contracts preserved? Yes. Same 8 queries in the same order, same result 1000000000, under the harness's per-run time limit (0.30-0.42 s on amd).

Session id: cron:clickhouse-impl-slot-5:20261016-141600

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @egor-click, could you review this and add can be tested (CI does not start without it)? Since #105987 folds materialize(<constant>) <cmp> <constant>, every query of datetime_comparison.xml measures only count() FROM numbers(1e9), which reds arm comparisons on unrelated PRs; wrapping each constant in identity makes the comparison run per row again.

@clickhouse-gh

clickhouse-gh Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6bb1e2f]

Summary: ✅


AI Review

Summary

Restores all eight queries in datetime_comparison.xml to measuring per-row comparisons by placing identity inside materialize. The current folding implementation respects this barrier, and the PR supplies before/after plan, execution-counter, and timing evidence. No actionable findings.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Oct 16, 2026
@egor-click egor-click added the can be tested Allows running workflows for external contributors label Oct 16, 2026
@alexey-milovidov alexey-milovidov self-assigned this Oct 16, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 16, 2026
Merged via the queue into ClickHouse:master with commit 9e5a81a Oct 16, 2026
352 of 353 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 16, 2026
@clickhouse-gh clickhouse-gh Bot added comp-datetime Date/DateTime/TimeZone datatypes and date-time semantics. 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-datetime Date/DateTime/TimeZone datatypes and date-time semantics. 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.

4 participants