github-actions[bot] commented on code in PR #70666:
URL: https://github.com/apache/doris/pull/70666#discussion_r4611243333
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java:
##########
@@ -688,19 +684,26 @@ 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())) {
// reinsertGroupExpr & existGroupExpr are in same Group,
so merge them.
- if (reinsertGroupExpr.getPlan() instanceof PhysicalPlan) {
-
reinsertGroupExpr.getOwnerGroup().replaceBestPlanGroupExpr(reinsertGroupExpr,
existGroupExpr);
- }
- // existingGroupExpression merge the state of
reinsertGroupExpr
- reinsertGroupExpr.mergeTo(existGroupExpr);
+ mergeDuplicateExpression(reinsertGroupExpr,
existGroupExpr);
} else {
// reinsertGroupExpr & existGroupExpr aren't in same
group, need to merge their OwnerGroup.
mergeGroup(reinsertGroupExpr.getOwnerGroup(),
existGroupExpr.getOwnerGroup(), planTable);
+ if (!reinsertGroupExpr.isUnused()) {
Review Comment:
[P2] Skip pending parents retired by recursive owner merges
The check here only handles the current parent; a successful recursive merge
can also retire another parent still queued in `needReplaceChild`. A reduced
acyclic Memo can be built through public `copyIn` (`P(G)=Project(k,G)`,
`Ei(G)=Project(k,ci,G)` with distinct constant Alias ExprIds, and
`F(G)=PhysicalProject(k,G)`, reusing the same slot `k`):
```text
L = Scan(k,...)
E0 = E0(L)
D = P(L)
S = P(E0)
B = P(E1(E0))
C = P(E2(E0))
Q = {P(B), F(S)}
R = {P(C), F(D)}
Root = {P(S), P(E4(Q)), P(E5(R))}
```
Run `MergeProjectsCBO` through `ApplyRuleJob` on B, C, then S's original
expression. B and C rediscover S, so Q and R each retain `P(S)` when their
recursive merge into Root is refused. The last rule application rediscovers D
and starts the permitted `S -> D` merge. If the identity-parent snapshot visits
`Q.F(S)` before both logical `P(S)` parents, it becomes `F(D)` and triggers a
permitted `Q -> R` merge. `Group.mergeTo` deduplicates Q's logical `P(S)` into
R's and clears its children, but Q's retired expression is still in the outer
snapshot. Its later `replaceChild(S,D)` immediately throws in
`Utils.replaceList` because the child list is empty, aborting planning.
Please recheck pending parents before mutating them after earlier recursive
calls, and cover this two-owner mixed logical/physical case with the relevant
parent orders. This differs from the existing threads: the recursive merge
succeeds and owner-local uniqueness holds; a different pending parent is
retired as a side effect.
--
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]