Code review comment: It is not necessary to call analyze for tableRelation separately, the analyze of query will perform the logic of table analyze

Code before review:
public static void analyze(UpdateStmt updateStmt, ConnectContext session) {
TableName tableName = updateStmt.getTableName();
MetaUtils.normalizationTableName(session, tableName);
MetaUtils.getStarRocks(session, tableName);
Table table = MetaUtils.getStarRocksTable(session, tableName);
if (!(table instanceof OlapTable && ((OlapTable) table).getKeysType() == KeysType.PRIMARY_KEYS)) {
throw unsupportedException("only support updating primary key table");
}
if (updateStmt.getWherePredicate() == null) {
throw new SemanticException("must specify where clause to prevent full table update");
}
List<ColumnAssignment> assignmentList = updateStmt.getAssignments();
Map<String, ColumnAssignment> assignmentByColName = assignmentList.stream().collect(
Collectors.toMap(assign -> assign.getColumn().toLowerCase(), a -> a));
SelectList selectList = new SelectList();
for (Column col : table.getBaseSchema()) {
SelectListItem item;
ColumnAssignment assign = assignmentByColName.get(col.getName().toLowerCase());
if (assign != null) {
if (col.isKey()) {
throw new SemanticException("primary key column cannot be updated: " + col.getName());
}
item = new SelectListItem(new CastExpr(col.getType(), assign.getExpr()), col.getName());
} else {
item = new SelectListItem(new SlotRef(tableName, col.getName()), col.getName());
}
selectList.addItem(item);
}
TableRelation tableRelation = new TableRelation(tableName);
tableRelation.setTable(table);
Scope tableScope = analyzeTable(tableRelation, tableName, table, session);
SelectRelation selectRelation =
new SelectRelation(selectList, tableRelation, updateStmt.getWherePredicate(), null, null);
AnalyzeState analyzeState = new AnalyzeState();
SelectAnalyzer selectAnalyzer = new SelectAnalyzer(session);
selectAnalyzer.analyze(
analyzeState,
selectRelation.getSelectList(),
selectRelation.getRelation(),
tableScope,
selectRelation.getGroupByClause(),
selectRelation.getHavingClause(),
selectRelation.getWhereClause(),
selectRelation.getOrderBy(),
selectRelation.getLimit());
selectRelation.fillResolvedAST(analyzeState);
updateStmt.setTable(table);
updateStmt.setUpdateRelation(selectRelation);
}

Line under review: Scope tableScope = analyzeTable(tableRelation, tableName, table, session);

Code after addressing the review:
public static void analyze(UpdateStmt updateStmt, ConnectContext session) {
TableName tableName = updateStmt.getTableName();
MetaUtils.normalizationTableName(session, tableName);
MetaUtils.getStarRocks(session, tableName);
Table table = MetaUtils.getStarRocksTable(session, tableName);
if (!(table instanceof OlapTable && ((OlapTable) table).getKeysType() == KeysType.PRIMARY_KEYS)) {
throw unsupportedException("only support updating primary key table");
}
if (updateStmt.getWherePredicate() == null) {
throw new SemanticException("must specify where clause to prevent full table update");
}
List<ColumnAssignment> assignmentList = updateStmt.getAssignments();
Map<String, ColumnAssignment> assignmentByColName = assignmentList.stream().collect(
Collectors.toMap(assign -> assign.getColumn().toLowerCase(), a -> a));
SelectList selectList = new SelectList();
for (Column col : table.getBaseSchema()) {
SelectListItem item;
ColumnAssignment assign = assignmentByColName.get(col.getName().toLowerCase());
if (assign != null) {
if (col.isKey()) {
throw new SemanticException("primary key column cannot be updated: " + col.getName());
}
item = new SelectListItem(new CastExpr(col.getType(), assign.getExpr()), col.getName());
} else {
item = new SelectListItem(new SlotRef(tableName, col.getName()), col.getName());
}
selectList.addItem(item);
}
TableRelation tableRelation = new TableRelation(tableName);
SelectRelation selectRelation =
new SelectRelation(selectList, tableRelation, updateStmt.getWherePredicate(), null, null);
QueryStatement queryStatement = new QueryStatement(selectRelation);
queryStatement.setIsExplain(updateStmt.isExplain(), updateStmt.getExplainLevel());
new QueryAnalyzer(session).analyze(queryStatement);
updateStmt.setTable(table);
updateStmt.setQueryStatement(queryStatement);
}