yujun777 opened a new pull request, #62754:
URL: https://github.com/apache/doris/pull/62754
### What problem does this PR solve?
Issue Number: N/A
Related PR: #62742
Problem Summary:
Three additional Nereids rewrite rules were not aware of `UniqueFunction`
(e.g. `rand()`, `uuid()`, `random()`) and could silently change the semantics
of SQL that uses such functions. This PR is batch 2 of the `UniqueFunction`
pushdown audit. The previously-reviewed batch 1 is in #62742.
1. **`PushDownFilterThroughSetOperation`**
Pushing a filter that references a `UniqueFunction` through `UNION
DISTINCT` / `INTERSECT` / `EXCEPT` duplicates each unique-fn call per child,
which changes result semantics (e.g. `rand() > 0.5` would be evaluated
independently for each branch instead of once above the set op). `UNION ALL`
remains safe, because the set op is a pure concatenation and every row
evaluates the filter exactly once below or above. The rewrite now splits
conjuncts: pushable conjuncts (`UNION ALL`, or not containing a unique
function) go through the child branches; non-pushable conjuncts stay above the
set op.
2. **`JoinUtils.isHashJoinCondition`**
A `t1.a + rand() = t2.b` condition was being classified as a hash join
condition. The hashCond path hashes each side independently, which would
re-evaluate `rand()` when probing and break equality semantics. Such conditions
now fall back to `otherJoinConjuncts` (nested loop join), preserving one-time
evaluation per pair.
3. **`ProjectOtherJoinConditionForNestedLoopJoin`**
The rule extracts sub-expressions of NLJ other conditions into child
projects as aliases. An expression containing a unique function must not be
materialized once above the scan and then referenced in the join, because that
separates its evaluation from the join pair. Expressions that contain a unique
function are now left inline in the other condition.
All three fixes follow the same pattern used in batch 1: an early no-op
branch when `expression.containsUniqueFunction()` is true.
### Release note
None
### Check List (For Author)
- Test: Regression test
- Added
`regression-test/suites/nereids_rules_p0/unique_function/push_down_filter_through_set_operation_with_unique_function.groovy`
- Added
`regression-test/suites/nereids_rules_p0/unique_function/join_hash_cond_extract_with_unique_function.groovy`
- Added
`regression-test/suites/nereids_rules_p0/unique_function/project_other_join_condition_for_nlj_with_unique_function.groovy`
- All existing `nereids_rules_p0/unique_function` suites still pass
- Behavior changed: No (corrects previously-incorrect semantics under
`rand()/uuid()/random()`)
- Does this need documentation: No
--
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]