morrySnow commented on code in PR #49345:
URL: https://github.com/apache/doris/pull/49345#discussion_r2006992229


##########
fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsCleaner.java:
##########
@@ -116,19 +116,35 @@ private void clearTableStats() {
                 // If ctlName, dbName and tblName exist, it means the table 
stats is created under new version.
                 // First try to find the table by the given names. If table 
exists, means the tableMeta is valid,
                 // it should be kept in memory.
+                boolean tableExist = false;
                 try {
-                    StatisticsUtil.findTable(stats.ctlName, stats.dbName, 
stats.tblName);
-                    continue;
+                    TableIf table = StatisticsUtil.findTable(stats.ctlName, 
stats.dbName, stats.tblName);
+                    // Tables may have identical names but different id, e.g. 
replace table.
+                    tableExist = table.getId() == id;
+                    if (!tableExist) {
+                        if (tableExistInInternalCatalog(internalCatalog, id)) {
+                            LOG.debug("Table {}.{}.{} found with ID {}.",
+                                    stats.ctlName, stats.dbName, 
stats.tblName, id);
+                            tableExist = true;
+                        }
+                    }
                 } catch (Exception e) {
                     LOG.debug("Table {}.{}.{} not found.", stats.ctlName, 
stats.dbName, stats.tblName);
+                    // If we couldn't find table by names, try to find it in 
internal catalog. This is to support older
+                    // version which the tableStats object doesn't store the 
names but only table id.
+                    // We may remove external table's tableStats here, but 
it's not a big problem.
+                    // Because the stats in column_statistics table is still 
available,
+                    // the only disadvantage is auto analyze may be triggered 
for this table.
+                    // But it only happens once, the new table stats object 
will have all the catalog,
+                    // db and table names.
+                    // Also support REPLACE TABLE
+                    if (tableExistInInternalCatalog(internalCatalog, id)) {
+                        LOG.debug("Table {}.{}.{} found with ID {}.",
+                                stats.ctlName, stats.dbName, stats.tblName, 
id);
+                        tableExist = true;
+                    }
                 }
-                // If we couldn't find table by names, try to find it in 
internal catalog. This is to support older
-                // version which the tableStats object doesn't store the names 
but only table id.
-                // We may remove external table's tableStats here, but it's 
not a big problem.
-                // Because the stats in column_statistics table is still 
available,
-                // the only disadvantage is auto analyze may be triggered for 
this table.
-                // But it only happens once, the new table stats object will 
have all the catalog, db and table names.
-                if (tableExistInInternalCatalog(internalCatalog, id)) {
+                if (tableExist) {

Review Comment:
   ```suggestion
                   if (tableExist || 
tableExistInInternalCatalog(internalCatalog, id)) {
   ```



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