github-actions[bot] commented on code in PR #67438:
URL: https://github.com/apache/doris/pull/67438#discussion_r3912697643
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java:
##########
@@ -309,14 +310,31 @@ public Expression visitElementAt(ElementAt elementAt,
ExpressionRewriteContext c
@Override
public Expression visitUnboundSlot(UnboundSlot unboundSlot,
ExpressionRewriteContext context) {
Optional<Scope> outerScope = getScope().getOuterScope();
- Optional<List<? extends Expression>> boundedOpt =
Optional.of(bindSlotByThisScope(unboundSlot));
- boolean foundInThisScope = !boundedOpt.get().isEmpty();
+ List<? extends Expression> bounded = ImmutableList.of();
+ boolean foundInThisScope = false;
+ boolean canBindOuterScope = bindSlotInOuterScope &&
outerScope.isPresent();
+
+ // A multipart name can be either a relation-qualified column (t.col)
or a nested field
+ // reference (col.field). In a correlated subquery, try the
relation-qualified interpretation
+ // in both visible scopes first, so an inner column named "t" does not
hide an outer alias "t".
+ if (canBindOuterScope && shouldPrioritizeRelationQualifier()
+ && unboundSlot.getNameParts().size() > 1) {
+ bounded = bindSlotByRelationQualifier(unboundSlot, getScope());
+ foundInThisScope = !bounded.isEmpty();
+ if (!foundInThisScope) {
+ bounded = bindSlotByRelationQualifier(unboundSlot,
outerScope.get());
Review Comment:
**[P1] Preserve local shadowing in custom analyzer scopes**
The relation-only prepass only checks `getScope()` before probing
`outerScope`, but that is not the complete local scope for the custom
HAVING/QUALIFY analyzers. For example, `bindHavingAggregate` constructs this
analyzer with `aggOutputScope` and relies on its `bindSlotByThisScope` override
to search the group-by/aggregate-child scopes. With outer `t(id=-1)` and inner
`t(id=1)`, `SELECT t.id FROM outer_t t WHERE EXISTS (SELECT 1 FROM inner_t t
HAVING max(t.id) > 0)` should bind `t.id` inside `max` to the inner scan. This
prepass misses it in aggregate output, finds the outer `t.id`, and then skips
the custom binder, turning the expression into a correlation and changing the
result. Please make the relation-priority phase search each analyzer's complete
local-scope order before the outer scope, and add reused-alias HAVING/QUALIFY
coverage.
--
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]