Sub topic 8
Column statistics: min, max, and null count
This chapter explains what statistics Parquet stores for each column chunk, where they live, and how readers use them. It assumes you know the Parquet layout (row groups, column chunks, pages, footer), basic Python, and how PyArrow tables and schemas work.
What column statistics are
When a Parquet writer finishes a column chunk, it records a few summary values about the data in that chunk. These values are called column statistics. The standard set is:
- min: the smallest non-null value in the chunk.
- max: the largest non-null value in the chunk.
- null_count: how many values in the chunk are null.
- distinct_count: an optional count of distinct values. Many writers leave it out, including PyArrow by default.
Statistics are stored per column chunk, so every row group has its own set for every column. They are written into the footer metadata, next to the row group and column chunk entries. A reader can therefore read them without touching any data pages.
Writers can also store statistics in page headers, one set per data page. Many readers ignore these. Newer files use the page index instead (a separate chapter covers it), which keeps page-level min and max values in a compact structure outside the pages.
Why they exist
A filtered query such as WHERE id >= 950000 normally needs every row checked. With statistics, the reader first asks a cheaper question: "Could any row in this row group match?" If the chunk's max for id is 99,999, the answer is no. The reader skips the whole row group without reading or decompressing its pages.
This is the basis of row group skipping, which the predicate pushdown chapter covers in detail. Here the focus is the statistics themselves: what they contain, how they behave, and where they fail.
Reading statistics with PyArrow
First write a file with ten row groups. This example uses the same table as the earlier chapters.
import pyarrow as pa
import pyarrow.parquet as pq
table = pa.table({
"id": list(range(1_000_000)),
"category": ["a", "b", "c", "d"] * 250_000,
})
pq.write_table(
table,
"events.parquet",
row_group_size=100_000,
compression="zstd",
)Now read the footer and print the statistics of the first column chunk of the first row group.
import pyarrow.parquet as pq
md = pq.ParquetFile("events.parquet").metadata
print(md.num_rows, md.num_row_groups)
col = md.row_group(0).column(0)
print(col.path_in_schema, col.compression)
print(col.total_compressed_size, col.total_uncompressed_size)
stats = col.statistics
print(stats.has_min_max, stats.min, stats.max, stats.null_count)For row group 0 of the id column, the last line prints True 0 99999 0. The chunk holds ids 0 to 99,999 and no nulls. Row group 1 would show 100000 and 199999, and so on.
The category column behaves differently. Every row group contains all four letters, so each chunk has min a and max d. A filter such as category == "b" cannot skip any row group using min and max alone. This shows the central rule: statistics help most when values are clustered, not spread evenly across the file.
Looking at every row group
To see the pattern across the whole file, loop over the row groups.
import pyarrow.parquet as pq
md = pq.ParquetFile("events.parquet").metadata
for i in range(md.num_row_groups):
stats = md.row_group(i).column(0).statistics
print(i, stats.min, stats.max, stats.null_count)The ranges are contiguous and do not overlap: 0 to 99,999, then 100,000 to 199,999, and so on. Non-overlapping ranges are the best case for skipping, because any filter value falls into at most one row group.
What each statistic is used for
| Statistic | Typical use | Example |
|---|---|---|
| min | Skip chunks where all values are below a lower bound | `id >= 950000` with chunk max 99,999 |
| max | Skip chunks where all values are above an upper bound | `id < 10` with chunk min 100,000 |
| null_count | Answer `IS NULL` and `IS NOT NULL` filters | Skip chunk for `IS NULL` when count is 0 |
| num_values | Compare with null_count to detect all-null chunks | All-null chunk can be skipped for any comparison |
A chunk whose null count equals its number of values has no min or max, because there are no non-null values. In PyArrow, has_min_max is False for such a chunk. Code that reads stats.min without checking has_min_max can fail on these chunks.
Skipping in practice
The fourth example from the plan reads one column and applies a filter.
import pyarrow.parquet as pq
result = pq.read_table(
"events.parquet",
columns=["id"],
filters=[("id", ">=", 950_000)],
)
print(result.num_rows)This prints 50000. Two savings apply. First, columns=["id"] means the category chunks are never read. Second, the filter lets the reader compare 950,000 with each row group's max. Row groups 0 to 8 have a max of at most 899,999, so they are skipped. Only row group 9 is read, and its rows all match.
The filter does not guarantee that skipping happens in every reader or API. Engines differ in which statistics they use and whether they apply them at all. Check your reader's documentation if performance matters.
Gotchas
Statistics are a hint, not an answer
Min and max say that values lie within a range. They do not say that any particular value is present. A chunk with min 1 and max 1,000 might not contain 500. Readers must still filter the rows they read. Statistics can prove that a chunk has no match. They cannot prove that it has one.
Skipping fails on unsorted data
Suppose ids were randomly shuffled before writing. Every row group would then have a min near 0 and a max near 999,999. Every filter range overlaps every chunk, and nothing is skipped. The file is identical in content, but skipping gives no benefit. Sorting or clustering data by the columns you filter on is the most effective way to improve skipping.
Strings and truncation
For string and binary columns, comparison follows byte order, not locale-aware ordering. Some writers also truncate long min and max values to keep the footer small. A truncated min is rounded down and a truncated max is rounded up, so the range remains a valid bound. The bounds just become looser, and skipping becomes less precise for long strings with shared prefixes.
Floating point and NaN
NaN does not compare as less or greater than anything. Older writers could produce wrong min and max values when a chunk contained NaN, so some readers ignore floating point statistics from old files. Check the writer version when results seem odd.
Legacy signed and unsigned ordering
Early Parquet versions defined min and max fields with an ambiguous sort order for some types, such as unsigned integers and strings. Newer files use min_value and max_value, which have a well-defined order. Readers may ignore the older fields for the types where they were unreliable. If statistics from an old file appear to be missing, this is a likely cause.
Statistics cost space
Statistics add bytes to the footer for every column in every row group. A file with thousands of row groups and hundreds of columns can have a footer of many megabytes, and readers must parse it before reading anything. This is one reason not to use very small row groups.
Disabling statistics
You can turn statistics off per file or per column when they are not useful, for example on a high-cardinality text column that is never filtered.
import pyarrow.parquet as pq
pq.write_table(
table,
"no_stats.parquet",
write_statistics=["id"],
)Here only id gets statistics. Passing write_statistics=False disables them for every column. Disable them only after confirming that no reader depends on them.
Checking whether skipping will help
A quick check is to compute how many row groups a filter could keep.
import pyarrow.parquet as pq
md = pq.ParquetFile("events.parquet").metadata
threshold = 950_000
kept = 0
for i in range(md.num_row_groups):
stats = md.row_group(i).column(0).statistics
if not stats.has_min_max or stats.max >= threshold:
kept += 1
print(f"{kept} of {md.num_row_groups} row groups must be read")This prints 1 of 10 row groups must be read. Note that the code treats missing statistics as "must read". That is the safe default: when a reader cannot prove a chunk has no match, it must read it.
Summary of the working model
- The writer computes min, max, and null count for each column chunk and stores them in the footer.
- The reader evaluates a filter against those values before reading data pages.
- A chunk is skipped only when its range cannot satisfy the filter.
- The benefit depends on how clustered the data is. Sorted or partitioned data skips well. Shuffled data does not.
Exercise
A file has 20 row groups. The column user_id was written from randomly ordered data, and each row group has min near 1 and max near 5,000,000. You run a query with the filter user_id == 4200. How many row groups will min/max statistics let the reader skip, and what could you change to improve this?
Show answer
Probably none. Every row group's range 1 to 5,000,000 contains 4200, so statistics cannot prove that any chunk lacks a match. To improve skipping, sort or cluster the data by user_id before writing so each row group covers a narrow, non-overlapping range. For equality lookups on unsorted data, Bloom filters are another option.
Exercise
A column chunk has 100,000 values and a nullcount of 100,000. What does `hasmin_max report for it, and how should a reader treat it for the filter value > 10`?
Show answer
has_min_max is False, because there are no non-null values to take a min or max from. A comparison such as value > 10 is never true for null, so the reader can skip the chunk. For value IS NULL, the chunk must be read, since every row matches.