yujun777 opened a new pull request, #62742:
URL: https://github.com/apache/doris/pull/62742
### What problem does this PR solve?
Issue Number: close #xxx
Related PR: #62705
Problem Summary:
Following up on #62705, several Nereids rewrite rules still moved predicates
containing non-idempotent (unique) functions such as rand() / uuid() /
random_bytes() across operator boundaries in ways that changed query
semantics. The common root cause is that a predicate like `rand() > 0.5`
has an empty input-slot set, so the `containsAll(emptySet)` / `allMatch`
guards used by these rules silently returned true and allowed the push
down / elimination.
This PR adds `containsUniqueFunction()` guards to the following rules:
1. PushDownFilterThroughRepeat: skip conjuncts with unique functions.
Pushing `rand() > x` below Repeat changes which rows feed each
grouping set and alters aggregate results.
2. PushDownFilterThroughWindow: skip conjuncts with unique functions.
Pushing a unique predicate below a window operator re-samples the
base rows and changes every window-function value.
3. PushDownFilterThroughPartitionTopN: same as Window — skip unique
conjuncts in the split loop.
4. PushDownFilterThroughSort (sort-elimination branch): do not drop the
sort when any order key contains a unique function. `ORDER BY rand()`
has empty input slots, so the old `allMatch` on an empty stream
returned true and wrongly eliminated the sort.
5. PushDownTopNThroughUnion / PushDownTopNDistinctThroughUnion: do not
push a TopN whose order keys contain unique functions below Union.
With non-idempotent ordering each branch would be sorted by a
different random draw than the global one.
### Release note
Fix wrong results when predicates / order keys containing rand(), uuid(),
random_bytes() or uuid_numeric() were pushed across Repeat, Window,
PartitionTopN, Sort, or Union boundaries.
### Check List (For Author)
- Test:
- Unit Test (FE): PushDownFilterThroughRepeatTest (3 new tests),
PushDownFilterThroughSortTest (+1 test for unique order key),
PushDownFilterThroughWindowTest (+1 test for unique conjunct).
- Regression Test: 5 new suites under
regression-test/suites/nereids_rules_p0/unique_function/.
- Behavior changed: Yes (queries that previously returned incorrect
results due to unsafe pushdown of unique-function predicates / order
keys will now return correct results).
- Does this need documentation: No
Co-authored-by: Copilot <[email protected]>
--
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]