CS PAPERS DEEP-READ · PAPER 64

C-Store: A Column-oriented DBMS

Stonebraker, Abadi, Madden, Cherniack, O'Neil et al. · MIT / Brandeis / UMass Boston / Brown · VLDB 2005

中文 →

What did this paper do?

In 2005 Michael Stonebraker and a group of database researchers built a prototype called C-Store that changed how a database puts data on disk: store it column by column instead of row by row. It sounds like a mere rearrangement, yet it made "boil a hundred million records down to one number" queries two orders of magnitude faster. BigQuery, Snowflake, ClickHouse, and the Parquet files strewn across every data lake all walk this road.

An analogy

Think of a database as a supermarket's books. The traditional way is keeping receipts: each sale's date, store, item and amount written on one slip, slips stacked up. Now the owner asks, "How much did we sell nationwide last year?" You need only one number — the amount — yet you must pull out every slip whole, glance at the amount, and put it back. Across a hundred million slips, nearly all the effort goes into hauling fields nobody looks at.

What's new

C-Store rearranges the books: copy every slip's "amount" into one long strip, every "store" into another, every "item" into a third. Asked about amounts, you carry only the amounts strip and never touch the rest. Same question, a fraction of the hauling.

How it pulls this off

And the new arrangement throws in three bonuses.

First, it compresses beautifully. A strip holds all the same kind of thing — in the "store" strip, "Downtown branch" may repeat for thousands of rows in a row, so you write one note: "Downtown branch, starting at row 1, for the next 5,000 rows." Better still, many questions can be answered without unpacking: to count that branch's sales, read the phrase "the next 5,000 rows" and you are done, never spreading it back out into 5,000 rows.

Second, the same data can be kept in several sort orders at once. Keep one copy ordered by date, another ordered by store — as if the same books were bound twice, once by date and once by branch, so every common question meets a copy already in the right order. A traditional database chases the same effect by building separate indexes; here, because columns compress so small, simply keeping extra copies is the better bargain. Those copies double as backups: when a machine dies, you ask the other copies for whatever it was holding.

Third, what about writing? Books that are neatly ordered and tightly packed are miserable to insert a line into. C-Store splits the operation in two: new data first lands in a small scratch pad (fast to write, uncompressed), and a background porter periodically merges what has piled up there into the big tidy ledger in bulk. Queries read both, so you never miss data that was just written.

What came of it

In the paper, C-Store ran a set of analytical queries two orders of magnitude faster than a commercial row-oriented database of the day, on less than half the disk. It became the company Vertica (bought by HP in 2011), and "columnar plus heavy compression" became the default shape of a data warehouse.

One honest cost: this arrangement is built for workloads that are read far more than written. For transactional work — editing orders one at a time and seeing the change instantly — storing row by row still suits better.

Remember one thing

Store by column and a query hauls only the columns it truly needs; a single column looks alike all the way down, so it compresses tiny and can often be computed on without unpacking; keep the same data in several sort orders so the copies serve as index and backup at once; and absorb the slow writes with a scratch pad plus a background bulk merge. Analytical databases changed generation here.

Want the projections, join indices, WS/RS diagrams and the numbers? → switch to the deep read