Skip to content

Fix flaky test 00612_pk_in_tuple_perf - #109039

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-00612-pk-in-tuple-perf-today-race
Jul 1, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-00612-pk-in-tuple-perf-today-race

Conversation

@groeneai

@groeneai groeneai commented Jul 1, 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):

...

Description

Fixes a rare flaky failure of 00612_pk_in_tuple_perf, seen on Stateless tests (amd_msan, WasmEdge, parallel, 1/2) and other slow builds.

The "non-const args in tuple" section used today() in both the INSERT (today() - number) and the SELECT ((u, d) IN ((0, today()), (1, today()))). today() is evaluated independently at INSERT time and at SELECT time (separate client invocations). If the wall clock crosses midnight (in the randomized session timezone) between the two, today()@select differs from today()@insert, so row 0 no longer matches and count() returns 0 instead of 1. rows_read stays 2 because the primary key still selects the same granules for u IN (0, 1), matching the observed CI diff exactly (-1/+0, rows_read unchanged). The 15-25x slowdown of the msan/WasmEdge build widens the INSERT->SELECT window, making the straddle occasionally happen.

Replace today() with a fixed toDate('2020-01-01'). It is still a non-const function expression (preserving the test's original intent to cover non-const tuple elements), but it is timezone-independent and identical across the INSERT and SELECT, so no midnight race is possible. The .reference (count = 1, rows_read = 2) is unchanged.

Reproduced deterministically with clickhouse local: inserting with today = 2020-06-15 then selecting with today = 2020-06-16 yields count() = 0, rows_read = 2 (the exact CI diff); the fixed version returns count() = 1, rows_read = 2 under both the default and the America/Hermosillo session timezone. 50/50 passes through clickhouse-test with randomization enabled.

CI report of the failure this fixes: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109011&sha=4531517ba0a51a968862bc9d6e085733de02e91b&name_0=PR&name_1=Stateless%20tests%20%28amd_msan%2C%20WasmEdge%2C%20parallel%2C%201%2F2%29

Version info

  • Merged into: 26.7.1.371 (included in 26.7 and later)

The "non-const args in tuple" section used today() in both the INSERT
(today() - number) and the SELECT ((u, d) IN ((0, today()), (1, today()))).
today() is evaluated independently at INSERT and SELECT time; if the wall
clock crosses midnight (in the randomized session timezone) between the two
client invocations, today()@select differs from today()@insert, so row 0 no
longer matches and count() returns 0 instead of 1 (rows_read stays 2, since
the primary key still selects the same granules). The 15-25x slowdown of the
amd_msan/WasmEdge build widens the INSERT->SELECT window and makes the
midnight straddle occasionally happen.

Replace today() with a fixed toDate('2020-01-01'). It is still a non-const
function expression (preserving the test's intent to cover non-const tuple
elements), but it is timezone-independent and stable across the two queries.

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

groeneai commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. clickhouse local: INSERT with today=2020-06-15 then SELECT with today=2020-06-16 → count()=0, rows_read=2 every time (the exact CI diff).
b Root cause explained? today() is evaluated separately at INSERT (today()-number) and SELECT ((u,d) IN ((0,today()),(1,today()))). A midnight straddle between the two client calls makes today()@select != today()@insert, so row 0 stops matching → count()=1→0; the PK still selects the same granules so rows_read=2 is unchanged. The msan/WasmEdge 15-25x slowdown widens the INSERT→SELECT window.
c Fix matches root cause? Yes. Replaces the wall-clock-dependent today() with a fixed toDate('2020-01-01'), removing the only source of non-determinism (the value is now identical across INSERT and SELECT).
d Test intent preserved / new tests added? Yes. The section's intent is "non-const args in tuple" (function expression, not a bare literal) — toDate('2020-01-01') is still a non-const function call. Assertions (count()=1, rows_read=2) and .reference are unchanged.
e Both directions demonstrated? Yes. Without fix: deterministic count()=0 under a simulated straddle. With fix: count()=1, rows_read=2 under default and America/Hermosillo timezones; 50/50 passes through clickhouse-test with randomization.
f Fix is general across code paths? N/A (flaky test fix, not a code bug). The first section already uses fixed literals; only the today()-based section had the race.
g Fix generalizes across inputs? N/A (flaky test fix, not a code bug).
h Backward compatible? N/A (test-only change, no settings/format/behavior change).
i Invariants and contracts preserved? N/A (test-only change).

Session id: cron:clickhouse-worker-slot-0:20260701-094200

@groeneai

groeneai commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

cc @CurtizJ — could you review this? It fixes a rare flake in 00612_pk_in_tuple_perf: the test used today() in both the INSERT and the SELECT, so a midnight straddle between the two client calls (widened by the slow msan/WasmEdge build) made count() drop from 1 to 0. Replaced with a fixed toDate('2020-01-01'), which is still a non-const tuple element but timezone-independent.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jul 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c5e22ee]

Summary: ✅


AI Review

Summary

This PR removes the wall-clock dependency from 00612_pk_in_tuple_perf by replacing today with a fixed toDate('2020-01-01') expression in the INSERT and matching IN predicate. The change preserves the test's expected count and rows_read checks while eliminating the midnight straddle that could make the test flaky. I found no correctness, safety, or review-thread issues to raise inline.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.82% 85.83% +0.01%
Functions 91.46% 91.46% +0.00%
Branches 78.28% 78.31% +0.04%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 77 line(s), 1 function(s) across 36 file(s) · Details

Top files
  • src/AggregateFunctions/AggregateFunctionQuantileExactExclusive.cpp: 5 line(s)
  • src/Functions/array/arrayNormalizedGini.cpp: 5 line(s)
  • src/AggregateFunctions/AggregateFunctionSequenceMatch.cpp: 4 line(s)
  • src/Analyzer/SetUtils.cpp: 4 line(s)
  • src/Functions/highlight.cpp: 4 line(s)

Full report

@groeneai

groeneai commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — c5e22ee

CI fully finished, fully green (Finish Workflow = success, CH Inc sync = success, all builds/functional/integration/stress/fuzzers pass). No failing tests, nothing PR-caused. The 00612_pk_in_tuple_perf test (the target of this fix, replacing today() with a fixed date to remove the INSERT/SELECT midnight-straddle race) passes across all variants.

Check / test Reason Owner
(no failing tests) CI fully green n/a

Session id: cron:our-pr-ci-monitor:20260701-150000

@alexey-milovidov alexey-milovidov self-assigned this Jul 1, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 1, 2026
Merged via the queue into ClickHouse:master with commit 16bb474 Jul 1, 2026
174 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 Jul 1, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…-in-tuple-perf-today-race

Fix flaky test 00612_pk_in_tuple_perf
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 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