Repository navigation
Fix a join returning rows whose WHERE equality of Tuple or Variant values is NULL - #124854
Conversation
…lter when it becomes a JOIN key A JOIN key matches a NULL nested in a Tuple, or a NULL Variant or Dynamic, as an ordinary value, while `equals` returns NULL for such a pair, so a WHERE equality turned into a JOIN key returned rows the WHERE drops. `CrossToInnerJoinPass` and `mergeFilterIntoJoinCondition` still use such an equality as a JOIN key, and now also keep it as a filter. The kept filter only sees pairs the key matched, so it cannot hit a Variant type mismatch, and the merge adds the key to the join once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the two call-site comments on keyMatchesNullAsValue to one line each; drop the narration of the add-once check. 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; 0 findings) plus my own cold review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261009-071200 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261009-054100 |
|
Workflow [PR], commit [6986b4b] Summary: ✅
AI ReviewSummaryThis PR fixes a real correctness gap in the join rewrites: when a Missing context / blind spots
Final Verdict✅ No new inline findings for the current diff. |
…c keys are disallowed With `allow_dynamic_type_in_join_keys = 0` (the default) the planner rejects a `Dynamic` JOIN key with ILLEGAL_COLUMN. `CrossToInnerJoinPass` still turned a comma/CROSS `WHERE a = d` into such a key, so a valid filtered cross join threw instead of filtering. `mergeFilterIntoJoinCondition` already leaves such an equality in the filter; the analyzer pass now does the same. `FROM t_int, t_dyn WHERE a = d` returns the matching rows (it threw on master and returned no rows on 26.8.18.2 / 26.3.42.3), the same as with `cross_to_inner_join_rewrite = 0`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Commit See the job log for details. |
CI finish ledger - 5d3339eEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261009-140011 |
|
Fixing PR for |
|
@groeneai merge master to pickup fix for |
Closes: #125936
Related: #67493
Related: #116358
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed wrong results of a
WHEREequality betweenTuplevalues withNullableelements, or betweenVariantvalues, over a comma,CROSSorINNERjoin: the pair whose equality isNULL, such astuple(NULL) = tuple(NULL), was returned. Withallow_dynamic_type_in_join_keys = 0, a comma orCROSSjoin with aWHEREequality on aDynamicvalue no longer returns no rows or fails withILLEGAL_COLUMN.Description
On 26.8.21.12 (and 26.3.33.24, master),
SELECT ta.k, tb.k FROM ta, tb WHERE ta.t = tb.toverTuple(Nullable(UInt64))columns returns the pair oftuple(NULL)rows although the equality isNULL. The same holds forCROSS JOIN,INNER JOIN ... ON ta.k = tb.k WHERE ta.t = tb.t,LowCardinality(Nullable)or nested-tuple elements, andVariantvalues. Over 2M rows with 10%tuple(NULL)the comma query counted 40001800000 rows instead of 1800000.CrossToInnerJoinPassandmergeFilterIntoJoinConditionturn such an equality into a JOIN key and drop it fromWHERE. A JOIN key matches a NULL inside aTuple, or a NULLVariant, as an ordinary value (the intendedJOIN ONsemantics, #67493), whileequalsreturnsNULL. Since #125195 (master only),(l.key, l.x) = (r.key, NULL)also reaches both places as one tuple equality, so this fixes #125936 too.The change: for these types both places still use the equality as a JOIN key and also keep it as a filter. The filter only sees pairs the key matched (or, pushed down,
t = tper side), so it cannot hit aVarianttype mismatch (NO_COMMON_TYPE); the plan optimization adds the key once. The cost is oneequalsper joined row, for these types only; the key and the hash join stay.JOIN ONand other types are unchanged. In04665aDynamickey now keeps its filter too. Withallow_dynamic_type_in_join_keys = 0,CrossToInnerJoinPassnow leaves aDynamicequality inWHERE, likemergeFilterIntoJoinCondition. Float keys (-0.0vs0, #116358) are a separate case, not changed here.Validation: the new test fails on master in 17 of 21 lines and passes with the fix, 50/50 with random settings. Each part of the change is proven necessary by a deletion mutation. 2005 existing join/tuple/variant/dynamic tests: only
04665changed.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/124854]
Version info
26.10.1.2480-master(included in26.10and later)