# Clustering Key

> Rows are kept in order by one column. Then a query can skip blocks.

**Field:** Data Engineering  
**Category:** Storage & Warehousing  
**Also known as:** Clustered Table, Cluster By, Data Clustering

## 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.

## Definition

A clustering key tells a warehouse to store rows with close values near each other. Unlike a partition, it does not cut the table into separate parts. It sorts the data inside the files, often on a column you filter by a lot. Then the engine skips blocks that cannot match. Snowflake and BigQuery both offer it.

## 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.

## Example code

```sql
ALTER TABLE events CLUSTER BY (customer_id);
```

In Snowflake. Rows for the same customer are kept close together.

## 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.

## Common mistake

Clustering a small table. It costs work to keep sorted and gives little back.

## Three principles

- **Sort, not split.** Rows are ordered inside files.
- **Skip blocks.** Out-of-range blocks are never read.
- **For busy filters.** Pick the column queries filter on most.

## Related terms

- [Data Partitioning](https://learn.benibix.com/term/data/data-partitioning)
- [Partition Pruning](https://learn.benibix.com/term/data/partition-pruning)
- [Snowflake](https://learn.benibix.com/term/data/snowflake)
- [Google BigQuery](https://learn.benibix.com/term/data/bigquery)

## Told apart from

- [Data Partitioning vs Clustering Key](https://learn.benibix.com/compare/data-partitioning-vs-clustering-key): People think partitioning and clustering are the same trick. One cuts a table into separate parts, often one per day. The other keeps the table whole but sorts the rows in it. Split on a column with few values, like a date. Cluster on one with many, like a customer ID.

---

Source: https://learn.benibix.com/term/data/clustering-key
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-16
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
