Run SELECT sum(amount) FROM sales WHERE year = 2025 on a table with a billion rows in a regular database, and you may wait minutes. Run the same query on ClickHouse, BigQuery or DuckDB, and it often comes back in seconds. Same data, same SQL. The difference is mostly about one decision: how the rows are laid out on disk.
Row storage: how most databases work
PostgreSQL, MySQL and SQL Server store data by row. All the values of one row sit together on a disk page:
page 1: [1, 2025-01-03, Algiers, 3, 1200] [2, 2025-01-03, Oran, 1, 400] ... This is ideal for transactional work. Loading customer 42 means reading one place on disk and getting all their columns at once. Inserting an order writes one row in one place. Updating it touches one row.
Now take the analytics query. It needs only two columns, year and amount, out of perhaps twenty. With row storage, the database must still read every page, and every page is full of the eighteen columns it does not need. Most of the disk reading is wasted.
Column storage: flip the layout
A column-oriented (columnar) database stores each column separately:
id: 1, 2, 3, 4, ... date: 2025-01-03, 2025-01-03, 2025-01-04, ... city: Algiers, Oran, Algiers, Algiers, ... qty: 3, 1, 2, 5, ... amount: 1200, 400, 800, 2000, ... The same query now reads only the date (or year) and amount columns. If the table has twenty columns of similar size, that is roughly a tenth of the data. That alone is a big gain, and three more effects add to it.
Why it is so much faster
1. Compression works better
A column holds values of one type, often repetitive. A city column might contain only a few dozen distinct values across a billion rows. Columnar engines use encodings that fit this:
- Dictionary encoding: store each distinct city once and replace values with small integers.
- Run-length encoding: "Algiers × 5,000" instead of 5,000 copies, especially effective when data is sorted.
- Delta encoding: store differences between consecutive numbers or dates.
Compressed columns are often many times smaller than the raw data. Less data on disk means less to read, and more of it fits in memory.
2. Vectorized execution
Because values of one column are packed together, the engine processes them in batches of thousands at a time, in tight loops the CPU can run with SIMD instructions. A row-by-row engine spends much of its time interpreting each row; a vectorized engine spends it adding numbers.
3. Skipping data
Columnar formats keep small statistics per block of rows, such as the minimum and maximum value. If a block's date range is all in 2023, a query for 2025 skips it without reading it. When data is sorted by a column that queries often filter on (like date), most blocks can be skipped.
A concrete example
Imagine a sales table with 1 billion rows and 20 columns, and this report:
SELECT city, sum(amount) AS revenue FROM sales WHERE sale_date >= '2025-01-01' GROUP BY city ORDER BY revenue DESC; What a columnar engine does, step by step:
- Reads only three columns:
sale_date,cityandamount. - Uses min/max statistics to skip blocks that hold only older dates.
- Reads the remaining blocks in compressed form;
cityis dictionary-encoded, so grouping works on small integers. - Sums
amountin vectorized batches, often in parallel across CPU cores.
A row store would read all 20 columns of every row (unless an index covers the query) and process them row by row. That is the gap you feel.
The price you pay
Columnar storage is not better in general. It is better for a specific workload.
Single-row lookups are slower. Fetching all columns of one row means reading from twenty separate column files and stitching the row back together.
Small writes are expensive. Inserting one row means appending to every column, and compressed blocks do not like being modified. Columnar engines prefer inserts in large batches. ClickHouse, for example, writes each insert as a new part and merges parts in the background, so thousands of tiny inserts per second cause trouble.
Updates and deletes are awkward. Many columnar systems implement them as background rewrites or as markers that hide old rows until a merge. They work, but they are not what the engine is built for.
Transactions are limited. Strong multi-row transactional guarantees are usually weaker than in PostgreSQL or MySQL.
Where you meet columnar storage
- Analytical databases and warehouses: ClickHouse, BigQuery, Snowflake, Amazon Redshift, DuckDB.
- File formats: Apache Parquet and ORC store data by column in files, which is why data lakes read them efficiently with engines like Spark or Trino.
- Extensions and hybrids: some row databases offer columnar options or indexes, such as columnstore indexes in SQL Server, for mixing the two.
Common mistakes
- Using a columnar database as the main application database. Your checkout flow does many small reads and writes per second; a row store fits it.
- Writing one row at a time into it. Batch inserts, or put a queue or buffer in front.
-
SELECT *on wide tables. It throws away the main advantage. Ask only for the columns you need. - Ignoring sort order. In engines like ClickHouse, the table's sort key decides how much data can be skipped. Pick it based on your most common filters.
How teams usually combine them
The common setup keeps the application on a row-oriented database (OLTP) and copies data, in batches or as a stream of changes, into a columnar store for reporting and analytics (OLAP). Each engine does the work it is shaped for.
Watch the animated version: https://youtu.be/uR6Mboxkdys
In short
- Row stores keep each row together: great for reading and writing single records.
- Column stores keep each column together: queries read only the columns they need.
- Better compression, vectorized execution and block skipping multiply the gain.
- The cost is slow single-row access and expensive small writes, so use columnar storage for analytics next to, not instead of, your transactional database.
Originally published at abdeldjalilchougui.biz.

