Skip to content

Fix DeltaLake trivial count over tables with deletion vectors - #115872

Merged
fm4v merged 5 commits into
ClickHouse:masterfrom
groeneai:deltalake-dv-trivial-count
Nov 1, 2026
Merged

fm4v merged 5 commits into
ClickHouse:masterfrom
groeneai:deltalake-dv-trivial-count

Conversation

@groeneai

@groeneai groeneai commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #114933

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 SELECT count() returning too many rows for a Delta Lake table whose deletes are stored as deletion vectors: the count came from the numRecords file statistics, which still include the removed rows. Closes #114933.

Description

On 26.8.18.2 and 26.9.9.28, SELECT count() over a Delta table with delta.enableDeletionVectors = true counts the deleted rows (310 instead of Spark's 260 on the issue's repro): the trivial-count optimization answers from the numRecords statistics in _delta_log and never consults the file's deletion vector. Any query that scans returns the correct answer.

TableSnapshot accumulates total_rows at two places, and both summed stats->num_records while holding the file's dv_info handle and ignoring it. delta-kernel documents that statistic as stale under a deletion vector in the same doc comment that names DvInfo::has_vector as the flag to consult (kernel/src/scan/state.rs).

Both sites now drop total_rows when a file carries a deletion vector, so count() becomes an ordinary scan, which already applies the vector correctly. That is what IcebergMetadata::totalRows already does under delete files. Subtracting the vector's cardinality, which _delta_log records, would keep the optimization, but the pinned delta-kernel does not expose that field through its FFI, so that needs a delta-kernel change first.

The delta_lake_snapshot_version disagreement the issue also reports has the same cause and is fixed too, since getTotalRows is version-agnostic. On the test fixture, whose vector removes 2 rows, pinning the version that carries the vector returned 4 before and returns 2 now, matching Spark's VERSION AS OF. A version pinned before the delete keeps the optimization. The issue's other symptom, system.tables.total_rows, already reports NULL for every data-lake table on master since #117584.

Extends test_deletion_vector, whose existing assertions use ORDER BY all, which makes the planner see the count() aggregate twice and decline the optimization, so they never reached this path. New arms cover a bare count(), both accumulation sites, a pinned read of the version carrying the vector, and two controls that the optimization is still applied where no vector is present.


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

Version info

  • Merged into: 26.11.1.1005-master (included in 26.11 and later)

groeneai and others added 2 commits August 21, 2026 20:01
A bare SELECT count() over a Delta table with delta.enableDeletionVectors
set answered from the numRecords file statistics, which still include the
rows a deletion vector removes, so it reported more rows than the table
has. Every query that scans returned the correct answer, which made the
count disagree with everything else the same table reported.
system.tables.total_rows over a DeltaLake engine table over-counted the
same way, reading the same IStorage::totalRows seam.

TableSnapshot accumulates total_rows at two places, the scan callback and
the metadata-only stats visitor, and both summed stats->num_records while
holding the file's dv_info handle and ignoring it. delta-kernel documents
that statistic as stale under a deletion vector in the same doc comment
that names DvInfo::has_vector as the flag to consult, in
kernel/src/scan/state.rs.

Both sites now drop total_rows when a file carries a deletion vector, so
totalRows returns nothing, applyTrivialCountIfPossible declines, and the
query takes the ordinary scan path that already applies the vector.
total_bytes is left alone, since a deletion vector adds its own file and
does not change the size of the data files.

An exact subtraction of the vector's cardinality is not available: the
field is not exposed by the FFI, and the two accessors that could reach it
read the deletion-vector file itself, which is the read this shortcut
exists to avoid. Failing closed is what IcebergMetadata::totalRows already
does when a table has delete files, and what the count-from-files path
already does through hasAttachedDeletes.

The existing test_deletion_vector assertions use ORDER BY all, which
resolves to the count() aggregate and so makes the planner see it twice
and decline the optimization, which is why they never reached this path.
They are kept as they are, and arms are added for a bare count(), the
absence of the trivial-count plan step, each of the two accumulation sites
via its log line, system.tables.total_rows, a version-pinned read, and a
table without a deletion vector as a control that the optimization still
applies there.

