Partitioning Data in Amazon S3
This lesson explains how partitioning stores data in folders by the value of one or more columns, so queries filtering on those columns read only the folders they need, and how poorly chosen partitions make queries worse.
Learning outcomes
After completing this lesson, you will be able to:
- Describe Hive-style partitioning.
- Choose partition keys from how data is queried.
- Manage many partitions with partition projection and indexes.
- Register new partitions in the Data Catalog.
How partitioning works
Partitioned data uses Hive-style folder names, for example s3://lake/sales/year=2026/month=01/day=05/. Queries filtering on partition columns read only matching folders (partition pruning). The Glue Data Catalog records each partition's location, or Athena calculates them with partition projection.
The following diagram shows a partitioned table and the folder a query reads.

Partition pruning
Choosing partition keys
Partition keys should reflect how the data is queried, because partitioning helps only when queries filter on the partition columns. The usual choice is the columns that appear most often in WHERE clauses, which is almost always a date, sometimes combined with a region or tenant.
Granularity matters as much as the choice of column. Each partition should hold at least a few hundred megabytes, so daily partitions are often enough, and hourly partitions suit only very high volumes. High-cardinality keys, such as user ID, should be avoided: they create millions of tiny partitions, each with a few small files, which makes listing files and planning queries slower than scanning unpartitioned data would be.
The following diagram compares a date partition key with a high-cardinality key.

A good partition key?
Managing many partitions
Partitioning makes queries faster, but very many partitions slow down query planning, because the engine must first list which partitions exist. Three features address this. Athena partition projection calculates partition locations from rules in the table properties, such as a date range and a path template, instead of reading them from the catalogue. It is fastest for predictable partition schemes and needs no crawler or MSCK REPAIR to add new partitions. Glue partition indexes let the catalogue find matching partitions quickly without returning them all.
Iceberg hidden partitioning partitions by a transform of a column, such as day(ts), and tracks files in its own metadata. Queries filter on the column itself, without separate partition columns, and partitioning can change over time without rewriting old data. The following table summarises the features.
| Feature | Benefit |
|---|---|
| Athena partition projection | Calculates partitions from configuration instead of reading the catalogue |
| Glue partition indexes | Speed up partition filtering in the catalogue |
| Iceberg hidden partitioning | Partitions by a transform such as day(ts) without partition columns in queries, and allows partition evolution |
Adding partitions
Engines that rely on the Data Catalog, such as Athena and Redshift Spectrum, see a new partition only after it has been registered there. There are several ways to register partitions. Glue crawlers discover new folders and add them, and in S3 event mode they crawl only the folders that changed, which is much faster than a full crawl. ETL jobs can update the catalogue as they write new data.
In Athena, MSCK REPAIR TABLE scans the table's location and adds any missing partitions, though it becomes slow on large tables, while ALTER TABLE ADD PARTITION adds specific partitions quickly. Partition projection avoids registration altogether: Athena calculates partition locations from a pattern in the table properties, such as a date range, so new partitions are queryable as soon as their data lands.
Registering partitions
The cost of a query before and after
A table of web logs holds three years of data (9 TB of gzipped JSON). A daily query for yesterday's errors scans everything. The following table shows the data scanned after each change.
| Change | Data scanned per query |
|---|---|
| Original layout | 9 TB |
Partition by dt | About 8 GB (one day) |
| Convert to Parquet with Snappy | About 1.5 GB |
| Select only 4 of 40 columns | About 150 MB |
Partitioning by date makes the largest difference, because the query filters on one day. Partitioning by user ID instead would have created millions of tiny partitions and made every query slower.
Why can partitioning on a high-cardinality key hurt performance?
Show answer
It creates huge numbers of small partitions and files, so planning and listing them costs more than the pruning saves.
Exam Tips
Remember for the exam
- Partition on columns used in WHERE clauses, usually the date.
- Over-partitioning on high-cardinality keys hurts performance.
- For many predictable partitions in Athena, use partition projection.
- To speed up partition filtering in the catalogue, use partition indexes.
- Iceberg hidden partitioning removes partition columns from queries.