Repository navigation
Push down volume-reducing functions in query plan - #106199
alexey-milovidov merged 72 commits into
Conversation
Move length / lengthUTF8 / empty / notEmpty below Filter, Sort, Limit and Expression steps so the wide source column gets pruned from the intermediate steps. Disabled by default; enable via the new setting query_plan_push_down_volume_reducing_functions. References ClickHouse#82378.
|
How does[n't] this relate to #86139? |
|
Workflow [PR], commit [8400cc8] Summary: ✅
AI ReviewSummaryThis PR adds a query-plan optimization that pushes supported volume-reducing functions below Tests
Final VerdictNeeds changes before merge: the added performance benchmark should be adjusted so it actually measures the optimization paths this PR introduces. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 396/446 (88.79%) · Uncovered code |
7a05bc2 to
ce7c70b
Compare
Restore the unconditional `arrayJoin` guard in `tryExecuteFunctionsAfterSorting` that a dangling `if` had gated behind the opt-in setting (reintroducing ClickHouse#82279 in the default plan), and run all bail-out guards in `tryPushDownVolumeReducingFunction` before mutating the parent so a late bail cannot leave the plan rewritten without the pushed step. Also drop the unrelated `USE_NURAFT` guard accidentally added to `gtest_compact_children_set.cpp`.
|
📊 Cloud Performance Report ✅ AI verdict: This PR adds a new query-plan optimization that pushes the string-length functions length, lengthUTF8, empty, and notEmpty below Sorting and Filter steps, replacing the wide String/FixedString argument with the fixed-size result. Neither flagged TPC-H query exercises those functions, so the change cannot plausibly alter their execution paths. Q17's flagged regression (median 64 to 101 ms) is downgraded to not sure because the source runs were very noisy and the diff is off-path; Q7 was already inside the master variance band and is likewise run-to-run variance. No PR-attributable regressions or improvements were found in the flagged set. clickbench🟢 No significant changes tpch_adapted_1_officialFlagged queries (2 of 22)
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. Debug info
|
…olume-reducing-functions
…olume-reducing-functions
The sibling alias is removed before the filter, so the volume-reducing function is correctly pushed down. ClickHouse#106199
|
🕵 Merged current |
…olume-reducing-functions
The check is `countIf(explain LIKE '%[volume-reducing functions]%') = 0`, which returns `1` when nothing is pushed — the desired outcome the test title states. The reference wrongly expected `0`, contradicting both the intent and the actual (correct) plan output in the Fast test: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106199&sha=92c2e55413f979659320dae421d916af4ffea6ab ClickHouse#106199 Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 Merged current |
| <query>SELECT length(arr) FROM volume_reducing_functions ORDER BY key FORMAT Null</query> | ||
|
|
||
| <!-- The wide column is only needed to evaluate the condition, so it is no longer copied | ||
| by the filter. This is the shape from issue #82378. --> | ||
| <query>SELECT avg(length(s)) FROM volume_reducing_functions WHERE notEmpty(s) FORMAT Null</query> |
There was a problem hiding this comment.
This benchmark still gives false confidence for the Performance Improvement claim because two of the added queries do not exercise this optimization at all.
length(arr)is now permanently rejected byisSupportedArgumentTypeinpushDownVolumeReducingFunctions.cpp, so this line is a no-op on both the baseline and patched binaries.- The motivating
avg(length(s)) ... WHERE notEmpty(s)shape only measures this pass whenoptimize_functions_to_subcolumns = 0; the new stateless regression suite pins that setting off for exactly that reason. Here it is left at the default, so the baseline can already rewritelength(s)through subcolumns and this benchmark misses the new filter case.
Please replace these with queries the new rewrite actually owns, for example by disabling optimize_functions_to_subcolumns for the issue-shaped filter query and by dropping the Array case or switching it to a supported String / FixedString workload.
|
@fastio @alexey-milovidov — title/description suggestions: Description (currently
Ignore if intentional. |
|
@fastio @novikd @alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
Adds a query plan optimization that pushes volume-reducing functions (
length,lengthUTF8,empty,notEmpty) below theSortingandFiltersteps, so those steps carry the fixed-size result instead of the originalString/FixedStringargument.The rewrite is done with
ActionsDAG::split: the function nodes form the first part, which becomes a new step below the child, and the second part becomes the parent step'sActionsDAGand reads the results as inputs. It only fires when the wide argument column really stops flowing through the child step — the column is removed from the child's output, and unless the child reads it itself it is not even produced below the child.tryExecuteFunctionsAfterSortingandtrySplitFilterkeep the pushed functions where they are, so the optimizations do not move the same nodes in opposite directions.For the shape from the issue below,
SELECT avg(length(s)) FROM test WHERE notEmpty(s), the filter still needssto evaluate its condition, butlength(s)is now computed before the filter, so the wide column is not copied for the surviving rows.Enabled by default; can be turned off with
query_plan_push_down_volume_reducing_functions = 0.An earlier attempt at the same optimization was #86139 by @talmawash, credited as a co-author.
Closes: #82378
Related: #86139
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added a query plan optimization that pushes volume-reducing functions (
length,lengthUTF8,empty,notEmpty) below theSortingandFiltersteps, replacing the wideString/FixedStringargument with the fixed-size result, so it is neither buffered by a sort nor copied by a filter. Controlled by the new settingquery_plan_push_down_volume_reducing_functions, enabled by default.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/106199]
Version info
26.8.1.1857(included in26.8and later)