# Column-Oriented Storage

**Also known as:** Columnar storage · Column store  
**Category:** Data & Storage (Where the data lives)  
**Complexity:** 3/5  
**Guide:** https://layra4.dev/architectures/data-storage/column-oriented-storage

*Keep each column together, so analytics reads only what it needs.*

A row store, such as Postgres or MySQL, keeps all of a row's fields together on disk. That is ideal for loading or updating one order. An analytics query is different: it sums one or two columns over millions of rows, and a row store must read every column of every row to do it.

A column store keeps each column's values together instead. A query that touches 3 of 100 columns reads about 3% of the data, and values of one type side by side compress very well. ClickHouse, DuckDB, Snowflake, BigQuery and Redshift work this way, and so do Parquet and ORC files in a data lake. The price is paid on writes: one new row touches every column.

> **In one sentence.** Lay data out by column, so a scan reads only the columns a query names, compressed well and processed in batches. Pay for it with slow single-row writes, and keep the system of record in a row store.

## Origin (2005)

The C-Store paper (Stonebraker et al., 2005) showed column stores beating row stores on analytics by large factors, and became Vertica. Google's Dremel paper (2010) applied the layout to nested records, and Parquet followed its design.

## Key concepts

### Row layout vs column layout

The same table, stored two ways. A row layout writes one record after another. A column layout writes all the ids, then all the regions, then all the amounts, each in its own file or block.

> rows: (1,eu,40) (2,us,15) (3,eu,22)    columns: id[1,2,3] region[eu,us,eu] amount[40,15,22]

### OLTP vs OLAP

OLTP is many small reads and writes of whole rows by key: orders, users, payments. OLAP is a few large queries that scan and aggregate some columns over many rows: reports and dashboards. Row stores suit the first, column stores the second.

- OLTP: milliseconds per query, thousands of queries a second
- OLAP: seconds per query over billions of rows
- Most systems need both, in two stores

### Compression and encoding

A column holds one type, often with few distinct values or in sorted order. Light encodings shrink it before general compression runs, and less data on disk means less to read.

- Dictionary: replace each region name with a small integer
- Run-length: store "eu" once with a count of 10,000
- Delta: store sorted timestamps as small differences

### Vectorized execution

The engine processes a batch of thousands of values from one column per step, not one row at a time. Tight loops over plain arrays use CPU caches and SIMD instructions well, so a core can scan hundreds of millions of values a second.

### Sort key and block statistics (Zone maps · Min/max indexes)

Data is stored sorted by a chosen key, and each block records the minimum and maximum of every column. A query filtered on the sort key skips every block whose range cannot match, without reading it.

### Parquet-style files

Parquet splits a file into row groups. Inside each group, every column is a separate chunk with its own encoding and min/max statistics. Files are immutable: a change means writing a new file, never editing one.

### Why point updates are expensive

One row is spread across a block per column, and those blocks are compressed and often immutable. Changing the row means rewriting the blocks, or writing a delete marker and a new version that a background merge folds in later.

- Writes land in a small buffer or a new part, then merge
- Updates and deletes are often asynchronous
- Many small writes mean many small parts and constant merging

## Design rules

### Keep transactions in a row store

The system of record belongs in an OLTP database. Copy its data into the column store for analytics, with batch loads or change data capture, and accept that the copy lags.

### Write in large batches

Aim for thousands to millions of rows per insert, or files of hundreds of megabytes. Buffer small events upstream, in a queue or a staging table, and flush them together.

### Pick the sort key from your filters

Sort by the columns most queries filter on, for example tenant and then time. Block statistics then skip most of the data. A sort key no query uses buys nothing.

### Name only the columns you need

A column store reads exactly the columns a query names. select * on a wide table reads every column and throws the main advantage away.

## Examples

### A column table, a scan and an expensive update

```sql
create table orders_analytics (
  order_id     UInt64,
  customer_id  UInt64,
  region       LowCardinality(String),       -- dictionary-encoded
  status       LowCardinality(String),
  amount_cents Int64 CODEC(ZSTD),
  created_at   DateTime CODEC(Delta, ZSTD),  -- sorted times compress to small deltas
  note         String
)
engine = MergeTree
partition by toYYYYMM(created_at)           -- whole months can be skipped or dropped
order by (region, created_at);              -- the sort key: what block skipping uses

-- Load in one large batch, not row by row. Each insert creates a new part on disk.
insert into orders_analytics
select order_id, customer_id, region, status, amount_cents, created_at, note
from staging_orders;

-- The report touches 3 of 7 columns, so it reads only those 3 from disk.
select region, sum(amount_cents) / 100 as revenue
from orders_analytics
where created_at >= now() - interval 30 day
group by region
order by revenue desc;

-- The expensive one: a point update rewrites every part that holds a match.
alter table orders_analytics update status = 'refunded' where order_id = 42;
```

ClickHouse syntax; other column stores have the same parts under other names. The table is sorted by region and time, with encodings per column. The report reads three columns out of seven. The update at the end is the costly one: it is a background mutation that rewrites every part holding a matching row.

## When to use

- Dashboards and reports that aggregate a few columns over millions of rows
- Events, logs and metrics that are appended and rarely changed
- A warehouse or data lake fed from the operational databases

## When not to use

- The system of record: orders, accounts, anything updated row by row
- High-rate lookups of one whole row by its key
- Small data: below a few million rows, Postgres with the right index is fast enough

## Benefits

- Scans read only the columns a query names
- Strong compression, often several times smaller than the row-store copy
- Batch processing that uses CPU caches and SIMD well

## Costs

- Single-row inserts, updates and deletes are slow or deferred
- A second copy of the data, and a pipeline to keep it fresh
- Reading one whole row means touching every column

## Pitfalls

- Inserting one row at a time, then watching merges fall behind until the store rejects writes for having too many parts.
- Running select * on a 200-column table and concluding that column stores are slow.
- Choosing a sort key that no query filters on, so every query reads every block.
- Writing thousands of tiny Parquet files to a lake, so queries spend more time opening files than reading them.

## Related patterns

- [Batch Processing](https://layra4.dev/architectures/data-storage/batch-processing) — how data usually gets into a column store
- [Change Data Capture](https://layra4.dev/architectures/data-storage/change-data-capture) — streaming row-store changes into the analytics copy
- [Object Storage](https://layra4.dev/architectures/data-storage/object-storage) — where Parquet files usually live
- [Database Indexes](https://layra4.dev/architectures/data-storage/database-indexing) — the row-store answer for fast point lookups

## Further reading

- *Designing Data-Intensive Applications, ch. 3* — Martin Kleppmann (2017) — Storage and retrieval, including column storage and OLAP.
- *C-Store: A Column-oriented DBMS* — Mike Stonebraker et al. (2005) — The paper that made the case for column stores in analytics.
- *The Design and Implementation of Modern Column-Oriented Database Systems* — Daniel Abadi, Peter Boncz, Stavros Harizopoulos, Stratos Idreos, Samuel Madden (2013) — A survey of compression, late materialization and vectorized execution.
