This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-rust.git
The following commit(s) were added to refs/heads/main by this push:
new 14e091948 perf: skip manifests with no live entries (#3708)
14e091948 is described below
commit 14e0919489a63d92449ffedaceff924899af99c4
Author: Jannik Steinmann <[email protected]>
AuthorDate: Tue Nov 17 21:42:48 2026 +0000
perf: skip manifests with no live entries (#3708)
fix: skip manifests with no live entries
Avoid opening manifests whose list counts prove there are no added or
existing files. Cover normal and copy-on-write planning with a removed
dead-only manifest.
---
crates/iceberg/src/scan/context.rs | 11 +-
crates/iceberg/src/scan/mod.rs | 271 ++++++++++++++++++++++++++++++++++++-
2 files changed, 280 insertions(+), 2 deletions(-)
diff --git a/crates/iceberg/src/scan/context.rs
b/crates/iceberg/src/scan/context.rs
index 818844512..5f6593afb 100644
--- a/crates/iceberg/src/scan/context.rs
+++ b/crates/iceberg/src/scan/context.rs
@@ -335,7 +335,13 @@ impl PlanContext {
// TODO: Ideally we could ditch this intermediate Vec as we return an
iterator.
let mut filtered_mfcs = vec![];
for manifest_file in manifest_files {
- let tx = if manifest_file.content == ManifestContentType::Deletes {
+ let is_delete = manifest_file.content ==
ManifestContentType::Deletes;
+ let has_live_files =
+ manifest_file.has_added_files() ||
manifest_file.has_existing_files();
+ if is_delete && !has_live_files {
+ continue;
+ }
+ let tx = if is_delete {
delete_file_tx.clone()
} else {
tx_data.clone()
@@ -362,6 +368,9 @@ impl PlanContext {
None
};
+ if !has_live_files {
+ continue;
+ }
let mfc = self.create_manifest_file_context(
manifest_file,
partition_bound_predicate,
diff --git a/crates/iceberg/src/scan/mod.rs b/crates/iceberg/src/scan/mod.rs
index 1f488796c..c3740911d 100644
--- a/crates/iceberg/src/scan/mod.rs
+++ b/crates/iceberg/src/scan/mod.rs
@@ -761,7 +761,7 @@ mod tests {
Array, ArrayRef, BooleanArray, Float64Array, Int32Array, Int64Array,
RecordBatch, RunArray,
StringArray,
};
- use futures::{TryStreamExt, stream};
+ use futures::{StreamExt, TryStreamExt, stream};
use parquet::arrow::ArrowWriter;
use uuid::Uuid;
@@ -4238,4 +4238,273 @@ mod tests {
.collect();
assert_eq!(y, (1100..1200).collect::<Vec<i64>>());
}
+
+ #[tokio::test]
+ async fn test_dead_only_manifests_are_skipped() {
+ use crate::spec::ManifestContentType;
+
+ for content in [ManifestContentType::Data,
ManifestContentType::Deletes] {
+ let mut fixture = TableTestFixture::new();
+ if content == ManifestContentType::Data {
+ fixture.setup_manifest_files().await;
+ } else {
+ fixture.setup_deadlock_manifests().await;
+ }
+ let snapshot =
fixture.table.metadata().current_snapshot().unwrap();
+ let scan = fixture
+ .table
+ .scan()
+ .with_filter(Reference::new("x").less_than(Datum::long(200)))
+ .build()
+ .unwrap();
+ let mut expected = if content == ManifestContentType::Deletes {
+ let tasks = scan
+ .plan_files()
+ .await
+ .unwrap()
+ .try_collect::<Vec<_>>()
+ .await
+ .unwrap();
+ assert_eq!(tasks.len(), 10);
+ assert!(tasks.iter().all(|task| task.deletes().len() == 1));
+ let cow_tasks = scan
+ .plan_cow_rewrite_files()
+ .await
+ .unwrap()
+ .map_ok(|file| file.scan_task)
+ .try_collect::<Vec<_>>()
+ .await
+ .unwrap();
+ [tasks, cow_tasks]
+ } else {
+ [vec![], vec![]]
+ };
+ for tasks in &mut expected {
+ tasks.sort_by(|a, b|
a.data_file_path().cmp(b.data_file_path()));
+ }
+ let context = scan.plan_context.as_ref().unwrap();
+ let list = context.get_manifest_list().await.unwrap();
+ let source = list
+ .entries()
+ .iter()
+ .find(|file| file.content == content)
+ .unwrap();
+ let manifest =
context.object_cache.get_manifest(source).await.unwrap();
+ let builder = ManifestWriterBuilder::new(
+ fixture.next_manifest_file(),
+ Some(snapshot.snapshot_id()),
+ fixture.table.metadata().current_schema().clone(),
+ fixture
+ .table
+ .metadata()
+ .default_partition_spec()
+ .as_ref()
+ .clone(),
+ );
+ let mut writer = if content == ManifestContentType::Data {
+ builder.build_v2_data()
+ } else {
+ builder.build_v2_deletes()
+ };
+ for entry in manifest.entries() {
+ writer.add_delete_entry(entry.as_ref().clone()).unwrap();
+ }
+ let mut manifest = writer.write_manifest_file().await.unwrap();
+ if content == ManifestContentType::Deletes {
+ manifest.partitions.as_mut().unwrap()[0].lower_bound =
Some(vec![0].into());
+ }
+ assert_eq!(
+ (manifest.added_files_count, manifest.existing_files_count),
+ (Some(0), Some(0))
+ );
+ assert!(manifest.deleted_files_count.unwrap() > 0);
+ fixture
+ .table
+ .file_io()
+ .delete(&manifest.manifest_path)
+ .await
+ .unwrap();
+ let mut manifests = if content == ManifestContentType::Deletes {
+ list.entries().to_vec()
+ } else {
+ vec![]
+ };
+ manifests.push(manifest);
+ let output = fixture
+ .table
+ .file_io()
+ .new_output(snapshot.manifest_list())
+ .unwrap()
+ .writer()
+ .await
+ .unwrap();
+ let mut writer = ManifestListWriter::v2(
+ output,
+ snapshot.snapshot_id(),
+ snapshot.parent_snapshot_id(),
+ snapshot.sequence_number(),
+ );
+ writer.add_manifests(manifests.into_iter()).unwrap();
+ writer.close().await.unwrap();
+ let table = Table::builder()
+ .metadata(fixture.table.metadata().clone())
+ .identifier(fixture.table.identifier().clone())
+ .file_io(fixture.table.file_io().clone())
+ .runtime(test_runtime())
+ .build()
+ .unwrap();
+ for cow in [false, true] {
+ let scan = table
+ .scan()
+
.with_filter(Reference::new("x").less_than(Datum::long(200)))
+ .build()
+ .unwrap();
+ let stream = if cow {
+ scan.plan_cow_rewrite_files()
+ .await
+ .unwrap()
+ .map_ok(|file| file.scan_task)
+ .boxed()
+ } else {
+ scan.plan_files().await.unwrap()
+ };
+ let mut actual = tokio::time::timeout(
+ std::time::Duration::from_secs(10),
+ stream.try_collect::<Vec<_>>(),
+ )
+ .await
+ .unwrap()
+ .unwrap();
+ actual.sort_by(|a, b|
a.data_file_path().cmp(b.data_file_path()));
+ assert_eq!(
+ actual,
+ expected[usize::from(cow)],
+ "content={content:?}, cow={cow}"
+ );
+ }
+ }
+ }
+
+ #[tokio::test]
+ async fn test_live_and_unknown_manifest_counts_preserve_tasks() {
+ use crate::spec::FormatVersion;
+
+ for (status, added, existing) in [
+ (ManifestStatus::Added, Some(1), Some(0)),
+ (ManifestStatus::Existing, Some(0), Some(1)),
+ (ManifestStatus::Added, None, Some(0)),
+ (ManifestStatus::Existing, Some(0), None),
+ (ManifestStatus::Added, None, None),
+ ] {
+ let mut fixture = TableTestFixture::new();
+ fixture.setup_manifest_files().await;
+ let snapshot =
fixture.table.metadata().current_snapshot().unwrap();
+ let scan = fixture.table.scan().build().unwrap();
+ let context = scan.plan_context.as_ref().unwrap();
+ let list = context.get_manifest_list().await.unwrap();
+ let manifest = context
+ .object_cache
+ .get_manifest(&list.entries()[0])
+ .await
+ .unwrap();
+ let entry = manifest
+ .entries()
+ .iter()
+ .find(|entry| entry.status() == status)
+ .unwrap();
+ let expected = vec![(entry.data_file().file_path().to_owned(),
vec![])];
+ let mut writer = ManifestWriterBuilder::new(
+ fixture.next_manifest_file(),
+ Some(snapshot.snapshot_id()),
+ fixture.table.metadata().current_schema().clone(),
+ fixture
+ .table
+ .metadata()
+ .default_partition_spec()
+ .as_ref()
+ .clone(),
+ )
+ .build_v1();
+ if status == ManifestStatus::Added {
+ writer.add_entry(entry.as_ref().clone()).unwrap();
+ } else {
+ writer.add_existing_entry(entry.as_ref().clone()).unwrap();
+ }
+ let mut manifest = writer.write_manifest_file().await.unwrap();
+ assert_eq!(
+ (manifest.added_files_count, manifest.existing_files_count),
+ (
+ Some(u32::from(status == ManifestStatus::Added)),
+ Some(u32::from(status == ManifestStatus::Existing))
+ )
+ );
+ manifest.added_files_count = added;
+ manifest.existing_files_count = existing;
+ let output = fixture
+ .table
+ .file_io()
+ .new_output(snapshot.manifest_list())
+ .unwrap()
+ .writer()
+ .await
+ .unwrap();
+ let mut writer = ManifestListWriter::v1(
+ output,
+ snapshot.snapshot_id(),
+ snapshot.parent_snapshot_id(),
+ );
+ writer.add_manifests(std::iter::once(manifest)).unwrap();
+ writer.close().await.unwrap();
+ let mut metadata = fixture.table.metadata().clone();
+ metadata.format_version = FormatVersion::V1;
+ let table = Table::builder()
+ .metadata(metadata)
+ .identifier(fixture.table.identifier().clone())
+ .file_io(fixture.table.file_io().clone())
+ .runtime(test_runtime())
+ .build()
+ .unwrap();
+ for cow in [false, true] {
+ let scan = table.scan().build().unwrap();
+ let counts = scan
+ .plan_context
+ .as_ref()
+ .unwrap()
+ .get_manifest_list()
+ .await
+ .unwrap();
+ assert_eq!(
+ (
+ counts.entries()[0].added_files_count,
+ counts.entries()[0].existing_files_count
+ ),
+ (added, existing)
+ );
+ let stream = if cow {
+ scan.plan_cow_rewrite_files()
+ .await
+ .unwrap()
+ .map_ok(|file| file.scan_task)
+ .boxed()
+ } else {
+ scan.plan_files().await.unwrap()
+ };
+ let tasks = tokio::time::timeout(
+ std::time::Duration::from_secs(10),
+ stream.try_collect::<Vec<_>>(),
+ )
+ .await
+ .unwrap()
+ .unwrap();
+ let actual: Vec<_> = tasks
+ .into_iter()
+ .map(|task| (task.data_file_path().to_owned(),
task.deletes().to_vec()))
+ .collect();
+ assert_eq!(
+ actual, expected,
+ "status={status:?}, added={added:?},
existing={existing:?}, cow={cow}"
+ );
+ }
+ }
+ }
}