Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,12 @@ public static boolean needAnalyzeColumn(TableIf table, Pair<String, String> colu
// 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +32,7 @@
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;
Expand Down Expand Up @@ -191,7 +193,8 @@ void testNeedAnalyzeColumn() throws DdlException {
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.
Expand All @@ -200,7 +203,12 @@ void testNeedAnalyzeColumn() throws DdlException {
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() {
Expand Down
Loading