Skip to content

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

Merged
robot-ch-test-poll4 merged 4 commits into
backport/26.9/128248from
cherrypick/26.9/128248
Nov 4, 2026
Merged

robot-ch-test-poll4 merged 4 commits into
backport/26.9/128248from
cherrypick/26.9/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.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]>
@groeneai

groeneai commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

The conflict is a modify/delete: RelationStatisticsEstimator.cpp does not exist on 26.9, 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.9 resolution of #126491; the hunk and the test are the same as on master. Against backport/26.9/128248 the merge changes only optimizeJoin.cpp and the two test files.

On the 26.9 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.9/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.9-cherrypick-128248
git push origin FETCH_HEAD:cherrypick/26.9/128248

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Thanks @groeneai. I checked your resolution and pushed it as a fast-forward (fc5cff982902). It is a two-parent merge of backport/26.9/128248, and against that base it changes only optimizeJoin.cpp and the two 05406_join_swap_array_join_estimate test files. The estimateReadRowsCount hunk is identical to the one in #128248, and hasElementFilter and RelationStats::imprecise_estimate both exist on 26.9. A -fsyntax-only compile of optimizeJoin.cpp on the 26.9 tree passes.

@robot-ch-test-poll4
robot-ch-test-poll4 merged commit 76a8b41 into backport/26.9/128248 Nov 4, 2026
1 check passed
@robot-ch-test-poll4
robot-ch-test-poll4 deleted the cherrypick/26.9/128248 branch November 4, 2026 15:00
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.

4 participants