Skip to content

Fix ORDER BY WITH FILL mis-placing generated rows around a NULL value - #117832

Open
groeneai wants to merge 9 commits into
ClickHouse:masterfrom
groeneai:fix-with-fill-null-key-order-110321
Open

groeneai wants to merge 9 commits into
ClickHouse:masterfrom
groeneai:fix-with-fill-null-key-order-110321

Conversation

@groeneai

@groeneai groeneai commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #110321

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed ORDER BY ... WITH FILL over a Nullable column with a single NULLS LAST fill key, where that key either comes first in ORDER BY or use_with_fill_by_sorting_prefix is enabled (the default): when a row held NULL in that key, a generated row could be emitted after that NULL instead of before it, be emitted twice, or be dropped, which made the result violate its own ORDER BY and could raise Equal values are not contiguous within the range assumed to be sorted in DISTINCT-in-order.

Description

Found by Stress test (amd_debug), STID 2508-4384. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110321&sha=42e6fb428c3380e4904795ba4e6136c94dc0a23c&name_0=PR&name_1=Stress%20test%20%28amd_debug%29

FillingRow compares fill values as Fields, where a NULL is unordered, while the ORDER BY positions it through nulls_direction. All three sites in FillingTransform that place a pending generated row therefore read "unordered", and generateSuffixIfNeeded's next_row.isNull() disjunct, added for the empty-result-set case, covers for them: right under NULLS FIRST, wrong under NULLS LAST.

Wrong results in a release build, with no DISTINCT or UNION:

SELECT number % 2 ? NULL : toNullable(toInt32(number)) AS x
FROM numbers(2) ORDER BY x ASC WITH FILL FROM 1 TO 3;
-- before: 0, 2, \N, 2   (FROM row dropped, 2 repeated after the NULL)
-- after:  0, 1, 2, \N

I supply the missing direction at those three sites, scoped to a single WITH FILL key that no defaulted ORDER BY key precedes - the only decidable case: with two or more keys a partial-NULL row sorts strictly between the all-real and all-NULL rows, so neither side of the latter is its place.

Measured over 288 generated WITH FILL shapes on pristine and fixed debug builds: 275 byte-identical, 10 mis-orderings repaired, none newly mis-ordered or aborting. The same rebuilds show both scope exclusions load-bearing - dropping the single-key conjunct re-aborts two two-key shapes - so the test pins only what this PR changes; say if you want the exclusions pinned too.

Left unchanged from master, each still able to raise the same exception under DISTINCT-in-order: two or more fill keys; NULLS FIRST, where FillingRow::findBorder reads a NULL next value as "no border" and fills past it; and use_with_fill_by_sorting_prefix = 0 with an ORDER BY key ahead of the fill key, whose default a generated row takes. STALENESS is only partly repaired: FillingRow::shift is untouched, so its mis-ordering and the exception remain.

How often this message is seen (CIDB)

The assertion text is a coarse bucket spanning about 15 distinct failure signatures, so the sub-family that actually carries a WITH FILL query is the useful count:

SELECT count() AS rows, uniqExact(pull_request_number) AS prs,
       countIf(head_ref = 'master' AND pull_request_number = 0) AS master_rows
FROM default.checks
WHERE check_start_time > now() - INTERVAL 30 DAY
  AND test_status IN ('FAIL','ERROR')
  AND test_context_raw LIKE '%Equal values are not contiguous%'
  AND test_context_raw LIKE '%WITH FILL%'
rows    prs     master_rows
13      12      0

Without the WITH FILL predicate the same 30 days give 208 rows / 175 PRs / 8 master rows, i.e. mostly unrelated mechanisms. The reported signature itself, STID 2508-4384, has 2 rows in 90 days and none on master: PR 108129 AST fuzzer (amd_debug, targeted, old_compatibility) on 2026-07-02 and this report on 2026-08-31.


Workflow [PR]
Sync PR [sync-upstream/pr/117832]

groeneai and others added 8 commits September 2, 2026 17:39
When a row has NULL in every WITH FILL key, FillingTransform cannot tell which
side of that row the fill range belongs on. FillingRow compares with Field
semantics, in which a NULL is unordered, while the ORDER BY gives it a definite
position through nulls_direction. Three sites therefore get "unordered" as the
answer, and the generated row is emitted after the NULL, emitted twice, or
dropped, so the result violates its own ORDER BY.

