Repository navigation
Conversation
`FillingRow::next` returned early whenever the next original value was NaN or infinite. ClickHouse#90255 added that to stop the ClickHouse#69261 hang, where the filling steps forever towards a NaN target with no TO. But the filling steps towards the border `findBorder` picks, the nearer of the TO/staleness constraint and the next original value, and when that border is a finite constraint before the non-finite value the stepping terminates on its own. The early return generated nothing before such a row, so the rows up to TO were produced after it (by the suffix, or by the next call in a later fill column), and with STALENESS the window border was replaced after the row and the rows were lost: SELECT arrayJoin([0., inf]) AS x ORDER BY x WITH FILL TO 3 -- 0, inf, 1, 2 instead of 0, 1, 2, inf An outer ORDER BY over it returned the same unsorted rows, because it trusts the order WITH FILL declares. Keep the early return only when no finite border comes before the value. For NaN with nulls_direction != 1 (DESC NULLS LAST, ASC NULLS FIRST) it stays as well: `accurateLess` orders NaN greatest, which is its sort position only for nulls_direction == 1, so the stepping and its callers misplace it there (dropping that clause makes [0, nan] NULLS FIRST FROM -1 TO 3 emit 0 twice). The 04657 case [0, nan, 5] STALENESS 2 now also returns 6, which is inside the staleness window of 5. Found in review of ClickHouse#118077. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Both non-finite stops in `FillingRow::next`, for a NaN or infinite cursor and for a NaN or infinite next original value, returned before the loop that fills the later fill keys towards their own constraints. That loop never steps the key at `pos`, so it cannot run into the ClickHouse#69261 hang; returning first only left the later keys of the current value unfilled, and they were produced after the next original row instead: SELECT a, b FROM (SELECT arrayJoin([(0., 0), (inf, 0)]) AS t, t.1 AS a, t.2 AS b) ORDER BY a WITH FILL, b WITH FILL TO 3 -- (0,0), (inf,0), (0,1), (0,2) instead of (0,0), (0,1), (0,2), (inf,0) The same happened with a `-inf` cursor before a finite row. Move both stops after the loop, so they guard only the step of `pos`. The NaN stop for nulls_direction != 1 stays before the loop: under ASC NULLS FIRST a NaN sorts first, but `less` does not place it before the cursor, so the loop would emit the later keys of a FROM cursor before the NaN row. Pin optimize_sorting_by_input_stream_properties = 1 on the outer ORDER BY case of 03239: with the randomized value 0 the outer sort repairs the order and the case no longer checks what a user sees by default. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the non-finite stop comment in FillingRow::next to one line; drop the sentence narrating its placement. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (2 rounds): 1 blocker + 1 major fixed, 2 findings declined
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261116-223800 |
|
Workflow [PR], commit [d56a164] Summary: ✅
AI ReviewSummaryThe fix restores bounded Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 8 s compile time in total, 7 of them have a recent master baseline. |
Related: #118077
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed wrong results of
ORDER BY ... WITH FILLwithTOorSTALENESSwhen the data contains an infinite value or, in ascending order, aNaN: generated rows were emitted on the wrong side of that value, so the result and an outerORDER BYover it were not sorted, and withSTALENESSthey were dropped.Description
On 26.10 (official 26.10.3.7),
SELECT arrayJoin([0., inf]) AS x ORDER BY x WITH FILL TO 3returns0, inf, 1, 2instead of0, 1, 2, inf, and an outerORDER BY xover it returns the same order, because the outer sort trusts theWITH FILLorder. The same happens withNaN, with-infunderDESC, withFROM, in a later fill column and withINTERPOLATE; withSTALENESSthe rows are lost ([0, inf] ... TO 5 STALENESS 3returns0, inf).Root cause.
FillingRow::nextstops at aNaNor infinite next original value (#90255, the fix of the #69261 hang) even when it steps towards a finiteTOor staleness border before that value, so the rows up to the border come after the row, or are dropped withSTALENESS. Its stops also returned before the later fill keys were filled.Change. Stop only when no finite border comes before the non-finite value, and only after the later fill keys are filled. For
NaNunderDESC NULLS LAST(theDESCdefault) orASC NULLS FIRSTthe old stop stays: theFieldcomparator ordersNaNgreatest, its sort position only forASC NULLS LASTandDESC NULLS FIRST.Tests. 14 queries appended to
03239_nan_with_fill(13 fail on master; one guards theNaNexception). In04657_with_fill_bounds_out_of_column_type_range,[0, nan, 5] ... STALENESS 2now also returns6, inside the staleness window of5.Unchanged (separate defects): after a leading infinity without
FROMno rows are generated ([-inf, 0, 3]stays-inf, 0, 3), and underDESC NULLS LASTorASC NULLS FIRSTgenerated rows are still misplaced around aNaN, because the comparator ordersNaNgreatest whatever theNULLSorder (theNULLS FIRSTpart is #118096).Found in review of #118077: #118077 (comment)
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/132176]