jayzhan211 commented on PR #27133:
URL: https://github.com/apache/datafusion/pull/27133#issuecomment-7254816881
@CuteChuanChuan sorry for not following up sooner. No, I didn't find a
smaller gate: `DecorrelateLateralJoin` rewrites one join at a time, so it needs
context from above, and your flag is the right shape. Please go ahead, with
these boundaries:
- A `Sort` with a fetch is a limit, so reset there too. Without `OFFSET`,
`PushDownLimit` folds `ORDER BY ... LIMIT n` into the Sort and drops the Limit
in the first pass. The gate leaves the join correlated in that pass, so the
second pass would decorrelate it under the top-k.
- On a semi, anti or mark join, only the subquery side always ignores
duplicates. The other side takes the parent's flag, so the issue's query plus
`WHERE EXISTS (SELECT 1 FROM t2 WHERE t2.t1_id = t1.id)` must still error.
- Please cover the `max` case rather than pin it: an Aggregate can set the
flag when every aggregate is `DISTINCT` or declares
`DistinctHandling::Insensitive`, which `EliminateAggregateDistinct` already
relies on. `Union` can pass the flag through as well.
For tests, besides the four queries and `max`, please add a statement error
test for each place the flag resets, so removing any of them fails a test:
`ORDER BY ... LIMIT`, `LIMIT` without `ORDER BY`, a window function, `count(*)
... GROUP BY`, and the `EXISTS` case above.
<details>
<summary>The boundaries as code (sketch)</summary>
```rust
/// Whether duplicate rows in input `i` of `parent` can't reach the result,
/// given `ignored`, the flag `parent` itself received.
fn input_ignores_duplicates(parent: &LogicalPlan, i: usize, ignored: bool)
-> bool {
match parent {
LogicalPlan::Aggregate(agg) =>
agg.aggr_expr.iter().all(ignores_duplicates),
LogicalPlan::Join(join) => match join.join_type {
JoinType::LeftSemi | JoinType::LeftAnti | JoinType::LeftMark =>
i == 1 || ignored,
JoinType::RightSemi | JoinType::RightAnti | JoinType::RightMark
=> i == 0 || ignored,
_ => ignored,
},
LogicalPlan::Sort(sort) => ignored && sort.fetch.is_none(),
LogicalPlan::Projection(_)
| LogicalPlan::Filter(_)
| LogicalPlan::SubqueryAlias(_)
| LogicalPlan::Union(_) => ignored,
_ => false,
}
}
fn ignores_duplicates(expr: &Expr) -> bool {
match expr {
Expr::Alias(alias) => ignores_duplicates(&alias.expr),
Expr::AggregateFunction(AggregateFunction { func, params }) => {
params.distinct || func.distinct_handling() ==
DistinctHandling::Insensitive
}
_ => false,
}
}
```
</details>
--
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]