From ceaa7907930a590439a53b3dbbe65ea18602d341 Mon Sep 17 00:00:00 2001 From: yangzhg <780531911@qq.com> Date: Wed, 19 Feb 2020 17:57:27 +0800 Subject: [PATCH] [Alter] Drop index when index column is dropped (#2941) --- .../doris/alter/SchemaChangeHandler.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/fe/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java b/fe/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java index 7d0822b80f..8fa3c91348 100644 --- a/fe/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java +++ b/fe/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java @@ -157,7 +157,7 @@ public class SchemaChangeHandler extends AlterHandler { } private void processDropColumn(DropColumnClause alterClause, OlapTable olapTable, - Map> indexSchemaMap) throws DdlException { + Map> indexSchemaMap, List indexes) throws DdlException { String dropColName = alterClause.getColName(); String targetIndexName = alterClause.getRollupName(); checkIndexExists(olapTable, targetIndexName); @@ -224,7 +224,18 @@ public class SchemaChangeHandler extends AlterHandler { } } } - + + Iterator it = indexes.iterator(); + while(it.hasNext()){ + Index index = it.next(); + for (String indexCol : index.getColumns()) { + if (dropColName.equalsIgnoreCase(indexCol)) { + it.remove(); + break; + } + } + } + long baseIndexId = olapTable.getBaseIndexId(); if (targetIndexName == null) { // if not specify rollup index, column should be dropped from both base and rollup indexes. @@ -1367,8 +1378,8 @@ public class SchemaChangeHandler extends AlterHandler { // add columns processAddColumns((AddColumnsClause) alterClause, olapTable, indexSchemaMap); } else if (alterClause instanceof DropColumnClause) { - // drop column - processDropColumn((DropColumnClause) alterClause, olapTable, indexSchemaMap); + // drop column and drop indexes on this column + processDropColumn((DropColumnClause) alterClause, olapTable, indexSchemaMap, newIndexes); } else if (alterClause instanceof ModifyColumnClause) { // modify column processModifyColumn((ModifyColumnClause) alterClause, olapTable, indexSchemaMap);