For a Nullable fill column with a sorting prefix the stray row lands in the same
chunk as the rows around it, and DISTINCT in order above the fill then trips
`Equal values are not contiguous within the range assumed to be sorted` in
ColumnNullable::getEqualRangeEndAssumeSorted. In a release build the same stream
is returned as wrong results: a duplicated row that survives SELECT DISTINCT,
and the row promised by the FROM bound missing.

The fix adds FillingRow::isNullsLast, a pure accessor over nulls_direction, and
consults it at the three sites that have to place a pending generated row:
the new-range preamble, the row loop, and generateSuffixIfNeeded. The one
overloaded condition in generateSuffixIfNeeded is split into the three questions
it was actually answering, so the empty-result-set case from ClickHouse#30888 is asked
explicitly through a new parameter instead of through the next_row.isNull()
proxy it had been borrowing.

FillingRow.cpp is deliberately untouched. Making its comparison nulls_direction
aware was tried and rejected: a NULL inside the filling row is ambiguous between
"this key has no FROM" and "a copied real NULL value", and disambiguating it
needs per-position set/unset state. Making FillingStep stop advertising
preserves_sorting was also rejected, because it removes the assert but leaves the
wrong output, which reproduces with no DISTINCT and no UNION at all.

Found by Stress test (amd_debug) on ClickHouse#110321, STID 2508-4384:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110321&sha=42e6fb428c3380e4904795ba4e6136c94dc0a23c&name_0=PR&name_1=Stress%20test%20%28amd_debug%29

Related: ClickHouse#114352

Known gap, pending a design decision: with two or more fill keys, a row whose
keys are all NULL can have partial-NULL rows sorting between it and where the
pending row is placed, so the row loop change can move a pre-existing stray row
from the end-of-stream chunk into a checked chunk. Measured in 2 of 192 two-key
shapes; single-key and non-Nullable shapes are unaffected.
The previous commit applied the fix to any number of WITH FILL keys. Measured
over 288 generated WITH FILL shapes on both a pristine and a fixed debug build,
that scope repaired 20 mis-ordered outputs but turned 2 of the 24 two-key
all-NULLS-LAST shapes from a silent mis-ordering into `Equal values are not
contiguous within the range assumed to be sorted` in debug builds, which is the
very exception this change exists to remove.

The placement question is only decidable for one fill key. With one, a row's
fill keys are either all real or all NULL, so the all-NULL rows form a single
block at one end of the range and a generated row belongs immediately before it
under NULLS LAST. With two or more there is a third class, rows holding a real
value in some keys and NULL in others, which sorts strictly between the two, and
no condition at these three sites can place a generated row relative to a class
the comparison cannot order. The 2 regressions are exactly that: the row loop
placed the pending row immediately before the all-NULL row, which is after a
partial-NULL row that sorts earlier.

So all three conditions are now gated on isSingleNullsLastFillKey, and
FillingRow::isNullsLast is reverted: with a whole-row flag it has no caller, and
FillingRow is untouched again.

The gate is two-sided and exact. Where it is false each site is textually what it
was before either commit, so those inputs are unchanged by construction; where it
is true the three sites behave exactly as the previous commit made them. Measured
on the same 288 shapes: 275 byte-identical to master, all 13 differences inside
the single-key NULLS LAST slice, 10 mis-ordered outputs repaired, none newly
mis-ordered and none newly raising the exception. The 24 in-scope shapes are
byte-identical between the two scopes, so nothing the previous commit fixed for a
single fill key is lost.

The cost is the 10 two-key improvements the wider scope also bought. Gating only
the row loop was rejected: it would keep some of them with no measured
regression, but it needs two different scopes at three sites in one function and
leaves the multi-key half safe only by measurement rather than inert by
construction.

Two or more fill keys, NULLS FIRST, and STALENESS are therefore unchanged from
master, and are listed in the pull request description.

Co-Authored-By: Claude Opus 5 <[email protected]>
`02562_with_fill_nullable` set `optimize_distinct_in_order = 1` and then
asserted only the result rows. The setting requests the optimization,
nothing asserted it was applied. `DistinctStep::transformPipeline` picks
`DistinctSortedStreamTransform` only when the distinct sort description is
non-empty, and otherwise falls back silently to the hash-based
`DistinctTransform`, which deduplicates without looking at the stream.

