Repository navigation
Check the top-K threshold again when delivering a Parquet row group - #131143
Conversation
TopN dynamic filtering checks a row group against the threshold before reading it. A row group served from the columns cache is ready almost at once, so all of them pass that check while the sorting transforms are still sorting the first chunks and the threshold is loose: with the cache, `ParquetTopKSkippedRowGroups` dropped from about 160 to 3 of 209 row groups and the query read five times more rows. Check the threshold once more when delivering a chunk: by then it reflects everything delivered before, and the check costs nothing. https://performance.ci.clickhouse.com/runs/pr-123890-0f4e0e78cb42e31fef159ff3e74a0eec321c772a #123890 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s cache Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [969dedc] Summary: ✅
AI ReviewSummaryReviewed PR #131143 at 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 units8 translation units recompiled, 35 s compile time in total, 8 of them have a recent master baseline. |
Since the top-K threshold is checked again when a row group is delivered, a row group can be skipped after its rows were read and counted in `rows_pass`. `getMatchedBuckets` then reported it as matched, while it never set `top_k_best_value`, so the TopK query condition cache entry kept it and often ended up empty. With the columns cache this made `05339_iceberg_top_k_query_condition_cache` fail (`where_path_2` found no entry). A row group skipped by a threshold that also filters rows holds no row of the result, so it is now unmatched, the same as one skipped before reading. CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=131143&sha=d8fc36319742ac5c0c1c650e7134441fedf12626&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20sequential%29 PR: #131143 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The file was read right after it was written, when its version token is not settled yet, so the columns cache was not used at all. Rewrite the test in shell, backdate the file with `touch`, populate the cache with both columns, enable TopN dynamic filtering explicitly, and assert `ColumnsCacheHits` on the warm reads. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 CI status:
|
…tion The columns cache is system-wide and only 100 MB in the test configuration. The test wrote about 22 MB of columns into it and required every warm read to hit the cache, but the tests running in parallel (and the concurrent copies of this test in the flaky check) evict its entries between two queries, so one of the warm reads sometimes got no hits at all. Shrink the file tenfold (still 100 row groups, and the descending top-K still crosses a tie boundary), and require only that at least one of the six warm reads hits the cache. Every warm read caches what it misses, so this still proves that the file is eligible for caching and that the cached delivery path is exercised. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=131143&sha=2420e58313d0d06a643f80a29e3ab9e28dd191b7&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20targeted%29 PR: #131143 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged |
|
🕵 The only red job was |
…-tsa-annotations Resolve the conflict with ClickHouse#131143 in ReadManager::read(): keep master's loop that re-checks the top-K threshold before delivery, and apply this branch's two edits to it (UniqueLock for delivery_mutex, and delivery_cv.wait_for on lock.getUnderlyingLock()). Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
TopN dynamic filtering checks a Parquet row group against the top-K threshold before reading it. A row group served from the columns cache is ready almost at once, so all of them pass that check while the sorting transforms are still sorting the first chunks and the threshold is still loose. With the cache,
ParquetTopKSkippedRowGroupsdropped from about 160 to 3 of 209 row groups, and the query sorted about five times more rows.Now the threshold is checked once more in
ReadManager::readwhen a chunk is delivered: by then it reflects everything delivered before, and the check costs nothing. Skipping a row group whose statistics bound is beyond the threshold is valid at any moment, since the threshold only tightens; the top-K query condition cache stays correct (such a row group holds no row of the result).This was found by the performance comparison of #123890 (enabling the columns cache by default):
parquet_top_k_threshold_streamswas 4x slower. Measured locally on that query: without the cache 0.019-0.025 s; with the cache, before 0.037 s, after 0.011-0.015 s (ParquetTopKSkippedRowGroups158-189 again).The new test
05629_parquet_top_k_columns_cachechecks that the results with the cache, cold and warm, equal those without it, with ties on the sort key.Performance report: https://performance.ci.clickhouse.com/runs/pr-123890-0f4e0e78cb42e31fef159ff3e74a0eec321c772a
Related: #123890
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
ORDER BY ... LIMITover Parquet files skips row groups by the top-K threshold also when they are served from the columns cache.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/131143]
Version info
26.11.1.2777-master(included in26.11and later)