Repository navigation
Conversation
Add ProfileEvents to estimate the effect of PREWHERE: - `GranulesSkippedByPrewhereReaders`: granules fully dropped by PREWHERE (every row filtered out, so the main reader read nothing from them). - `GranulesReadByPrewhereReaders`: granules on which PREWHERE was evaluated. - `RowsSkippedByPrewhereReaders`: rows filtered out by PREWHERE. Together with the existing `RowsReadByPrewhereReaders` these are the four counters requested in the issue. The granule counters are computed per part in `MergeTreeReadersChain` from the final, all-steps-applied result rather than per read block: a granule can be split across read blocks (`max_block_size` is not a multiple of `index_granularity`) and a later PREWHERE step can drop a granule that an earlier one kept. Pieces of a split granule are recombined by mark, so each granule is counted once and counted as dropped only when all of it was filtered out. This makes the counts exact and independent of `max_block_size`. Closes: ClickHouse#42045
|
Workflow [PR], commit [8e475cb] Summary: ✅
AI ReviewSummaryAdds three Final Verdict✅ Approve. |
`GranulesSkippedByPrewhereReaders` undercounted a fully dropped granule that was split across read blocks (CI `Fast test` reported 609 instead of 610 on `05569_prewhere_dropped_granules_profile_events`). `rows_per_granule` is the post-PREWHERE survivor count only for complete granules; for an incomplete trailing granule its filtering is deferred, so it still holds the raw rows read. The accounting read that as "survived" and lost one drop. Take the per-granule survivor count from `final_filter` instead, via the new `ReadResult::survivingRowsPerGranule` (popcount of each granule's segment, handling dense and sparse filters; falls back to `rows_per_granule` only when no filter is pending). This is exact regardless of block/thread splitting and for multi-condition PREWHERE. The test now pins `max_threads` so the dropped granule deterministically lands on a range boundary, and adds a multi-condition PREWHERE case.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units398 translation units recompiled, 4024 s compile time in total, 398 of them have a recent master baseline. |
…uning Address two miscounts found by the CI AI review: - On early termination (e.g. LIMIT) the granule counts were published only when the read task ran to the end, so they stayed at zero. Count a granule as read as soon as PREWHERE touches it, and count it dropped only once it is known to be read in full; a granule cut off by early termination is counted read but not dropped. - Marks pruned by a skip index or the query condition cache before PREWHERE reads them (zero-row placeholders from `canSkipMark`) were attributed to PREWHERE. Track the rows actually read per granule (`raw_rows_per_granule`) and skip granules PREWHERE never evaluated. Add `05570_prewhere_granule_events_limit_and_skip_index` covering both paths.
`RowsSkippedByPrewhereReaders` and `GranulesSkippedByPrewhereReaders` count rows and granules rejected by PREWHERE, but a rejected granule is only physically skipped by the main reader when its rejected rows exceed the shrink threshold in `ReadResult::optimize`; otherwise the main reader still reads them. Reword the descriptions to describe logical filter rejection and drop the claims that the main reader read nothing from a rejected granule or did not receive the rejected rows.
The test asserts exact per-reader PREWHERE granule counts for a single-server read plan. Under parallel replicas the LIMIT early- termination case is non-deterministic: how many granules each replica reads before the coordinator's stop signal reaches it is a timing race, so the count varies run to run. Add the no-parallel-replicas tag.
…nation - Finalize a dropped granule once the reader's cursor proves it fully read, not only at task end, so an early LIMIT still counts it. - Mark the real query-PREWHERE step (is_query_prewhere) and count only it; measure granules from survivors entering PREWHERE, excluding on-fly mutations, lightweight deletes and row policies. Extend 05570 and add 05571.
The completed-granule check used numReadRowsInCurrentGranule() == 0, which left a complete, fully-rejected granule pending when the cursor stopped partway through a later granule emptied by an earlier filter. Finalize once the cursor advances past the pending mark. Cover it with a drop_behind case in 05570.
|
@olegkkruglov @leshikus — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
… runtime filter in the query condition cache" This reverts commit 64da8a0, reversing changes made to be89302. Conflicts resolved by keeping the later changes in the same lines: `is_query_prewhere` (ClickHouse#130645), the `last_reader_evaluating_defaults` argument (ClickHouse#128452), `readsSameColumns` (ClickHouse#124880), `follows_top_k_filter` (ClickHouse#129882), and the PREWHERE query condition cache write of ClickHouse#115522 in its own form before it merged ClickHouse#122380. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add ProfileEvents to estimate the effect of PREWHERE, as requested in #42045:
GranulesSkippedByPrewhereReaders— granules fully rejected by PREWHERE (every row filtered out).GranulesReadByPrewhereReaders— granules on which PREWHERE was evaluated.RowsSkippedByPrewhereReaders— rows rejected by PREWHERE.These complement the existing
RowsReadByPrewhereReaders. They are logical filter counts: a rejected row or granule is not necessarily avoided by the main reader, since a fully-rejected granule is only physically skipped when its rejected rows exceed the shrink threshold. The granule counters are computed per part from the final, all-steps-applied read result, so a granule split across read blocks is counted once and counted as rejected only when all of it was filtered out — exact and independent ofmax_block_size.These counters measure work actually performed at read time, so like
read_rowsthey are non-deterministic under parallel replicas with early termination: aLIMITquery is cancelled once the initiator has enough rows, and how many granules each replica read before the cancellation reached it is a timing race. The regression test05570_prewhere_granule_events_limit_and_skip_indexis therefore scoped to a single-server read plan (no-parallel-replicas); the counters remain correct and are deterministic for full scans.Closes: #42045
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added ProfileEvents to estimate the effect of PREWHERE:
GranulesReadByPrewhereReaders,GranulesSkippedByPrewhereReaders, andRowsSkippedByPrewhereReaders.Workflow [PR]
Sync PR [sync-upstream/pr/130645]
Version info
26.11.1.2072-master(included in26.11and later)