github-actions[bot] commented on code in PR #63763:
URL: https://github.com/apache/doris/pull/63763#discussion_r3502766087
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AggScalarSubQueryToWindowFunction.java:
##########
@@ -139,7 +159,8 @@ && checkAggregate()
&& checkJoin()
&& checkProject()
&& checkRelation(apply.getCorrelationSlot())
- && checkFilter(outerFilter);
+ && checkFilter(outerFilter)
+ && checkUniqueCorrelatedTable(apply.getCorrelationSlot());
}
Review Comment:
This needs a join-type gate, not just a no-ON-condition gate. `checkJoin()`
currently accepts any `LogicalJoin` whose `getOnClauseCondition()` is empty,
and the SQL grammar allows condition-less `LEFT SEMI`, `LEFT ANTI`, and outer
joins. Those shapes are not safe for this window rewrite.
For example, with an outer child like `dim_unique d LEFT SEMI JOIN fact f`
and a scalar aggregate `SUM(f2.v)`, `checkRelation()` still records `fact` as
the shared table and `ExpressionUtils.replace(function, innerOuterSlotMap)`
rewrites the aggregate to `SUM(f.v) OVER (...)`. But
`JoinUtils.getJoinOutput()` intentionally outputs only the left side for left
semi/anti joins, so the new `LogicalWindow` can reference `f.v` above a child
that does not produce it.
Outer joins have a separate wrong-result case: `COUNT(*)` over an empty
shared table returns `0` in the original scalar subquery, but after rewriting
over `dim_unique d LEFT OUTER JOIN fact f`, the window sees the null-extended
outer-join row and `COUNT(*) OVER (PARTITION BY d.k)` becomes `1`.
Please reject non-inner/non-cross joins in this rule, or explicitly prove
the join is row-preserving and exposes every shared slot required by the
replaced aggregate and hoisted predicates.
--
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]