Skip to content

Cherry pick #128248 to 26.8: Leave the row estimate of a filtered array join unknown in join reordering - #128929

Merged
robot-clickhouse merged 4 commits into
backport/26.8/128248from
cherrypick/26.8/128248
Nov 4, 2026
Merged

robot-clickhouse merged 4 commits into
backport/26.8/128248from
cherrypick/26.8/128248

Conversation

@robot-clickhouse

Copy link
Copy Markdown
Member

Original pull-request #128248

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 3 commits October 30, 2026 13:30
…ering

Since #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 #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]>
…-unknown

Leave the row estimate of a filtered array join unknown in join reordering
@robot-clickhouse robot-clickhouse added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels Nov 3, 2026
`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]>
@groeneai

groeneai commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

The conflict is a modify/delete: RelationStatisticsEstimator.cpp does not exist on 26.8, because #120232 split it out of optimizeJoin.cpp on master only. I applied the change of #128248 to estimateReadRowsCount in optimizeJoin.cpp, on top of the 26.8 resolution of #126491. ArrayJoinStep has no element filter on 26.8 (no query_plan_fuse_filter_into_array_join), so there only a filter above the step leaves the estimate unknown. The test drops the two settings 26.8 does not have, so its "element filter" and "filter step" queries are the same query there; the reference is unchanged. Against backport/26.8/128248 the merge changes only optimizeJoin.cpp and the two test files.

On the 26.8 tree (clang-22, debug) 05406_join_swap_array_join_estimate passes, 50 of 50 with random settings. With the optimizeJoin.cpp hunk reverted, the three filtered cases give 0 1 0 instead of 1 0 1 (#128220).

I cannot push to cherrypick/26.8/128248. The merge is on my fork and its first parent is this PR's head 85015d0bb160, so applying it is a fast-forward:

git fetch https://github.com/groeneai/ClickHouse.git groeneai/resolve-26.8-cherrypick-128248
git push origin FETCH_HEAD:cherrypick/26.8/128248

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Thanks @groeneai. I pushed your merge 70956a05f70d to cherrypick/26.8/128248 as a fast-forward. Against backport/26.8/128248 it changes only optimizeJoin.cpp and the two 05406_join_swap_array_join_estimate test files. A -fsyntax-only check of optimizeJoin.cpp on the 26.8 tree passes.

@robot-clickhouse
robot-clickhouse merged commit 43e97d5 into backport/26.8/128248 Nov 4, 2026
1 check passed
@robot-clickhouse
robot-clickhouse deleted the cherrypick/26.8/128248 branch November 4, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants