hello-stephen commented on code in PR #71224:
URL: https://github.com/apache/doris/pull/71224#discussion_r4751858526
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/AnalyzeCTE.java:
##########
@@ -92,7 +92,16 @@ public Rule build() {
ctx.cascadesContext.addPlanProcesses(outerCascadesCtx.getPlanProcesses());
// should construct anchor from back to front, because the cte
behind depends on the front
for (int i = result.second.size() - 1; i >= 0; i--) {
- root = new LogicalCTEAnchor<>(result.second.get(i).getCteId(),
result.second.get(i), root);
+ LogicalCTEProducer<Plan> producer = result.second.get(i);
+ LogicalSubQueryAlias<?> alias = (LogicalSubQueryAlias<?>)
producer.child();
+ // Sink binding may add a typed output while retaining every
original CTE slot.
+ // Anchor the final producer so the new consumer mapping has a
matching output.
+ LogicalPlan finalPlan =
result.first.getAnalyzedCTEPlan(alias.getAlias()).get();
Review Comment:
[P2] Refresh each producer from its original CTE binding
With `lower_case_table_names=1` or `2`, this ordinary query passes the
existing case-sensitive duplicate-name check:
```sql
WITH c AS (SELECT 1 AS x),
C AS (SELECT x + 1 AS y FROM c)
SELECT y FROM C;
```
The consumer inside `C` is bound to the earlier `c` CTEId, but `CTEContext`
folds names and keeps the last binding. This lookup therefore returns `C`'s
definition when refreshing **both** producers. The reduced dependency
`Producer(c, x=1) -> Producer(C, y=c.x+1)` becomes `Producer(c, y=c.x+1)`,
which refers to itself and no longer produces the original `x` ExprId.
`CTEInline.visitLogicalCTEConsumer` consequently cannot remap that producer
slot, breaking a previously plannable query even without a spatial write.
Refresh through the binding matching the producer's CTEId, or reject
case-folded duplicate names before registration, and cover this catalog mode in
a test.
--
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]