Skip to content

perf: Combine integer null checks in Parquet row filters - #27744

Open
Shekharrajak wants to merge 1 commit into
apache:mainfrom
Shekharrajak:perf/parquet-combine-integer-null-checks
Open

Shekharrajak wants to merge 1 commit into
apache:mainfrom
Shekharrajak:perf/parquet-combine-integer-null-checks

Conversation

@Shekharrajak

Copy link
Copy Markdown

Which issue does this PR close?

Related to the TPC-DS q68 investigation in apache/datafusion-comet#6418. The reported SF1000 slowdown still needs end-to-end validation.

Rationale for this change

The Parquet reader applies each pushed IS NOT NULL check as a separate row selection. When most rows pass, applying those selections repeatedly adds work. When an early check drops many rows, sequential evaluation can save work by skipping decoding for later columns.

What changes are included in this PR?

Build a single Parquet row-filter candidate when the predicate consists of two or more direct integer-column IS NOT NULL checks and the sum of their null counts is at most 25% of the rows in every row group.

What is the testing strategy for this PR?

The regression test covers sparse nulls.

The q68 scan was 8.1% faster. In an earlier run, unconditional grouping took 32.0 ms on the clustered-null input, compared with 11.3 ms for sequential checks. The null-count guard kept that case on the sequential path.

Are there any user-facing changes?

The optimization is internal to the Parquet reader and uses the existing filter pushdown settings.

@github-actions github-actions Bot added the datasource Changes to the datasource crate label Nov 25, 2026
@mbutrovich
mbutrovich self-requested a review November 25, 2026 20:09

@mbutrovich mbutrovich left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Shekharrajak for looking into the q68 regression. Going query by query is how we're finding these costs (see #26169), but the fix should target the general cause a query exposes, not that query's exact shape. A path tuned to one query's predicates costs every user maintenance and rarely helps other workloads. It's an easy trap when one number is the target, and coding agents fall into it often, so a perf change should show its gain beyond the query that motivated it.

I don't think the run reported in apache/datafusion-comet#6418 reaches this code. The row filter is built only when pushdown_filters is true (opener). Comet sets that option only when spark.comet.parquet.rowFilterPushdown.enabled is true (jni_api.rs). That flag defaults to false at the benchmarked commit (CometConf.scala), and the benchmark config doesn't set it. q46 also pushes the same four IsNotNull filters to store_sales as q68 (q46, q68), and q46 got faster in that run. How did you measure the 8.1% q68 scan speedup (scale factor, engine, settings, and number of runs)?

Comment on lines +500 to +506
let combined = if predicates.len() > 1
&& predicates.iter().all(|predicate| {
predicate
.downcast_ref::<IsNotNullExpr>()
.and_then(|check| check.arg().downcast_ref::<Column>())
.and_then(|column| file_schema.fields().get(column.index()))
.is_some_and(|field| field.data_type().is_integer())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fires only when every conjunct is IS NOT NULL on an integer column. That is the exact shape of q68's store_sales scan, but the cost it avoids isn't specific to integers or to null checks. #25727 measured each row filter stage at 4 to 16 ns per evaluated row regardless of the predicate. A Utf8 or Date32 null check, or a single ss_quantity > 0 conjunct next to the null checks, leaves every stage in place under this PR.

Why integers only? Could we solve this for any conjunct that removes few rows? One option is to decide stage grouping from an estimate of the rows each conjunct removes, which null counts give exactly for IS NOT NULL. Another is to build on the adaptive work tracked in #22883, which measures each stage's cost and benefit at runtime and moves non-selective conjuncts out of the row filter. #25727 places conjuncts one at a time over the per-conjunct candidates this function returns, so merging them here would also hide them from that work.

fn has_sparse_nulls(projection: &ProjectionMask, metadata: &ParquetMetaData) -> bool {
metadata.row_groups().iter().all(|group| {
// The sum bounds how many rows early predicates could skip.
let null_budget = group.num_rows().cast_unsigned() / 4;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does the 25% budget come from? The description has two data points: q68, and a clustered-null input where grouping took 32.0 ms against 11.3 ms sequential. The guard only counts nulls, so a clustered layout with 20% nulls passes it and gets grouped, which loses the page skipping that made sequential evaluation win in your clustered case.

Could you add a benchmark in its own commit before this change, so the benchmark bot can compare against it? It should sweep the null fraction across the threshold, with both scattered and clustered nulls, and include a case this change doesn't touch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

datasource Changes to the datasource crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants