The idea: a column store in one file

Apache Parquet is a file format for analytics. Spark, Hive, Trino, DuckDB, pandas, BigQuery and Snowflake all read it. It stores a table by column, like the column store in Row store vs Column store, but inside one ordinary file that can sit on a laptop or in object storage such as S3. The file is built so that a reader can find out what is inside cheaply, and then read only the parts a query needs.

A Parquet file from start to end: the magic PAR1, row group 0, row group 1 and row group 2, each made of four column chunks trip_id, city, fare and day, each chunk made of pages; then the footer with the schema and each chunk's offset, size and min/max; then the 4-byte footer length and PAR1 again.
Rows are cut into row groups, each row group into one column chunk per column, each chunk into pages; the footer at the end describes them all.

Row groups, column chunks and pages

The writer buffers rows until it has a row group, a horizontal slice of the table (here 1,000 rows; real files use about 128 MB to 1 GB, set by parquet.block.size or Arrow's row_group_size). It then writes the row group one column at a time. The values of one column in one row group form a column chunk. A chunk is a list of pages (about 1 MB each, parquet.page.size): an optional dictionary page first, then data pages. A page is the unit that is encoded and compressed (Demo: write the file).

Row groups keep the file usable for very large tables: a writer needs only one row group in memory, and different readers can work on different row groups at the same time.

The writer only knows where each chunk starts and how big it is after writing it. So the metadata goes at the end: the footer (FileMetaData, encoded with Thrift) holds the schema, the number of rows, and for every column chunk its byte offset, size, encodings and statistics: min, max and the null count. After the footer come its length (4 bytes) and the magic PAR1. A reader starts at the end: it reads the last 8 bytes, learns the footer length, reads the footer, and only then decides what else to read.

Dictionary encoding

A column often repeats a few values. Dictionary encoding stores each distinct value once in the dictionary page and replaces every value by its small integer index. The city chunk has 1,000 values but only 4 distinct cities, so each index needs just 2 bits. Its 9,250 PLAIN bytes become a 37-byte dictionary plus a 253-byte data page (Demo: dictionary + bit-packing).

A writer tries the dictionary first and keeps it only when it helps. In fare every value in a row group is different. The dictionary would be as large as the data, and the indices would only add to it, so the writer falls back to PLAIN, the values one after another (Demo: PLAIN fallback).

The RLE / bit-packing hybrid

The indices are stored with one encoding that mixes two methods. When 8 or more equal indices come in a row, they become an RLE run: a count and the value, once. Otherwise they are bit-packed: 8 indices at a time, each in exactly bit width bits. The day column is sorted, so its indices are 10 runs of 100. They shrink to 10 runs of 3 bytes, and the whole chunk goes from 4,000 bytes to 71 (Demo: dictionary + RLE).

Two chunks encoded. City: values Hanoi, Saigon, Hanoi, Da Nang and so on become the dictionary 0 Hanoi, 1 Saigon, 2 Da Nang, 3 Hue and indices 0 1 0 2 0 1 3 0, bit-packed at 2 bits each: 9,250 bytes to 290. Day: values 1 times 100, 2 times 100 and so on become dictionary 1 to 10 and 10 RLE runs: 4,000 bytes to 71.
Mixed indices are bit-packed; long runs of one index become a single (count, value) pair.

Run-length encoding by itself is shown on Row store vs Column store. Here it works on the dictionary indices, not on the values. After encoding, each page can also be compressed with a codec such as Snappy or ZSTD.

Projection and predicate pushdown

Projection: a query reads only the column chunks of the columns it names. SELECT SUM(fare) reads the three fare chunks, 12,000 bytes, plus 336 bytes of footer and tail. A file written row by row would make it read all 63,750 bytes (Demo: projection).

Predicate pushdown: the reader checks the WHERE clause against each row group's min and max before reading it. For day = 25, row group 0 holds days 1 to 10 and row group 1 days 11 to 20, so neither can contain day 25. Both are skipped without being read. Only row group 2's day and fare chunks are read: 4,407 bytes in all (Demo: predicate pushdown).

The read path of SELECT SUM(fare) WHERE day = 25: 1, read the last 8 bytes and the 328-byte footer; 2, compare day = 25 with each row group's min and max: row group 0 days 1 to 10 skipped, row group 1 days 11 to 20 skipped, row group 2 days 21 to 30 kept; 3, read only the day and fare chunks of row group 2. Total 4,407 bytes, against 63,750 for a row file.
The footer turns a scan of the whole file into one small read plus two column chunks.
QueryRow groups readBytes read
SUM(fare)3 of 3 (no WHERE)12,336
SUM(fare) WHERE day = 251 of 34,407
COUNT(*) WHERE fare >= 49503 of 3 (none skipped)12,336
* WHERE trip_id = 15001 of 3, all 4 columns8,697
city, COUNT(*) WHERE day BETWEEN 9 AND 122 of 31,058
any query on the row-by-row fileall63,750

Statistics need sorted data

Min/max only skips data when the values of the filter column are clustered. The file was written in day order, so each row group covers a narrow range of days. fare is spread over every row group: each one has fares from about 500 to over 4,950. So fare >= 4950 cannot skip anything, even though only a few rows match (Demo: filter on unsorted fare). That is why data pipelines often sort or partition by the column that queries filter on most, usually a date. The same idea as zone maps and the sorted files of File organizations.

A Parquet file is written once and never changed in place, so it suits batch loads, not row-by-row updates. Data warehouses on top of it (see the cube in Star schema & OLAP cube) add new files and rewrite old ones in the background, much like the compaction in LSM tree vs B+ tree.

What the page leaves out

The byte sizes are a simplified model: no page headers, no compression codec, a fixed 328-byte footer, and row groups of 1,000 rows instead of hundreds of megabytes. Real writers also differ in small ways (when an RLE run starts, the bit width of a one-entry dictionary). It leaves out nested columns with repetition and definition levels (and so NULLs), other encodings such as DELTA_BINARY_PACKED and BYTE_STREAM_SPLIT, the page index and bloom filters that skip pages inside a chunk, logical types such as dates and decimals, and table formats (Iceberg, Delta Lake, Hudi) that track many Parquet files. MariaDB does not read Parquet files itself; the SQL is the kind that DuckDB, Spark or Trino run on them.

On the mind map

Open the Databases & Storage mind mapDatabases& StorageSchema and storage: how rows land on diskSchema and storageIndexes: find rows without a full scanIndexesRunning a query: parse, plan, executeRunning a queryCost-based optimizer: estimate rows, pick cheapest planCost-based optimizerQuery rewrites: same answer, simpler queryQuery rewritesTransactions: ACID: isolation and recoveryTransactionsApps and connections: the client side of the databaseApps and connectionsMongoDB: documents, replica sets, shardsMongoDBRelational, document, graphRelational, document, graphone résumé as tables, JSON and a graphNormalizationNormalizationeach fact once: no partial, transitive depsClosure, Keys, BCNFClosure, Keys, BCNFBCNF can lose an FD; 3NF never has toRow vs column storeRow vs column storerows for lookups, columns for SUMStar schema & OLAP cubeStar schema & OLAP cuberoll-up = GROUP BY; slice = WHEREParquet file formatFooter min/max skips row groupsLSM vs B+ treeLSM vs B+ treeLSM: fast writes; B+ tree: fast readsSQLite internalsSQLite internalsone file of pages, a b-tree per tableER model to tablesER model to tablesentities, relations, keys become tablesEER specialization mappingEER specialization mappingDisjoint in A/B needs triggers; C uses CHECKIntegrity constraints & FKsIntegrity constraints & FKs1062 dup, 1452 no parent, 1451 has childrenOpen the Databases & Storage mind mapDatabases & Storagehow rows land on diskSchema and storageRelational, document, graphRelational, document, graphone résumé as tables, JSON and a graphNormalizationNormalizationeach fact once: no partial, transitive depsClosure, Keys, BCNFClosure, Keys, BCNFBCNF can lose an FD; 3NF never has toRow vs column storeRow vs column storerows for lookups, columns for SUMStar schema & OLAP cubeStar schema & OLAP cuberoll-up = GROUP BY; slice = WHEREParquet file formatFooter min/max skips row groupsLSM vs B+ treeLSM vs B+ treeLSM: fast writes; B+ tree: fast readsSQLite internalsSQLite internalsone file of pages, a b-tree per tableER model to tablesER model to tablesentities, relations, keys become tablesEER specialization mappingEER specialization mappingDisjoint in A/B needs triggers; C uses CHECKIntegrity constraints & FKsIntegrity constraints & FKs1062 dup, 1452 no parent, 1451 has children
This page on the Databases & Storage mind map · 58 pages in 8 branches · open it to see the whole map and test yourself in recall mode.