hello-stephen commented on code in PR #70352:
URL: https://github.com/apache/doris/pull/70352#discussion_r4731502256
##########
fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java:
##########
@@ -2200,37 +2218,84 @@ public int getAsInt() {
buildIndexChange = true;
lightSchemaChange = false;
} else if (alterClause instanceof DropIndexClause) {
- if (processDropIndex((DropIndexClause) alterClause,
olapTable, newIndexes)) {
- return;
- }
- lightSchemaChange = false;
-
DropIndexClause dropIndexClause = (DropIndexClause)
alterClause;
- List<Index> existedIndexes = olapTable.getIndexes();
- Index found = null;
- for (Index existedIdx : existedIndexes) {
- if
(existedIdx.getIndexName().equalsIgnoreCase(dropIndexClause.getIndexName())) {
- found = existedIdx;
- break;
+
+ if (dropIndexClause.hasPartitionSpec()) {
+ // Delete the physical index files and keep the
table-level index definition.
+ List<Index> existedIndexes = olapTable.getIndexes();
+ Index found = null;
+ for (Index existedIdx : existedIndexes) {
+ if
(existedIdx.getIndexName().equalsIgnoreCase(dropIndexClause.getIndexName())) {
+ found = existedIdx;
+ break;
+ }
}
- }
- // for inverted index, light schema change is supported in
both cloud and local mode;
- // for ngram index, light schema change is supported only
in cloud mode;
- boolean supportLightIndexChange = false;
- if (Config.isCloudMode()) {
- if (enableAddIndexForNewData) {
- supportLightIndexChange = (
- found.getIndexType() == IndexType.NGRAM_BF
- || found.getIndexType() ==
IndexDef.IndexType.INVERTED);
+ if (found == null) {
+ if (dropIndexClause.isSetIfExists()) {
+ LOG.info("drop index[{}] which does not exist
on table[{}]",
+ dropIndexClause.getIndexName(),
olapTable.getName());
+ return;
+ }
+ throw new DdlException("index " +
dropIndexClause.getIndexName() + " does not exist");
}
- } else {
- supportLightIndexChange = found.getIndexType() ==
IndexDef.IndexType.INVERTED
- || found.getIndexType() ==
IndexDef.IndexType.ANN;
- }
- if (found != null && supportLightIndexChange) {
+ if (found.getIndexType() != IndexType.INVERTED) {
+ throw new DdlException(
+ "Only inverted index supports DROP INDEX
ON PARTITION");
+ }
+ // For a VARIANT column the BE finds only values
indexes under the root column, so a
+ // partition drop of any other index on it would
finish without deleting anything.
+ for (String indexColumn : found.getColumns()) {
+ Column column = olapTable.getColumn(indexColumn);
+ if (column != null &&
column.getType().isVariantType()) {
+ throw new DdlException("DROP INDEX ON
PARTITION is not supported for index "
+ + found.getIndexName() + " on VARIANT
column " + column.getName());
+ }
+ }
+ if (!olapTable.isPartitionedTable()) {
+ throw new DdlException("table " +
olapTable.getName()
+ + " is not partitioned, cannot drop index
with partitions");
+ }
+ Set<String> specifiedPartitions = new
HashSet<>(dropIndexClause.getPartitionNames());
+ for (String partName : specifiedPartitions) {
+ if (olapTable.getPartition(partName) == null) {
+ throw new DdlException("partition " + partName
+ " does not exist");
+ }
+ }
+
+ if (!Config.enable_light_index_change) {
+ throw new DdlException(
+ "DROP INDEX ON PARTITION requires
enable_light_index_change=true");
+ }
+ Set<Long> specifiedPartitionIds =
specifiedPartitions.stream()
+ .map(partName ->
olapTable.getPartition(partName).getId())
+ .collect(Collectors.toSet());
+ checkNoIndexChangeJobOnPartitions(db, olapTable,
+ ImmutableList.of(found),
specifiedPartitionIds);
+
alterIndexes.add(found);
+ indexOnPartitions.put(found.getIndexId(),
specifiedPartitions);
Review Comment:
[P2] Reject partitions with remote rowsets before scheduling physical drops
For a shared-nothing table whose selected partition has already cooled down
under a `storage_policy`, `DROP INDEX idx ON t PARTITION (p1)` schedules a
successful no-op: `Tablet::pick_candidate_rowsets_to_build_inverted_index()`
only selects `rs->is_local()` rowsets, and
`IndexBuilder::do_build_inverted_index()` returns OK when that set is empty.
The job reaches FINISHED while the remote index files and rowset index metadata
remain present. This branch also retains the catalog definition, so queries on
p1 continue to use the index. Reject affected partitions or implement remote
rowset index removal before accepting the operation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]