That stream check is what this file most needs to keep. A stream
`(0,1) (0,2) (0,\N) (0,1) (1,1) (1,2) (1,\N)`, one row re-emitted and none
dropped, reduces under `DistinctTransform` to exactly the six reference rows
in the reference order, so the test would stay green while
`DistinctSortedStreamTransform` raises the `Equal values are not contiguous`
logical error on the non-contiguous `(0,1)`.

Assert the transform with `EXPLAIN PIPELINE` wrapped in a subquery, so the
assertion does not depend on the plan text layout. The comment above the
query is also corrected: the order-sensitive reference does check that the
generated rows are sorted, what needs both the subquery and the setting is
the contiguity check on the underlying stream.

The assertion is live rather than vacuous: it returns 1 with
`optimize_distinct_in_order = 1` and 0 with `optimize_distinct_in_order = 0`,
under both `enable_analyzer = 1` and `enable_analyzer = 0`.
…ey is defaulted

`isSingleNullsLastFillKey` decided the `NULLS LAST` placement from the fill
description alone, but `FillingTransform` only builds a sorting prefix when
`use_with_fill_by_sorting_prefix` is set. With the setting off, an `ORDER BY`
key that precedes the fill key is an ordinary column, so `insertFromFillingRow`
gives a generated row that key's default value instead of the original row's.
That key is the first sort key, so it decides the generated row's position
before the fill key is consulted, and relocating the row to a fill-key-correct
place can then violate the full `ORDER BY`.

Measured on

    SELECT toInt32(number) - 2 AS p, number % 2 ? NULL : toNullable(toInt32(number)) AS x
    FROM numbers(2) ORDER BY p ASC, x ASC NULLS LAST WITH FILL FROM 1 TO 2
    SETTINGS use_with_fill_by_sorting_prefix = 0

master returns the sorted `(-2,0), (-1,NULL), (0,1)`, while the earlier commits
on this branch returned `(-2,0), (0,1), (-1,NULL)`, with `p` running -2, 0, -1.

`isSingleNullsLastFillKey` now also requires that no `ORDER BY` key precede the
fill key when the sorting prefix is not built, which makes every such site
textually equal to master again. Over the 24-cell
`use_with_fill_by_sorting_prefix = 0` sweep this trades 6 of the 12 `UNSORTED`
to `clean` repairs back for zero rightward transitions: the 6 that remain are
the ones with no preceding key, and all 12 cells that do have one become
byte-identical to master. Queries with the setting at its default are
unaffected, since the new condition is a disjunction on it.

Copying a preceding key's value into generated rows instead is precisely what
`use_with_fill_by_sorting_prefix = 0` opts out of, so that is deliberately not
done here.
…rder `DISTINCT`

Two gaps in `02562_with_fill_nullable`, both of which let a real regression pass.

`isNullPlacementDecidable` returns true when the sorting prefix is built, when
`ORDER BY` is empty, or when the fill key is the first sort key. Only the first
of those three was exercised: cases 1 to 3 run at the default
`use_with_fill_by_sorting_prefix = 1`, where the first disjunct short-circuits,
and case 4 pins the predicate being false by placing `p` ahead of the fill key.
Deleting the third disjunct therefore left the whole file green while every
query that has the setting off and the fill key first silently reverted to the
old, wrongly ordered output. The new case is that query. It returns
`0, 1, 2, NULL` here and `0, 2, NULL, 2` both on master and with the disjunct
deleted, so it pins the repaired behaviour rather than the pre-existing one.

The `EXPLAIN PIPELINE` assertion collapsed two `DistinctStep`s into
`count() > 0` over rows matching `DistinctSortedStreamTransform`. That is
satisfied by the upper stage alone, so if only the lower stage, the one sitting
on `FillingTransform`, degraded to the hash `DistinctTransform`, the hash stage
would drop the non-contiguous duplicate before the sorted stage could see it:
no abort, the six result rows unchanged, and the assertion still green with the
bug present. It now requires that no hash stage exist anywhere in the pipeline,
which is equivalent to every stage being the in-order one because
`DistinctStep::transformPipeline` emits `DistinctSortedStreamTransform` when
`distinct_sort_desc` is non-empty and `DistinctTransform` otherwise, and this
query builds no `IN` or `JOIN` set for `CreatingSetsStep` to add one. Asserting
a stage count instead would pin an unrelated planner detail, and
`EXPLAIN PIPELINE` may render repeated processors collapsed, so a row count is
not a reliable proxy for one.

Co-Authored-By: Claude Opus 5 <[email protected]>
The predicate no longer only asks whether there is a single `NULLS LAST` fill
key: it also requires that the fill key is the key which decides a generated
row's position, so that no preceding `ORDER BY` key the row would default can
decide it first. The old name misread worst at the
`current_value.isNull() ? ... : less(...)` site, where it said "if the value is
`NULL`, insert if there is a single `NULLS LAST` fill key", which is not the
condition being tested. The helper's own comment already says "decidable", so
the names now follow it.

Identifier text only. No condition, comment or signature changes.

Co-Authored-By: Claude Opus 5 <[email protected]>
`WITH FILL` fills the half-open range `[FROM, TO)`, and equal bounds are legal:
`PlannerSorting` and `InterpreterSelectQuery` reject only a strictly inverted
range, so `FROM 1 TO 1` parses in both directions and under both analyzers and
must fill nothing.

Of the three sites this branch touches, the new-range preamble in
`FillingTransform::transformRange` is the only one that inserts without asking
whether the filling row still satisfies its constraints: the row loop conjoins
`FillingRow::isConstraintsSatisfied`, and `generateSuffixIfNeeded` returns early
on it. Master never reached the preamble's insert for a `NULL` first value,
because `less(fill_from, NULL, dir)` is always false there: `accurateLess` maps a
Null operand to `isPositiveInfinity` or `isNegativeInfinity`, and a plain SQL
`NULL` is neither. Replacing that arm with `null_placement_decidable` earlier on
this branch made the unguarded insert reachable for the first time, so

    SELECT if(number < 100, NULL, toNullable(toInt32(number))) AS x
    FROM numbers(2) ORDER BY x ASC WITH FILL FROM 1 TO 1

returned `1, NULL, NULL` here against `NULL, NULL` on master, with the `1`
outside the range the query declared. `ORDER BY x DESC` was the same defect,
since `DESC` defaults to `NULLS LAST`.

The `NULL` arm now conjoins `FillingRow::isConstraintsSatisfied`, which also
makes the three sites consistent. `null_placement_decidable` guarantees a single
fill key, and at size 1 that accessor reduces to true when `fill_to` is unset and
to `less(row[0], fill_to, dir)` otherwise, so `TO 1` no longer inserts while
`TO 3` and a missing `TO` are unchanged. Exactness is preserved: when
`null_placement_decidable` is false the arm is false, which is what master's
`less(fill_from, NULL, dir)` always returned.

The non-`NULL` arm's insert stays unguarded. It is pre-existing and behaves
identically on master, where `x = [5]` with `FROM 1 TO 1` also emits `1, 5`, so
guarding it would change output for existing queries and is left alone.

Co-Authored-By: Claude Opus 5 <[email protected]>
`02562_with_fill_nullable` had no case with an empty `[FROM, TO)` range, so
neither of its oracles could see a row inserted outside the declared range. The
order-sensitive reference cannot: under `NULLS LAST` a spurious `1` ahead of the
trailing `NULL` rows is itself in order, so nothing about the row ordering is
violated. The `EXPLAIN PIPELINE` assertion cannot either, since it pins only
which `DISTINCT` transform runs.

The two new queries use `FROM 1 TO 1`, one `ASC` and one `DESC`, over the file's
existing all-`NULL` `Nullable(Int32)` idiom. Both return the two `NULL` rows and
nothing else. Dropping `FillingRow::isConstraintsSatisfied` from the preamble's
`NULL` arm makes both emit a leading `1` and reddens the file, while the five
pre-existing cases stay green, because they use `TO 3` or `TO 2`, where that
conjunct is true.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 3, 2026
@groeneai

groeneai commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: one residual, already noted in the description

⚠️ The multi-key and NULLS FIRST scope guards are not pinned by a committed case. Both are
proven load-bearing by per-arm rebuilds instead: dropping the single-key conjunct takes two two-key
NULLS LAST shapes from rc=0 to rc=134, and dropping the NULLS LAST conjunct relocates the
NULLS FIRST rows. I left them unpinned because a committed case would assert behaviour this change
leaves byte-identical to master, and the file already carries seven cases for a 42-line fix. Tell me
if you want them pinned.

💡 Fixed before publishing: the fix was narrowed from any number of fill keys to one, because the
wider scope turned 2 of 24 two-key shapes into the same exception it removes; FROM 1 TO 1 no longer
fills an empty range around a NULL; and the test now asserts that the in-order DISTINCT is the
transform it exercises, since the hash one drops the non-contiguous duplicate before the sorted one
can see it.

@clickhouse-gh

clickhouse-gh Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8fdf5e9]

Summary: ❌

job_name test_name status info comment
AST fuzzer (amd_debug, targeted) FAIL
Logical error: 'Equal values are not contiguous within the range assumed to be sorted' (STID: 2508-4384) FAIL cidb

AI Review

Summary

This PR narrows the WITH FILL fix to the cases where a generated row's position around a NULL fill key is actually decidable, and it adds focused stateless coverage for the repaired NULLS LAST cases plus the two regressions raised in discussion (FROM = TO and missing TO). I did not find a remaining correctness issue in the touched FillingTransform paths.

Missing context / blind spots
  • ⚠️ Praktika currently exposes only Build profile diff for this PR. I could not validate the new 02562_with_fill_nullable cases against a current functional CI run or a local build; a green stateless run, and ideally the stress family that originally found the bug, would close that gap.
Final Verdict

✅ No new inline review findings to post. The current head addresses the discussed upper-bound regression, and the remaining risk is limited to missing functional CI evidence rather than a code-level defect I can point to.

LLVM Coverage Report

Measured on commit 8fdf5e9.

Metric Baseline Current Δ
Lines 88.70% 88.70% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 81.00% 81.00% +0.00%

Changed lines: Changed C/C++ lines covered: 45/45 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 3, 2026
@groeneai

groeneai commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

cc @yariks5s @davenger, could you review this? FillingRow compares fill values as Fields, where a NULL is unordered, so all three sites in FillingTransform that place a pending generated row read "unordered" around a NULL fill key and emit it after the NULL, emit it twice, or drop it. I supply the nulls_direction the ORDER BY already carries, scoped to the single-fill-key case in which the placement is decidable.

@PedroTadim

Copy link
Copy Markdown
Member

cc @yakov-olkhovskiy

@zlareb1

zlareb1 commented Sep 3, 2026

Copy link
Copy Markdown
Member

I traced both new insert sites end to end and the fix is sound for its claimed scope: the headline FROM..TO shape, the all-NULL preamble, the TO-only duplicate-after-NULL, the DESC analog, NULL at a chunk boundary (the next_row/filling_row state carries across chunks and the site at the flush point fires correctly), and the per-range suffix under a sorting prefix all come out right, and I verified the non-decidable fallback (NULLS FIRST, multiple fill keys) degrades byte-identically to master because accurateLess on a plain NULL versus a value was already unconditionally false in both directions. STALENESS cannot interact with the new inserts since STALENESS + FROM is rejected at validation.

One behavior change looks undisclosed and worth a decision before merge. With FROM but no TO, a trailing NULL now materializes the bare FROM row that master never emitted. For rows [0, NULL] with ORDER BY x ASC WITH FILL FROM 1: at the NULL row should_insert_first is true, the new decidability disjunct passes, and isConstraintsSatisfied is vacuously true because with no TO and no STALENESS there is no constraint at all — so the output becomes 0, 1, \N where master (verified on a 26.9 build) produces 0, \N. The all-NULL variant does the same through the preamble site: [NULL, NULL] with FROM 1 becomes 1, \N, \N instead of \N, \N. Two reasons to treat this as a defect rather than a side effect: the documentation defines an omitted TO as "use maximum expr field value from ORDER BY", which for [0, NULL] is 0, making the fill range [1, 0) empty; and the PR's own convention for an empty result set with FROM 1 and no TO is to emit nothing (the suffix path returns before the insert), so whether the FROM row exists now depends on a NULL row being present versus no rows at all. The committed NULL tests all carry both FROM and TO, so nothing pins this case either way. If the emission is intended, it deserves a test and a line in the description; if not, the insert sites need a "has a real upper bound" condition next to isConstraintsSatisfied rather than the vacuous pass.

Minor, no action needed: isNullPlacementDecidable reads the raw sort description rather than the deduplicated one, which can only deny decidability (a missed fix, never a wrong row), and the interpolation for the new inserts now derives from the pre-NULL row instead of the NULL row, which is an improvement.

@clickhouse-gh

clickhouse-gh Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 8fdf5e908 with master fb0b23675 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

8 translation units recompiled, 14 s compile time in total, 8 of them have a recent master baseline.

Job report

