Sub topic 10
Predicate pushdown and row group skipping
This chapter assumes you know the Parquet layout (row groups, column chunks, pages, footer) and the min, max, and null count statistics stored per column chunk. It also assumes you can read basic PyArrow code. Here you will see how a reader turns a filter into a list of row groups it never has to read.
What predicate pushdown means
A predicate is a condition that each row either satisfies or does not, such as id >= 950000. Predicate pushdown means handing that condition to the file reader, so it can avoid reading data that cannot match. The alternative is to read everything into memory and filter afterward.
Parquet makes this possible because every column chunk records statistics in the footer. The reader looks at the footer first, tests the predicate against the statistics, and only fetches the column chunks that might contain matches.
Two savings are available:
- Column projection reads only the columns you ask for. This comes from columnar layout and needs no statistics.
- Row group skipping drops whole row groups whose statistics prove no row can match. This is the subject of this chapter.
Projection and skipping combine. A query that selects one column and filters on another touches only those column chunks, and only in row groups that survive the filter.
The skipping decision
For each row group, the reader evaluates the predicate against the statistics of the filtered column. There are three possible outcomes:
| Outcome | Meaning | Action |
|---|---|---|
| Cannot match | Statistics prove no row satisfies the predicate | Skip the row group |
| Must match | Statistics prove every row satisfies it | Read it, and a smart engine can skip per-row evaluation |
| May match | Statistics cannot decide | Read it and filter row by row |
The key point is that statistics are conservative. They can prove a row group is irrelevant, but they can never prove it is relevant. A "may match" row group is still read in full, and the exact row-level filter runs on the decoded values.
Worked example with min and max
The file events.parquet from earlier chapters holds one million rows in ten row groups of 100,000 rows. The id column is sorted, so each row group covers a distinct range:
| Row group | min id | max id |
|---|---|---|
| 0 | 0 | 99,999 |
| 1 | 100,000 | 199,999 |
| ... | ... | ... |
| 9 | 900,000 | 999,999 |
Consider the predicate id >= 950000. Row groups 0 through 8 have a max below 950,000, so no row in them can match. They are skipped. Only row group 9 can contain matches, since its range 900,000 to 999,999 overlaps the predicate. That group is read, and the row-level filter keeps ids 950,000 to 999,999.
Here is the read in PyArrow:
import pyarrow.parquet as pq
result = pq.read_table(
"events.parquet",
columns=["id"],
filters=[("id", ">=", 950_000)],
)
print(result.num_rows)This prints 50000. Nine of ten row groups were never fetched, and only the id column chunk of the tenth was read.
Rules for common predicates
Given a row group with minimum lo and maximum hi for the column, these tests decide whether it can be skipped:
| Predicate | Skip when |
|---|---|
| `x = v` | `v < lo` or `v > hi` |
| `x > v` | `hi <= v` |
| `x >= v` | `hi < v` |
| `x < v` | `lo >= v` |
| `x <= v` | `lo > v` |
| `x IN (v1, v2, ...)` | every value lies outside `[lo, hi]` |
| `x IS NULL` | `null_count = 0` |
| `x IS NOT NULL` | `null_count` equals the row count |
Predicates combined with AND skip a row group if any one clause allows a skip. Predicates combined with OR skip it only if every clause allows a skip. A negated or computed predicate, such as NOT (x = 5) or lower(name) = 'bob', often cannot be tested against raw min and max, so engines may not skip anything.
Why data order decides everything
Skipping works only when row groups cover narrow, mostly non-overlapping ranges. Compare two layouts of the same values:
- Sorted or clustered by the filter column. Each row group has a tight range. A selective predicate overlaps one or two groups.
- Randomly ordered. Every row group has a min near the global min and a max near the global max. Every predicate "may match" in every group, and nothing is skipped.
You can see this directly. The category column in the example repeats a, b, c, d, so every row group has min a and max d. A filter such as category == "c" cannot skip anything, because "c" falls inside every range.
import pyarrow.parquet as pq
md = pq.ParquetFile("events.parquet").metadata
for i in range(md.num_row_groups):
s = md.row_group(i).column(1).statistics
print(i, s.min, s.max)Every line prints a d. The statistics are valid, but they carry no selective power.
The practical consequence: sort or partition your data by the columns you filter on most before writing. Time columns and identifiers that grow with insertion order often cluster naturally. High-cardinality columns that arrive in random order do not.
Edge cases and gotchas
Missing or disabled statistics
Some writers omit statistics, or the writer was configured to disable them. When has_min_max is false, the reader must treat the row group as "may match". Check this in the footer if skipping seems not to work.
Null handling
Min and max ignore nulls. A row group of all nulls has no min or max at all, so only null_count helps there. A predicate such as x = 5 never matches a null, so engines can skip an all-null group, but only if they check null count.
String and binary truncation
For long strings, some writers store truncated 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 stays valid. It may be slightly wider than the real range, which can cause a few unnecessary reads but never wrong results.
Floating-point values
NaN values compare unequal to everything. Older writers handled NaN inconsistently in statistics, and cautious readers ignore statistics for float columns that might contain NaN. If you filter on floats and see no skipping, this is a possible cause.
Sort order of types
Statistics rely on a defined ordering for each type. Unsigned integers, decimals, and strings have specific ordering rules. Statistics written for types with ambiguous ordering, particularly in very old files, may be ignored by modern readers.
Footer cost
The reader must read the footer before it can skip anything. With thousands of tiny row groups, the footer is large, and parsing it can cost more than the skipping saves. Chapter-level guidance on sizing comes later in the tutorial.
Verifying that skipping happens
Do not assume pushdown worked. Two checks help:
- Inspect the statistics, as in the loop above, and confirm that ranges are narrow for your filter column.
- Compare the work done with and without the filter. Time the read and compare the bytes fetched, or use your engine's query plan output, which often reports row groups scanned versus skipped.
The filters argument in pq.read_table uses statistics for skipping and also applies the exact row filter, so the returned rows are always correct. Passing a filter never changes results, only the amount of work.
Exercise
A file has four row groups with the following min and max for the price column: group 0 is 1 to 50, group 1 is 40 to 90, group 2 is 85 to 120, group 3 is 200 to 300. Which row groups can be skipped for the predicate price > 100, and which for price = 60?
Show answer
For price > 100, skip a group when its max is at most 100. Group 0 (max 50) and group 1 (max 90) are skipped. Groups 2 and 3 are read. For price = 60, skip a group when 60 is outside [min, max]. Group 0 (max 50), group 2 (min 85), and group 3 (min 200) are skipped. Only group 1 (range 40 to 90) is read.
Exercise
A table of one billion rows is written in random order by user_id, in 1,000 row groups. A query filters on user_id = 12345. Why will row group skipping likely skip almost nothing, and what change at write time would help?
Show answer
With random order, every row group's min and max span nearly the whole userid range, so 12345 falls inside almost every range and every group "may match". Sorting or clustering the data by `userid` before writing makes each group cover a narrow range, so only one or a few groups overlap 12345 and the rest are skipped.