Skip to content

Fix exception in projection calculation on empty blocks during merge - #98458

Merged
alexey-milovidov merged 2 commits into
masterfrom
fix-projection-empty-block-ttl
Mar 2, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
fix-projection-empty-block-ttl

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Mar 2, 2026 •

Copy link
Copy Markdown
Member

Linked issues

Summary

  • When TTL deletes all rows from a block during merge, aggregate projections with constant GROUP BY keys (e.g., GROUP BY 0.674) produce 1 row from 0 input rows, violating the ProjectionDataSink row count invariant and causing a LOGICAL_ERROR exception
  • Return an empty block early from calculateByQuery when the input has 0 rows
  • Added a test reproducing the scenario: a table with short TTL, an aggregate projection with constant GROUP BY, and a merge after rows expire

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=65930adc230a1309eca807a6b851b1a917f35feb&name_0=MasterCI&name_1=BuzzHouse%20%28amd_msan%29

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):

Fix LOGICAL_ERROR exception "Projection cannot increase the number of rows in a block" when merging parts with TTL that deletes all rows and an aggregate projection with a constant GROUP BY key.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

🤖 Generated with Claude Code

Version info

  • Merged into: 26.3.1.268
  • Backported to: 26.2.19.34

When TTL deletes all rows from a block during merge, the block has 0 rows.
Aggregate projections with constant `GROUP BY` keys (e.g., `GROUP BY 0.674`)
produce 1 row from 0 input rows, violating the `ProjectionDataSink` row
count invariant and causing a LOGICAL_ERROR exception.

Return an empty block early from `calculateByQuery` when the input has 0 rows.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=65930adc230a1309eca807a6b851b1a917f35feb&name_0=MasterCI&name_1=BuzzHouse%20%28amd_msan%29

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Mar 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [188c276]

Summary: ✅

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 2, 2026
The test now uses `max_number_of_merges_with_ttl_in_pool = 0` to prevent
background TTL merges from emptying the parts before `OPTIMIZE TABLE FINAL`.
Without this setting, background merges process TTL and produce empty parts
before the test can trigger the merge that exercises the bug.

Also improved the test structure: insert data BEFORE `ADD PROJECTION` so
that parts lack the projection metadata, forcing `calculateProjections`
(rebuild path) during the final merge. Combined with a TTL `WHERE` clause
to disable the `all_data_dropped` short-circuit in `TTLTransform`, this
ensures 0-row blocks reach `calculateProjections`.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

The fix makes sense.

@alexey-milovidov alexey-milovidov self-assigned this Mar 2, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Mar 2, 2026
Merged via the queue into master with commit 3fddc96 Mar 2, 2026
144 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-projection-empty-block-ttl branch March 2, 2026 14:16
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 2, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label May 18, 2026
robot-ch-test-poll3 added a commit that referenced this pull request May 18, 2026
Cherry pick #98458 to 26.2: Fix exception in projection calculation on empty blocks during merge
robot-clickhouse added a commit that referenced this pull request May 18, 2026
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label May 18, 2026
alexey-milovidov added a commit that referenced this pull request May 18, 2026
Backport #98458 to 26.2: Fix exception in projection calculation on empty blocks during merge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v25.12-must-backport v26.2-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants