Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

Databases & SQLData series

OLTP vs OLAP

The dashboard query takes forty seconds and the checkout query takes four milliseconds, and both run on the same server. That gap is the OLTP and OLAP split, and it starts in how the data is stored.

Quick reference

OLTPOLAP
WorkloadShort writes, point readsLong scans, aggregates
Typical queryOne row by primary keyMillions of rows, grouped
IndexesMany, narrow, coveringFew, columnar, compressed
StorageRow store, 8 kB pagesColumn store, compressed
LatencyMilliseconds per querySeconds to minutes
Scale byMore connections, shardingMore workers, partitions

OLTP (Many short reads and writes): The checkout database: many short transactions, one row at a time.

pgbench -c 32 -T 60

OLAP (Few large scans, many columns): The warehouse: few long scans, many columns, one answer.

sql
SELECT count(*) FROM events;
  • OLTP → write fast, read one row, stay correct.
  • OLAP → read everything, once, and forgive latency.

Explained

The workload OLTP is the database behind checkout: many short transactions, each reading or writing one row by primary key. Latency is the product, so it is measured in milliseconds and the schema is normalised to keep writes cheap. OLAP is the warehouse behind the dashboard: few queries, each scanning millions of rows and grouping them. Throughput matters more than per-query latency.

The storage A row store keeps a whole row together, so a point lookup reads one page. A column store keeps each column apart and compresses it, so a scan of three columns never touches the other thirty. That is why an OLTP index is narrow and many, and an OLAP table is wide, partitioned and columnar.

Where the line blurs Some managed warehouses now offer row-store tables for small dimensions, and PostgreSQL extensions add columnar storage to an OLTP database. The labels describe a workload, not a product.

The honest caveat: a small warehouse on a row store can beat a badly modelled column store, and an HTAP system that claims both usually pays for it somewhere. Measure your queries before you move them.

The lesson: choose the workload first, then the storage; the label is a shortcut, not a specification.

OLTP writes the row. OLAP reads the world.

More notes: Databases & SQL

Open in the notes app: search, filters, copy This note on GitHub