github-actions[bot] commented on code in PR #70666:
URL: https://github.com/apache/doris/pull/70666#discussion_r4598922185
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java:
##########
@@ -688,9 +684,6 @@ public void mergeGroup(Group source, Group destination,
HashMap<Long, Group> pla
GroupExpression existGroupExpr =
groupExpressions.get(reinsertGroupExpr);
if (existGroupExpr != null) {
Preconditions.checkState(existGroupExpr.getOwnerGroup() !=
null);
- // remove reinsertGroupExpr from its owner group to avoid
adding it to existGroupExpr.getOwnerGroup()
- // existGroupExpr.getOwnerGroup() already has this
reinsertGroupExpr.
- reinsertGroupExpr.setUnused(true);
if
(existGroupExpr.getOwnerGroup().equals(reinsertGroupExpr.getOwnerGroup())) {
Review Comment:
[P2] Deduplicate retained alternatives within their owner group
Successive refused merges can now leave two equal active expressions in the
same group: the global lookup keeps finding an ancestor's expression, so this
same-owner branch never deduplicates the retained copies. A reduced acyclic
Memo can be built with public `copyIn` calls (`P(G)=Project(k,G)`,
`Ei(G)=Project(k,ci,G)`, the same slot `k` throughout, and distinct constant
Alias ExprIds):
```text
S = Scan(k,...)
A = P(S)
B = P(E1(S))
C = P(E2(S))
D = E3(S)
Q = {P(B), P(C), P(D)}
X = E4(Q)
Z = P(E5(D))
Root = {P(A), P(X), P(Z)}
```
Run `MergeProjectsCBO` through `ApplyRuleJob` on B, C, then Z. B and C each
rediscover A and merge into it. Both Q parents become `P(A)`; each global
lookup returns Root's `P(A)`, and each recursive `mergeGroup(Q,Root)` refuses
because `Root -> X -> Q`. Q therefore retains two equal `P(A)` alternatives. Z
then rediscovers Q's unique `P(D)` alternative, so `mergeGroup(Z,Q)` is
permitted. `Group.mergeTo` builds its target map with `Collectors.toMap` and
throws `IllegalStateException` on Q's duplicate keys, aborting planning.
This is a distinct failure from thread 4596832416's fixed immediate
`isUnused()` exception: it requires repeated refusals and later fails
owner-local uniqueness. Preserve that uniqueness even when the global canonical
expression belongs to another dependent group, and add a multi-alternative
refusal case followed by a successful CBO merge into that group.
--
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]