Repository navigation
Do not drop unreferenced dictionary values in Parquet PREWHERE when the condition cannot throw - #128342
Conversation
…REWHERE step can throw The last PREWHERE step over a dictionary-encoded column is evaluated once per dictionary value through a ColumnReplicated. Each row subgroup first dropped the unreferenced values (buildUsedRowsFilter + compactIndexes over every index), so that the step never evaluates a value no read row references. That is only needed when a function of the step can throw on such a value. IFunctionBase::canThrow answers this conservatively, so when every function node that is not constant-folded answers false, the dictionary values are kept as they are. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`empty` and `notEmpty` read only the sizes or the bytes of String, FixedString, Array, Map, UUID, IPv4 and IPv6 values (Nullable and LowCardinality are unwrapped by the default implementations), so they cannot throw on any value of these types. They did not describe it, so IFunctionBase::canThrow answered true. The default optimize_empty_string_comparisons rewrites `s != ''` to `notEmpty(s)`, so the rewrite dropped the property that notEquals has. Every consumer of IFunctionBase::canThrow now treats them as harmless on extra rows: the reordering of `and`/`or` arguments and of AND-chain atoms in WHERE, and the Parquet reader, which can now skip the dictionary compaction for `PREWHERE s != ''`. 05259 gets a case where `notEmpty` and `s != ''` are moved in front of a throwing atom. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…f test 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) plus my own review (1 nit).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20261031-042600 |
|
cc @grantholly-clickhouse @george-larionov, could you review this and add the |
|
Workflow [PR], commit [5b51d7e] Summary: ✅
AI ReviewSummaryThe PR skips dictionary compaction for a final Parquet Missing context / blind spots
Final Verdict✅ Approve — no code changes requested; pending CI validation remains as noted above. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units25 translation units recompiled, 213 s compile time in total, 25 of them have a recent master baseline. |
…s cannot throw They read only the sizes or the bytes of the values. `URL <> ''` is rewritten to `notEmpty(URL)` (`optimize_empty_string_comparisons`), so without this a PREWHERE step before it keeps filtering its block. Same change as in ClickHouse#128342, which needs it for Parquet; it drops out when either PR is merged first. Found, analysed and measured by @ snelheidai in ClickHouse#128442 and ClickHouse#128454. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2fdb487
…uet reader After merging master, `Reader::Step` no longer has the `actions` member (this PR replaced it with `actions_pool`), but master added a new use of it in `Reader::prepareDictionaryDecoding` (from #128342). Read the DAG from the prototype of the pool, as the neighbouring check already does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Faster
PREWHEREover a dictionary-encodedStringorFixedStringcolumn of a Parquet file when the condition cannot throw, for examples != '': the dictionary indexes of each block are no longer scanned and renumbered first. ClickBench Q11 and Q12 over Parquet are about 15% faster.Description
Closes: #128322
Since #126397, the last PREWHERE step over one dictionary-encoded Parquet column runs once per dictionary value. Before running it, every row subgroup scanned and renumbered all its dictionary indexes (
ColumnIndex::removeUnusedRowsInIndexedData), so that the step never sees a value that no read row references. That only matters when a function of the step can throw on such a value (addDayson'garbage'in05331). In ClickBench Q12 it took about 6% of the CPU samples.Changes:
Reader::preparePrewhereasksIFunctionBase::canThrowfor every function of the last step that is not constant-folded. If none can throw, the dictionary and the decoded indexes are used as they are. Steps with a function that does not describe whether it can throw (and,or,LIKE,IN, ...) keep dropping the unreferenced values.emptyandnotEmptyimplementcanThrowIfKnown: for String, FixedString, Array, Map, UUID, IPv4 and IPv6 (also under Nullable and LowCardinality) they read only sizes or bytes. This is needed becauseoptimize_empty_string_comparisonsrewritess != ''tonotEmpty(s). It also lets the short-circuit reordering ofWHEREatoms evaluatenotEmptybefore a throwing condition (new case in05259).Validation: release build, x86, 4 threads, ClickBench
hits.parquet, 20 alternating pairs, 95% CI: Q11 284 -> 233 ms (0.84x [0.80, 0.87]), Q12 317 -> 274 ms (0.85x [0.83, 0.87]); an A/A run gives 0.995x [0.975, 1.015]. No ClickBench query is significantly slower, and all 43 return the same results withmax_threads = 1.05331gets a case where every row subgroup leaves dictionary values unreferenced, andparquet_prewhere_dictionary_encoded.xmlgets a sparse dictionary column queried withPREWHERE m != ''(0.88x locally).The analysis comes from #128322 by @ snelheidai. Its patch (marking the used values while decoding) is not used: skipping the scan is simpler and removes all of the per-row work.
Workflow [PR]
Sync PR [sync-upstream/pr/128342]
Version info
26.11.1.1709-master(included in26.11and later)