jayzhan211 commented on PR #25574:
URL: https://github.com/apache/datafusion/pull/25574#issuecomment-5824382028
Thanks @Xuanwo , one suggestion here
The hand-written `col = literal` match covers only one shape and duplicates
`infer_join_predicates_impl` in this file. Every matching pair has equal keys,
so any deterministic predicate over only left key columns also holds for the
matching right keys. Reusing the helper also mirrors `IN`, ranges and `OR` on
the key. The same-type check can go: coercion already wraps mismatched keys in
`CAST`, so they are never direct columns. I tried this locally and
`asof_join.slt` passes unchanged. It's fine to do this in a follow-up.
```diff
- // A literal comparison on an equal, same-typed key has the
- // same value for every matching pair. Mirroring it to the
- // right can prune groups without changing the ASOF
candidate.
- let mut right_predicates = Vec::new();
- for predicate in &push_predicates {
- ...
- }
+ // Every matching pair has equal key values, so a
deterministic
+ // predicate over left keys holds for the matching right
keys.
+ let join_col_keys = join
+ .on
+ .iter()
+ .filter_map(|(l, r)| Some((l.try_as_col()?,
r.try_as_col()?)))
+ .collect::<Vec<_>>();
+ let mut inferred = InferredPredicates::new(JoinType::Inner);
+ infer_join_predicates_impl::<true, false>(
+ &join_col_keys,
+ &push_predicates,
+ &mut inferred,
+ )?;
+ let right_predicates = inferred
+ .predicates
+ .into_iter()
+ .filter(|p| {
+ p.column_refs()
+ .iter()
+ .all(|c|
join.right.schema().is_column_from_schema(c))
+ })
+ .collect::<Vec<_>>();
```
With this change, both of these prune the right input as well:
```sql
SELECT * FROM l ASOF JOIN r MATCH_CONDITION (l.ts >= r.ts) ON l.k = r.k
WHERE l.k IN (1, 3);
SELECT * FROM l ASOF JOIN r MATCH_CONDITION (l.ts >= r.ts) ON l.k = r.k
WHERE l.k > 1;
```
--
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]