github-actions[bot] commented on code in PR #62742:
URL: https://github.com/apache/doris/pull/62742#discussion_r3128992800
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownTopNThroughUnion.java:
##########
@@ -61,6 +61,8 @@ public class PushDownTopNThroughUnion implements
RewriteRuleFactory {
public List<Rule> buildRules() {
return ImmutableList.of(
logicalTopN(logicalUnion().when(union -> union.getQualifier()
== Qualifier.ALL))
+ .when(topN -> topN.getOrderKeys().stream()
+ .noneMatch(key ->
key.getExpr().containsUniqueFunction()))
Review Comment:
There's still a parallel set-operation rewrite with the same issue:
`PushDownFilterThroughSetOperation` copies every conjunct into every child
without checking `containsUniqueFunction()`. For `SELECT * FROM (SELECT 1 UNION
SELECT 1) u WHERE rand() > 0.5`, the original plan evaluates `rand()` once
after `UNION DISTINCT` (keep probability 0.5), but the rewritten plan evaluates
it once per branch and the row survives if either branch passes (probability
0.75). `INTERSECT` and `EXCEPT` have the same problem, so this batch still
leaves a wrong-result path open.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownFilterThroughRepeat.java:
##########
@@ -72,7 +72,8 @@ public Rule build() {
Set<Expression> notPushedPredicates = Sets.newHashSet();
for (Expression conjunct : filter.getConjuncts()) {
Set<Slot> conjunctSlots = conjunct.getInputSlots();
- if (commonGroupingSetExpressions.containsAll(conjunctSlots)) {
+ if (commonGroupingSetExpressions.containsAll(conjunctSlots)
+ && !conjunct.containsUniqueFunction()) {
Review Comment:
Same non-idempotent gap still exists in `PushDownJoinOtherCondition`. That
rule only checks `predicate.getInputSlots()`, so `ON rand() > 0.5` (empty slot
set) and `ON t1.id + rand() > 5` are still pushed to one child for inner/cross
joins. That changes evaluation from once per joined row to once per left/right
input row: with one left row joining two right rows, the original plan can keep
one pair and drop the other, while the rewritten plan can only keep both or
none. Since this PR is fixing exactly this class of unique-function pushdown
bug, I think we need the same `containsUniqueFunction()` guard there as well.
--
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]