Repository navigation
Leave the row estimate of a filtered array join unknown in join reordering - #128248
alexey-milovidov merged 2 commits into
Conversation
…ering Since ClickHouse#126491 the array-join branch of `estimateReadRowsCount` estimates an array join as 100 rows per input row. It ignored both the filter passed from above (a `FilterStep` over the array join, e.g. with `query_plan_fuse_filter_into_array_join = 0`) and the step's own element filter (`ArrayJoinStep::hasElementFilter`), so a filtered array join got a known, inflated row count and `swap_on_sizes` built the hash table from the other, possibly much larger, input. Like the other branches of the function do for a filter they cannot account for, a filtered array join now has no row estimate, unless its input is estimated at 0 rows, which a filter cannot change. An unfiltered array join keeps the multiplier. Closes ClickHouse#128220 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The build side alone also passes with any known estimate of `s` up to 1000 rows, so N1-N3 now also count the plans showing `s[no_stats~?]`. 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; 2 rounds, 1 finding, 0 in round 2) plus my own review.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261030-140400 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261030-125800 |
|
cc @vdimir @davenger, could you review this and add the |
|
Workflow [PR], commit [0d0dad8] Summary: ✅
AI ReviewSummaryThis PR makes the row estimate unknown for a filtered Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 17 s compile time in total, 7 of them have a recent master baseline. |
85015d0
|
#126491 now has |
Backport #128248 to 26.10: Leave the row estimate of a filtered array join unknown in join reordering
`estimateReadRowsCount` is in `optimizeJoin.cpp` on 26.8: it moved to `RelationStatisticsEstimator.cpp` only with #120232, which is master-only. So the change of #128248 is applied there, on top of the 26.8 resolution of #126491, with one adaptation: `ArrayJoinStep` has no element filter on 26.8 (`query_plan_fuse_filter_into_array_join` does not exist there), so only a filter above the step leaves the row count unknown. The test `05406_join_swap_array_join_estimate` drops the settings that do not exist on 26.8 (`query_plan_fuse_filter_into_array_join`, `query_plan_lower_array_join_function`), so its "element filter" and "filter step" queries are the same query there. The reference is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #128248 to 26.8: Leave the row estimate of a filtered array join unknown in join reordering
…join unknown in join reordering
`estimateReadRowsCount` is in `optimizeJoin.cpp` on 26.9: it moved to `RelationStatisticsEstimator.cpp` only with #120232, which is master-only. So the change of #128248 is applied there, on top of the 26.9 resolution of #126491. The hunk is the same as on master. The test `05406_join_swap_array_join_estimate` is the same as on master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #128248 to 26.9: Leave the row estimate of a filtered array join unknown in join reordering
…join unknown in join reordering
Backport #128248 to 26.8: Leave the row estimate of a filtered array join unknown in join reordering
Backport #128248 to 26.9: Leave the row estimate of a filtered array join unknown in join reordering
…join unknown in join reordering
…join unknown in join reordering
… join unknown in join reordering
Closes: #128220
Related: #126491
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Since #126491 (master only, not in 26.10), a join with an
ARRAY JOINorarrayJoinsubquery that filters the array-joined elements estimates that input as 100 rows per input row, as if the filter did not exist. The hash join then builds from the other input, which can be much larger.The array-join branch of
estimateReadRowsCountestimates its input without the filter, which is correct because the filter reads the array join output. But it then multiplied by 100 without checking either the filter passed from above (query_plan_fuse_filter_into_array_join = 0, or a filter the fuse pass does not take) or the step's own element filter (ArrayJoinStep::hasElementFilter). The MergeTree and sub-join branches of the function return no estimate for a filter they cannot account for.A filtered array join now has no row estimate, unless its input is estimated at 0 rows (the #126481 case). An unfiltered array join keeps the estimate of 100 rows per input row.
05406_join_swap_array_join_estimategets four new cases: element filter, filter step, a non-loweredarrayJoinwith a filter, and an empty input with an element filter. The first three fail on master. On a debug build, a 5,000,000-row table joined to anARRAY JOINover 100,000 rows filtered to 11 builds the hash table from 5,000,000 rows on master (344 MiB peak) and from 11 rows with this change (4.3 MiB). The result is the same.Trade-off: when the element filter is unselective and the array join is written on the right, the written order is kept, as on 26.10. A 1,000-row table joined to the same array join with
WHERE k >= 0builds 100,000 rows instead of 1,000.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128248]
Version info
26.11.1.944-master(included in26.11and later)