Repository navigation
Cherry pick #126491 to 26.8: Estimate an array join as 100 rows per input row in join reordering - #128690
Conversation
An array join multiplies each input row by its array size, which is not estimated, so since #98533 an `ExpressionStep` with `arrayJoin` gives no row estimate, and an `ArrayJoinStep` (the lowered `arrayJoin` function and the `ARRAY JOIN` clause) never gave one. The hash join swap needs an estimate on both inputs, so a join with an array join input over a read that selects no rows kept building the other, possibly huge, input. `RelationStats` now carries `proven_empty`, set only by the read branch whose exact range analysis selected no rows and kept by steps that cannot add rows. An array join over such an input is estimated at 0 rows; any other array join keeps returning no estimate, because a child row count is neither an upper nor a lower bound and an estimated zero (a keyless aggregation, a truncated statistics selectivity) is not emptiness. Related: #126481 Co-Authored-By: Claude Opus 5.5 <[email protected]>
A statistics estimate of 0 rows is only an estimate, so an array join over such a read kept no estimate and the hash join kept building the other input. Execution-time part pruning proves the read empty only when it runs: it is off with `use_statistics_for_part_pruning = 0` (which `compatibility` below 26.4 sets) and under FINAL. The issue's LEFT JOIN query runs with the former, its INNER JOIN query with FINAL. When the statistics estimate of a MergeTree read is 0, the estimator now asks the statistics part pruner whether the read's filter excludes every analyzed part. The check shares its conditions and its per-part test with `filterPartsByStatistics`, which is only split, not changed. It does not depend on `use_statistics_for_part_pruning`, because it skips no part and only feeds the join order. Under FINAL it holds only for ReplacingMergeTree, whose FINAL picks stored rows; SummingMergeTree and the other merging modes compute new rows. It is stricter than part pruning on stale statistics: any pending mutation or patch part, or a part storing a filtered column with another type than the table (a killed MODIFY COLUMN), gives no proof. Related: #126481 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop comments that narrate the new code and shorten the field and function contracts to one line each. Co-Authored-By: Claude Opus 5.5 <[email protected]>
An array join made the row estimate of its relation unknown, so a hash join never compared the sides and kept building from the other side, even when the array join input was empty (#126481). Multiply the input estimate by 100 instead (the sizes of the arrays are unknown), as suggested in review. This replaces the emptiness proof by range analysis and part statistics of the previous commits, which is reverted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nput Estimate an array join as 100 rows per input row 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 #126491 is applied there, with two adaptations: - the third argument (`for_runtime_filter_transport`) of the recursive call does not exist on 26.8 and is dropped; - `toUInt64Saturating` (added by #124008, master-only) does not exist on 26.8, so the file gets a static copy of it with the same body. The setting `query_plan_lower_array_join_function` does not exist on 26.8 (`arrayJoin` is never lowered to an `ArrayJoinStep` there), so the test `05406_join_swap_array_join_estimate` drops it from four queries. Those queries then run the `arrayJoin` expression path, with the same result, and the reference is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The conflict is a modify/delete: On the 26.8 tree (clang-22, debug) I cannot push to #126491 alone also brings #128220 to 26.8: with a filter on the array-joined elements, this resolution builds the hash table from the larger table ( |
Original pull-request #126491
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-picklocally.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:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job