mbutrovich commented on code in PR #27744:
URL: https://github.com/apache/datafusion/pull/27744#discussion_r4700366208


##########
datafusion/datasource-parquet/src/row_filter.rs:
##########
@@ -480,16 +497,35 @@ pub(crate) fn prebuild_row_filter_candidates(
     // Split into conjuncts:
     // `a = 1 AND b = 2 AND c = 3` -> [`a = 1`, `b = 2`, `c = 3`]
     let predicates = split_conjunction(expr);
-    let candidates: Vec<FilterCandidate> = predicates
-        .into_iter()
-        .map(|expr| {
-            FilterCandidateBuilder::new(Arc::clone(expr), 
Arc::clone(file_schema))
-                .build(metadata)
-        })
-        .collect::<Result<Vec<_>, _>>()?
-        .into_iter()
-        .flatten()
-        .collect();
+    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())

Review Comment:
   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.



##########
datafusion/datasource-parquet/src/row_filter.rs:
##########
@@ -461,6 +462,22 @@ impl PrebuiltRowFilterCandidate {
     }
 }
 
+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;

Review Comment:
   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.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to