Partitioning and Data Skipping
How Hive does it, and why that's fragile
s3://warehouse/events/dt=2024-01-01/hour=14/part-00000.parquetProblem 1 · Skipping quietly stops working
Say the table is partitioned by dt, a string. A query filters on WHERE event_timestamp > '2024-01-01 10:00:00' instead. The planner has no way to know dt was derived from event_timestamp, so it scans every partition. The answer is still correct — it's just slow, and nothing tells you unless you go check the query plan.
Problem 2 · The scheme is fixed at creation
A table partitioned by day outgrows itself and needs hourly partitions instead. Hive gives you no way to change that short of rewriting every historical file into the new layout.
Iceberg's hidden partitioning
Iceberg stores the partitioning rule in table metadata as a partition spec: (source column, transform) → partition field. Iceberg applies that transform itself, so nothing gets frozen into a folder name that you then have to know about and filter on by hand.
| Transform | Example | Use case |
|---|---|---|
identity | partition = raw column value | Low-cardinality categoricals (region) |
year / month / day / hour | partition = truncated timestamp | Time-series data — the overwhelmingly common case |
bucket(N, col) | partition = hash(col) % N | High-cardinality columns with no natural grouping (user_id) — spreads rows across N fixed buckets instead of one partition per value |
truncate(N, col) | partition = first N characters or digits | Group a high-cardinality column more coarsely, without hashing |
Partition evolution
Because the rule lives in metadata, not in the file layout, ALTER TABLE events SET PARTITION SPEC (hour(event_timestamp)) only changes what happens from now on. Old files keep their old spec-id, new files use the new one, and a query spanning both periods reads each side under its own scheme automatically. Nothing gets rewritten.
metadata.json tracks multiple partition-specs, each with a spec-id:
spec-id 0: day(event_timestamp) ← files written before the ALTER
spec-id 1: hour(event_timestamp) ← files written after
manifest files record which spec-id their files were written under,
so planning correctly interprets each file's partition values using
the spec that was active when it was written.That fully solves problem #2 — something no Hive table can do, and today, no Delta table either, without a full rewrite.
Delta's partitioning: Hive-style, with file stats on top
Delta partitions the Hive way: the partitionValues in each add action are literal directory-style keys, exactly what you declared in CREATE TABLE … PARTITIONED BY (dt), with no transform layer. So Delta has problem #1 too — filtering on anything but the literal partition column gets no help from partitioning.
What Delta relies on instead — and does well — is skipping files by statistics, using the same add.stats min/max/null-count data from the Delta's transaction log part. This works on any column, partitioned or not:
SELECT * FROM events WHERE user_id = 500000
-- user_id is NOT a partition column — Hive-style pruning gives zero help.
-- Delta uses the per-file min/max stats in `add` actions to skip files whose
-- [min,max] range for user_id can't contain 500000 — same mechanism as
-- Iceberg's manifest column stats (§2), with no partitioning involved.Z-ordering — multi-column data skipping
Min/max stats only help if similar values actually sit together in the same file. If a file's user_id values are scattered across the whole range, its [min,max] covers everything and there's nothing to skip. Z-ordering (OPTIMIZE events ZORDER BY (user_id)) rewrites files so similar rows land together, narrowing each file's range:
✗ Without Z-order — stats useless
file A: user_id min=1, max=999998
file B: user_id min=3, max=999991
→ every file spans the whole range
→ nothing can ever be pruned✓ With Z-order — stats prune well
file A: user_id min=1, max=50000
file B: user_id min=50001, max=100000
→ tight ranges
→ a point predicate skips almost everythingZ-ordering can cover several columns at once (ZORDER BY (user_id, event_type)) and still skip well on a filter against either one — a single-column sort can't do that. It isn't free: it runs during compaction (see Compaction and maintenance) and rewrites the files it touches. Iceberg's equivalent is sort orders declared in metadata (ALTER TABLE … WRITE ORDERED BY) plus compaction. Multi-column interleaving specifically is a Delta/Databricks feature.
Worked example: where partitioning helps, and where it stops helping
Setup: an events table partitioned by day, 3 years of history, ~20 files per day — so ~1,095 partitions and ~21,900 data files. Iceberg has roughly one manifest per daily commit (~1,095 manifests, ~20 file rows each). Delta's latest checkpoint is a single Parquet file with 21,900 add rows.
Query A — filters on the partition column
WHERE event_timestamp >= '2024-06-01' AND event_timestamp < '2024-06-02'| Iceberg | Delta | |
|---|---|---|
| Step 1 | Read manifest list — 1,095 rows | Read checkpoint, scan partitionValues.dt — 21,900 rows, 1 column |
| What gets skipped | Min/max values drop 1,094 manifests without opening them | The column filter drops 21,880 rows without reading their stats column |
| Step 2 | Open the 1 surviving manifest → 20 file rows, check stats | 20 surviving rows → check stats |
| Open data files | Only the files whose stats also match — identical on both sides |
Both do the same small amount of data work here — the difference is metadata work. Iceberg never opens the 1,094 irrelevant manifests at all. Delta scans one column across all 21,900 rows. Both are cheap, and this is where partitioning clearly pays off for both.
Query B — filters on a non-partition column
WHERE user_id = 500000| Iceberg | Delta | |
|---|---|---|
| Does partition info help? | No — user_id isn't the partition column | No — same reason |
| What happens | Opens all 1,095 manifests and checks user_id stats on all 21,900 file rows | Checks user_id stats on all 21,900 rows already loaded from the checkpoint |
| Result | Both land in the same ballpark — this is purely about stats and how well the data is clustered |
The thing to remember: Iceberg's edge only shows up on Query-A-shaped queries at large scale, where skipping a manifest means never reading anything about the files inside it. Neither system's partitioning helps Query B at all.
Side-by-side
| Iceberg | Delta Lake | |
|---|---|---|
| How partitioning works | Hidden — the rule lives in metadata, and the planner derives the value from your filter on the source column | Hive-style — real partition columns you have to filter on directly |
| Changing it later | supported the new scheme applies going forward, old files are left alone | full rewrite no built-in way to change it |
| Filtering on a non-partition column | Min/max stats in the manifests (see Iceberg's metadata tree) | Min/max in add.stats (see Delta's transaction log), much better with Z-ordering |
| Skipping on several columns at once | Sort orders plus compaction | Z-ordering — more mature tooling here |
The Invariants
- Guarantees: Both keep per-file column stats, so planning can skip whole files without opening them — with or without partitioning.
- Does not guarantee: Neither removes the need for compaction to make that skipping worth anything. A table of small, randomly ordered files has min/max ranges that are technically correct and useless. Skipping only works when similar rows sit together, and only compaction, sorting, and Z-order jobs make that happen (see Compaction and maintenance).