Closes: ClickHouse#114933

Co-Authored-By: Claude Opus 5 <[email protected]>
…on-vector test

The version-pinned arm asserted delta_lake_snapshot_version = 1, which in this
fixture is the overwrite that precedes the DELETE, so it read a snapshot with no
deletion vector and stayed green with both guards reverted. Enumerating
_delta_log shows version 2 is the DELETE: its add entry carries the
deletionVector next to "numRecords":4, while 2 rows survive. Pinning that
version returned 4 before this fix and returns 2 now, which is what Spark
reports for VERSION AS OF 2 and what a scanning query with the same pin already
returned. getTotalRows takes no version branch, so the pinned read goes through
the same two accumulations as an unpinned one.

The test now appends a row after the DELETE, so the version carrying the vector
is an older snapshot rather than also being the newest one, and asserts the
newest version too, which is over-counted as well because the vector stays on
the surviving file. The pre-delete version keeps its arm and gains a plan-step
assertion, giving the cluster parametrization a control that the optimization
can still apply.

The other statistics site had an arm in one direction only. Which site publishes
depends on the order of queries rather than on how the table is named:
getSnapshotStats caches, and the scan callback fills that cache only when it is
empty, so a table that is counted before it is ever scanned always answers from
the metadata-only visitor. The existing control counts first, so nothing
asserted that the scan callback still publishes a row count, and a callback that
published nothing at all would have passed. A second table over the same
vector-free data is now scanned first and then asserted for its log line, an
exact count, the plan step, and an exact total_rows.

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 Aug 21, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review — 2 rounds, 4 findings, all agreed and fixed before publication

Two rounds of an internal cold review plus an independent second-model pass, run before this PR was
opened. Round 1, against d6f36b5bbef6, found four issues, all agreed and fixed. Round 2, against
723415a22773, found none. Recorded for transparency about what was checked.

# Severity Finding Verdict
❌ 1 blocker The version-pinned test arm pinned the snapshot before the delete, so it exercised the no-deletion-vector branch and could not fail if the fix were reverted. The description also classified the issue's delta_lake_snapshot_version symptom as a separate defect on the strength of a measurement of that same pre-delete snapshot. AGREE, fixed
❌ 2 major Same finding, reached independently by the second model, which added that reverting both guards left the arm green. AGREE, fixed
⚠️ 3 major Nothing asserted that the scan-callback accumulation still publishes a real total_rows, so an implementation that always returned nothing from that site would have passed every assertion. AGREE, fixed
💡 4 nit On the cluster parametrization, the "trivial count declined" assertion ran without its companion positive control. AGREE, fixed

On finding 1 the arm now pins the version that carries the vector and asserts the count that version
has, keeping the pre-delete version as a positive control, and the description states what was
measured: the pinned disagreement has the same cause and is fixed here.

On finding 3 the review's own proposed remedy was wrong. It assumed the control was a table function,
when that control already used an engine table, so the real discriminator was measured instead:
whichever query runs first decides which of the two sites publishes, because the statistics cache is
filled only while empty. The added control is therefore scanned before it is counted and asserts an
exact total_rows. A mutation that makes that site publish nothing now fails it, while every
pre-existing assertion still passes.

Verified sound in both rounds and unchanged: both accumulation sites are the complete set
(ffi::Stats has exactly three occurrences, the third a forwarding wrapper); the predicate is a
field read on the FFI struct, not a call that touches storage; the read at the scan callback happens
before the handle is moved, which the compiler enforces; total_bytes is correctly untouched; and
the surrounding carriers (count-from-files, change data feed, the legacy non-kernel metadata, the
sparsity-filter count, the cluster and old-analyzer paths) either already fail closed or are fixed
by the same change.

One point noted and not treated as blocking: the assertions that identify which accumulation site ran
read a log line whose publication is guarded by a try_lock, so under contention it could be absent.
test_table_statistics already asserts on these exact two messages, each arm scans a freshly created
table with a single query, and the failure mode is a failing test rather than a silent pass.

Fix plans and evidence are internal; the resulting arms are all in this PR's test diff.

