Skip to content
mentoor

Topic 1 of 5 · 4 min read

Why columnar storage scans fast

Goal: Explain from a query's shape whether a row store or a column store will answer it faster and why.

A column store keeps each column's values together on disk, so a report that touches 3 of 80 columns reads about that much of the table instead of all of it. A row store such as PostgreSQL or MySQL InnoDB keeps each row together, which is ideal when you fetch or update one whole row.

Check yourself · 1 of 3

A report sums one column across 500 million rows of a 60-column table. Why does a column store usually answer it faster than a row store?

Choose one answer

Why it matters

Most reporting queries read a few columns across millions of rows: sum revenue by country, count events by day. A row store has to read every column of every row page to answer them. An analytics engine such as DuckDB, ClickHouse, BigQuery or Snowflake reads only the columns named in the query. Less disk read means faster answers and a smaller bill on engines that charge by bytes scanned.

How it works

  1. Column pruning. Only the columns in SELECT, WHERE, GROUP BY and JOIN are read. SELECT * throws this advantage away.
  2. Compression. Values in one column look alike (a country column holds a few dozen distinct strings), so dictionary, run-length and delta encodings shrink them well. Mixed row data compresses worse.
  3. Vectorized execution. The engine processes batches of values from one column in tight loops that use CPU caches and SIMD instructions, instead of interpreting one row at a time.
  4. Skipping. Files and blocks carry min and max values per column, so a filter on a date range can skip whole blocks unread.

The trade-off is writes and point lookups. Changing one row means touching every column's storage. Fetching one order by id is fast in a row store with an index and slower in a column store. This is why you keep the checkout on PostgreSQL and send a copy of the data to an analytics engine.

Before and after

A reporting query on a 200-million-row events table with 60 columns:

-- Slow on a row store, wasteful anywhere
SELECT * FROM events WHERE event_date >= '2026-11-01';

-- Reads two columns plus the filter column
SELECT country, count(*) AS n
FROM events
WHERE event_date >= '2026-11-01'
GROUP BY country;

The first query returns 60 columns to a client that will use two. The second lets a column store read three column chunks and skip blocks outside the date range.

What goes wrong

  • Running dashboards on the production row store. Wide scans compete with checkout traffic for disk and memory.
  • Using a column store as an app database. Single-row updates and many tiny inserts are slow and create many small files or parts.
  • Writing SELECT * out of habit. An assistant often generates it by default; ask for named columns.
  • Assuming columnar means faster for everything. A query that needs every column of a few rows is a row-store job.

Examples

Pick the layout from the query

Two requests hit the same orders data. "Show order 8841 with all its fields" is a point lookup of one whole row, so a row store with an index on the id fits. "Revenue by month for 2026" reads two columns across all rows, so a column store fits. If both are needed, keep the orders in PostgreSQL and replicate them to an analytics engine for the second.

Stop the dashboard from hurting checkout

A dashboard query that scans a 90-column orders table on the production PostgreSQL server slows page loads at noon. Moving the same query to a nightly Parquet export queried with DuckDB takes the load off production and reads only the 4 columns the chart uses.

Key points

  • A column store reads only the columns a query names, so wide tables with narrow reports scan far less data.
  • Similar values in one column compress well, which cuts both disk reads and storage cost.
  • Vectorized execution and per-block min and max values let engines skip work, not just do it faster.
  • Row stores win at fetching or updating single whole rows; column stores win at scanning many rows for a few columns.
  • SELECT * removes most of the columnar advantage, so name the columns you need.

Common mistakes

  • Running wide reporting scans on the same row-store database that serves customers.
  • Choosing a column store for an app that mostly updates single rows.
  • Leaving SELECT * in reporting queries and paying to read columns nobody uses.
  • Believing column stores replace transactional databases instead of complementing them.

Check yourself · 2 of 3

Which request is a better fit for a row store such as PostgreSQL than for a column store?

Choose one answer

Check yourself · 3 of 3

A dashboard query uses SELECT * on a 60-column events table in a column store but charts only 2 columns. What is the best fix?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic