Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

OPTIMIZE

Focus mode
OPTIMIZE - Amazon Athena

Optimizes rows in an Apache Iceberg table by rewriting data files into a more optimized layout based on their size and number of associated delete files.

Note

OPTIMIZE is transactional and is supported only for Apache Iceberg tables.

Syntax

The following syntax summary shows how to optimize data layout for an Iceberg table.

OPTIMIZE [db_name.]table_name REWRITE DATA USING BIN_PACK [WHERE predicate]
Note

Only partition columns are allowed in the WHERE clause predicate. Specifying a non-partition column will cause the query to fail.

The compaction action is charged by the amount of data scanned during the rewrite process. The REWRITE DATA action uses predicates to select for files that contain matching rows. If any row in the file matches the predicate, the file is selected for optimization. Thus, to control the number of files affected by the compaction operation, you can specify a WHERE clause.

Configuring compaction properties

To control the size of the files to be selected for compaction and the resulting file size after compaction, you can use table property parameters. You can use the ALTER TABLE SET TBLPROPERTIES command to configure the related table properties.

Additional resources

Optimize Iceberg tables

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.