Difficulty: Advanced
What is columnar storage, and why is it much faster than row storage for analytical (OLAP) queries?
Columnar storage writes all values of one column together on disk, instead of storing each row's values together. Analytical queries usually touch a few columns across millions of rows, so a columnar engine reads only those columns, compresses them far better because similar values sit side by side, and processes them in tight CPU-friendly batches. The cost is that inserting or updating single rows is slow, which is why OLTP databases stay row-oriented.
Consider an orders table with columns id, city, amount, status, created_at:
(1, Pune, 450, PAID, ...), (2, Delhi, 1200, PAID, ...) and so on. Fetching one order reads one place.city values, another holds all amount values.Now run SELECT city, SUM(amount) FROM orders GROUP BY city on a table with 40 columns. A row store has to read every column of every row from disk. A column store reads just two columns, roughly 5% of the data.
Values in one column share a type and often repeat:
city, a million consecutive "Pune" values become one pair (Pune, 1,000,000).status column with 4 distinct values needs only 2 bits per row.Less data on disk means less I/O, and many engines can operate on compressed data directly.
created_at >= '2026-10-01' skips whole blocks.| Aspect | Row store (OLTP) | Column store (OLAP) |
|---|---|---|
| Fetch one full record | Fast | Slow, must stitch many columns |
| Single-row insert/update | Fast | Slow, usually batched |
| Aggregation over few columns | Slow on large tables | Very fast |
| Compression ratio | Modest | High |
| Examples | PostgreSQL, MySQL, Oracle | ClickHouse, BigQuery, Snowflake, Redshift |
Column stores handle writes by buffering them and writing large immutable chunks, merging later (ClickHouse's MergeTree parts, Parquet files rewritten by compaction). Updates and deletes are often expensive or asynchronous.
A company like Swiggy or Flipkart typically keeps orders in a row-oriented OLTP database for the app, streams changes into a columnar warehouse or lake (Parquet on S3 queried by Spark or Trino), and runs dashboards there. Some systems blend both: PostgreSQL has columnar extensions, and SQL Server offers columnstore indexes.
| Row store | Column store | |
|---|---|---|
| Data read from disk | All 40 columns | Only city and amount |
| Compression | Mixed types per page | Similar values together |
| Execution | Row at a time | Vectorized batches |
| Block skipping | Needs an index | Min/max per block |
CREATE TABLE orders_analytics (
order_id UInt64,
city LowCardinality(String), -- dictionary encoded
amount_paise UInt64,
status LowCardinality(String),
created_at DateTime
)
ENGINE = MergeTree
ORDER BY (city, created_at); -- sorting improves compression and skipping
-- Reads only 3 columns, skips blocks outside October
SELECT city, sum(amount_paise) / 100 AS revenue_rupees
FROM orders_analytics
WHERE created_at >= '2026-10-01'
GROUP BY city
ORDER BY revenue_rupees DESC;
The sort key keeps similar values together, which improves compression and lets min/max metadata skip irrelevant blocks.
Columnar Storage, OLAP, Column Compression, Vectorized Execution, Parquet