Skip to content

Fix mark rows mismatch during lightweight delete with non-adaptive granularity - #102592

Closed
Daedalus-Icarus wants to merge 1 commit into
ClickHouse:masterfrom
Daedalus-Icarus:fix/issue-98585
Closed

Daedalus-Icarus wants to merge 1 commit into
ClickHouse:masterfrom
Daedalus-Icarus:fix/issue-98585

Conversation

@Daedalus-Icarus

Copy link
Copy Markdown
Contributor

Lightweight DELETE mutations on tables with index_granularity_bytes = 0 (non-adaptive granularity) could cause a logical error after DETACH/ATTACH: "Incorrect mark rows for part ... in-memory N, on disk 8192".

The root cause: DELETE reports affectsAllColumns() == true, so MutateAllPartColumnsTask created a new index granularity object instead of reusing the source part's granularity. The new object was adjusted during writing to match the actual row count, but non-adaptive mark files don't store per-mark granularity, so validateColumnOfFixedSize saw a mismatch between the in-memory value and the fixed 8192 assumed from settings.

The fix reuses the source part's granularity for lightweight deletes, since they only update the _row_exists column without changing the row count.

Closes #98585
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=8bc6bb7c5c71412f303aa0705d11b667e2a6659c&name_0=MasterCI&name_1=BuzzHouse%20%28amd_debug%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 "Incorrect mark rows" during lightweight DELETE on tables with index_granularity_bytes = 0 after DETACH/ATTACH.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

No documentation changes are needed for this bug fix.

…anularity

Lightweight `DELETE` mutations on tables with `index_granularity_bytes = 0`
(non-adaptive granularity) could cause a logical error after `DETACH`/`ATTACH`:
"Incorrect mark rows for part ... in-memory N, on disk 8192".

The root cause: `DELETE` reports `affectsAllColumns() == true`, so
`MutateAllPartColumnsTask` created a new index granularity object instead of
reusing the source part's granularity. The new object was adjusted during
writing to match the actual row count, but non-adaptive mark files don't
store per-mark granularity, so `validateColumnOfFixedSize` saw a mismatch
between the in-memory value and the fixed 8192 assumed from settings.

The fix reuses the source part's granularity for lightweight deletes, since
they only update the `_row_exists` column without changing the row count.

Closes #98585
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=8bc6bb7c5c71412f303aa0705d11b667e2a6659c&name_0=MasterCI&name_1=BuzzHouse%20%28amd_debug%29
@Avogar Avogar added the can be tested Allows running workflows for external contributors label Apr 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ab3ce57]

Summary: ❌

job_name test_name status info comment
Fast test failure
02932_lwd_and_mutations FAIL cidb
04097_lightweight_delete_nonadaptive_granularity FAIL cidb
clickhouse-test FAIL cidb
Build (amd_debug) dropped
Build (amd_asan_ubsan) dropped
Build (amd_tsan) dropped
Build (amd_msan) dropped
Build (amd_binary) dropped
Build (arm_debug) dropped
Build (arm_asan_ubsan) dropped
Build (arm_tsan) dropped
Build (arm_msan) dropped

AI Review

Summary

This PR fixes a real correctness issue where lightweight DELETE on non-adaptive granularity parts could later trigger an "Incorrect mark rows" exception after DETACH/ATTACH. The code change in MutateTask is targeted and aligns with the root cause (preserving source index granularity for lightweight deletes). I found one minor issue in the new test comments (a typo), but no blockers or major correctness/safety regressions in the patch itself.

Findings

💡 Nits

  • [tests/queries/0_stateless/04097_lightweight_delete_nonadaptive_granularity.sql:4] Typo in the test comment: a "Incorrect mark rows" logical error should be an "Incorrect mark rows" logical error.
    • Suggested fix: replace a with an.
ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Apr 13, 2026
-- Tags: no-replicated-database

-- Lightweight DELETE on a table with non-adaptive index granularity (index_granularity_bytes = 0)
-- should not cause a "Incorrect mark rows" logical error after DETACH/ATTACH.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Typo in the test description: a "Incorrect mark rows" logical error should be an "Incorrect mark rows" logical error.

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

Projects

None yet

2 participants