Skip to content

Fix logical error in FillingTransform for INTERPOLATE aliasing a WITH FILL column - #110103

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-fillingtransform-interpolate-staleness-3366-35de
Jul 14, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-fillingtransform-interpolate-staleness-3366-35de

Conversation

@groeneai

@groeneai groeneai commented Jul 11, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #101099

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 a Invalid number of rows in Chunk logical error when an INTERPOLATE target is an alias of a WITH FILL column with the old analyzer (enable_analyzer = 0). Such queries are now rejected with a clear INVALID_WITH_FILL_EXPRESSION error.

Description

Found by the AST fuzzer on PR #101099 (STID: 3366-35de, AST fuzzer (amd_debug)), on a PR that only touches ProcessList and does not touch FillingTransform -- a pre-existing trunk bug. Fix provided in this separate PR per @ alexey-milovidov's request.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101099&sha=4e01b0f24bf0c5eb934973bb3ea83a976479cce0&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29

Deterministic minimal reproducer (old analyzer only):

SELECT * FROM (SELECT 1 AS a0, a0 AS a4 ORDER BY a0 WITH FILL INTERPOLATE (a4)) SETTINGS enable_analyzer = 0;
-- Logical error: 'Invalid number of rows in Chunk ...: expected 2, got 1' -> abort

Root cause: with the old analyzer, an INTERPOLATE target that only aliases a WITH FILL column is not materialized as a separate column, so interpolate_column_positions resolves to the same header position as fill_column_positions. Each generated gap-fill row is then written into that position twice (once by the filling loop, once by the interpolate loop) while other columns get a single insert, producing a chunk with inconsistent row counts. The new analyzer materializes a distinct column, so it is unaffected.

The FillingTransform constructor already guards the analogous sorting-prefix-vs-interpolate overlap. This PR adds the same guard for the fill-vs-interpolate overlap. Interpolating a column that IS the fill column is meaningless (its value is fully determined by the fill), so rejecting it with INVALID_WITH_FILL_EXPRESSION is the correct behavior; no previously-working query is affected (these queries abort today).

Version info

  • Merged into: 26.7.1.951 (included in 26.7 and later)

… FILL column

With the old analyzer (enable_analyzer=0), an INTERPOLATE target that only
aliases a WITH FILL column is not materialized as a separate column, so its
header position coincides with the fill column position. A generated gap-fill
row is then written twice into that position (once by the filling loop, once
by the interpolate loop) while other columns get a single insert, producing a
chunk with inconsistent row counts and a "Invalid number of rows in Chunk"
LOGICAL_ERROR abort at FillingTransform.cpp.

Reject this configuration in the FillingTransform constructor with a clear
INVALID_WITH_FILL_EXPRESSION exception, mirroring the existing guard for the
sorting-prefix-vs-interpolate overlap. Interpolating a column that IS the fill
column is meaningless (its value is fully determined by the fill), and the new
analyzer already materializes a distinct column so it is unaffected.

Found by the AST fuzzer (STID 3366-35de).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. SELECT * FROM (SELECT 1 AS a0, a0 AS a4 ORDER BY a0 WITH FILL INTERPOLATE (a4)) SETTINGS enable_analyzer=0; aborts every time (LOGICAL_ERROR Invalid number of rows in Chunk).
b Root cause explained? Yes. Old analyzer does not materialize a separate column for an INTERPOLATE target that only aliases a WITH FILL column, so interpolate_column_positions == fill_column_positions; each gap-fill row is inserted twice into that shared position (filling loop + interpolate loop) while other columns get one insert -> inconsistent chunk row counts -> checkNumRowsIsConsistent abort.
c Fix matches root cause? Yes. The constructor now detects the fill-vs-interpolate position overlap and rejects it with INVALID_WITH_FILL_EXPRESSION, mirroring the existing sort-prefix-vs-interpolate guard. Not a band-aid: interpolating a column that IS the fill column is meaningless.
d Test intent preserved / new tests added? New test 04402_with_fill_interpolate_fill_column_overlap added: asserts the overlap query is rejected (old analyzer), still returns a row on the new analyzer, and that a legit INTERPOLATE on a non-fill column still works.
e Demonstrated in both directions? Yes. Without fix: server aborts (LOGICAL_ERROR). With fix: clean INVALID_WITH_FILL_EXPRESSION exception, server alive; legit queries unaffected.
f Fix is general, not a narrow patch? Yes. The guard covers any fill/interpolate position overlap, not just the reproducer shape (any number of columns, any alias chain resolving to a fill position). Sibling sort-prefix overlap was already guarded; this completes the pair.
g Generalizes across inputs / datatypes / wrappers? Yes. Guard is purely positional (compares header positions), independent of column type, Nullable/LowCardinality/Array wrappers, STEP/STALENESS/TO clauses, or number of interpolate targets.
h Backward compatible? Yes. Queries that hit this overlap abort the server today, so no working query regresses; the change converts a crash into a clear user error. No setting default, on-disk, or wire format changed.
i Invariants and contracts preserved? Yes. Upholds the FillingTransform invariant that every output column receives exactly one insert per generated row; the guard rejects the only configuration that violated it. Chunk row-count consistency contract preserved.

