kosiew commented on code in PR #26281:
URL: https://github.com/apache/datafusion/pull/26281#discussion_r4694886573
##########
datafusion/optimizer/src/push_down_filter.rs:
##########
@@ -1607,6 +1525,198 @@ fn rewrite_projection(
Ok((projection, keep_predicates))
}
+/// Pushes the conjuncts of `predicate` into `scan`, as far as the source of
the
+/// scan accepts them, and keeps the rest in a filter above the scan. `changed`
+/// tells whether the caller already changed the predicate, so that a result
+/// without a pushdown still reports the change.
+fn push_down_into_table_scan(
+ predicate: Expr,
+ scan: TableScan,
+ changed: bool,
+) -> Result<Transformed<LogicalPlan>> {
Review Comment:
Could we simplify the helper to borrow the scan, accept indexed predicates,
and return the updated scan with the positions of exact predicates?
eg
```
fn push_down_into_table_scan<'a>(
scan: &TableScan,
candidates: impl IntoIterator<Item = (usize, &'a Expr)>,
) -> Result<Option<(TableScan, HashSet<usize>)>> {
if scan.fetch.is_some() || scan.skip.is_some_and(|n| n > 0) {
return Ok(None);
}
let (positions, predicates): (Vec<_>, Vec<_>) = candidates
.into_iter()
.filter(|(_, p)| !p.contains_scalar_subquery() && !p.is_volatile())
.unzip();
if predicates.is_empty() {
return Ok(None);
}
let supported = scan.source.supports_filters_pushdown(&predicates)?;
// Collect accepted predicates and exact positions.
// Return None if unchanged; retain try_with_filters as a backstop.
}
```
Both callers can then build their residual filters using without_exact(...).
## Behavior improvements
- Bounds: Reject any fetch or positive skip before asking the provider.
Today supports_filters_pushdown(...)? runs before try_with_filters checks the
bounds. A provider that returns an error can then stop optimization of a scan
that could never accept the filter. skip = 0 alone still negotiates.
- Empty candidates: Avoid calling the provider when no predicates are
eligible.
- Residual order: Preserve the original conjunct order instead of moving
volatile and subquery predicates last. This respects the ordering preserved by
reorder_predicates. It changes the plan text when a volatile or subquery
conjunct sits next to a non-exact pushed conjunct. No push_down_filter test is
affected, but I haven't checked the sqllogictests.
## Additional simplifications
- Eliminate the temporary Filter construction and unpacking.
- Avoid premature scan cloning and unnecessary filter reconstruction.
- Remove the changed parameter.
- Replace expression-equality matching with positional tracking.
--
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]