Skip to main content
ReferenceApplies to: Unified engine deployments
Data compaction reads eligible data files and writes a new layout. Bin packing combines small files. Sorting orders records by chosen columns within the rewritten output. Z-order places values from several columns near each other to help some multi-column filters.

Before you start

Choose a writable Iceberg catalog in Workbench and an unused practice namespace. These examples use maintenance_docs, as described in Inspect and prepare a table. Native maintenance currently requires Iceberg format v2.

Create, compact, and check a table

This complete script creates six rows in three writes, checks the logical data, compacts eligible files, and checks the same totals again. It replaces only maintenance_docs.data_demo.
Both aggregate queries should return: The row query should still return IDs 1 through 6 with their original values. The 1 MiB output target and 8 MiB group limit are small practice values, not a production sizing recommendation.

Read the maintenance result

Select the CALL statement’s result in Workbench’s statement selector. Refresh the table’s Inspection view and compare current data-file counts, sizes, and snapshot identity. Fewer files with unchanged visible rows is the intended outcome for small-file compaction. Exact counts depend on file eligibility and the writer. Zero rewritten files is a valid no-op when no group qualifies. Files are grouped within their partitions. Several partitions can produce several output files. Compaction does not change the table’s partition specification.

Sort by a column

Run the setup above first. This alternative sorts rewritten data by region, then id. min_input_files => 1 allows an eligible single-file group after the earlier bin-pack call.
The logical result remains six rows and total 210. Sorting the file layout does not guarantee the order of a later SELECT; use ORDER BY when query output needs an order. This call does not set a permanent sort rule for later writes.

Z-order several columns

Z-order is another layout strategy for the same practice table. It requires distinct column names with supported types.
The row count and total remain unchanged. Compare real filter queries before choosing sort or Z-order for a production table. The six-row example teaches the command; it is too small to measure useful query speed.

Size work for the available memory

max_group_size_bytes limits candidate input grouping. It is not a promise about decoded memory use. Compressed input can expand when read, and sorting needs working memory. The provider also applies the instance’s file, byte, and memory limits. For resource-limit failures, use smaller groups or ask the operator to review maintenance task limits. Keep target_file_size_bytes no greater than max_group_size_bytes. This provider does not currently accept a where argument to select a subset of table files for these calls.

Clean up

After the operation finishes, remove only the practice table:
Continue with delete compaction, manifest optimization, or the procedure reference.
Last modified on November 4, 2026