@clickhouse-gh clickhouse-gh Bot closed this Aug 21, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Aug 21, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, 100%. SELECT count() FROM deltaLake(<table with a deletion vector>) returns 4 where the surviving row count is 2, on every run; system.tables.total_rows for a DeltaLake engine table over the same path returns 4. No randomization involved. test_storage_delta/test.py::test_deletion_vector with the added arms is the repro command.
b Root cause explained? applyTrivialCountIfPossible answers a bare SELECT count() from storage->totalRows(), which for DeltaLake reaches TableSnapshot::getSnapshotStats().total_rows. That value is accumulated at two places, and both sum the file's numRecords statistic while holding the file's dv_info handle and ignoring it. delta-kernel documents num_records as stale under a deletion vector in the same doc comment that names DvInfo::has_vector as the flag to consult (kernel/src/scan/state.rs), so the shortcut reports rows a deletion vector logically removed. system.tables.total_rows reads the same seam.
c Fix matches root cause? Yes. Both accumulations now decline when the file carries a deletion vector, using the predicate already present in the same file. No widened bound, no disabled or skipped test, no new setting, no guard at a downstream symptom site.
d Test intent preserved / new tests added? No existing assertion weakened or removed: the two ORDER BY all counts and the Row indexes size 2 for file check are kept verbatim. The existing test_deletion_vector is extended rather than replaced by a new file. New arms: bare count(), trivial-count plan step absent, both accumulation sites with their log discriminators, system.tables.total_rows NULL, total_bytes still positive, a read pinned to the version that carries the vector, and two positive controls that the optimization still applies where no vector is present, one pinned before the delete and one on a table without a vector at all.
e Both directions demonstrated? Yes, same test on two Build-ID-verified binaries. Base 9be83031c37bd5da9c6cf47b9c99d537ed9ea022: 2 failed, assert 2 == 4, on both on_cluster parametrizations. Fix 454ba308c82517daa4af2b017a1d366e6fdbffbc: 2 passed, and 10 passed over a 5x repeat. test_table_statistics (the non-deletion-vector total_rows path) still passes. Because the base run stops at the first new arm, each remaining arm was additionally checked in isolation, catching every assertion separately: the pinned-version arms fail on base (2 == 4, plan step present) and pass on the fix, while the pre-delete pinned control passes on both.
f Fix is general across code paths? Both accumulation sites fixed, not one. grep "ffi::Stats" returns exactly three hits in the file and the third is the forwarding wrapper, so there is no further site. Legacy non-kernel DeltaLakeMetadata declares no totalRows override and inherits return {}. The count-from-files path already fails closed via hasAttachedDeletes, which is why optimize_count_from_files = 0 does not change the wrong answer. Change-data-feed reads are excluded twice over. IcebergMetadata::totalRows already fails closed under delete files. Five mutations confirm each site independently, each reddening a different assertion: reverting either guard, reading the handle after it is moved, forcing the predicate either way, and making one site publish nothing at all.
g Fix generalizes across inputs? The fixture's DELETE produces both shapes in one snapshot, a deletion vector in one partition and a whole-file removal in another, so mixed files are covered. Asserted for both the deltaLake table function and a DeltaLake engine table, for both on_cluster parametrizations (so deltaLakeCluster too), and across three snapshot versions: one before the delete, the one that introduces the vector, and a later one that inherits it, the last of which shows this is not confined to the newest version. Both publication orders are covered, since counting before scanning and scanning before counting reach different accumulation sites, and each is asserted in both the deletion-vector and the no-vector direction.
h Backward compatible? Yes. No setting, no format, no serialization change, so no SettingsChangesHistory.cpp entry. optimize_trivial_count_query = 0 behaves as before. system.tables.total_rows becomes NULL instead of a wrong number for such tables, which is the same trade IcebergMetadata::totalRows already makes under delete files, and it is disclosed in the description.
i Invariants and contracts preserved? The fail-close rides on the existing std::optional contract, whose else branch already set std::nullopt, so no new state is introduced. In the scan callback the flag is read before the handle is moved into the file list and before any lock is taken; it touches no shared state and cannot throw, since dv_info_has_vector is a field read that opens nothing. No allocation, no I/O, no lock, and no early-return path is changed; the callback still returns true and the queue notification is untouched. The ordering is compiler-enforced: moving the read after the move makes the local unused and the build fails on -Werror,-Wunused-variable.

