Columnar storage: the unit of fetch
Columnar layout leaves disk speed unchanged and changes the unit of fetch, so different queries become cheap.
Storage hardware does not get faster when you choose columns. What changes is what one trip to disk returns. A row layout returns every field of a record, so point lookups by key are cheap. A column layout returns a contiguous run of one field, so aggregations over one field are cheap. The layout decides which queries the disk can answer in few trips.
A row store keeps every column of one record in adjacent bytes, usually inside fixed-size pages, so one read returns every field the record holds. A column store writes each column into its own run, so values from column three sit next to other values from column three, and a scan over one column reads one contiguous run. Every column still shares one row order, so position i in each file refers to the same record. A point read therefore opens each column the query names and stitches values together by offset. Parquet packs column chunks into row groups, 128 MB by default, and stores minimum and maximum statistics for each chunk. A reader that wants values above 60 can skip any chunk whose recorded maximum is 55 without reading its bytes.
The abstraction hides the write path and the sort-order commitment. An insert into a row store touches one page. An insert into a column store touches one file per column, and inserting into the middle of a sorted column file shifts everything after it. Consider an events table with dozens of columns, where a team moves everything to columns so a dashboard can average one field over a time range. The dashboard gets cheap, but the product page that loads one full record by key now opens dozens of files, reassembles the values, and decompresses chunks to recover single fields. Analytical columns typically compress 2-10x, yet decompressing a chunk costs work even when a query wants one value. The disk did not change. The set of cheap queries did.
Count the columns and rows each query touches before choosing a layout. Few columns over many rows points to columns. Whole records fetched by key point to rows. If the system needs both, keep a row buffer in memory, flush it in bulk as columnar files, and let compaction merge them while preserving sort order. Choose one sort order for the whole table, since every column inherits it, and pick that order by the most common filter. Budget the write path honestly: one row insert becomes one insert per column unless you batch, so use columnar storage only when writes arrive in bulk or can be batched. Measure point reads after the change, not only the dashboard.
- Parquet row group
- 128 MB
- Analytical compression
- 2-10x
- Vector batch
- hundreds to thousands of values
- Columns fetched by a one-field aggregate
- 1
Default size of the unit a reader can skip using its statistics.
Typical ratio when values of one type sit together, which makes dictionary and run-length encoding cheap.
Values processed per call, so per-call overhead spreads across the batch.
A column layout reads only that column, while a row layout still reads every column in each row.
The naive design for an analytical engine inside a process looks like SQLite with a faster loop: read one tuple, evaluate the expression, write one tuple, repeat. Each step is cheap on its own. The query still touches every column of every row, and each function call pays interpreter overhead.
The wall is instruction count and cache misses. Every row drags unused columns through the cache, and the per-call overhead repeats for every value. A faster loop does not remove that cost, because the cost follows the number of calls and the bytes moved, not the arithmetic.
DuckDB takes the other path. Storage is columnar, so a query reads only the columns it names, and execution passes vectors of values through compiled kernels. Batching a few hundred values amortises the overhead, so the same expression runs about an order of magnitude faster without changing its logic. The 2019 SIGMOD demo paper describes this vectorized, in-process design.