Columnar database

Also known as: column-oriented database

On this page 7

A columnar database, also called a column-oriented database, is a database that stores the values of each table column contiguously on disk, instead of storing complete rows together. Among database models, it is the standard design for analytical workloads, where queries scan millions or billions of rows but read only a few columns.

Storing columns separately lets the engine read only the data a query needs, compress similar values very efficiently and process them in batches with vectorized CPU instructions. The price is slower handling of individual row inserts, updates and lookups, which remain the strength of row-oriented transactional databases.

How columnar storage organizes data

In a row store, one record’s values sit next to each other: id, date, customer, amount. In a column store, all ids form one sequence, all dates another and all amounts a third. A query such as summing amounts by month then reads only the date and amount columns, skipping every other column entirely.

Columns are usually split into segments, row groups or granules of thousands to millions of values. Each segment stores metadata such as the minimum and maximum value, so the engine can skip whole segments that cannot match a filter, a technique called data skipping or zone maps. Values at the same position in different columns belong to the same logical row, which lets the engine reassemble rows when needed.

The table below contrasts the two storage layouts for the same query patterns.

Query patternRow storeColumn store
Aggregate one column over many rowsReads every full rowReads one compressed column
Fetch one complete record by keyOne contiguous readOne read per column
Insert a single rowAppend one recordTouch every column file
Bulk load millions of rowsEfficientVery efficient in batches
Filter on a sorted columnIndex neededSegment skipping works naturally
Row-oriented versus column-oriented storage

Compression and vectorized execution

Because a column holds values of one type with similar content, it compresses far better than mixed rows. Compression ratios of several times to more than ten times are common on real analytical data, depending on value repetition and sort order.

EncodingHow it worksBest suited data
Dictionary encodingReplaces values with small integer codesLow-cardinality text
Run-length encodingStores a value and its repeat countSorted or repetitive columns
Delta encodingStores differences between valuesTimestamps, sequences
Bit packingUses only the needed bits per valueSmall integer ranges
General compressionLZ4 or Zstandard on blocksAny remaining redundancy
Common column encodings

Execution engines process data in vectors or batches of values rather than one row at a time. Tight loops over arrays of one type fit CPU caches and SIMD instructions well, and many operators can work directly on compressed or dictionary-encoded data, saving both I/O and CPU time.

The columnar model is often confused with the wide-column database, despite the similar name. Wide-column stores such as Cassandra organize data by row key and column family and are optimized for distributed key-based access, not for analytical scans.

ModelPhysical layoutPrimary workload
Columnar databaseEach column stored separatelyAnalytics, reporting, OLAP
Row-oriented relationalComplete rows togetherTransactions, OLTP
Wide-column databaseRows by key with flexible columnsHigh-volume key access
Time-series databaseOften columnar per series and timeMetrics and events
In-memory databaseData held in RAM, row or columnVery low latency
Columnar databases and neighboring database models

Many systems are hybrids. Some relational engines add columnar indexes or column-store tables next to row storage, and several time-series databases use columnar files internally, so the boundaries are about storage layout rather than product category.

When a columnar database is the right choice

A columnar database is the right choice when the dominant workload consists of large scans, aggregations and joins over historical data, typically in data warehouses, business intelligence, log analytics and product analytics.

  • Wide tables with selective queries: dozens or hundreds of columns, of which each query uses a few.
  • Append-mostly data such as events, logs, transactions and measurements.
  • Batch or micro-batch loading rather than constant single-row updates.
  • Interactive analytics where users expect results over billions of rows in seconds.
  • Cost-sensitive storage, where strong compression lowers disk and cloud storage bills.

Columnar file formats such as Apache Parquet and ORC apply the same principles to data lakes, letting query engines read column chunks directly from object storage without a dedicated database server.

Limitations and design pitfalls

The main limitation is inefficient row-level change. Updating or deleting one record touches many column segments, so columnar engines typically buffer writes in a row-oriented delta store and merge them later, or mark rows as deleted and rewrite segments in the background.

MistakeEffectBetter approach
Using SELECT starReads every column, losing the main benefitSelect only needed columns
Frequent single-row insertsMany tiny segments, slow mergesInsert in batches
Poor sort keyWeak compression and little skippingSort by common filter columns
Using it as an OLTP storeHigh latency for point updatesKeep transactions in a row store
Common mistakes with columnar databases

The decisive recommendation is to separate transactional and analytical workloads: keep operational data in a row-oriented system and load it into a columnar database through batch or streaming pipelines.

Explained without jargon

A columnar database stores data by column instead of by row. All the dates sit together, all the prices sit together, and so on.

Imagine a spreadsheet of every sale a shop has ever made. To add up all prices, a row-based system reads every line from left to right. A columnar system reads just the price column and ignores everything else. The key takeaway is that columnar databases answer big summary questions very quickly, but they are slower at changing single records.

A typical use case

An online retailer stores about 2 billion order line records with more than 80 columns, including product, price, discount, region, device and campaign. Analysts run daily reports such as revenue by region and week, and the queries on the transactional row-oriented database take many minutes and slow down the shop itself.

The data team copies orders every hour into a columnar database, sorted by order date and region. Each report now reads only four or five compressed columns and skips segments outside the requested dates. The stored data shrinks to a fraction of its original size, and typical reports finish in a few seconds. The result is fast, self-service analytics with no load on the production shop database.