englefly commented on code in PR #11566:
URL: https://github.com/apache/doris/pull/11566#discussion_r940237585


##########
fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java:
##########
@@ -776,6 +790,21 @@ public SlotDescriptor registerColumnRef(TableName tblName, 
String colName) throw
             d = resolveColumnRef(colName);
         } else {
             d = resolveColumnRef(newTblName, colName);
+            //in reanalyze, the inferred expr may contain upper level table 
alias, and the upper level alias has not
+            // been PROCESSED. So we resolve this column without tbl name.
+            // For example: a view V "select * from t where t.a>1"
+            // sql: select * from V as t1 join V as t2 on t1.a=t2.a and t1.a 
in (1,2)
+            // after first analyze, sql becomes:
+            //  select * from V as t1 join V as t2 on t1.a=t2.a and t1.a in 
(1,2) and t2.a in (1, 2)
+            // in reanalyze, when we process V as t2, we indeed process sql 
like this:
+            //    select * from t where t.a>1 and t2.a in (1, 2)
+            //  in order to resolve t2.a, we have to ignore "t2"
+            // ===================================================
+            // Someone may concern that if t2 is not alias of t, this fix will 
cause incorrect resolve. In fact,
+            // this does not happen, since we push t2.a in (1.2) down to this 
inline view, t2 must be alias of t.
+            if (d == null) {
+                d = resolveColumnRef(colName);
+            }

Review Comment:
   @morrySnow could u review, please? this is the main part of fix.



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to