Repository navigation
Evaluate PREWHERE functions of a dictionary-encoded Parquet column once per value - #124131
Conversation
For a PREWHERE condition over one dictionary-encoded column, such as ClickBench q11 `WHERE MobilePhoneModel <> ''`, the v3 Parquet reader gathered the string of every row and then evaluated the condition on every row, although a row group holds only a few dozen distinct values. When the last PREWHERE step has a single input column that no earlier step reads, read its dictionary-encoded pages as dictionary indexes and pass the step a `ColumnReplicated` over the chunk's dictionary values, so that `IExecutableFunction` evaluates each function once per value. The values are first compacted to the entries the subgroup's (already filtered) rows reference, so the step evaluates only values of rows it would see anyway; this does not rely on `canThrow`, which has false negatives (e.g. `addDays(String, ...)`). Steps whose expression is sensitive to the evaluation count (stateful, side effects, not deterministic in the query) keep the per-row path, as do types for which lazy replication does not pay (`isLazyReplicationUseful`), nullable and array columns, and chunks whose dictionary is large relative to the subgroup. A page that is not dictionary-encoded (a dictionary that fell back to PLAIN in the middle of a chunk) materializes what was read and continues as before. All outputs are materialized right after the last step, and delivery converts any remaining `ColumnReplicated`. New profile event `ParquetRowsDecodedAsDictionaryIndexes`. Based on the analysis in ClickHouse#124030. Closes ClickHouse#124030 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…pty dictionary, as the filtered and fused decodes already do; the new path relies on it. The ParquetReaderPrewhere gtest fixture gives its primitive columns the root level that SchemaConverter always sets. 05331 checks that the page-index query C is read as dictionary indexes. 05331 adds a FixedString(16) column and a PREWHERE over it, read as dictionary indexes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A UInt32, a Nullable(String) with a zero null_count statistic, an Array(String) and a String whose dictionary is larger than half the rows each get a PREWHERE query with a hash oracle and a zero routing row. The Nullable query also checks that the file records null_count = 0, so the static output_nullable check is the only thing keeping that column off the dictionary-index path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… of the column A narrow result, such as the UInt8 of a comparison, is gathered back to rows, so functions applied to it still run per row. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the applyPrewhere comment that restates the lambda, shorten the preparePrewhere one to one line, and backtick class and function names in the added comments. 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, then 1, 2 and 0 on the re-reviews) plus my own review (1 blocker, 3 nits).
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261005-155700 |
|
Workflow [PR], commit [32e261a] Summary: ✅
AI ReviewSummaryThis PR speeds up the Findings❌ Blockers
Final Verdict❌ Not ready to merge: the replicated dictionary path is still unsound for short-circuit |
| PrimitiveColumnInfo & pc = primitive_columns.at(output_info.primitive_start); | ||
| if (pc.first_step_to_calculate == steps.size() && !pc.output_nullable && !pc.group_nullable && pc.levels.back().rep == 0 | ||
| && isLazyReplicationUseful(pc.decoded_type->createColumn())) | ||
| pc.decode_dictionary_as_replicated = true; |
There was a problem hiding this comment.
This optimization still admits short-circuit expressions such as if, multiIf, and and or, but the compaction in decodePrimitiveColumn only drops dictionary values rejected by earlier PREWHERE steps. Inside the last step, lazy short-circuit execution goes through maskedExecute/ColumnFunction::filter, which keeps the original nested ColumnReplicated dictionary and only filters its indexes. If a masked branch contains a false-negative canThrow function — the PR description already calls out addDays(String, ...) — IExecutableFunction::execute can still evaluate that branch on dictionary entries that no surviving row will ever touch, and raise an exception that row-wise short-circuit execution would suppress.
A concrete repro is a single-column last step like PREWHERE if(d = 'garbage', 0, addDays(d, 1) > toDateTime('2020-01-03 00:00:00')) on a dictionary-encoded String column d: rows with d = 'garbage' should never evaluate addDays, but this path still can. Please either exclude DAGs with short-circuit functions from decode_dictionary_as_replicated, or re-compact filtered replicated captures after maskedExecute before reducing the branch.
|
📊 Cloud Performance Report ✅ AI verdict: No query showed a performance change that can be traced to this PR. The only flagged row is clickbench Q33. Its +5.1% (1025.5 ms to 1078 ms) falls inside master's normal range of 960-1243 ms, the query's history is noisy, and it remains not_sure. The PR only changes the Parquet PREWHERE path, which now reads dictionary-encoded columns as dictionary indexes. Q33 is a GROUP BY over a native table and never runs that code, so the result is consistent with the diff and there was no reason to override it. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d once per value `getDictionaryValues` materializes each dictionary entry once per column chunk. With `apply_string_filters_during_scan` it went through `Dictionary::index` with the string filter mask, which also reported every entry to the shared `StringValueFilter`, so its adaptive disable and its profile counters were driven by the dictionary's cardinality rather than by the rows the scan sees. The values evaluated by the last PREWHERE step do not need the mask, so gather them unmasked, as the dictionary pruning path does. When a chunk falls back from dictionary to PLAIN pages, the indexes already decoded for the subgroup are now gathered through `Dictionary::index`, as the per-row path does, so those rows are masked and counted like the rest of the subgroup instead of being copied from the cached values. Measured with `StringValueFilterValuesChecked`: on a file with one dictionary-encoded and two PLAIN row groups it was 20020 (20 dictionary entries plus 20000 PLAIN values) and is now 20000; on pyarrow files whose `late` column falls back mid-chunk it is 60000, same as master (29000 without the second change). Results are unchanged (4,446-query differential against master with the filter enabled). 05055 checked that the filter is applied to dictionary-encoded pages with a single-column PREWHERE, which now takes the replicated path and so only passed through the counters this commit removes. A second conjunct on `id` keeps `s` in an earlier step, where the masked per-row decoding is used. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
I checked: they don't conflict, and they can merge in either order with no follow-up change.
|
CI finish ledger - 32e261aEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261011-020007 |
|
Let's also ask the same question @groeneai |
|
No. The two PRs speed up different parts of the read, and the gains add up.
Measured on current master
With #124186 reverted on the same master, q11 does not change (1.04, 0.96-1.13) while its own query takes 1.77x as long. So #124186 does not move q11, and this PR does not move the query #124186 targets. Query results are identical across the three builds. The PR merges cleanly with current master, and |
Since #124131, the only input of the last PREWHERE step on a dictionary-encoded Parquet `String` column is read as dictionary indexes when no earlier step reads it (`decode_dictionary_as_replicated`), and its dictionary values come from `Reader::getDictionaryValues` with `use_string_value_filter = false`. So a single-column `PREWHERE s LIKE '%R%'` no longer passes through `StringValueFilter` and `StringValueFilterValuesReplaced` stays 0, which made the last line of 05339 print 0 on every master run since d64fd50. #124131 adapted 05055 for the same reason (32e261a), but 05339 was added by #124507 after #124131's last CI run, so it was never adapted. Add the same always-true conjunct `AND id < 100000` to the three PREWHERE queries: the conjunct order is kept, so `s` is read by the first of two steps and goes through the masked `Dictionary::appendIndexes` path the test checks. It goes on the two `apply_string_filters_during_scan = 0/1` comparison queries too, because with the single-column shape both arms read indexes and the comparison compared nothing. The reference does not change. Validated on a debug build of d64fd50: the old test fails 6/6, the new one passes 50/50 randomized (66667 replaced, 0 rows read as indexes). Reporting the mask lookups through `updateStats` instead of `updateStatsWithoutPerValueChecks` makes the new test fail 8/8 (5712-6384 replaced). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-tuple-all-shapes Master reverted ClickHouse#124131 (`ColumnReplicated` decoding of dictionary-encoded PREWHERE columns). Dropped the previous resolution's combination of `decode_dictionary_as_replicated` with `group_null_maps` in `Reader::decodePrimitiveColumn` and the adapted gate in `Reader::preparePrewhere`; the PR's own `group_null_maps` logic is kept. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-chunks Master reverted ClickHouse#124131, removing `getDictionaryValues` next to the PR's `column_chunks` and `cached_column_chunks` members in `Reader.h`; kept only the PR's members. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Master reverted #124131, so the Parquet reader no longer produces `ColumnReplicated`: dropped the `convertToFullColumnIfReplicated` calls after `getOrFormOutputColumn` in `ReadManager::read` and in `Reader::addToColumnsCacheWrite`, and the `ParquetRowsDecodedAsDictionaryIndexes` declaration. In `05055_string_filters_during_scan_parquet.sh`, took master's queries and kept `use_columns_cache = 0`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…argeted checks The coverage selection cannot see a test until a `master` coverage run records it, so a test that landed on `master` after the PR's last CI run escapes it. The `Config Workflow` job of the merge queue (which unshallows the repository) now finds the stateless tests and integration test modules changed on the first-parent history of the queue base after the PR head commit time (or after the merge base, if the PR merged `master` since), keeps the 30 stateless and 10 integration ones whose names share most words with the files the PR changes, and stores them. Both merge-queue targeted checks add them to the selection as mandatory tests. The window and ranking follow #126406. Replayed on the merge-queue commits of the two known cases: for #117198 the integration selection includes `test_storage_delta/test_writes_interop.py` and `test_storage_delta/test.py`; for #124131 the stateless selection includes `05339_string_filters_during_scan_parquet_short_dictionary_values`. The merge-queue targeted jobs are no longer cached: their selection depends on the queue entry and the attempt, neither of which is in the digest.
Edited by the nightly changelog CI job following .claude/skills/edit-changelog/SKILL.md. Changelog-revert: 126396 124131 Revert "Evaluate PREWHERE functions of a dictionary-encoded Parquet column once per value" Changelog-deleted-entry: 124131 [Performance Improvement] [section] * In a `PREWHERE` condition on a single dictionary-encoded column of a `Parquet` file (strings and other values wider than eight bytes), the functions applied to that column are now evaluated once per dictionary value instead of once per row, and only the rows that pass are materialized. ClickBench Q11 (`WHERE MobilePhoneModel <> ''`) over `hits.parquet` is about 22% faster. [#124131](#124131) ([Groene AI](https://github.com/groeneai)).
The merge-queue flaky check reran only the PR's own new/changed tests. That catches a `master` change breaking the PR's tests, but not the reverse: the PR breaking a test that landed on `master` after the PR's last CI run. This is how ClickHouse#124131 broke `05339_string_filters_during_scan_parquet_short_dictionary_values` from ClickHouse#124507 and was reverted by ClickHouse#126396. The `Config Workflow` job of the merge queue, which has the commit history, now finds the tests changed on the first-parent history of the queue base after the PR head commit time (or after the merge base, if the PR merged `master` since), and stores them for the flaky check. When there are more than 30, the ones whose names share more words with the names of the files changed by the PR come first. For the merge-queue commit of ClickHouse#124131 (`d64fd503b42e`), the range has 819 tests, and 05339 is selected second. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #124030
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
In a PREWHERE condition on a single dictionary-encoded column of a Parquet file (strings and other values wider than 8 bytes), the functions applied to that column are now evaluated once per dictionary value instead of once per row, and only the rows that pass are materialized. ClickBench Q11 (
WHERE MobilePhoneModel <> '') overhits.parquetis about 22% faster.Description
For a PREWHERE step over one dictionary-encoded column the v3 reader gathered every row's value and evaluated the condition on every row, although a
hits.parquetrow group holds about 40 distinctMobilePhoneModelvalues.When the last PREWHERE step has a single input column that no earlier step reads, its dictionary-encoded pages are read as indexes, and the step gets a
ColumnReplicatedover the chunk's dictionary values, compacted to the entries the subgroup's rows reference.IExecutableFunctionthen evaluates each function of that column once per value; a narrow result, such as a comparison'sUInt8, is gathered back to rows, and functions of it run per row. The compaction means the step never sees a value of a row an earlier step rejected, without relying oncanThrow. Per-row evaluation is kept for expressions sensitive to the evaluation count, for values of at most 8 bytes (most numbers,Bool, shortFixedString), for Nullable and array columns, for large dictionaries, and from the first non-dictionary page of a chunk on. New profile eventParquetRowsDecodedAsDictionaryIndexes. The unfiltered dictionary-index decode now rejects a page that indexes an empty dictionary, as the filtered and fused decodes already did. That column is not checked against theapply_string_filters_during_scanfilter, so05055moves its dictionary cases to an earlier step.Validation (x86,
max_threads = 4,max_parsing_threads = 4, 8 paired runs, 95% CI):parquet_prewhere_dictionary_encoded.xml: 0.45 to 0.58; the existing five unchanged.The issue's fused mask is not part of this change.
Workflow [PR]
Sync PR [sync-upstream/pr/124131]
Version info
26.11.1.110-master(included in26.11and later)