From 86901f8defd645132bf4fc7b970a8bb1c0b58efb Mon Sep 17 00:00:00 2001 From: root Date: Fri, 24 Apr 2026 05:35:30 -0500 Subject: [PATCH] queryd/delta: fix CompactResult.base_rows unit mismatch (6-line fix) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before: `base_rows = pre_filter_rows - delta_count` subtracted a FILE count (delta_batches.len()) from a ROW count (pre_filter_rows), producing a meaningless "rough" approximation the comment acknowledged. Now: base_rows is captured directly from the pre-extend state. Same for delta_rows, which now reports actual delta row count instead of file count. Workspace baseline warnings unchanged at 11. Flagged by scrum iter 4-7 as a PRD §8.6 contract gap (upsert semantics); this closes the reporting half. Full dedup work remains queued. Co-Authored-By: Claude Opus 4.7 (1M context) --- crates/queryd/src/delta.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/queryd/src/delta.rs b/crates/queryd/src/delta.rs index 30dcc4a..af5ccc8 100644 --- a/crates/queryd/src/delta.rs +++ b/crates/queryd/src/delta.rs @@ -84,14 +84,17 @@ pub async fn compact( // Load deltas let delta_batches = load_deltas(store, dataset_name).await?; let delta_count = delta_batches.len(); + // Row counts captured before extend; previously base_rows subtracted delta_count (files) from rows — unit mismatch. + let base_row_count: usize = base_batches.iter().map(|b| b.num_rows()).sum(); + let delta_row_count: usize = delta_batches.iter().map(|b| b.num_rows()).sum(); let has_tombstones = !tombstones.is_empty(); let nothing_to_do = delta_batches.is_empty() && !has_tombstones; if nothing_to_do { return Ok(CompactResult { - base_rows: base_batches.iter().map(|b| b.num_rows()).sum(), + base_rows: base_row_count, delta_rows: 0, - final_rows: base_batches.iter().map(|b| b.num_rows()).sum(), + final_rows: base_row_count, deltas_merged: 0, tombstones_applied: 0, rows_dropped_by_tombstones: 0, @@ -99,7 +102,7 @@ pub async fn compact( } base_batches.extend(delta_batches); - let pre_filter_rows: usize = base_batches.iter().map(|b| b.num_rows()).sum(); + let pre_filter_rows: usize = base_row_count + delta_row_count; // If primary key specified, deduplicate (keep last occurrence) let merged_batches = if let Some(_pk) = primary_key_col { @@ -183,8 +186,8 @@ pub async fn compact( ); Ok(CompactResult { - base_rows: pre_filter_rows - delta_count, // rough base-before-deltas - delta_rows: delta_count, + base_rows: base_row_count, + delta_rows: delta_row_count, final_rows, deltas_merged: delta_count, tombstones_applied: tombstones.len(),