yujun777 commented on PR #62754:
URL: https://github.com/apache/doris/pull/62754#issuecomment-4303533165
Thanks for the review. Addressing the concern about
`AddProjectForUniqueFunction.JoinRewrite` still materializing repeated
`UniqueFunction`s into the left child project.
This is a pre-existing trade-off in that rule and is **intentionally out of
scope for this PR**. Brief explanation:
1. Doris expands `expr BETWEEN a AND b` into `expr >= a AND expr <= b`,
which duplicates any `UniqueFunction` inside `expr`. Once duplicated, there is
no in-planner way to recover the original single-call semantics "draw one
random value and check it against both bounds", unless we keep the `BETWEEN`
unsplit or re-deduplicate above the join — both of which are larger structural
changes.
2. Once the duplication exists inside an NLJ condition, the choice is
between:
- **Leaving two independent `UniqueFunction` calls in the NLJ
other-condition** (per join pair, but two independent samplings, so
`P(a<=r<=b)` becomes two independent events instead of one joint event);
- **Materializing one alias into the left child project** (per-left-row
evaluation; strictly fewer calls and shared by all right rows for the same left
row).
Neither preserves the user's intended `BETWEEN` semantics for a random
expression, because those semantics were already destroyed by the
`BETWEEN`-split step. The left-child materialization is chosen as the less-bad
option: it at least keeps the two bound checks consistent with a single value,
which is closer to what the user writes. Two independent `rand()` calls against
`>=` and `<=` is strictly worse for this common pattern.
3. This PR targets the set of Nereids rewrite rules that **introduce new
duplication** or **move a `UniqueFunction` through a rule in a way that changes
its evaluation cardinality**. `AddProjectForUniqueFunction.JoinRewrite` does
not introduce new duplication; it consolidates already-duplicated calls. It is
therefore a separate concern and will be revisited, if at all, together with a
deeper fix to the `BETWEEN` expansion or a join-condition-preserving dedup path.
4. Existing regression coverage in `add_project_for_unique_function.groovy`
(`qt_join_1`) already pins this trade-off shape, so any future change to it
will be visible in a single reviewable diff.
For the three rules in this PR (`PushDownFilterThroughSetOperation`,
`ProjectOtherJoinConditionForNestedLoopJoin`, and now `InferPredicates` for
EXCEPT/INTERSECT), the fix scope is correct and complete.
--
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]