Repository navigation
Revert "Revert "Convert OUTER join to INNER join by null-rejecting join conditions"" - #119305
Conversation
|
Workflow [PR], commit [c67bd70] Summary: ✅
AI ReviewSummaryThis PR reintroduces planner-derived Missing context / blind spots
Final Verdict✅ No new review findings. The earlier LLVM Coverage ReportMeasured on commit c67bd70.
Changed lines: Changed C/C++ lines covered: 318/337 (94.36%) · Uncovered code |
…L filter resolvePlannerOnlyFilters rebuilds a FilterStep with remove_filter = true, using a surviving conjunct's result_name as the filter column name. Because collectFilterConjuncts unwraps aliases, that conjunct can be a column of the step's own output header: filter push-down wraps a pushed predicate in a __filter<name> alias so the removal cannot hit the same-named stream column (ActionsDAG.cpp:3768-3779), and the unwrap discards that protection. checkAndRemoveFilterColumn then erases the column, shrinking the step's output header. The pass replaces node.step outright, so no updateInputHeader reaches the parent JoinStepLogical, whose expression DAG still holds an input node for the erased column, and that node cannot be pruned because the column is also one of the join's outputs. chooseJoinOrder is the first consumer to notice: JoinExpressionActions requires the DAG's input count to equal the left plus right header widths, and aborts with "Input nodes size mismatch in dag". With the join reorder disabled the same inconsistent plan reaches execution and throws NOT_FOUND_COLUMN_IN_BLOCK instead, and a NATURAL JOIN variant, where both sides carry a column of that name, throws UNKNOWN_IDENTIFIER. Re-establish the alias at the rebuild site when the chosen filter node's name collides with the step's output header, which is the same operation, for the same reason, as the push-down site. A Nullable join key is needed to reproduce: it makes the join condition null-rejecting, which is what makes deriveNotNullFiltersFromJoin emit the planner-only marker. Related: #114817 Co-Authored-By: Claude Opus 5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes919 object files changed (+477.48 KiB total), 3 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units2122 translation units recompiled, 12835 s compile time in total, 2122 of them have a recent master baseline. |
…to-inner-by-join-condition
…r optimizer isNullPropagatingFunction in optimizeJoin.cpp decided null propagation from the function name alone and listed CAST / _CAST unconditionally. For a cast that is a property of the target type, not of the name: casting NULL to a non-Nullable type raises CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN instead of returning NULL. So strictOnRelations reported a relation as "evaluates to NULL when all of R's columns are NULL" where the runtime actually raises. That claim flows through predicateNullRejectingRelations to cda_nr_rels (gated by trust_null_rejection = join_use_nulls) to ConflictJoinOp::nr_rels, where a set bit turns a null-rejection-dependent assoc matrix entry from a conflict into a permitted reordering. Observable effect, with join_use_nulls = 1 and the LEFT/LEFT shape t1 LEFT JOIN t2 ON t1.a = t2.a LEFT JOIN t3 ON CAST(t2.k AS Int64) = t3.k: every configuration raises Code 349 except dpsub with conflict detector A or C, which reassociate into t1 LEFT JOIN (t2 LEFT JOIN t3) and thereby skip the throwing evaluation. This is a consistency hardening rather than a bug fix: there is no wrong result in either direction, because a non-Nullable cast never yields a value that could make a null-extended row match, and both experimental settings default to false while the default solver is greedy, so nothing reads nr_rels in a default build. The gate uses isNullableOrLowCardinalityNullable(node.result_type), which is the same predicate ClickHouse#119305 adds on FunctionConvert / ExecutableFunctionCast, so the analysis and the runtime agree by construction. Once that PR lands, the cast branch here can delegate to IFunction::isNullPropagating. Only CAST is gated on its result type: the INPUT leaf and the comparison and arithmetic names must not be, because under join_use_nulls = 1 a non-Nullable base column becomes Nullable in the join output while the DAG node keeps its pre-join type, so gating those would drop relations that are correctly reported today. The new test asserts the Join/Read plan skeleton per arm at query_plan_optimize_join_order_limit > 0, since the reordering under test is only reachable with dpsub plus a conflict detector. It carries two non-vacuity controls: a CAST(... AS Nullable(Int64)) arm that must still reassociate, which reddens if every cast is rejected instead of only the non-Nullable ones, and a plain-predicate arm proving the detector is what moves the plan. It asserts the plan rather than the exception because coupling a test to error preservation across plan shapes would assert a guarantee ClickHouse does not make. It is also the first stateless coverage of the trust_null_rejection = true branch, as no existing test combines a conflict detector with join_use_nulls = 1. Requested by @ m-selmi at ClickHouse#119305 (comment) Co-Authored-By: Claude Opus 5 <[email protected]>
…to-inner-by-join-condition
`05182_join_order_conflict_detector_cast_null_propagation` asserts a join plan shape, and it makes `t1` look expensive through `param__internal_join_table_stat_hints` to get the reordering it wants to observe. When the table carries automatic statistics that do not include `basic`, the optimizer has its own estimate, costs the join the other way, and both reassociation arms - the non-vacuity controls - stop reassociating, so the test fails on the plan lines while every row and exception arm still agrees. `clickhouse-test` randomizes `auto_statistics_types` to a random subset of `uniq, uniq_v2, tdigest, countmin, basic`, so a run reddens whenever the subset leaves `basic` out. Measured against master `7fe32951` with `clickhouse local`: `uniq` alone, `uniq_v2` alone, `tdigest` alone, `countmin` alone and `uniq_v2,tdigest` all flip the plan, while `''`, `basic`, `basic,uniq`, `basic,tdigest`, `basic,countmin`, `basic, uniq_v2` (the default) and the full set of five keep the plan the reference records. Creating the tables with `auto_statistics_types = ''` pins it: the whole test output then matches its reference, and the three `CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN` arms still raise. The test only became reachable this way when ClickHouse#119305 re-landed the OUTER-to-INNER conversion, which is what makes these joins reorderable at all: CIDB has 0 failures in 12428 runs over 1267 commits before `a88f878d7`, and 26 in 506 runs over 120 commits after it. Caused by: ClickHouse#119305 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
@m-selmi, it broke the CI again. |
Edited following .claude/skills/edit-changelog/SKILL.md. Manual catch-up run of the NightlyChangelog edit step, verified with `verify_edit` of `ci/jobs/changelog_nightly.py`. Changelog-revert: 119284 119279 Revert "Revert "Print file offsets in the bare fatal stack traces and build the release binary as PIE"" Changelog-revert: 120118 117137 Revert "Fix wrong results for `plus`/`minus` keys with a non-integer operand" Changelog-revert: 120119 119305 Revert "Convert `OUTER` join to `INNER` join by null-rejecting join conditions" again Changelog-deleted-entry: 114817 [Performance Improvement] [section] * Convert `OUTER JOIN` to `INNER JOIN` when a later `JOIN` condition filters out its `NULL`-extended rows, and filter `NULL` join keys directly at the table scan when column statistics show it is selective. Only conditions of the form `expr1` OP `expr2` are considered, where OP is one of `=`, `<`, `<=`, `>`, `>=`. Each side can be a column or an expression that propagates `NULL`s. Controlled by the new settings `query_plan_derive_not_null_filters_from_joins` (enabled by default), `query_plan_allow_derived_not_null_filters_execution` (enabled by default) and `query_plan_max_selectivity_for_not_null_filters_execution` (0.7 by default). [#114817](#114817) ([Hechem Selmi](https://github.com/m-selmi)). [#119305](#119305) ([Alexey Milovidov](https://github.com/alexey-milovidov)). Changelog-deleted-entry: 117137 [Bug Fix (user-visible misbehavior in an official stable release)] [section] * Fix wrong results when a `GROUP BY`, `DISTINCT`, `LIMIT BY` or window `PARTITION BY` key was `plus` or `minus` of a partition column with a non-integer constant, for example `x + 1.0` on `Float64` or `d + INTERVAL 1 MONTH` on `Date`. Such a key was assumed injective, so each table partition was evaluated independently without the cross-partition merge; where the key collapses distinct values onto one (float rounding, end-of-month arithmetic, a DST transition) the query returned one row or window frame per partition instead of one per group. Affects the default-enabled `allow_aggregate_partitions_independently`, `allow_distinct_partitions_independently`, `allow_limit_by_partitions_independently`, `allow_creating_set_partitions_independently`, `allow_window_partitions_independently` and `optimize_distributed_group_by_sharding_key`. [#117137](#117137) ([Groene AI](https://github.com/groeneai)). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Reverts #119275
Workflow [PR]
Sync PR [sync-upstream/pr/119305]
Version info
26.9.1.1483(included in26.9and later)