Repository navigation
Fix flaky test 02465_limit_trivial_max_rows_to_read - #112199
PedroTadim merged 3 commits into
Conversation
The statement `SELECT a FROM t_max_rows_to_read LIMIT 1` has no ORDER BY, so its result is unspecified: any row of the table is a legal answer. On a single reader the first granule is read first, so the answer happened to be 0 and the reference file has asserted that one particular unspecified answer since the test was written. Under parallel replicas the read is split into per-replica mark ranges and whichever replica answers first supplies the row that LIMIT 1 keeps, so the assertion is not stable and the test fails intermittently with a one-line reference diff of 32 instead of 0. 32 is not a random row. On the failing lane all parts are on object storage, so PartRangesReadInfo takes the remote branch where both merge_tree_min_rows_for_concurrent_read_for_remote_filesystem and its bytes counterpart default to 0, and minMarksForConcurrentRead collapses to merge_tree_min_read_task_size = 8 marks per task. With index_granularity = 4 the second task begins at mark 8, whose first row is 8 * 4 = 32. On a local disk the same formula yields a single task covering the whole part, which is why the failure only appears on the object-storage lanes and why earlier local-disk reproduction attempts could only ever observe 0. Project a constant instead, so every legal row selection produces the reference value. The reference file does not change, because it already asserts 0. What the line measures is unchanged, verified rather than assumed: EXPLAIN still shows ReadFromMergeTree and ReadFromRemoteParallelReplicas, read_rows and ProfileEvents['SelectedMarks'] are identical before and after (4 and 25), and lowering max_rows_to_read to 3, 2 or 1 still raises TOO_MANY_ROWS at exactly the old thresholds, on both analyzers. The read is not eliminated because chooseSmallestColumnToReadFromStorage injects the table's single column. max_rows_to_read = 20 and index_granularity = 4, which are what the test actually measures, are untouched, and no setting is pinned, so nothing leaks into the following statements. A no-parallel-replicas tag or a parallel_replicas_blacklist entry was deliberately avoided: either would remove the whole test from that lane, where it otherwise runs green thousands of times, while only one of its seven statements is affected.
The comment above the changed statement carried the concrete value observed in CI and the mark arithmetic behind it. That context depends on the default of merge_tree_min_read_task_size, so it would become wrong while the test stays correct, and it duplicates what the commit message of the previous commit and the pull request description already explain in full. Keep only what a reader cannot infer from the code: the result is unspecified without ORDER BY because parallel replicas split the read into per-replica mark ranges, a constant is projected for that reason, and max_rows_to_read is what the line measures. No behaviour change: the statement, the settings and the reference file are untouched.
The failure was reported with a CI report link, so record it here as well as in the pull request description. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111968&sha=3084113c10b2726a333dc26732034c039ac441ab&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29 Pull request the report belongs to: ClickHouse#111968 No change to the tree: the fix and its test edit are in the previous commits.
Internal second-model review (click to expand)An independent reviewer and a second model reviewed this change over three rounds before it was
The substance of the change was verified independently rather than taken on trust: that the |
Pre-PR validation gate (click to expand)
|
|
cc @KochetovNicolai — could you review this? Test-only: |
|
Workflow [PR], commit [d6474e8] Summary: ❌
AI ReviewSummaryThis PR removes a flaky assertion in Final VerdictStatus: ✅ Approve |
CI finish ledger - d6474e8CI fully finished on this head: 174 check-runs, 0 queued or in progress,
The failing hunk is Session id: cron:our-pr-ci-monitor:20260728-130000 |
b719314
Related: #111968
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed flaky test
02465_limit_trivial_max_rows_to_read.Description
The statement
SELECT a FROM t_max_rows_to_read LIMIT 1has noORDER BY, so its result isunspecified: any row of the table is a legal answer. On a single reader one stream reads the
first granule first, so the answer happened to be
0and the.referencefile has assertedthat one particular unspecified answer since the test was written. Under parallel replicas the
read is split into per-replica mark ranges and whichever replica answers first supplies the row
that
LIMIT 1keeps, so the assertion is not stable.The test therefore fails intermittently with a one-line reference diff, always the same wrong
value:
32is not a random row. On this lane all parts are on object storage, soPartRangesReadInfotakes the remote branch where bothmerge_tree_min_rows_for_concurrent_read_for_remote_filesystemandmerge_tree_min_bytes_for_concurrent_read_for_remote_filesystemdefault to0, andminMarksForConcurrentReadcollapses tomerge_tree_min_read_task_size= 8 marks per task.With
index_granularity = 4the second task begins at mark 8, whose first row is8 * 4 = 32. On a local disk the same formula yields one task covering the whole part, whichis why the failure only ever appears on the object-storage lanes.
The fix makes the asserted output invariant instead of pinning the reader: the statement now
projects a constant, so every legal row selection produces the reference value. The
.referencefile is unchanged, because it already asserts0.What the line measures is unchanged, and I verified that rather than assuming it:
EXPLAINstill showsReadFromMergeTreeandReadFromRemoteParallelReplicas, andEXPLAIN PIPELINEstill showsMergeTreeSelect(pool: ReadPoolParallelReplicas, ...). Theread is not eliminated: with no column referenced,
chooseSmallestColumnToReadFromStorageinjects the table's single column.
read_rowsandProfileEvents['SelectedMarks']fromsystem.query_logare identicalbefore and after the change (
4and25).max_rows_to_readaccounting is still live on the new form: lowering it to 3, 2 or 1 stillraises
TOO_MANY_ROWS, at exactly the same thresholds as the old form. This also holds withenable_analyzer = 0.The assertion is also self-protecting, which is why a constant projection does not make it
vacuous: the line prints exactly one row only if a row was really read, so if the read were
ever eliminated the output would lose a line and the test would fail, and if the original
trivial-
LIMITaccounting regressed the statement would raiseTOO_MANY_ROWSand the testwould fail too. Only the identity of the returned row stopped being asserted.
max_rows_to_read = 20andindex_granularity = 4, which are what the test actuallymeasures, are untouched, and no setting is pinned, so nothing leaks into the following
statements. The two
TOO_MANY_ROWSstatements on this table keep exercising parallel-replicalimit enforcement on this lane.
I did not add
-- Tags: no-parallel-replicasand did not add the test totests/parallel_replicas_blacklist.txt: either would remove the whole test from theParallelReplicas lane, where it otherwise runs green thousands of times, and only one of its
seven statements is affected. A blacklist entry would additionally report the test as
NOT_FAILED("test succeeded but is listed in the blacklist") on every passing run.The same shape is already used in the tree for the same reason, in
tests/queries/0_stateless/01913_exact_rows_before_limit.sql.CI report. The failure this fixes, on the lane it appears on:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111968&sha=3084113c10b2726a333dc26732034c039ac441ab&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29
There is no open issue for this test; I searched and found none, so there is nothing to close
here. Over the last 30 days the test failed this way on four unrelated pull requests and never
on master, always on the object-storage ParallelReplicas lanes.
Reproduction. An object-storage server with a three-replica parallel-replicas cluster.
With the test's own settings the broken form returned
32on 1 of 2000 runs, and the fixedform returned
0on 2000 of 2000. Withparallel_replicas_local_plan = 0, which the testrunner randomizes, the rate rises: the broken form returned
32on 7 of 200 runs and thefixed form on 0 of 200.
clickhouse-test --s3-storage --test-runs 50is green, as is a runwith
enable_analyzer = 0.Not fixed here. The same statement has a second, unrelated failure mode on the
distributed planvariant of this lane:TOO_MANY_ROWS max rows: 20.00, current rows:followed by
24.00,25.00or100.00. That is per-replica limit accounting rather than rowidentity, so an output-invariance change cannot address it, and all three occurrences over the
last 90 days are confined to one open pull request that changes exactly that machinery.
Version info
26.8.1.433(included in26.8and later)