Session id: cron:clickhouse-impl-slot-7:20260821-212300

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @kssenii, could you review this? The DeltaLake trivial count answered from the numRecords file statistics, which still include rows a deletion vector removes, so both row-accumulation sites in TableSnapshot now decline to report a count for such a file and the query falls back to the scan path that applies the vector correctly.

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [981c78f]

Summary: ✅


AI Review

Summary

This PR fixes DeltaLake trivial count() over snapshots that carry deletion vectors by making both cached row-count accumulation paths decline numRecords in that case, so the query falls back to the scan path that already applies the vector correctly. I did not find a remaining correctness, concurrency, or caching bug in the current diff; the new test coverage also exercises both accumulation sites and the version-pinned path that originally regressed.

Missing context / blind spots
  • ⚠️ CI is still in progress, and I did not re-run tests/integration/test_storage_delta/test.py::test_deletion_vector locally, so the Spark/MinIO integration path is validated here by code inspection rather than by a fresh runtime repro.
Final Verdict

✅ No blocking issues found in the current diff.

@clickhouse-gh

clickhouse-gh Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 981c78f94 with master 61038e48a (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

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

Job report

@scanhex12 scanhex12 self-assigned this Aug 24, 2026
context->total_data_files += 1;
context->total_bytes += size;
if (stats && context->total_rows.has_value())
if (stats && !has_deletion_vector && context->total_rows.has_value())

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.

@groeneai don't we have any stat that means "number of deleted rows" to calculate total rows with deletion vectors?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes and no: the statistic exists in the format, but not at the seam this code sits on.

add.deletionVector.cardinality ("number of rows the given DV logically removes") is a required field in the log schema, so the number is in _delta_log. What this callback gets, though, is a SharedDvInfo handle from delta-kernel, and the FFI exposes exactly four entry points on it: dv_info_has_vector, selection_vector_from_dv, row_indexes_from_dv, free_kernel_dv_info. grep -c cardinality over contrib/delta-kernel-rs/ffi/src is 0. The field lives on DeletionVectorDescriptor, and DvInfo::deletion_vector is pub(crate) while delta_kernel_ffi is a separate crate from delta_kernel, so the FFI layer cannot reach it either. Upstream main is the same: has_vector, get_selection_vector, get_row_indexes are the only public accessors.

The two reachable routes both open the DV file (get_selection_vector/get_row_indexes -> DeletionVectorDescriptor::read/row_indexes -> storage.read_files). Doing that during metadata processing gives up the point of the trivial-count shortcut, and the strace in #114933 shows that file is not opened today.

One argument against subtracting even with the number in hand: kernel conditions the numRecords guarantee on the DV being absent ("For any file where the deletion vector is not present ... must be present and accurate"), and says that under deletion vectors the stats "may be somewhat outdated". So numRecords - cardinality rests on an accuracy assumption the library explicitly declines to make.

Falling back to a real scan is also what the symmetric engine already does: IcebergMetadata::totalRows returns {} when a snapshot has live delete files, and hasAttachedDeletes does the same on the count-from-files path.

If you do want the exact subtraction, it is reachable: the repo carries its own delta-kernel-rs fork with local ffi patches (free_engine_builder, the set_builder_option error path), so a dv_info_cardinality export plus a pub fn cardinality() on DvInfo is a small addition there. I would rather do that as a separate PR after this one lands than put a contrib bump inside a bug fix, but it is your call.

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.

@groeneai let's integrate these stats in our code then, if they exist

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Acknowledged, I will implement it.

The number is still not reachable at this seam. At the pinned commit (88ff5a947478), and on upstream main as well, DvInfo exposes only has_vector, get_selection_vector and get_row_indexes, DvInfo::deletion_vector is pub(crate), and grep -c cardinality ffi/src/scan.rs is 0, while DeletionVectorDescriptor::cardinality itself is a public i64. So the route is a cardinality() accessor on DvInfo plus a dv_info_cardinality export in ClickHouse/delta-kernel-rs, then subtracting it in this callback, keeping the bail-out only for files whose handle carries no usable number.

One sequencing constraint: the submodule pin can only move to a commit that exists in ClickHouse/delta-kernel-rs, and I have read access only there, so the fork change needs a PR of its own merged first. My preference is to keep this PR as the fail-close fix, so the wrong count is corrected in the meantime, and put the subtraction on top once the fork side is in. If you would rather ship both together, say so and I will hold this one until the fork change lands. I will post the links here either way.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Written and measured, but not opened as a PR, and that last part is what I need your call on.

The accessor is DvInfo::cardinality() -> Option<i64> plus a dv_info_cardinality FFI export: +23/-1 in two files, purely additive, Cargo.lock untouched, against ClickHouse/v0.23.0 (our pin is that branch tip, so the pin bump afterwards is a fast-forward). Diff below.

I did not take numRecords - cardinality on trust, since Stats documents the statistics as possibly outdated under deletion vectors. I built ClickHouse against the patch and compared the metadata count against a full scan of the same snapshot across ten deletion-vector shapes. They agreed every time, including the one I expected to break it: successive DELETEs against a single file, where cardinality turns out to be cumulative rather than the last delta. Removing the subtraction made those comparisons disagree.

What I need: I have no push access on ClickHouse/delta-kernel-rs, and that repository's AI_POLICY.md asks that agents not post there unless maintainers configured it, so I would rather not open a PR there on my own initiative. Either take the diff and push it yourself, or tell me to open it from a fork and I will.

One caveat if you take it as it stands. The doc comment I wrote spells out numRecords minus cardinality as the way to get the surviving count, but Stats only promises accuracy when no vector is present, and DvInfo is shared with the CDF scan path, which has no numRecords at all. So that sentence claims more than the kernel does. Before opening a PR there I would cut it back to describing the field and leave the arithmetic to the caller. The code itself does not change.

Also worth knowing whichever way it lands: that fork's ClickHouse/v0.23.0 tip is already red in its own CI (build, test, coverage, ffi_test, format, msrv), and cargo test -p delta_kernel does not compile there with any feature set. Ten #[cfg(test)] closures still return () where visit_scan_files now wants bool (kernel/src/scan/log_replay.rs:1536,1628, plus 8 sites in kernel/src/parallel/parallel_phase.rs). So the accessor's unit assertions cannot run in that CI until those are repaired. I verified them locally with a throwaway repair and kept it out of the change.

This PR is unaffected either way, and the subtraction lands here once the pin moves. Its fail-close already reports the correct count, only without the shortcut.

Kernel-side diff (+23/-1)
diff --git a/ffi/src/scan.rs b/ffi/src/scan.rs
index c6cb752..baaa0be 100644
--- a/ffi/src/scan.rs
+++ b/ffi/src/scan.rs
@@ -481,6 +481,18 @@ pub unsafe extern "C" fn dv_info_has_vector(dv_info: Handle<SharedDvInfo>) -> bo
     dv_info.has_vector
 }
 
