Repository navigation
Conversation
`optimizePrewhere` keeps every PREWHERE input among the PREWHERE outputs (`splitAndFillPrewhereInfo`, needed for DEFAULT expressions), and `updatePrewhereOutputsIfNeeded` does the same for an explicit PREWHERE that reads one column. `ReadFromMergeTree` drops the outputs the parent does not use in `removeUnusedColumns`; `ReadFromFile` and `ReadFromURL` did not implement it, so the Parquet reader filtered and copied those columns only for the next step to drop them (ClickBench Q31: 13M non-empty `SearchPhrase` strings). `ReadFromFile` and `ReadFromURL` now implement `removeUnusedColumns` through `removeUnusedPrewhereInputsFromFormatInfo`, which removes the pass-through PREWHERE inputs the parent does not need from a copy of the PREWHERE actions and from the format header. The Parquet reader then reads them as PREWHERE-only columns (`FormatFilterInfo::additional_columns`, `only_for_prewhere`), the path an explicit multi-column PREWHERE already takes. The PREWHERE column itself leaves the output the same way, as `remove_prewhere_column`, when nothing above uses it. Nothing is removed with a DEFAULT column (`AddingDefaultsTransform` evaluates it over the returned columns) or a row-level filter (its inputs stay in the header), and never a hive partition or virtual column. `initKeyConditionOnce` fills `additional_columns` also without a filter DAG, since a PREWHERE input can now be missing from the header whatever the filter DAG is. Object storage applies the PREWHERE after the format for files whose schema changed, which needs the inputs, so `ReadFromObjectStorageStep` is not changed. Release build, File(Parquet) over hits.parquet, 10 alternating A/B runs: `count() PREWHERE URL <> ''` -41% wall / -23% CPU, `sum(ResolutionWidth) WHERE URL <> ''` -37% / -23%, `count() PREWHERE SearchPhrase <> ''` -13% CPU, Q31 / Q32 -7% / -6% CPU; controls unchanged; results identical. Patch from issue ClickHouse#124029. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the duplicated contract comment in ReadFromURL and two comments restating function names; condense the removeUnusedPrewhereInputsFromFormatInfo doc to two lines. 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 rounds, 3 findings) plus my own cold review of every round.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261006-012600 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261005-224503 |
|
Workflow [PR], commit [217abc8] Summary: ❌
AI ReviewSummaryReviewed #124124 at Final VerdictStatus: ✅ Approve. No required changes identified. |
|
📊 Cloud Performance Report 🟢 AI verdict: One query was flagged: ClickBench Q20 is -40.0% faster (220 ms to 132 ms), and CPU time fell by about half. The shift is large and consistent, so the hard-trust rule keeps the improvement verdict as it is. The attribution does not fit the diff, though. This PR only drops PREWHERE-only columns from the output of file()/url() reads (ReadFromFile, ReadFromURL, FormatFilterInfo), and ClickBench Q20 reads the MergeTree hits table, which never runs that code. Do not count this gain as an effect of the PR. Re-running against an exact-base baseline should confirm whether it comes from a master change between the base and the PR head. The new parquet_prewhere_only_columns perf test is the right place to measure what this change actually does. clickbench🟢 1 improved Flagged 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
|
Build profile diff (arm_release)Commit See the job log for details. |
…where-only-columns Adapt `ReadFromFile::removeUnusedColumns` and `ReadFromURL::removeUnusedColumns` to the single-pass interface of removing unused columns from master: they now take the unneeded output positions and return the dropped ones, and `canRemoveColumnsFromOutput` no longer exists. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #124029
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reads from
fileandFile, and fromurlandURLover HTTP(S), with aPREWHERE(including aWHEREmoved toPREWHERE) no longer return the columns that only thePREWHEREuses, so the Parquet reader does not filter and copy them. For example,SELECT count() FROM hits PREWHERE URL <> ''over ClickBench'shits.parquettakes about 40% less time, and ClickBench Q31 and Q32 overFile(Parquet)use about 6-7% less CPU.Description
optimizePrewherekeeps every PREWHERE input among the PREWHERE outputs, soReadFromFileandReadFromURLreturned the columns the condition was computed from even when no step above used them.ReadFromMergeTreealready removes such columns inremoveUnusedColumns;ReadFromFileandReadFromURLdid not implement it.They now implement
removeUnusedColumnsthrough one helper inprepareReadingFromFormat, which removes the pass-through PREWHERE inputs the parent does not need (and the PREWHERE column itself, asReadFromMergeTreedoes) from a copy of the PREWHERE actions and from the format header. The Parquet reader then reads them as PREWHERE-only columns, the path an explicit multi-columnPREWHEREalready takes. Nothing is removed with aDEFAULTcolumn or a row policy.FormatFilterInfo::initKeyConditionOncealso collects the PREWHERE inputs missing from the header when there is no filter DAG. Object storage (ReadFromObjectStorageStep) applies the PREWHERE after the format for files with a changed schema, so it is not changed here.The patch is from the issue, with the row-policy check moved into the helper.
Release build,
File(Parquet)overhits.parquet, 10 alternating A/B server runs, paired ratio and 95% CI:count() ... PREWHERE URL <> ''sum(ResolutionWidth) ... WHERE URL <> ''count() ... PREWHERE SearchPhrase <> ''WatchIDfilterResults were identical, also in a differential run of Q31, Q32 and Q37-Q43 across a settings matrix. #122952 changes the
removeUnusedColumnsinterface; if it lands first, I will port this PR to it.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/124124]