Repository navigation
Fix a join returning a pair of NaN rows for a WHERE float equality - #126071
alexey-milovidov merged 1 commit into
Conversation
A JOIN key treats a NaN as equal to a NaN (bitwise in a hash join, by `compareAt` in a sorting merge join), while `nan = nan` is false. When `query_plan_merge_filter_into_join_condition` or `CrossToInnerJoinPass` turns a `WHERE a.f = b.g` conjunct into a JOIN key and drops it from the filter, a pair of NaNs is returned that the query rejects. Extend the predicate that keeps such a conjunct in the filter (added for NULLs nested in a Tuple) to floats: Float32, Float64 and BFloat16, at the top level, under Nullable/LowCardinality and as Tuple elements. The equality is still a JOIN key, so the hash join is kept and only NaN pairs are dropped by the filter. Array and Map are not affected: their `equals` treats NaN as equal, like the key. The `-0.0` direction (the key misses `-0.0 = 0.0`) is the hash table key semantics and is not changed here. Related: ClickHouse#116358 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; 2 findings in round 1, 0 in the delta recheck).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261015-163400 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261015-161600 |
|
Workflow [PR], commit [e172e01] Summary: ✅
AI ReviewSummaryPreserves floating-point Missing context / blind spots
Final VerdictStatus: ✅ Approve. |
|
cc @m-selmi @antaljanosbenjamin, could you review this? It extends the #124854 guard to floats: a |
alexey-milovidov
left a comment
There was a problem hiding this comment.
While I don't like the fact that someone wants to fix this, the fix itself is good and well contained.
fac8f9e
Backport #126071 to 26.10: Fix a join returning a pair of `NaN` rows for a `WHERE` float equality
Related: #116358
Related: #124854
Related: #115970
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 between float values over a comma,CROSSorINNERjoin, or in a correlatedEXISTS: a pair ofNaNvalues was returned, althoughnan = nanis false.Description
On 26.8.18.2 (and 26.9.16.11, master),
SELECT count() FROM a INNER JOIN b ON a.k = b.k WHERE a.f = b.greturns 1 when both rows holdnan, and 0 withquery_plan_merge_filter_into_join_condition = 0. The same holds for comma andCROSSjoins, a correlatedEXISTS (SELECT 1 FROM b WHERE b.g = a.f),full_sorting_merge, andFloat32,BFloat16,Nullable,LowCardinalityorTupleelement floats. 26.3 and 26.7 return 0 for theINNERand comma joins.mergeFilterIntoJoinConditionandCrossToInnerJoinPassturn such an equality into a JOIN key and drop it from the filter. A JOIN key treats aNaNas equal to aNaN(bitwise in a hash join, bycompareAtin a sorting merge join; the documentedJOIN ONbehaviour), whileequalsfollows IEEE.The change extends the check #124854 added for
NULLs nested in aTuple(keyMatchesNullAsValue, renamed tokeyMatchesValuesEqualsRejects) to float types: the equality stays a JOIN key and is also kept as a filter, which is pushed down asf = fper side. The hash join stays.JOIN ON, non-float types, andArray/Map(whoseequalsalready treatsNaNas equal) are unchanged. On 2M rows per side (debug build), the comma join took 0.071 s before and 0.075 s after,INNER JOIN ... WHERE a.f = b.g0.155 s and 0.168 s.The
-0.0direction of #116358 (the key does not match-0.0to0) is the hash table key semantics, handled by #115970.Validation: the new test fails on master in all 14 data lines and both float
EXPLAINlines and passes with the fix, 50/50 with random settings. Each part of the change is proven necessary by a mutation. 1414 existing join tests: no new failures.Workflow [PR]
Sync PR [sync-upstream/pr/126071]
Version info
26.11.1.174-master(included in26.11and later)