+/// Number of rows the deletion vector of the [`SharedDvInfo`] logically removes, or `None` if
+/// there is no deletion vector. [`Stats::num_records`] still counts those rows, so the number of
+/// rows that survive in the file is `num_records` minus this value. No deletion vector is read.
+///
+/// # Safety
+/// Engine is responsible for passing a valid `SharedDvInfo` handle.
+#[no_mangle]
+pub unsafe extern "C" fn dv_info_cardinality(dv_info: Handle<SharedDvInfo>) -> OptionalValue<i64> {
+    let dv_info = unsafe { dv_info.as_ref() };
+    dv_info.info.cardinality().into()
+}
+
 /// This callback will be invoked for each valid file that needs to be read for a scan.
 ///
 /// The arguments to the callback are:
diff --git a/kernel/src/scan/state.rs b/kernel/src/scan/state.rs
index d7b8036..26168d3 100644
--- a/kernel/src/scan/state.rs
+++ b/kernel/src/scan/state.rs
@@ -48,6 +48,14 @@ impl DvInfo {
         self.deletion_vector.is_some()
     }
 
+    /// Number of rows the Deletion Vector of this file logically removes, or `None` if the file
+    /// has no Deletion Vector. [`Stats::num_records`] still counts those rows, so the number of
+    /// rows that survive in the file is `num_records` minus this value. The count comes from the
+    /// log action and needs no access to the Deletion Vector itself.
+    pub fn cardinality(&self) -> Option<i64> {
+        self.deletion_vector.as_ref().map(|dv| dv.cardinality)
+    }
+
     pub(crate) fn get_treemap(
         &self,
         engine: &dyn Engine,
@@ -234,7 +242,7 @@ impl<T> FilteredRowVisitor for ScanFileVisitor<'_, T> {
 #[cfg(test)]
 mod tests {
     use crate::actions::get_commit_schema;
-    use crate::scan::state::ScanFile;
+    use crate::scan::state::{DvInfo, ScanFile};
     use crate::scan::test_utils::{add_batch_simple, run_with_validate_callback};
 
     #[derive(Clone)]
@@ -257,6 +265,7 @@ mod tests {
         );
         assert_eq!(scan_file.partition_values.get("non-existent"), None);
         assert!(scan_file.dv_info.deletion_vector.is_some());
+        assert_eq!(scan_file.dv_info.cardinality(), Some(2));
         let dv = scan_file.dv_info.deletion_vector.unwrap();
         assert_eq!(dv.unique_id(), "uvBn[lx{q8@P<9BNH/isA@1");
         assert!(scan_file.transform.is_none());
@@ -275,5 +284,6 @@ mod tests {
             context,
             validate_visit,
         );
+        assert_eq!(DvInfo::default().cardinality(), None);
     }
 }

@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Sep 4, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Hi @scanhex12, gentle ping: any update on the DvInfo::cardinality accessor for ClickHouse/delta-kernel-rs (discussion above)? Would you push it yourself, or should I open it from a fork? Thanks.

@PedroTadim

Copy link
Copy Markdown
Member

@scanhex12 are you continuing to review this, or should we ask @SmitaRKulkarni for help?

groeneai and others added 2 commits October 10, 2026 19:13
Master now reports NULL `total_rows` and `total_bytes` in `system.tables`
for every data-lake table (`StorageSystemTables.cpp`, `isDataLake`), so
these arms either pass for that reason or fail on the merged head
(`total_bytes > 0` reads `\N`). The remaining `count()` and `EXPLAIN`
arms still cover both statistics sites in both directions: forcing the
scan-callback site to publish no row count turns the `plain_scanned`
trivial-count-step assertion red while every deletion-vector arm passes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the delta-kernel source citation from the hasDeletionVector comment; the PR description carries it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai changed the title Fix DeltaLake trivial count and total_rows over tables with deletion vectors Fix DeltaLake trivial count over tables with deletion vectors Oct 10, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review, round 4 (after the master merge)

Subject: d71e2adddbe2c (test-only) plus a comment-only trim, on top of the master merge 7a94807c. No code change in src/ since the reviewed fix. Second-model review: 0 findings. My own review: 0 blocking.

✅ The four dropped system.tables assertions measured nothing this PR controls: master reports NULL there for every data-lake table (#117584). The scan-callback site keeps an arm in each direction: forcing it to publish no row count turns the plain_scanned trivial-count-step assertion red.

💡 Noted, not blocking: the description's cardinality sentence now matches the thread above; parseDVHandle could reuse the new helper; the scan-callback log assertions rely on an uncontended try_lock, as test_table_statistics does.

@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Dear @scanhex12, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@fm4v
fm4v added this pull request to the merge queue Nov 1, 2026
Merged via the queue into ClickHouse:master with commit 5a18d4b Nov 1, 2026
163 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 1, 2026
@clickhouse-gh clickhouse-gh Bot added comp-delta-lake Delta Lake tables: reading Delta metadata through delta-kernel-rs (table snapshots, schema and ty... and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 22, 2026
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-delta-lake Delta Lake tables: reading Delta metadata through delta-kernel-rs (table snapshots, schema and ty... groeneai-origin-request PR origin: a maintainer pinged or directed groeneai 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.

DeltaLake: trivial SELECT count() over a table with deletion vectors counts the deleted rows (numRecords summed, DV cardinality ignored)

6 participants