Session id: cron:clickhouse-worker-slot-2:20260711-164000

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @KochetovNicolai @vdimir — could you review? Small fix in the FillingTransform constructor: reject the case where an INTERPOLATE target aliases a WITH FILL column (old analyzer), which currently aborts with Invalid number of rows in Chunk. Mirrors the existing sorting-prefix-vs-interpolate guard.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jul 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [03a44d3]

Summary: ✅


AI Review

Summary

This PR adds a constructor-time guard in FillingTransform that rejects INTERPOLATE targets collapsing onto the same output position as a WITH FILL column, converting an old-analyzer logical error into a user-facing INVALID_WITH_FILL_EXPRESSION. I reviewed the current diff, prior PR discussion, and the current code path around column-position setup and row insertion, and I did not find a correctness regression or a missing required follow-up in the patched state.

Final Verdict

✅ No blockers or majors found in the current diff.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.80% 85.80% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 78.00% 78.00% +0.00%

Changed lines: Changed C/C++ lines covered: 8/9 (88.89%) · Uncovered code

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 03a44d3

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Integration tests (amd_tsan, 3/6) / test_replicated_database::test_replicated_table_structure_alter flaky (chronic — 12 master hits + many unrelated PRs / 30d; unrelated to this PR's FillingTransform diff) #110030 (ours, open)
Stress test (amd_msan) / Got read request from replica A for unknown stream B (STID 5217-5b3d) flaky (parallel-replicas reading-coordinator trunk logical error; 6 PRs incl. master / 30d; unrelated to FillingTransform) a fix task is moved to pending (investigating at full effort — fixing-PR link to follow here)
Mergeable Check / PR rollup of the above owned via the rows above

This PR touches only src/Processors/Transforms/FillingTransform.cpp (a WITH FILL / INTERPOLATE ctor guard) plus a stateless regression test. Neither failure is in a code path this diff can affect — both are pre-existing trunk flakiness.

Session id: cron:our-pr-ci-monitor:20260712-010000

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a common use case? Does pre-existing logical error always fire? Otherwise, if we break existing working queries, it may not be backward compatible, even though it's only for the old analyzer.

@vdimir vdimir self-assigned this Jul 14, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

@vdimir Good question. I built the matrix on a debug binary (old analyzer, enable_analyzer = 0) with and without this patch. INTERPOLATE that aliases a WITH FILL column is rejected today in every case except one degenerate one:

  • Any such query that produces at least one output row aborts today with the Invalid number of rows in Chunk LOGICAL_ERROR (server abort in debug/sanitizer builds), e.g. the single-row reproducer, WITH FILL FROM..TO forcing gap rows, INTERPOLATE (a4 AS a4 + 1), etc.
  • The only variant that currently "works" is one over empty input (0 rows): no gap-fill row is generated, so the double-insert never happens and it returns an empty result. Add any row and the same query aborts.
  • When the INTERPOLATE target aliases a fill column via a real (non-constant) source column name, it is already rejected earlier with error 475 ("participating in ORDER BY expression and can't be INTERPOLATE output").

So the patch does not break any query that returns data today; it only converts an abort-on-any-data (empty-input-only success) into a clear, consistent error.

On "common use case": INTERPOLATE on the fill column itself is contradictory. The fill sequence already determines that column's value on generated rows, so interpolating the same column is meaningless. The common, useful case (INTERPOLATE on a non-fill column) is unaffected and still works.

This also matches the constructor's pre-existing symmetric guard for the sorting-prefix-vs-INTERPOLATE overlap, which rejects unconditionally too (including empty input). Rejecting the fill-vs-INTERPOLATE overlap the same way keeps the two consistent.

Happy to narrow it if you prefer, but given the only preserved-today behavior is an empty-result query that crashes on any data, I think the unconditional reject is the correct fix. New analyzer materializes a distinct column and is unaffected either way.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 14, 2026
Merged via the queue into ClickHouse:master with commit 2b4ea4c Jul 14, 2026
345 of 347 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 14, 2026
pull Bot pushed a commit to Lobinson1/ClickHouse that referenced this pull request Jul 15, 2026
The repo-wide style rule rejecting the "new analyzer" wording (ClickHouse#110160)
and the test 04402_with_fill_interpolate_fill_column_overlap.sql with a
"The new analyzer materializes ..." comment (ClickHouse#110103) were merged
independently, each with CI that predated the other, so every branch
containing both now fails "Style check". Reword the comment to
"The analyzer materializes ..." as the rule suggests. This is the only
occurrence in the repository.

Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ngtransform-interpolate-staleness-3366-35de

Fix logical error in FillingTransform for INTERPOLATE aliasing a WITH FILL column
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The repo-wide style rule rejecting the "new analyzer" wording (ClickHouse#110160)
and the test 04402_with_fill_interpolate_fill_column_overlap.sql with a
"The new analyzer materializes ..." comment (ClickHouse#110103) were merged
independently, each with CI that predated the other, so every branch
containing both now fails "Style check". Reword the comment to
"The analyzer materializes ..." as the rule suggests. This is the only
occurrence in the repository.

Co-Authored-By: Claude Fable 5 <[email protected]>
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 pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants