Repository navigation
Conversation
… waits to be decoded A row group is compared with the top-K threshold when it is admitted and at its OffsetIndex stage, which for a file read without index work runs right after admission. The row groups admitted before any threshold exists then wait in the ColumnData queue (about 1/5 of the parsing threads once the low watermark is exceeded) while the threshold tightens, and their pages are still read and their sort column decoded before __topKFilter drops every row. ReadManager::scheduleTask now repeats the check when the first task of a row subgroup's step is dequeued. On a skip it sets filter.rows_pass = 0, the state applyPrewhere uses when every row is filtered out, so no page is prefetched or decoded and the subgroup is released by the existing path. All tasks of the batch pass through scheduleTask in this thread before bulkSchedule, so they all see it. The row group is counted in ParquetTopKSkippedRowGroups only when none of it was decoded. No query condition cache change is needed on master: a plain-key entry is never written after a read that applies the threshold, and under the TopK key (ClickHouse#122064) a late-skipped row group gets the same verdict as one skipped at admission. The open ClickHouse#124827 writes plain-key entries after statistics-only reads and marks skipped row groups at the two older skip points; whichever of the two merges second marks this one too, and the String-key arm of 05346 fails until it does. hits.parquet, 4 threads, release: SELECT WatchID FROM hits ORDER BY WatchID LIMIT 10 155 -> 108.5 ms (0.71 [0.57, 0.88], 20 pairs), 173 -> 190 of 226 row groups skipped. Proposed by @ snelheidai in ClickHouse#124670. Closes ClickHouse#124670 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 3 findings over 2 rounds) plus my own review (5 findings). One fix round.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261009-114200 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261009-105600 |
|
Workflow [PR], commit [94a4491] Summary: ✅
AI ReviewSummaryPR #124899, reviewed at Missing context / blind spots
Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units13 translation units recompiled, 88 s compile time in total, 13 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.07 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
|
📊 Cloud Performance Report ✅ AI verdict: This PR only changes the Parquet ReadManager top-K late-skip path ( clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
The flaky check stopped 05346 as too slow on amd_tsan (180-192 s of the 180 s limit) and killed it at the 600 s timeout on amd_binary, amd_debug and amd_asan_ubsan. The check enables the thread fuzzer, which costs about 40 ms per 100-row Parquet subgroup, so each full read of the 80000-row file at input_format_parquet_max_block_size = 100 took 31-33 s there, and the test had about 50 of them: the unoptimized side of the result comparisons, the reference reads and counts of the cache arm, and the reads of the String-key tripwire. No full read is left: - the results of the three queries in four configurations are compared with fixed rows in the reference, in order; - the late-skip and cache arms repeat the read until it skips 38 row groups (at most 20 times), taking the counters from --print-profile-events; - the late-skip arms also assert that a skipped row group reads no page: the sort column has one page per row group, so skipped plus ParquetReadPages is 40; without rows_pass = 0 the counter alone still passed, and the sum is 41-42; - the String-key tripwire for ClickHouse#124827 runs only when a 4-row probe shows statistics skipping String row groups without the per-row filter. The probe prints 0 on master; with ClickHouse#124827 it prints 1 and the 5 reads and the cache-on count run, so whichever of the two merges second updates the reference and adds the skipped_by_top_k mark in scheduleTask; - the final cache-on count is removed: it only covered the query condition cache rule that master already has (no plain-key entry after a top-K read). Debug build, randomized, -j 8: fix 50/50 OK, base 20/20 FAIL (no read skips 38 row groups), fix without rows_pass = 0 10/10 FAIL (pages), this branch with ClickHouse#124827 at a32dd7a and the mark 20/20 OK on the armed reference, without the mark 20/20 FAIL (count 26000-30000 of 40000). From the per-query times of the amd_binary flaky check, the test now takes about 55 s there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…coding The check in scheduleTask runs when a row subgroup's step is dequeued. One scheduling pass can dequeue several row groups' tasks (up to the ColumnData stage's share of the parsing threads, about 1/5) and batch them, so a task can still wait behind other decodes, in its batch or in the pool, while the threshold tightens. runTask now repeats the check when the step's last unfinished task starts: the step's other tasks have finished, so no other thread reads filter.rows_pass. Both sites share skipIfExcludedByTopK. The pages of such a subgroup are already prefetched, so only the decode is saved. Debug build, a file of 200 row groups x 100000 random UInt64 keys, SELECT k ... ORDER BY k LIMIT 10, 20 runs each. Row groups the threshold excluded when their first decode task started, decoded anyway, per query: - 32 parsing threads, one subgroup per row group: 8.15 (max 32) -> 0 - 32 parsing threads, default block size: 3.1 (max 12) -> 0 - 20 parsing threads: 1.6-1.75 -> 0 - 8 parsing threads: 0 -> 0 Results equal use_top_k_dynamic_filtering = 0 in 180 runs (5 queries; 2, 8 and 32 threads; 3 block sizes; PREWHERE on and off) and in 90 under TSan with no report; the parquet top-K tests pass, under TSan too. The skipped_by_top_k mark of ClickHouse#124827 now goes into skipIfExcludedByTopK. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 54eba38Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261010-033010 |
|
@groeneai #124827 merged first (2026-10-31), so per this PR's description its late skip now has to set the mark. One store in row_subgroup.filter.rows_pass = 0;
+ row_group.skipped_by_top_k.store(true);Why it is needed on current master: at default settings, a Parquet Test: the only CI run (54eba38) predates #124827. On current master the Evidence: the above is from source (master 5053961, this PR at 54eba38, #124195 at 74b8a36). The wrong cached counts without the mark come from agent runs on stacked branches, not CI: yours with #124827 as of 2026-10-09 (10 of 10, validation comment) and ours with our own |
…p-k-late-skip For `RowGroup::skipped_by_top_k` (ClickHouse#124827), which the late top-K skip now has to set.
ClickHouse#124827 reports a row group skipped by a statistics-only top-K threshold as possibly matching in the query condition cache, but only if skipped_by_top_k is set. The late check did not set it, so a String ORDER BY ... LIMIT read at the default settings recorded such row groups as not matching its WHERE, and a later read with the same WHERE missed their rows. skipIfExcludedByTopK now sets the mark for every subgroup and step it drops, not only where it counts the profile event. 05346: the String key section is no longer conditional, now that ClickHouse#124827 is merged. It runs on its own file of 10 row groups, because the read that uses the cache entry decodes every row subgroup of every row group (about 50 s for the 40 row groups of t.parquet under the flaky check's thread fuzzer, locally). The columns cache is disabled in all sections: it reads each row group in one row subgroup, so no row group waits behind another. Debug build of this branch merged with master 5053961, 05346 with random settings: 50 of 50 pass; without the mark the cached count() is 1000 or 2000 instead of 10000 in 20 of 20 runs; with master's ReadManager the late skip sections fail in 10 of 10. Before the columns cache pin, 13 of 50 runs failed, all with use_columns_cache = 1 and enable_writes_to_columns_cache = 1. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Added in 38e388a, after merging master for |
The late top-K re-check in `runTask` can drop a row subgroup after the
other tasks of its step have decoded their columns. For an output column
with several leaves (`Map`, `Tuple`, `Array(Tuple)`) whose last leaf is
skipped, the decoded leaves are never moved into an output column, so
they stayed in `RowSubgroup::columns` until the reader was destroyed,
while `clearRowSubgroup` already returned their reservation to the
scheduler. Measured on a 153-row-group file: `SELECT s FROM f WHERE
t != ('', '') ORDER BY s LIMIT 10` (a statistics-only `String` key, the
tuple read in a PREWHERE step) kept 8.5-17 MB in a quarter of the runs.
`clearRowSubgroup` now resets each `ColumnSubchunk`, so a dropped
subgroup frees the buffers its reservation covers.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 335dacdEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261101-023003 |
With one sort column the top-K threshold skips a Parquet row group whose minimum (maximum for DESC) equals it. A skip that happens after the row group has already returned some rows (the per-subgroup recheck of ClickHouse#124899) kept the best value of the returned rows as the row group's best value, so the TopK query condition cache recorded the row group as empty whenever that value sorts past the final threshold, although the unread rows may equal it. Overlapping runs can then mark every tied row group, and a later run returns no row. Report the bound of the statistics first: it sorts no later than any row of the row group. On this branch alone a skipped row group has returned no rows, so this changes nothing until ClickHouse#124899 is merged too. Measured with ClickHouse#124899's ReadManager change applied (debug build): two Parquet files whose only k = 0 row is in the last row subgroup, 16 overlapping `ORDER BY k LIMIT 1` reads, then one more read. Before: no row in 22 of 30 cycles through file(), 1 of 40 with a File table. After: 0 of 60 and 0 of 40. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…p-k-late-skip # Conflicts: # src/Processors/Formats/Impl/Parquet/ReadManager.cpp
Since ClickHouse#131143 the reader checks the top-K threshold again when delivering a row group, and counts a row group it stops there in `ParquetTopKSkippedRowGroups` although its pages were read. So a read without the late check can now reach 38 skipped row groups, and "skipped plus read pages" is no longer 40 when such a row group is counted (41-43 in 12 of 40 runs of the merged tree). The arms of the late skip now wait for a read that reads 1 or 2 pages of the sort column: without the late check every read reads at least 3 (230 of 230 reads, 12 of 12 test runs fail), with it 79% of the reads under 8 concurrent clients read 1 or 2. Since ClickHouse#132712 the writer settings are randomized in stateless tests, and a data page size of 1 or 1024 bytes splits the sort column of a row group into several pages. The test pins `output_format_parquet_data_page_size` to at least 64 KiB, one page per row group (measured for every other randomized writer setting). The conflict in `ReadManager::clearRowSubgroup` is resolved by taking master's version from ClickHouse#132621, which frees all the storage of the row subgroup and so also the decoded leaves that the late skip can leave behind.
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=4 K_base=18 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
Skip Parquet row groups the top-K threshold excludes while their data waits to be decoded
Closes: #124670
Related: #115798
Related: #123639
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
ORDER BY ... LIMITover Parquet files no longer decodes a row group that the running top-K threshold excluded while the row group's data was waiting to be decoded:SELECT WatchID FROM hits ORDER BY WatchID LIMIT 10overhits.parquetis 29% faster at 4 threads. Closes #124670.Description
Proposed by @ snelheidai in #124670.
A row group is compared with the top-K threshold at admission (and at
OffsetIndex, right after it without index work), and again when delivered (#131143). Row groups admitted before any threshold exists wait for a decoding thread while it tightens, and are still read and decoded.Change.
ReadManagerrepeats the check when a row subgroup's step is dequeued and when the step's last unfinished task starts decoding, and on a skip setsfilter.rows_pass = 0, the existing "all rows filtered out" state. Such a skip also setsskipped_by_top_k: a statistics-onlyStringtop-K read writes a plain-key query condition cache entry (#124827), in which only a marked row group counts as possibly matching.Measured (release,
clickhouse local, 4 cores and 4 parsing threads,hits.parquet, 20 alternating pairs, 95% CI):SELECT WatchID ... ORDER BY WatchID LIMIT 10SELECT * ... ORDER BY WatchID DESC LIMIT 10... WHERE SearchPhrase <> '' ORDER BY UserID LIMIT 10Controls are within noise; with 20 parsing threads the gain shrinks (0.76).
Validation. New test
05346_parquet_top_k_late_skip: results agree in four configurations; a read whose row groups wait reads only 1 or 2 pages of the sort column forUInt64andStringkeys (at least 3 on master); a cached rerun after a late skip uses the entry and returns the same rows; afterString-key reads at the default settings, a cachedcount()returns all 10000 rows (1000 or 2000 without the mark). Two 4-thread queries inparquet_top_k_row_group_order.xml.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/124899]