OPTIMIZE TABLE
Rewrite data files to an optimal size, combining small files or splitting large files. For more information about optimizing tables, see Optimizing Tables.
SyntaxOPTIMIZE TABLE <table_name>
[ REWRITE DATA USING BIN_PACK
[ ( { TARGET_FILE_SIZE_MB | MIN_FILE_SIZE_MB | MAX_FILE_SIZE_MB | MIN_INPUT_FILES } = <value> [, ... ] ) ]
]
Parameters
<table_name>
String
The path of the Iceberg table that you want to optimize.
REWRITE DATA USING BIN_PACK
Optional
Either compacts smaller files or splits larger ones to the optimal file size using the BIN_PACK
strategy. This parameter is used by default to optimize a table, but you can optionally include this parameter in your query to specify additional options to check the file sizes in your selected table.
[ ( { TARGET_FILE_SIZE_MB | MIN_FILE_SIZE_MB | MAX_FILE_SIZE_MB | MIN_INPUT_FILES } = <value> [, ... ] ) ]
Number
Optional
The options available for the REWRITE DATA USING BIN_PACK clause. See the following table for the options that are supported.
Option Name | Default Value | Description |
---|---|---|
| 256 MB | Controls the target size of the files that are generated. |
| 0.75 times the value of | Files that are smaller in size than |
| 1.8 times the value of | Files that are larger in size than |
| 5 | The minimum number of qualified files needed to be considered for compaction. |
Examples
Rewriting the data files in the specified table to Dremio's optimal supported file sizeOPTIMIZE TABLE demo.example_table
OPTIMIZE TABLE demo.example_table
REWRITE DATA USING BIN_PACK
OPTIMIZE TABLE demo.example_table
REWRITE DATA USING BIN_PACK (TARGET_FILE_SIZE_MB=256)
OPTIMIZE TABLE demo.example_table
REWRITE DATA USING BIN_PACK (MIN_FILE_SIZE_MB=100, MAX_FILE_SIZE_MB=1000)
OPTIMIZE TABLE demo.example_table
REWRITE DATA USING BIN_PACK (MIN_INPUT_FILES=10)
OPTIMIZE TABLE demo.example_table
REWRITE DATA USING BIN_PACK (MIN_FILE_SIZE_MB=100, MAX_FILE_SIZE_MB=1000, TARGET_FILE_SIZE_MB=512)