<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Small_files_problem</id>
	<title>Small files problem - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Small_files_problem"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Small_files_problem&amp;action=history"/>
	<updated>2026-12-06T00:07:36Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://openlakehouse.io/w/index.php?title=Small_files_problem&amp;diff=75&amp;oldid=prev</id>
		<title>Open Lakehouse Wiki sync: Sync from open-lakehouse/wiki@9783fe6</title>
		<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Small_files_problem&amp;diff=75&amp;oldid=prev"/>
		<updated>2026-11-22T21:29:56Z</updated>

		<summary type="html">&lt;p&gt;Sync from open-lakehouse/wiki@9783fe6&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Infobox concept&lt;br /&gt;
| name            = Small files problem&lt;br /&gt;
| also_known_as   = Small file problem; file fragmentation&lt;br /&gt;
| field           = Data storage, table maintenance&lt;br /&gt;
| key_parts       = Target file size, compaction, write-time file sizing, clustering&lt;br /&gt;
| implementations = [[Apache Iceberg]], [[Delta Lake]], [[Apache Hudi]], [[Apache Spark]]&lt;br /&gt;
| related         = [[Copy-on-write and merge-on-read]], [[Deletion vector]], [[Partition]], [[Structured Streaming]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-22|the Apache Iceberg 1.12.0 documentation (configuration, maintenance, Spark procedures, Spark writes, Spark Structured Streaming), the Delta Lake optimizations documentation, the Apache Hudi file sizing, clustering and configuration documentation (version 1.2.1), and Apache Spark 4.3.0 (SQLConf.scala and the 4.3.0 documentation)}}&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;small files problem&amp;#039;&amp;#039;&amp;#039; is the slowdown and extra cost that occur when a table&amp;#039;s data is spread across many files that are much smaller than the size the storage and query engines work best with. Every file adds metadata to track, a request to open it, and planning and scheduling work, so a table with many small files is slower to query and maintain than the same data in fewer, larger files.&amp;lt;ref name=&amp;quot;hudi-size&amp;quot;&amp;gt;{{Cite web |url=https://hudi.apache.org/docs/file_sizing |title=File Sizing (version 1.2.1) |publisher=Apache Hudi |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;ice-proc&amp;quot;&amp;gt;{{Cite web |url=https://iceberg.apache.org/docs/latest/spark-procedures/ |title=Spark Procedures |publisher=Apache Iceberg |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; In an [[open lakehouse]], small files come mostly from frequent small writes, and every major [[open table format]] provides compaction and write-time sizing to control them.&lt;br /&gt;
&lt;br /&gt;
== Causes ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Streaming and micro-batch writes.&amp;#039;&amp;#039;&amp;#039; Each batch commits its own files. The Iceberg documentation notes that the amount of data written by a streaming process is typically small, which makes the table metadata track many small files.&amp;lt;ref name=&amp;quot;ice-stream&amp;quot;&amp;gt;{{Cite web |url=https://iceberg.apache.org/docs/latest/spark-structured-streaming/ |title=Spark Structured Streaming |publisher=Apache Iceberg |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; Hudi&amp;#039;s clustering documentation describes the same tension: ingestion prefers small files for parallelism and freshness, while queries degrade with many small files.&amp;lt;ref name=&amp;quot;hudi-cluster&amp;quot;&amp;gt;{{Cite web |url=https://hudi.apache.org/docs/clustering |title=Clustering (version 1.2.1) |publisher=Apache Hudi |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Many partitions per write task.&amp;#039;&amp;#039;&amp;#039; A file cannot span a table partition, and in Spark a file cannot be larger than the task that writes it. When one Spark task writes to several Iceberg partitions, each partition gets its own, smaller file.&amp;lt;ref name=&amp;quot;ice-writes&amp;quot;&amp;gt;{{Cite web |url=https://iceberg.apache.org/docs/latest/spark-writes/ |title=Spark Writes |publisher=Apache Iceberg |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; High-cardinality [[Partition|partitioning]] multiplies the number of files per commit.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Compression and columnar encoding.&amp;#039;&amp;#039;&amp;#039; The size on disk is much smaller than the in-memory size of the task&amp;#039;s rows, because the data is compressed and columnar. The Iceberg documentation gives the example that a 100 MB Spark task produces a file much smaller than 100 MB.&amp;lt;ref name=&amp;quot;ice-writes&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Row-level changes.&amp;#039;&amp;#039;&amp;#039; Merge-on-read writes add small delete files. Iceberg&amp;#039;s maintenance guide recommends compacting small position delete files because of the metadata and file-open overhead they add.&amp;lt;ref name=&amp;quot;ice-maint&amp;quot;&amp;gt;{{Cite web |url=https://iceberg.apache.org/docs/latest/maintenance/ |title=Maintenance |publisher=Apache Iceberg |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Costs ==&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Metadata.&amp;#039;&amp;#039;&amp;#039; Iceberg tracks every data file in manifests, so more files means more metadata, and small files cause an unnecessary amount of it.&amp;lt;ref name=&amp;quot;ice-proc&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;File open and request cost.&amp;#039;&amp;#039;&amp;#039; Hudi&amp;#039;s documentation points out that object stores such as S3 rate-limit requests per prefix, and that each file needs at least one request regardless of size, plus fixed costs to open and close it.&amp;lt;ref name=&amp;quot;hudi-size&amp;quot; /&amp;gt; Spark models this fixed cost with &amp;lt;code&amp;gt;spark.sql.files.openCostInBytes&amp;lt;/code&amp;gt; (default 4 MB) when packing files into read partitions.&amp;lt;ref name=&amp;quot;sparkconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Planning and scheduling.&amp;#039;&amp;#039;&amp;#039; More files mean more tasks, which adds scheduling overhead and memory pressure to Spark, Flink or Hive jobs.&amp;lt;ref name=&amp;quot;hudi-size&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Storage efficiency.&amp;#039;&amp;#039;&amp;#039; Many small files can compress less well and need more index and statistics metadata.&amp;lt;ref name=&amp;quot;hudi-size&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remedies by project ==&lt;br /&gt;
=== Apache Iceberg ===&lt;br /&gt;
Iceberg writers roll over to a new file when it reaches &amp;lt;code&amp;gt;write.target-file-size-bytes&amp;lt;/code&amp;gt;, default 536870912 bytes (512 MB); delete files have a separate target, &amp;lt;code&amp;gt;write.delete.target-file-size-bytes&amp;lt;/code&amp;gt;, default 64 MB.&amp;lt;ref name=&amp;quot;ice-conf&amp;quot;&amp;gt;{{Cite web |url=https://iceberg.apache.org/docs/latest/configuration/ |title=Configuration |publisher=Apache Iceberg |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; Because a Spark task may be too small to reach the target, the Iceberg documentation advises controlling what data each task receives with &amp;lt;code&amp;gt;write.distribution-mode&amp;lt;/code&amp;gt; or an explicit repartition.&amp;lt;ref name=&amp;quot;ice-writes&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For existing files, the &amp;lt;code&amp;gt;rewrite_data_files&amp;lt;/code&amp;gt; procedure compacts small files into larger ones, using bin-packing by default or a sort. Its options include &amp;lt;code&amp;gt;target-file-size-bytes&amp;lt;/code&amp;gt; (defaulting to the table&amp;#039;s target), &amp;lt;code&amp;gt;min-file-size-bytes&amp;lt;/code&amp;gt; (75% of the target), &amp;lt;code&amp;gt;max-file-size-bytes&amp;lt;/code&amp;gt; (180% of the target) and &amp;lt;code&amp;gt;min-input-files&amp;lt;/code&amp;gt; (5).&amp;lt;ref name=&amp;quot;ice-proc&amp;quot; /&amp;gt; The &amp;lt;code&amp;gt;rewrite_manifests&amp;lt;/code&amp;gt; procedure addresses the matching problem in metadata, since fast appends in streaming workloads can leave many small manifest files.&amp;lt;ref name=&amp;quot;ice-stream&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
-- Apache Iceberg (Spark SQL): compact one day&amp;#039;s files toward 512 MB&lt;br /&gt;
CALL catalog.system.rewrite_data_files(&lt;br /&gt;
  table   =&amp;gt; &amp;#039;db.events&amp;#039;,&lt;br /&gt;
  where   =&amp;gt; &amp;#039;event_date = &amp;quot;2026-11-21&amp;quot;&amp;#039;,&lt;br /&gt;
  options =&amp;gt; map(&amp;#039;target-file-size-bytes&amp;#039;, &amp;#039;536870912&amp;#039;)&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Delta Lake ===&lt;br /&gt;
Delta Lake&amp;#039;s &amp;lt;code&amp;gt;OPTIMIZE&amp;lt;/code&amp;gt; command (from 1.2.0) coalesces small files into larger ones by bin-packing and can be limited to a partition predicate with &amp;lt;code&amp;gt;WHERE&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;delta-opt&amp;quot;&amp;gt;{{Cite web |url=https://docs.delta.io/optimizations-oss/ |title=Optimizations |publisher=Delta Lake |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Auto compaction (from 3.1.0) runs synchronously after a successful write and compacts small files in the affected partitions. It is enabled with the table property &amp;lt;code&amp;gt;delta.autoOptimize.autoCompact&amp;lt;/code&amp;gt; or the session setting &amp;lt;code&amp;gt;spark.databricks.delta.autoCompact.enabled&amp;lt;/code&amp;gt;, uses a 128 MB target by default, and is tuned with &amp;lt;code&amp;gt;spark.databricks.delta.autoCompact.maxFileSize&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.databricks.delta.autoCompact.minNumFiles&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;delta-opt&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Optimized writes (from 3.1.0) shuffle data before writing so that each partition receives fewer, larger files, at the cost of extra write latency. The feature is off by default and is enabled with the table property &amp;lt;code&amp;gt;delta.autoOptimize.optimizeWrite&amp;lt;/code&amp;gt;, the setting &amp;lt;code&amp;gt;spark.databricks.delta.optimizeWrite.enabled&amp;lt;/code&amp;gt;, or the writer option &amp;lt;code&amp;gt;optimizeWrite&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;spark.databricks.delta.optimizeWrite.binSize&amp;lt;/code&amp;gt; (default 512 MiB) sets the target in-memory size of each output file.&amp;lt;ref name=&amp;quot;delta-opt&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Apache Hudi ===&lt;br /&gt;
Hudi sizes files during writes. On insert and upsert, it adds records to existing files smaller than &amp;lt;code&amp;gt;hoodie.parquet.small.file.limit&amp;lt;/code&amp;gt; (default 104857600 bytes, 100 MB) until they approach &amp;lt;code&amp;gt;hoodie.parquet.max.file.size&amp;lt;/code&amp;gt; (default 125829120 bytes, 120 MB). The &amp;lt;code&amp;gt;bulk_insert&amp;lt;/code&amp;gt; operation does not size files this way.&amp;lt;ref name=&amp;quot;hudi-size&amp;quot; /&amp;gt; For merge-on-read tables, &amp;lt;code&amp;gt;hoodie.merge.small.file.group.candidates.limit&amp;lt;/code&amp;gt; (default 1) limits how many small file groups an upsert may expand, to limit rewriting.&amp;lt;ref name=&amp;quot;hudi-size&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After writes, Hudi&amp;#039;s clustering table service stitches small files into larger ones and can sort data for locality. It runs inline after each write when &amp;lt;code&amp;gt;hoodie.clustering.inline&amp;lt;/code&amp;gt; is true, or asynchronously with &amp;lt;code&amp;gt;hoodie.clustering.async.enabled&amp;lt;/code&amp;gt;; both default to false.&amp;lt;ref name=&amp;quot;hudi-cluster&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;hudi-conf&amp;quot;&amp;gt;{{Cite web |url=https://hudi.apache.org/docs/configurations |title=All Configurations |publisher=Apache Hudi |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; Files under &amp;lt;code&amp;gt;hoodie.clustering.plan.strategy.small.file.limit&amp;lt;/code&amp;gt; (default 314572800 bytes) are candidates.&amp;lt;ref name=&amp;quot;hudi-conf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Apache Spark ===&lt;br /&gt;
Spark settings shape how many files a write produces, independent of the table format.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.sql.files.maxRecordsPerFile&amp;lt;/code&amp;gt; caps the rows in one output file; the default 0 means no limit.&amp;lt;ref name=&amp;quot;sparkconf&amp;quot; /&amp;gt;&lt;br /&gt;
* The &amp;lt;code&amp;gt;COALESCE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;REPARTITION&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;REBALANCE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;REBALANCE_BY_SIZE&amp;lt;/code&amp;gt; SQL hints, and the matching &amp;lt;code&amp;gt;coalesce&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;repartition&amp;lt;/code&amp;gt; Dataset methods, control the number of output files. &amp;lt;code&amp;gt;REBALANCE&amp;lt;/code&amp;gt; asks adaptive query execution (AQE) for output partitions of reasonable size, to avoid files that are too small or too big, and is ignored when AQE is disabled.&amp;lt;ref name=&amp;quot;spark-hints&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-ref-syntax-qry-select-hints.html |title=Hints (Spark 4.3.0 documentation) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* With AQE (&amp;lt;code&amp;gt;spark.sql.adaptive.enabled&amp;lt;/code&amp;gt;, default true), &amp;lt;code&amp;gt;spark.sql.adaptive.coalescePartitions.enabled&amp;lt;/code&amp;gt; (default true) merges small shuffle partitions toward &amp;lt;code&amp;gt;spark.sql.adaptive.advisoryPartitionSizeInBytes&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;spark-tuning&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/sql-performance-tuning.html |title=Performance Tuning (Spark 4.3.0 documentation) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;sparkconf&amp;quot; /&amp;gt; The Iceberg documentation notes that this advisory size measures shuffle data, not the compressed columnar file, so it must be set larger than the desired file size.&amp;lt;ref name=&amp;quot;ice-writes&amp;quot; /&amp;gt;&lt;br /&gt;
* On the read side, &amp;lt;code&amp;gt;spark.sql.files.maxPartitionBytes&amp;lt;/code&amp;gt; (default 128 MB) and &amp;lt;code&amp;gt;spark.sql.files.openCostInBytes&amp;lt;/code&amp;gt; control how many small files are packed into one read partition.&amp;lt;ref name=&amp;quot;sparkconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Copy-on-write and merge-on-read]]&lt;br /&gt;
* [[Deletion vector]]&lt;br /&gt;
* [[Structured Streaming]]&lt;br /&gt;
* [[Partition]]&lt;br /&gt;
* [[Shuffle]]&lt;br /&gt;
* [[Open table format]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Navbox open lakehouse}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Concepts]]&lt;br /&gt;
[[Category:Glossary terms]]&lt;br /&gt;
[[Category:Table formats]]&lt;/div&gt;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>