Repository navigation
Fix flaky 01780_column_sparse: order the arrayFilter result before limiting it - #119686
Conversation
`01780_column_sparse` ends with
SELECT arrayFilter(x -> x % 2 = 1, arr2) FROM t_sparse WHERE arr2 != [] LIMIT 5;
`t_sparse` is `ORDER BY tuple()`, so there is no implicit row order to fall
back on, and once the table is read by more than one stream the five rows that
survive `LIMIT` arrive in an arbitrary order. Every "result differs with
reference" failure of this test over the last 400 days - six of them, the most
recent in `Stateless tests (amd_release, distributed cache, meta in keeper, s3
storage, parallel)` - is the same permutation of that one statement's output,
and the 2026-04-08 instance on a master push ran with a randomized
`index_granularity` of 3, which maximises the number of marks and hence of
reading streams.
`ORDER BY id` makes the choice of rows deterministic. It is the order the
reference already records, so only the echoed query text changes.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [53220ab] Summary: ✅ AI ReviewSummaryThis PR makes the last query in Final Verdict
|
…arse-nondeterministic-limit
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119686&sha=09ae8c074aeaaf2588f26ec4f0d5e4a00f856e8e&name_0=PR&name_1=Stateless%20tests%20%28amd_binary%2C%20flaky%20check%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. The only red on this PR was |
|
Acknowledged, and no fix is in progress: no open or merged PR touches For context, CIDB says the slowness is a single draw rather than a chronically slow test: one FAIL in 30 days (the one in this flaky check), and inside that same 50-run batch p50 was 6.3s, p95 7.7s, max 208.4s. On the ordinary lanes it stays cheap, e.g. |
|
Fix: #120968 From that job's own logs the draw was |
Stateless tests (amd_binary, flaky check) on ClickHouse#119686 failed this test at 208.35 s against the 180 s cap (TEST_MAX_RUN_TIME_IN_SECONDS, tests/clickhouse-test:214, enforced at :3770-3775). The test is untouched by that PR; the flaky check matches test names by prefix, so a change to 01780_column_sparse.sql selects 01780_column_sparse_alter too and runs it 50 times, each with a fresh randomized settings draw. That draw was index_granularity 1. With index_granularity_bytes 17728586 (never binding) and min_bytes_for_wide_part 1073741824 (so the part is Compact), the 2000-row INSERT produced one part with 2001 marks. SET mutations_sync = 2 then makes each ALTER wait for a mutation that rewrites the whole part one granule at a time, so every per-chunk fixed cost is paid 2000 times. From the failing job's own part_log: DROP COLUMN + RENAME took 82 990 ms (Seek 2002, CompressedReadBufferBlocks 4000) and MODIFY COLUMN 103 184 ms (Seek 2003, FunctionExecute 2000, RWLockAcquiredReadLocks 2000), with the three uniqExact reads adding 16 770 ms. CPU is a small fraction of that wall time and MutatePartStart is logged in the same second as the ALTER, so this is neither data volume nor scheduling delay. Speeding the test up is not available: in the other 49 draws of the same batch no single statement exceeded 1.31 s, so there is no slow step. The granule count is the variable, and unlike the row count (an oracle input, via the 1-in-11 and 1-in-13 densities behind the reference counts 182 and 155) it is purely a randomizer artefact. So bound the two settings that set granule size instead. clickhouse-test already applies exactly these two bounds, for exactly this reason, at tests/clickhouse-test:2101-2103, but only on sanitizer, debug and coverage builds; amd_binary is none of those, so randint(1, 65536) applied in full. This test opts into the same bound rather than widening the global one. index_granularity_bytes is clamped as well because adaptive granularity takes the minimum of the two, so a low byte draw shrinks granules even at index_granularity 100: measured, 1024 gives 49 marks against 21 at 100000. Coverage is kept. index_granularity still ranges over [100, 65536], i.e. 1 to 20 granules over 2000 rows, so multi-granule sparse serialization is still exercised, and the assertions are untouched: the Sparse kind is chosen once per part at INSERT in MergeTreeDataWriter::writeTempPartImpl (choose_kind = true) and the mutations inherit it (MutateTask.cpp, choose_kind = false), while index_granularity affects only mark layout. The test's output is byte-identical to the reference at index_granularity 1, 100 and 8192, and with index_granularity_bytes 1024 and 100000. Validated through the runner with 6000 randomized runs per arm: without this line 7 runs produced granules below 100 rows (worst 5 rows, 400 marks), with it none did and the worst run sits on the intended floor of 20 marks. The directive itself fails silently when unparsed, so it was also checked against the real parser and randomizer over 20000 draws, with a negative control that corrupts one character of the prefix and brings sub-100 draws back (25 of 20000, minimum 1). The seven sibling 01780_column_sparse* tests are subject to the same randomizer but show no too-long failure in 30 days of CIDB, so they are left alone. Asked for in ClickHouse#119686 (comment) Co-Authored-By: Claude Opus 5 <[email protected]>
|
Backporting to fix CI |
Backport #119686 to 26.7: Fix flaky `01780_column_sparse`: order the `arrayFilter` result before limiting it
Backport #119686 to 26.9: Fix flaky `01780_column_sparse`: order the `arrayFilter` result before limiting it
…`arrayFilter` result before limiting it
Backport #119686 to 26.8: Fix flaky `01780_column_sparse`: order the `arrayFilter` result before limiting it
Backport #119686 to 26.3: Fix flaky `01780_column_sparse`: order the `arrayFilter` result before limiting it
…order the `arrayFilter` result before limiting it
…order the `arrayFilter` result before limiting it
…order the `arrayFilter` result before limiting it
01780_column_sparseends witht_sparseisORDER BY tuple(), so there is no implicit row order to fall back on, and once the table is read by more than one stream the five rows that surviveLIMITarrive in an arbitrary order.Every "result differs with reference" failure of this test over the last 400 days — six of them — is the same permutation of that one statement's output, across
Stateless tests (amd_debug, distributed plan, s3 storage, parallel),(amd_debug, AsyncInsert, s3 storage, parallel),(amd_tsan, s3 storage, parallel),(amd_binary, ParallelReplicas, s3 storage, parallel)andFast test. Two of them were on master pushes rather than pull requests; the 2026-04-08 one ran with a randomizedindex_granularityof 3, which maximises the number of marks and hence of reading streams:ORDER BY idmakes the choice of rows deterministic. It is the order the reference already records, so only the echoed query text changes. The statement was added without an ordering in 2022 and the file has not been touched since; the test is untracked by any flakiness issue.Found while triaging the CI of an unrelated pull request, where the most recent instance appeared.
Changelog category (leave one):
Workflow [PR]
Sync PR [sync-upstream/pr/119686]
Version info
26.9.2.35,26.8.11.47,26.7.14.46,26.3.33.150