[BugFix] fix NPE of information_schema.analyze_status when db is dropped (backport #62796) (#62813)

Co-authored-by: Murphy <96611012+murphyatwork@users.noreply.github.com>
This commit is contained in:
mergify[bot] 2025-09-08 03:18:01 +00:00 committed by GitHub
parent 0649cfb7a8
commit d82390e5a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 1 deletions

View File

@ -101,7 +101,6 @@ public class AnalyzeStatusSystemTable extends SystemTable {
}
}
TAnalyzeStatusItem item = new TAnalyzeStatusItem();
itemList.add(item);
item.setCatalog_name("");
item.setDatabase_name("");
item.setTable_name("");
@ -118,6 +117,7 @@ public class AnalyzeStatusSystemTable extends SystemTable {
continue;
}
} catch (MetaNotFoundException ignored) {
continue;
}
String columnStr = "ALL";
@ -135,6 +135,7 @@ public class AnalyzeStatusSystemTable extends SystemTable {
item.setEnd_time(DateUtils.formatDateTimeUnix(analyze.getEndTime()));
item.setProperties(analyze.getProperties() == null ? "{}" : analyze.getProperties().toString());
item.setReason(analyze.getReason());
itemList.add(item);
}
return res;

View File

@ -20,6 +20,7 @@ import com.google.common.collect.Maps;
import com.starrocks.analysis.TableName;
import com.starrocks.catalog.Database;
import com.starrocks.catalog.Table;
import com.starrocks.catalog.system.information.AnalyzeStatusSystemTable;
import com.starrocks.common.util.UUIDUtil;
import com.starrocks.journal.JournalEntity;
import com.starrocks.persist.OperationType;
@ -28,9 +29,11 @@ import com.starrocks.server.GlobalStateMgr;
import com.starrocks.sql.common.MetaUtils;
import com.starrocks.sql.optimizer.statistics.CachedStatisticStorage;
import com.starrocks.sql.plan.ConnectorPlanTestBase;
import com.starrocks.thrift.TAnalyzeStatusReq;
import com.starrocks.thrift.TUniqueId;
import com.starrocks.transaction.InsertTxnCommitAttachment;
import com.starrocks.transaction.TransactionState;
import com.starrocks.utframe.StarRocksAssert;
import com.starrocks.utframe.UtFrameUtils;
import mockit.Mock;
import mockit.MockUp;
@ -319,4 +322,32 @@ public class AnalyzeMgrTest {
transactionState.setTxnCommitAttachment(new InsertTxnCommitAttachment(0));
GlobalStateMgr.getCurrentState().getAnalyzeMgr().updateLoadRows(transactionState);
}
@Test
public void testQuery() throws Exception {
final String dbName = "db_analyze_status";
StarRocksAssert starRocksAssert = new StarRocksAssert(connectContext);
starRocksAssert
.withDatabase(dbName)
.useDatabase(dbName)
.withTable("create table t1 (c1 int, c2 int) properties('replication_num'='1')");
UtFrameUtils.mockDML();
starRocksAssert.getCtx().executeSql("insert into t1 values (1,1)");
starRocksAssert.getCtx().executeSql("analyze table t1 with sync mode");
// Add the analyze status but drop the table
Database db = starRocksAssert.getDb(dbName);
Table table = starRocksAssert.getTable(dbName, "t1");
AnalyzeStatus analyzeStatus = new NativeAnalyzeStatus(100,
db.getId(), table.getId(),
ImmutableList.of("c1", "c2"), StatsConstants.AnalyzeType.FULL,
StatsConstants.ScheduleType.ONCE, Maps.newHashMap(), LocalDateTime.now());
GlobalStateMgr.getCurrentState().getAnalyzeMgr().addAnalyzeStatus(analyzeStatus);
starRocksAssert.dropDatabase(dbName).withDatabase(dbName);
TAnalyzeStatusReq request = new TAnalyzeStatusReq();
AnalyzeStatusSystemTable.query(request);
}
}