Repository navigation
Fix projections returning lightweight-deleted rows after a mutation rebuilds them on a Wide part - #111809
Conversation
… mode) A normal (non-aggregate) projection with no WHERE is calculated at QueryProcessingStage::FetchColumns, which stops before the WHERE step. The lightweight-delete rebuild path injected WHERE _row_exists = 1 into the projection query to drop deleted rows, but at FetchColumns that filter was never applied, so the projection was rebuilt from all rows including the deleted ones and a projection-served query could return deleted rows. The deletion mask is a data-level filter independent of the projection query, so for the FetchColumns path drop the deleted rows from the input block directly. The _part_offset column, when present, is filtered by the same mask so surviving rows keep their original parent offsets. FetchColumns is kept because the projection part is sorted afterwards by writeTempProjectionPart. Filtered and aggregate projections already ran at WithMergeableState and applied the injected filter correctly; that path is unchanged. Closes: ClickHouse#111791 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-author-slot-1:20260724-135200 |
Internal second-model review — adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 4 findings across 1 full pass + 1 fix round + 1 delta recheck).
Severity: ❌ blocker / Session id: cron:clickhouse-author-slot-1:20260724-135200 |
|
cc @CurtizJ — could you review this? A normal projection with no WHERE is rebuilt at |
|
Workflow [PR], commit [e4e17f6] Summary: ✅
AI ReviewSummaryReviewed Missing context / blind spots
Findings
Final Verdict |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 18/18 (100.00%) · Uncovered code |
CI finish ledger - 8b8a425CI is finished. Finish Workflow passed; all builds, integration, unit, fuzzer, and flaky-check runs are green. The new
None of the failures touch the projection / lightweight-DELETE code path this PR changes. Session id: cron:our-pr-ci-monitor:20260725-000000 |
|
Fixing PR for the The which is the query #110048 fixes (it restores the per-query storage-cache pinning that #108728 defeated, so a query keeps reading the table version it was planned against when a concurrent |
|
@Algunenano the fix is small, maybe you can review this PR? |
|
@CurtizJ this should be easy to review |
|
@alexey-milovidov you have to be the one to review it 😄 |
|
Friendly bump @alexey-milovidov! We’re running into this issue on ClickHouse Cloud and would appreciate a look when you have a chance. Thanks! |
|
@groeneai please fix the failing test and update WhatIfProjectionEstimator.cpp if needed |
|
The fix now applies the deletion mask in two ways: a source-block filter for normal projections without a
Option 1 looks like the simplest correct fix to me, unless there is a reason to keep the aggregate/filtered path untouched (for example, backport risk). This comment was written by AI. |
…jection type Filter the source block by `_row_exists` for normal, filtered and aggregate projections alike, and remove the `WHERE _row_exists = 1` AST injection. For a filtered or aggregate projection the existing `WHERE` then runs on the surviving rows, which selects the same rows as the old combined condition, and the deletion handling no longer depends on the stage chosen for the projection. `FilterDescription` accepts a const, sparse or nullable mask. `EXPLAIN WHATIF` modelled the old behaviour, where a normal projection without a `WHERE` kept the deleted rows. Its whole-part scan now reads the materialized `_row_exists` mask and drops the deleted rows after the read limits are charged, so a deleted-heavy part still counts every row it scans. A part whose rows are all deleted gets no projection part from the writer, so it is charged its parent ranges, as `optimizeUseNormalProjections` does, and when no part read keeps a row the empirical estimate is declined, since the real optimizer then rejects the projection. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Both done in 2608c7a. Design: I took option 1. Failing test: The lightweight delete projection tests and the |
…ild-normal-projection-stale # Conflicts: # src/Storages/MergeTree/WhatIfProjectionEstimator.cpp
… lightweight deletes Master's estimator now reads a sample of granules past `projection_scan_budget_rows` and maps every sampled row to the granule it came from to model the whole part. Since the projection input drops lightweight-deleted rows, the estimator drops them too, so the sample no longer lines up with the granules read and the whole-part row count it scales to still includes the deleted rows. In a debug build this aborts on `chassert(granule_of_row.size() == data.rows)`, in a release build the estimate is wrong. Follow the estimator's existing treatment of offset filters on a sample: report the estimate as unsupported, before anything is read. The whole-part scan (within the budget) keeps the exact handling of deleted rows. 05176: master's read-limit check now refuses the 1000-row scan before reading, so the mostly-deleted case reports that reason instead of the in-scan one. The deleted rows still count against the limit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Merged master to resolve the conflict with the new sampling in One interaction I left as is: with |
…lightweight deletes A projection part rebuilt by a lightweight delete in `rebuild` mode does not store the deleted rows, so a read with `apply_deleted_mask = 0` served by a projection returned only the surviving rows while the base table returned the deleted ones too. This already held for filtered and aggregate projections, and the pre-filter in `calculateByQuery` made it hold for normal ones. `canUseProjectionForReadingStep` now rejects projections for such reads, so the read falls back to the parent parts. Tables without lightweight deletes keep using projections. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - e4e17f6Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The Session id: cron:our-pr-ci-monitor:20261106-173005 |
|
About the |
f0f6023
…l-projection-stale Fix projections returning lightweight-deleted rows after a mutation rebuilds them on a Wide part
Cherry pick #111809 to 26.8: Fix projections returning lightweight-deleted rows after a mutation rebuilds them on a Wide part
…ed rows after a mutation rebuilds them on a Wide part
…l-projection-stale Fix projections returning lightweight-deleted rows after a mutation rebuilds them on a Wide part
Cherry pick #111809 to 26.9: Fix projections returning lightweight-deleted rows after a mutation rebuilds them on a Wide part
…l-projection-stale Fix projections returning lightweight-deleted rows after a mutation rebuilds them on a Wide part
Cherry pick #111809 to 26.10: Fix projections returning lightweight-deleted rows after a mutation rebuilds them on a Wide part
…ed rows after a mutation rebuilds them on a Wide part
…ted rows after a mutation rebuilds them on a Wide part
Backport #111809 to 26.10: Fix projections returning lightweight-deleted rows after a mutation rebuilds them on a Wide part
Backport #111809 to 26.9: Fix projections returning lightweight-deleted rows after a mutation rebuilds them on a Wide part
Backport #111809 to 26.8: Fix projections returning lightweight-deleted rows after a mutation rebuilds them on a Wide part
Closes: #111791
Related: #118375
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed projections returning rows removed by a lightweight
DELETEafterALTER UPDATE,MATERIALIZE PROJECTIONorCLEAR COLUMNrebuilt them on a Wide part. A query withapply_deleted_mask = 0no longer uses projections when the table has lightweight-deleted rows, since projections do not store them. On release branches this also fixes a normal projection without aWHEREkeeping the rows removed by arebuild-mode lightweightDELETE, which #118375 fixed on master.Description
On 26.9.16.11 and on master, after a lightweight
DELETE, a projection rebuilt byALTER UPDATE,MATERIALIZE PROJECTIONorCLEAR COLUMNon a Wide part returns the deleted rows, and a query withapply_deleted_mask = 0served from a projection misses them.#111791 itself was fixed on master by #118375; this PR also fixes it on release branches when backported.
A mutation that rewrites only some columns of a Wide part gave the projection rebuild no
_row_exists;MutationsInterpreternow reads it in a readonly stage.ProjectionDescription::calculateByQueryfilters its input by_row_existsfor every projection type, after_part_offsetis generated so the surviving rows keep their parent offsets.EXPLAIN WHATIFhandles lightweight-deleted rows since #125792; hereWhatIfProjectionEstimatoronly stops reading_row_existstwice when the projection stores it, which fails an assertion on master.Backports: against master, this diff removes the
WHERE _row_exists = 1injection and theFetchColumnsfilter that #118375 added tocalculateByQuery; release branches have only the injection. A backport needs thecalculateByQuerychanges from 8b8a425 and 2608c7a (and their follow-ups 7a9c4d6, deec4d0) applied to the pre-#118375 code.Fixing affected projections rebuilt prior to this fix
Projections built before this fix can still contain lightweight-deleted rows: normal projections rebuilt by a lightweight
DELETEwithlightweight_mutation_projection_mode = 'rebuild', and any projection rebuilt byALTER UPDATE,MATERIALIZE PROJECTIONorCLEAR COLUMNon a Wide part after a lightweightDELETE. Upgrading does not repair them. A merge of the part rebuilds them, except withdeduplicate_merge_projection_mode = 'ignore', where they stay stale permanently. To repair them directly:MATERIALIZE PROJECTIONalone does not rebuild an existing projection part.Workflow [PR]
Sync PR [sync-upstream/pr/111809]
Version info
26.11.1.2120-master(included in26.11and later)26.10.8.5,26.9.33.15,26.8.41.17