diff --git a/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java b/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java index 93b22f26c1ab543..8573325a5b8eb1e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java +++ b/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java @@ -119,6 +119,8 @@ public class SchemaChangeHandler extends AlterHandler { public int cycleCount = 0; + public int maxColUniqueId = Column.COLUMN_UNIQUE_ID_INIT_VALUE; + public SchemaChangeHandler() { super("schema change", Config.default_schema_change_scheduler_interval_millisecond); } @@ -143,7 +145,8 @@ private boolean processAddColumn(AddColumnClause alterClause, OlapTable olapTabl //only new table generate ColUniqueId, exist table do not. if (olapTable.getMaxColUniqueId() > Column.COLUMN_UNIQUE_ID_INIT_VALUE) { - column.setUniqueId(olapTable.getMaxColUniqueId() + 1); + maxColUniqueId++; + column.setUniqueId(maxColUniqueId); } return addColumnInternal(olapTable, column, columnPos, targetIndexId, baseIndexId, @@ -201,10 +204,9 @@ public boolean processAddColumns(AddColumnsClause alterClause, OlapTable olapTab //for new table calculate column unique id if (olapTable.getMaxColUniqueId() > Column.COLUMN_UNIQUE_ID_INIT_VALUE) { - int maxColUniqueId = olapTable.getMaxColUniqueId(); for (Column column : columns) { - column.setUniqueId(maxColUniqueId + 1); maxColUniqueId++; + column.setUniqueId(maxColUniqueId); } } @@ -1542,6 +1544,10 @@ private void getAlterJobV2Infos(Database db, List> schemaChange getAlterJobV2Infos(db, ImmutableList.copyOf(alterJobsV2.values()), schemaChangeJobInfos); } + public void setMaxColUniqueId(int maxColUniqueId) { + this.maxColUniqueId = maxColUniqueId; + } + @Override public void process(List alterClauses, String clusterName, Database db, OlapTable olapTable) throws UserException { @@ -1549,6 +1555,8 @@ public void process(List alterClauses, String clusterName, Database try { //alterClauses can or cannot light schema change boolean ligthSchemaChange = true; + //for multi add colmuns clauses + this.setMaxColUniqueId(olapTable.getMaxColUniqueId()); // index id -> index schema Map> indexSchemaMap = new HashMap<>(); for (Map.Entry> entry : olapTable.getIndexIdToSchema(true).entrySet()) { @@ -1655,8 +1663,8 @@ public void process(List alterClauses, String clusterName, Database } } // end for alter clauses - LOG.debug("processAddColumns, table: {}({}), getMaxColUniqueId(): {}, ligthSchemaChange: {}", olapTable.getName(), - olapTable.getId(), olapTable.getMaxColUniqueId(), ligthSchemaChange); + LOG.debug("processAddColumns, table: {}({}), maxColUniqueId: {}, ligthSchemaChange: {}", olapTable.getName(), + olapTable.getId(), maxColUniqueId, ligthSchemaChange); if (ligthSchemaChange) { //for schema change add/drop value column optimize, direct modify table meta. @@ -1666,6 +1674,8 @@ public void process(List alterClauses, String clusterName, Database createJob(db.getId(), olapTable, indexSchemaMap, propertyMap, newIndexes); } } finally { + //reset schema change max col unique id + maxColUniqueId = Column.COLUMN_UNIQUE_ID_INIT_VALUE; olapTable.writeUnlock(); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeJobV2.java b/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeJobV2.java index 0bb0bae43ab6d5a..9a1bbfc44896c0b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeJobV2.java +++ b/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeJobV2.java @@ -625,7 +625,7 @@ private void onFinished(OlapTable tbl) { maxColUniqueId = column.getUniqueId(); } } - tbl.setMaxtColUniqueId(maxColUniqueId); + tbl.setMaxColUniqueId(maxColUniqueId); LOG.debug("fullSchema:{}, maxColUniqueId:{}", tbl.getFullSchema(), maxColUniqueId); tbl.setState(OlapTableState.NORMAL); diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java index e1cfe106cd2436c..febcf24210b0cb8 100755 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java @@ -5036,7 +5036,7 @@ public void modifyTableAddOrDropColumns(Database db, OlapTable olapTable, Map(entry.getValue())); } //4. call schame change function, only for dynamic table feature. - SchemaChangeHandler schemaChangeHandler = new SchemaChangeHandler(); + SchemaChangeHandler schemaChangeHandler = new SchemaChangeHandler(); + schemaChangeHandler.setMaxColUniqueId(olapTable.getMaxColUniqueId()); boolean ligthSchemaChange = schemaChangeHandler.processAddColumns(addColumnsClause, olapTable, indexSchemaMap, true); if (ligthSchemaChange) { //for schema change add column optimize, direct modify table meta.