seawinde commented on code in PR #66287:
URL: https://github.com/apache/doris/pull/66287#discussion_r3755078379


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CollectRelation.java:
##########
@@ -314,9 +314,29 @@ protected void parseAndCollectFromView(List<String> 
tableQualifier, View view, C
     }
 
     private void collectFromTableStream(BaseTableStream tableStream, 
CascadesContext cascadesContext,
-                                        TableFrom tableFrom, 
Optional<UnboundRelation> unboundRelation) {
+                                        TableFrom tableFrom) {
         StatementContext statementContext = 
cascadesContext.getConnectContext().getStatementContext();
-        List<String> tableQualifier = tableStream.getBaseTableFullQualifiers();
-        statementContext.getAndCacheTable(tableQualifier, tableFrom, 
unboundRelation);
+        TableIf baseTable = tableStream.getBaseTableNullable();
+        if (baseTable == null) {
+            throw new AnalysisException("Table ["
+                    + tableStream.getBaseTableFullQualifiers().get(2) + "] 
does not exist");
+        }
+
+        // Cache the ID-resolved base table so planner locks the object used 
during binding.
+        Map<List<String>, TableIf> tables;
+        switch (tableFrom) {
+            case QUERY:
+                tables = statementContext.getTables();
+                break;
+            case INSERT_TARGET:
+                tables = statementContext.getInsertTargetTables();
+                break;
+            case MTMV:
+                tables = statementContext.getMtmvRelatedTables();
+                break;
+            default:
+                throw new AnalysisException("Unknown table from " + tableFrom);
+        }
+        tables.put(baseTable.getFullQualifiers(), baseTable);

Review Comment:
   Addressed in `a7850adc43a`.
   
   `CollectRelation` now only validates that the stream base resolves by its 
persisted stable ID; it no longer writes the implicit base object into the 
qualifier-to-relation cache. `StatementContext.lock()` expands each collected 
`BaseTableStream` into its stable-ID base table only in the existing local 
ID-ordered lock queue. This keeps `tables[db.b] -> B` intact while still 
locking both the explicit table B and stream base A. No additional 
statement-level dependency collection was introduced. The external-metadata 
preload guard also recognizes the implicit stream-base plan lock.
   
   Added coverage for:
   - a latch-controlled pre-lock interleaving that collects B, renames `B: b -> 
c` and `A: a -> b`, then verifies `tables[db.b]` remains B while the stream 
still resolves A by stable ID;
   - locking both the explicit relation and stream base without locking the 
stream object or replacing the relation cache entry;
   - recognizing the stream base lock in external metadata preload.
   
   Rebased onto the latest `master` and verified with:
   `./run-fe-ut.sh --run 
org.apache.doris.catalog.DropTableStreamTest,org.apache.doris.nereids.StatementContextTest,org.apache.doris.nereids.trees.plans.ExplainTableStreamPlanTest`
   
   Result: 40 tests run, 0 failures, 0 errors, and the FE reactor finished with 
`BUILD SUCCESS`.



-- 
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]

Reply via email to