github-actions[bot] commented on code in PR #70666:
URL: https://github.com/apache/doris/pull/70666#discussion_r4663316980
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/memo/GroupExpression.java:
##########
@@ -296,6 +303,8 @@ public void mergeToNotOwnerRemove(GroupExpression target) {
this.children.forEach(child -> child.removeParentExpression(this));
this.children.clear();
this.ownerGroup = null;
+ // Mark unused only after detaching: a recursive owner-group merge can
be rejected to avoid a cycle.
+ this.setUnused(true);
Review Comment:
[P2] Keep remaining rule results attached when retiring their input
Retained equal alternatives can now retire the expression currently
executing an `ApplyRuleJob`, while that job still has cached matches. A reduced
acyclic Memo can be built with public `copyIn` (`P` projects the same slot `k`,
`Ei` adds a constant, every `E0` reuses the same constant Alias ExprId, and `F`
is `Filter(TRUE,...)`):
```text
L = Scan(k,...)
T = F(L)
A = {E0(T)}
B = {E0(E2(T)), E0(E6(L))}
C = E0(E3(T))
Q = P(B)
R = {P(T), P(C)}
Root = {P(A), F(Q), F(R)}
```
Run `MergeProjectsCBO` through `ApplyRuleJob` on Root.P(A), R.P(C) and its
generated P(E3(T)), then B's first expression and C, then B's second expression
(now owned by A), and finally Q.P(A), leaving other generated jobs pending. B/C
merge into A; Q/R retain P(A) because their recursive merges into Root are
refused. Root.P(A) and retained R.P(A) already carry MERGE_PROJECTS, while B's
moved second expression creates the late A.E0(L).
Q's first cached match produces existing R.P(T), permits Q->R, and
`Group.mergeTo` coalesces/detaches the executing Q.P(A) here. Later cached P(L)
is therefore copied by `ApplyRuleJob` with target=null into a disconnected
group. The survivor/ancestor masks prevent regeneration, and the nonproject
filter boundaries block rooted project-chain recovery. Subsequent orphan
P(E6(L))->P(L) merges only combine disconnected owners; P(E2(T))->P(T)
reconnects a separate owner. Thus a valid cheaper projection alternative never
participates in rooted costing.
Please resolve the live surviving owner for the remaining cached results and
cover this applied-mask/late-alternative case. Simply stopping on unused would
still discard those results. This is distinct from the existing
queued-parent-snapshot finding: it concerns the currently running rule's cached
matches.
--
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]