[branch-2.1] Picks "[opt](autoinc) Forbid some schema change when the table has auto-increment column #37186" (#37331)
## Proposed changes picks https://github.com/apache/doris/pull/37186
This commit is contained in:
@ -642,6 +642,11 @@ public class SchemaChangeHandler extends AlterHandler {
|
||||
modColumn.setName(oriColumn.getName());
|
||||
modColumn.setUniqueId(oriColumn.getUniqueId());
|
||||
|
||||
if (!modColumn.equals(oriColumn) && oriColumn.isAutoInc() != modColumn.isAutoInc()) {
|
||||
throw new DdlException("Can't modify the column["
|
||||
+ oriColumn.getName() + "]'s auto-increment attribute.");
|
||||
}
|
||||
|
||||
// handle the move operation in 'indexForFindingColumn' if has
|
||||
if (hasColPos) {
|
||||
// move col
|
||||
@ -719,6 +724,12 @@ public class SchemaChangeHandler extends AlterHandler {
|
||||
} // end for handling other indices
|
||||
|
||||
if (typeChanged && !lightSchemaChange) {
|
||||
Optional<Column> autoIncCol = olapTable.getBaseSchema(true).stream()
|
||||
.filter(col -> col.isAutoInc()).findFirst();
|
||||
if (autoIncCol.isPresent()) {
|
||||
throw new DdlException("Can not modify column " + modColumn.getName() + " becasue table "
|
||||
+ olapTable.getName() + " has auto-increment column " + autoIncCol.get().getName());
|
||||
}
|
||||
/*
|
||||
* In new alter table process (AlterJobV2), any modified columns are treated as new columns.
|
||||
* But the modified columns' name does not changed. So in order to distinguish this, we will add
|
||||
@ -835,6 +846,10 @@ public class SchemaChangeHandler extends AlterHandler {
|
||||
int posIndex = -1;
|
||||
boolean hasPos = (columnPos != null && !columnPos.isFirst());
|
||||
|
||||
if (newColumn.isAutoInc()) {
|
||||
throw new DdlException("Can not add auto-increment column " + newColumn.getName());
|
||||
}
|
||||
|
||||
for (int i = 0; i < modIndexSchema.size(); i++) {
|
||||
Column col = modIndexSchema.get(i);
|
||||
if (col.getName().equalsIgnoreCase(newColName)) {
|
||||
@ -904,6 +919,10 @@ public class SchemaChangeHandler extends AlterHandler {
|
||||
boolean lightSchemaChange = olapTable.getEnableLightSchemaChange();
|
||||
String newColName = newColumn.getName();
|
||||
|
||||
if (newColumn.isAutoInc()) {
|
||||
throw new DdlException("Can not add auto-increment column " + newColumn.getName());
|
||||
}
|
||||
|
||||
// check the validation of aggregation method on column.
|
||||
// also fill the default aggregation method if not specified.
|
||||
if (KeysType.AGG_KEYS == olapTable.getKeysType()) {
|
||||
|
||||
Reference in New Issue
Block a user