🗄️Clustering Key
Also known as Clustered Table, Cluster By, Data Clustering
Rows are kept in order by one column. Then a query can skip blocks.
Think of it like
It is like keeping books on a shelf in A to Z order. You still have one shelf, but finding a book is quick.
Example
A table is split by day and clustered by customer. A query for one customer on one day reads a few blocks of one part.
Why it matters
It helps where splitting a table cannot. A column with millions of values, like a customer ID, is a bad split but a good cluster key.
Definition
Example code
sql
ALTER TABLE events CLUSTER BY (customer_id);Common mistake
Key takeaways
- 1Sort, not split. Rows are ordered inside files.
- 2Skip blocks. Out-of-range blocks are never read.
- 3For busy filters. Pick the column queries filter on most.