This is an automated email from the ASF dual-hosted git repository.

zhangstar333 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 74373aafea4 [bug](analyze) fix the auto analyze column stats not work 
when have same table id (#59922)
74373aafea4 is described below

commit 74373aafea42f5c48414502305dcbf019af3a4c6
Author: zhangstar333 <[email protected]>
AuthorDate: Fri Jan 16 23:57:33 2026 +0800

    [bug](analyze) fix the auto analyze column stats not work when have same 
table id (#59922)
    
    ### What problem does this PR solve?
    Problem Summary:
    because the external catalog gen db_id and table_id by names.
    so new catalog may have same table_id as the drop old catalog.
---
 .../org/apache/doris/statistics/util/StatisticsUtil.java     |  6 ++++++
 .../org/apache/doris/statistics/util/StatisticsUtilTest.java | 12 ++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java 
b/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java
index 08920176534..014c9ace70f 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java
@@ -1077,6 +1077,12 @@ public class StatisticsUtil {
         // Table never been analyzed, need analyze.
         if (tableStatsStatus == null) {
             return true;
+        } else {
+            long ctlId = table.getDatabase().getCatalog().getId();
+            //external catalog may have same table id. as the id is generated 
by genIdByName.
+            if (ctlId != tableStatsStatus.ctlId) {
+                return true;
+            }
         }
         // User injected column stats, don't do auto analyze, avoid overwrite 
user injected stats.
         if (tableStatsStatus.userInjected) {
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/statistics/util/StatisticsUtilTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/statistics/util/StatisticsUtilTest.java
index 7d63ade6af0..11e71d7c4b8 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/statistics/util/StatisticsUtilTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/statistics/util/StatisticsUtilTest.java
@@ -18,6 +18,7 @@
 package org.apache.doris.statistics.util;
 
 import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Database;
 import org.apache.doris.catalog.KeysType;
 import org.apache.doris.catalog.MaterializedIndexMeta;
 import org.apache.doris.catalog.OlapTable;
@@ -31,6 +32,7 @@ import org.apache.doris.common.Pair;
 import org.apache.doris.common.util.PropertyAnalyzer;
 import org.apache.doris.datasource.ExternalCatalog;
 import org.apache.doris.datasource.ExternalTable;
+import org.apache.doris.datasource.InternalCatalog;
 import org.apache.doris.datasource.hive.HMSExternalCatalog;
 import org.apache.doris.datasource.hive.HMSExternalDatabase;
 import org.apache.doris.datasource.hive.HMSExternalTable;
@@ -191,7 +193,8 @@ class StatisticsUtilTest {
         Column column = new Column("testColumn", PrimitiveType.INT);
         List<Column> schema = new ArrayList<>();
         schema.add(column);
-        OlapTable table = new OlapTable(200, "testTable", schema, null, null, 
null);
+        OlapTable realTable = new OlapTable(200, "testTable", schema, null, 
null, null);
+        OlapTable table = Mockito.spy(realTable);
         HMSExternalCatalog externalCatalog = new HMSExternalCatalog();
         HMSExternalDatabase externalDatabase = new 
HMSExternalDatabase(externalCatalog, 1L, "dbName", "dbName");
         // Test olap table auto analyze disabled.
@@ -200,7 +203,12 @@ class StatisticsUtilTest {
         table.setTableProperty(new TableProperty(properties));
         Assertions.assertFalse(StatisticsUtil.needAnalyzeColumn(table, 
Pair.of("index", column.getName())));
         table.setTableProperty(null);
-
+        InternalCatalog catalog1 = Mockito.mock(InternalCatalog.class);
+        Database db1 = Mockito.mock(Database.class);
+        Mockito.when(db1.getId()).thenReturn(100L);
+        Mockito.when(table.getDatabase()).thenReturn(db1);
+        Mockito.when(db1.getCatalog()).thenReturn(catalog1);
+        Mockito.when(catalog1.getId()).thenReturn(0L);
         new MockUp<HMSExternalTable>() {
             @Mock
             protected synchronized void makeSureInitialized() {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to