`FROM` without `TO` (and without `STALENESS`, which validation rejects together
with `FROM`) leaves `FillingRow` with no constraint at all, so
`isConstraintsSatisfied` is vacuously true and the two `NULL` arms added by this
pull request emitted the bare `FROM` row in front of a trailing `NULL`: rows
`[0, NULL]` with `ORDER BY x ASC WITH FILL FROM 1` returned `0, 1, \N` instead
of `0, \N`, and `[NULL, NULL]` returned `1, \N, \N` instead of `\N, \N`.

An omitted `TO` makes the sequence of filling use the maximum `expr` field value
from `ORDER BY`, and a `NULL` is never that value, so the range is empty and no
row belongs in it. The same input without the trailing `NULL` already emits no
`FROM` row, so whether that row exists must not depend on a `NULL` being
present.

`hasSomeConstraints` is the existing test for a real upper bound, already paired
with `isConstraintsSatisfied` in `generateSuffixIfNeeded`. Require it in the two
`NULL` arms as well; the non-`NULL` arms keep their previous conditions exactly.

Reported by zlareb1.
@groeneai

groeneai commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

Reproduced both shapes on the head and against a master build: [0, NULL] with ORDER BY x ASC WITH FILL FROM 1 gave 0, 1, \N where master gives 0, \N, and [NULL, NULL] gave 1, \N, \N where master gives \N, \N. It was not intended, so it is guarded rather than documented: 8fdf5e9

Your reading of the cause is right, and one more control makes it decisive: the same input without the trailing NULL already emits no FROM row on either build ([0] with FROM 1 gives 0), so whether that row exists must not depend on a NULL being present. hasSomeConstraints is the existing test for a real upper bound and generateSuffixIfNeeded already pairs it with isConstraintsSatisfied, so I now require it in the two NULL arms as well; the non-NULL arms keep their previous conditions unchanged. Both shapes match master again, the headline FROM 1 TO 3 case still returns 0, 1, 2, \N, and both are pinned in 02562_with_fill_nullable.

Agreed on the two minor points, and I left both as they are: the raw sort description can only deny decidability, and the interpolation source follows from where the insert happens.

Verification: 24-test WITH FILL/INTERPOLATE regression list green, 02562_with_fill_nullable 50/50 at -j 8.

@groeneai

groeneai commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 8fdf5e9

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
fixing-PR link will be posted here when it opens.

Check / test Reason Owner / fixing PR
AST fuzzer (amd_debug, targeted) / Logical error: 'Equal values are not contiguous within the range assumed to be sorted' (STID 2508-4384) pre-existing on master: the NULLS FIRST case this description already lists as left unchanged a fix task is created (investigating at full effort, fixing-PR link to follow here)

That red carries the assertion this PR exists to remove, so the attribution needs measurement rather than a
claim. The targeted fuzzer mutated one of the new 02562_with_fill_nullable queries into the NULLS FIRST
arm, which isNullPlacementDecidable excludes, so on that arm this patch is textually master. Both debug
builds, optimize_distinct_in_order = 1:

shape                                             master bb3c0a85   this head 8fdf5e90
the fuzzer's own query, fill key ASC NULLS FIRST   abort             abort
the same query, fill key ASC NULLS LAST           abort             0 1 / 0 2 / 0 \N / 1 1 / 1 2 / 1 \N

The second line is the control: the null direction is the only difference between the two, and it is what
decides whether the fix applies. So the fuzzer found the residual, not a regression. The defect needs neither
a sorting prefix nor DISTINCT, and is identical on both builds, which is why I am tracking it separately
instead of widening this PR:

SELECT if(number < 7, NULL, toInt32(number)) AS x FROM numbers(1)
ORDER BY x ASC NULLS FIRST WITH FILL FROM 1 TO 3;
-- both builds: 2, \N, 2   (1 dropped, 2 repeated around the NULL)

Mergeable Check and CH Inc sync are both green at this head.

Session id: cron:clickhouse-maint-slot-14:20260903-200600

@groeneai

groeneai commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the ledger row above: #118096

It covers the NULLS FIRST half this description lists as unchanged, so STID 2508-4384 and the wrong
results behind it are owned there. The two do not interact in either merge order: every guarded site in
#118096 is gated on nulls_direction != direction, every site here on the equality, and the 27-shape
matrix over the excluded shapes is byte-identical across both.

@clickhouse-gh clickhouse-gh Bot added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Sep 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants