Skip to content

Core: Reduce DeleteFileIndex memory for file-scoped position deletes - #18359

Open
raunaqmorarka wants to merge 2 commits into
apache:mainfrom
raunaqmorarka:delete-file-index-memory
Open

raunaqmorarka wants to merge 2 commits into
apache:mainfrom
raunaqmorarka:delete-file-index-memory

Conversation

@raunaqmorarka

Copy link
Copy Markdown
Contributor

DeleteFileIndex copies every v2 position delete with its file_path lower and upper bounds, plus the column sizes, value counts and null counts for that column. For a file-scoped position delete the two bounds are the same path, which the index only uses to compute the referenced data file location. This PR copies such deletes without column stats and records the location in referencedDataFile, the same shape a DV already has. Deletes that reference the same data file share one location String. Position deletes that span multiple data files keep the file_path bounds as before.

Motivation

A Trino coordinator heap dump showed DeleteFileIndex holding 4.3M position delete entries for 1.57M data files at about 2.25 KB per entry, roughly 9.7 GB, and the coordinator ran out of memory while planning. Most of the retained size per entry was the two ByteBuffer bounds and the stats maps around them, duplicated for every delete on the same data file.

Results

JOL retained size of a DeleteFileIndex built from a v2 delete manifest with 100k position deletes and 150-char paths:

data files before after
100k (one delete per file) 2122.6 B/delete 810.6 B/delete
37k (2.7 deletes per file) 1908.1 B/delete 596.1 B/delete

Testing

Extended DeleteFileIndexTestBase with file-scoped, preset referencedDataFile, and multi-file position delete cases that check the copied fields and stats.

AI assistance (Claude Code) was used to draft the code, tests and the JOL measurement harness. I reviewed the logic and ran the tests and measurements myself.

@github-actions github-actions Bot added the core label Oct 3, 2026
Comment thread core/src/main/java/org/apache/iceberg/DeleteFileIndex.java
Comment thread core/src/main/java/org/apache/iceberg/DeleteFileIndex.java
A position delete whose file_path bounds name a single data file is
matched by location, so the copy records the data file in
referencedDataFile and drops column stats.

JOL retained bytes per delete, 100k v2 position deletes, 150-char paths:

| data files | before   | after   |
|------------|----------|---------|
| 100k (1:1) | 2122.6 B | 810.6 B |
| 37k (2.7:1)| 1908.1 B | 717.0 B |
Position deletes of the same data file hold one location String.

JOL retained bytes per delete, 100k v2 position deletes, 150-char paths,
2.7 deletes per data file: 717.0 B before, 596.1 B after.
@raunaqmorarka
raunaqmorarka force-pushed the delete-file-index-memory branch from 90ee9c7 to 5d9dd27 Compare October 8, 2026 03:23
Comment on lines +518 to +522
private static DeleteFile copyWithMinStats(DeleteFile file) {
if (file.content() == FileContent.EQUALITY_DELETES) {
// copy with stats for better filtering against data file stats
return file.copyWithStats(Set.copyOf(file.equalityFieldIds()));
}

@findinpath findinpath Oct 8, 2026 •

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.

see #18338 (comment)

This changes what DeleteFile.lowerBounds()/valueCounts()/nullValueCounts() return, not just how they're used for predicate matching.

cc @pvary

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These copies only reach callers through FileScanTask.deletes(). Metadata tables open manifests directly and still see full stats. On main the index already keeps only the file_path stats on these copies and drops the rest. For a file-scoped delete, this PR moves that one value from the file_path bounds into referencedDataFile. So ContentFileUtil.referencedDataFile() and isFileScoped() return the same result. Position deletes that span several data files keep their bounds.

Comment thread core/src/main/java/org/apache/iceberg/DeleteFileIndex.java
@raunaqmorarka

Copy link
Copy Markdown
Contributor Author

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants