Physical Data Layout

Where bytes physically sit decides what a query must read. File size, compaction, partitioning, pruning, cardinality, clustering and bucketing — the highest-leverage and least-visible decisions in analytics.

Physical Data Layout

Two datasets with identical rows and identical schemas can differ by an order of magnitude in what a query must read. The difference is which rows share a file and which files share a directory.

Q · The rows are the same, the schema is the same and the query is the same — so why does one copy of this dataset cost far more to query than the other?
File Size and the Small-Files Problem

The same bytes split into a million objects behave nothing like the same bytes in a hundred. On object storage the cost is per request, so this is a problem about file count, not data volume.

Q · The table holds the same data it held last month and the same total size, but every query against it got slower. What changed?
File Compaction

Rewriting many small files into fewer larger ones. What it buys, what it costs, and what a reader sees if it is halfway through when their query starts.

Q · The table is made of far too many files. Rewriting them into fewer, larger ones fixes the reads — so what does that rewrite cost, and what happens to everyone reading the table while it runs?
Partitioning

Putting a column's value into the directory path so a reader can exclude data without opening it. The cheapest skip available, and the only one that costs nothing to evaluate.

Q · Why does writing `date=2026-08-24` into the directory name make a query cheaper than storing exactly the same date as a column inside the files?
Partition Pruning

The planner eliminating partitions before reading. It is a best-effort behaviour, not a guarantee — and there are four common predicate shapes that silently defeat it while looking completely correct.

Q · The table is partitioned by date, the query filters on date, and it still read the whole table. What stopped the planner from pruning?
Partition Cardinality

A partition key with too many distinct values produces more metadata than data. The target is enough rows per partition to justify a file, and few enough partitions to list.

Q · How many partitions is too many — and how would you know before you have written four years of them?
Clustering and Sort Order

Within a partition, the order rows were written in decides how selective file statistics are. Sorting is what turns a min/max into a skip, and it decays as soon as you stop maintaining it.

Q · Inside a single partition, does the order the rows were written in change anything? The answer is the same rows either way — so why would it?
Bucketing

Hashing a key into a fixed number of files so that rows with the same key always land in the same bucket. One physical technique, and it earns its keep almost exclusively when it lets a join skip the shuffle.

Q · When is it worth deciding, at write time, exactly which file every row will live in — and what does that buy that sorting does not?
The Partitioning Decision

Five questions that decide a partition key: what the filters carry, how many distinct values, how much data per partition, how often data is appended, and whether the distribution is skewed. Answer them from data, not from intuition.

Q · Given this table and the queries that actually run against it, what should the partition key be — and is the honest answer sometimes that there should not be one?