This is an automated email from the ASF dual-hosted git repository.
airborne12 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 5d3b20272b8 [fix](cloud) Reject DROP INDEX ON PARTITION in cloud mode
(#71041)
5d3b20272b8 is described below
commit 5d3b20272b87e6167824f6222247a98efefd17f3
Author: Jack <[email protected]>
AuthorDate: Tue Dec 1 13:48:06 2026 +0800
[fix](cloud) Reject DROP INDEX ON PARTITION in cloud mode (#71041)
### Background
`DROP INDEX idx ON t PARTITION (p)` (#62181) deletes the inverted index
files of the named partitions and keeps the index in the table schema.
In shared-nothing mode the BE rewrites the rowsets of those partitions
with a rowset schema that no longer lists the index. In cloud mode an
index change is an index-change compaction that brings rowsets whose
schema version is older than the table's up to the current table schema,
and the meta-service stores one rowset schema per (index_id,
schema_version).
### What problem does this PR solve?
Issue Number: None
Related PR: #62181 (introduced DROP INDEX ON PARTITION), #70357 (same
feature on branch-4.1, has the bug), #70352 (same feature for
branch-4.2, open, has the bug)
PR Type: Bugfix
Problem Summary:
In cloud mode, `DROP INDEX ... ON PARTITION` and `ALTER TABLE ... DROP
INDEX ... PARTITION` report success and their job reaches FINISHED, but
the index stays: queries on the partition keep using it and its files
are never deleted. This PR rejects both statements in cloud mode with a
clear error. Dropping the index from the whole table, and `BUILD INDEX
... PARTITION`, still work in cloud mode; the PR adds a cloud regression
case for the latter.
On a cloud cluster, with `t_part_drop(k1 INT, v1 VARCHAR(50), INDEX
idx_v1 (v1) USING INVERTED)` range-partitioned into `p1` and `p2`:
```sql
DROP INDEX idx_v1 ON t_part_drop PARTITION (p1);
```
| | Result |
|---|---|
| Before | Succeeds; `SHOW BUILD INDEX` shows a FINISHED job `DROP INDEX
idx_v1` on `p1`; `SELECT * FROM t_part_drop WHERE k1 < 100 AND v1 =
'aaaaa'` still reports `RowsInvertedIndexFiltered: 2`, as before the
drop |
| After | `ERROR 1105 (HY000): errCode = 2, detailMessage = DROP INDEX
ON PARTITION is not supported in cloud mode`; no job is created |
### Details
- **Frequency:** Always in cloud mode, on every `DROP INDEX ... ON
PARTITION` and `ALTER TABLE ... DROP INDEX ... PARTITION`.
- **Root cause:** A partition drop keeps the table schema, so
`SchemaChangeHandler.buildOrDeleteTableInvertedIndices` sends each
tablet the current schema version and the full index list, including the
dropped index. `EngineCloudIndexChangeTask` ignores `is_drop_op` and
`alter_inverted_indexes`, and
`CloudTablet::pick_a_rowset_for_index_change` picks only rowsets whose
schema version is older than the requested one, so rowsets written at
the current version are skipped and the job finishes without deleting
anything; older rowsets would be rebuilt with the full list and keep the
index.
- **Why existing tests missed it:** Unit tests: the partition-drop cases
in `IndexChangeJobTest` run in shared-nothing mode, `CloudIndexTest`
covers only whole-table index changes, and `CloudIndexChangeTaskTest`
mocks `pick_a_rowset_for_index_change` and never sends a drop.
Regression: `test_drop_index_on_partition` runs in cloud_p0, but it
checks only that new jobs appear and reach FINISHED, that the index
metadata stays, and query results, which are the same with or without
the index; nothing checks that the index stopped being used. This PR
changes its cloud-mode expectation to the new error.
- **Fix:** `DropIndexOp.validate` rejects a partition spec in cloud
mode, next to the existing partition-spec checks; both statement forms
pass through it before any table lookup or job creation. Supporting the
drop would need a rowset schema that differs from the table schema at
the same schema version, which the meta-service schema store does not
allow (`put_schema_kv` keeps the first schema of a version), so this PR
rejects it instead.
- **Other paths and branches:** Shared-nothing mode is not affected:
`EngineIndexChangeTask` honors `is_drop_op`. A whole-table `DROP INDEX`
in cloud mode changes the table schema and works. Master has the bug
since #62181, branch-4.1 through #70357, and branch-4.2 will with
#70352; branch-4.0 and branch-3.1 lack the statement.
- **Behavior change:** In cloud mode both statement forms now fail at
analysis, also with `IF EXISTS`. Shared-nothing mode is unchanged.
### Testing
All runs were local and predate a rebase onto a CI-only master commit;
the tested files are unchanged.
- `IndexChangeJobTest#testDropIndexOnPartitionRejectedInCloudMode` fails
on the unfixed code (`Expected org.apache.doris.common.AnalysisException
to be thrown, but nothing was thrown`) and passes with the fix; it also
checks that a whole-table drop still validates. `IndexChangeJobTest`,
`CloudIndexTest`, and `SchemaChangeHandlerTest` pass.
- On a doris-compose cloud cluster built from master, with the FE jar
swapped between the unfixed and fixed builds:
- `test_drop_index_on_partition` fails on the unfixed FE (`Expect
exception msg contains 'DROP INDEX ON PARTITION is not supported in
cloud mode', but meet 'null'`) and passes on the fixed FE, also when
rerun.
- The new `test_cloud_build_index_on_partition` passes on both.
`RowsInvertedIndexFiltered` for `p1`/`p2` is 0/0 before the build, 2/0
after building `p1` (no job for `p2`), and 2/2 after building `p2`.
- The example above ran there too.
- Not run locally: the shared-nothing part of
`test_drop_index_on_partition`, unchanged by this PR; CI P0 runs it.
---
.../trees/plans/commands/info/DropIndexOp.java | 6 ++
.../org/apache/doris/alter/IndexChangeJobTest.java | 19 ++++++
.../test_cloud_build_index_on_partition.out | 19 ++++++
.../test_cloud_build_index_on_partition.groovy | 72 ++++++++++++++++++++++
.../test_drop_index_on_partition.groovy | 31 ++++++++++
5 files changed, 147 insertions(+)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/DropIndexOp.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/DropIndexOp.java
index 9c942df3ca2..7b1bc8f2f97 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/DropIndexOp.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/DropIndexOp.java
@@ -21,6 +21,7 @@ import org.apache.doris.alter.AlterOpType;
import org.apache.doris.catalog.info.PartitionNamesInfo;
import org.apache.doris.catalog.info.TableNameInfo;
import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.Config;
import org.apache.doris.common.UserException;
import org.apache.doris.qe.ConnectContext;
@@ -101,6 +102,11 @@ public class DropIndexOp extends AlterTableOp {
tableName.analyze(ctx.getNameSpaceContext());
}
if (partitionNamesInfo != null) {
+ // Cloud mode keeps one rowset schema per schema version, so it
cannot drop an index from
+ // only some partitions while the table schema keeps it.
+ if (Config.isCloudMode()) {
+ throw new AnalysisException("DROP INDEX ON PARTITION is not
supported in cloud mode");
+ }
if (partitionNamesInfo.isTemp()) {
throw new AnalysisException(
"DROP INDEX ON PARTITION does not support temporary
partitions");
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/alter/IndexChangeJobTest.java
b/fe/fe-core/src/test/java/org/apache/doris/alter/IndexChangeJobTest.java
index 22b3f16e2e3..db98ca0bbde 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/alter/IndexChangeJobTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/alter/IndexChangeJobTest.java
@@ -1058,6 +1058,25 @@ public class IndexChangeJobTest {
Assertions.assertEquals(2, dropIndexOp.getPartitionNames().size());
}
+ @Test
+ public void testDropIndexOnPartitionRejectedInCloudMode() throws Exception
{
+ PartitionNamesInfo partition = new PartitionNamesInfo(false,
Lists.newArrayList("p1"));
+ DropIndexOp partitionDrop = new DropIndexOp("index1", false, null,
true, partition);
+ DropIndexOp tableDrop = new DropIndexOp("index1", false, null, true,
null);
+ String originalCloudUniqueId = Config.cloud_unique_id;
+ try {
+ Config.cloud_unique_id = "test_cloud_drop_index_on_partition";
+ // Dropping the index from the whole table still works in cloud
mode.
+ tableDrop.validate(new ConnectContext());
+ AnalysisException e =
Assertions.assertThrows(AnalysisException.class,
+ () -> partitionDrop.validate(new ConnectContext()));
+ Assertions.assertTrue(e.getMessage().contains("DROP INDEX ON
PARTITION is not supported in cloud mode"),
+ e.getMessage());
+ } finally {
+ Config.cloud_unique_id = originalCloudUniqueId;
+ }
+ }
+
@Test
public void testDropIndexOnPartitionRejectsNonPartitionedTable() throws
UserException {
// testTable1 uses SinglePartitionInfo (non-partitioned), so DROP
INDEX ON PARTITION should fail
diff --git
a/regression-test/data/inverted_index_p0/cloud_build_index/test_cloud_build_index_on_partition.out
b/regression-test/data/inverted_index_p0/cloud_build_index/test_cloud_build_index_on_partition.out
new file mode 100644
index 00000000000..5dd30656884
--- /dev/null
+++
b/regression-test/data/inverted_index_p0/cloud_build_index/test_cloud_build_index_on_partition.out
@@ -0,0 +1,19 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !sql --
+1 aaaaa
+
+-- !sql --
+101 aaaaa
+
+-- !sql --
+1 aaaaa
+
+-- !sql --
+101 aaaaa
+
+-- !sql --
+1 aaaaa
+
+-- !sql --
+101 aaaaa
+
diff --git
a/regression-test/suites/inverted_index_p0/cloud_build_index/test_cloud_build_index_on_partition.groovy
b/regression-test/suites/inverted_index_p0/cloud_build_index/test_cloud_build_index_on_partition.groovy
new file mode 100644
index 00000000000..83f90b19344
--- /dev/null
+++
b/regression-test/suites/inverted_index_p0/cloud_build_index/test_cloud_build_index_on_partition.groovy
@@ -0,0 +1,72 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// In cloud mode, BUILD INDEX ON PARTITION builds the index only for the named
partitions.
+suite("test_cloud_build_index_on_partition") {
+ if (!isCloudMode()) {
+ return
+ }
+
+ def timeout = 60000
+
+ // With a light CREATE INDEX, rows loaded before the index get it only
from BUILD INDEX.
+ sql "set enable_add_index_for_new_data = true"
+ sql "set enable_profile = true"
+ sql "set profile_level = 2"
+
+ sql "DROP TABLE IF EXISTS test_cloud_build_index_on_partition"
+ sql """
+ CREATE TABLE test_cloud_build_index_on_partition (
+ k1 int NOT NULL,
+ v1 varchar(50) NOT NULL
+ )
+ DUPLICATE KEY(`k1`)
+ PARTITION BY RANGE(`k1`) (
+ PARTITION p1 VALUES LESS THAN (100),
+ PARTITION p2 VALUES LESS THAN (200)
+ )
+ DISTRIBUTED BY HASH(`k1`) BUCKETS 1
+ """
+ sql """
+ INSERT INTO test_cloud_build_index_on_partition VALUES
+ (1, 'aaaaa'), (2, 'bbbbb'), (3, 'ccccc'),
+ (101, 'aaaaa'), (102, 'bbbbb'), (103, 'ccccc')
+ """
+
+ def p1_query = "SELECT * FROM test_cloud_build_index_on_partition WHERE k1
< 100 AND v1 = 'aaaaa'"
+ def p2_query = "SELECT * FROM test_cloud_build_index_on_partition WHERE k1
>= 100 AND v1 = 'aaaaa'"
+
+ sql "CREATE INDEX idx_v1 ON test_cloud_build_index_on_partition(v1) USING
INVERTED"
+ check_inverted_index_filter_rows(p1_query, 0)
+ check_inverted_index_filter_rows(p2_query, 0)
+
+ // SHOW BUILD INDEX also lists jobs of earlier tables with this name, so
compare counts.
+ def show_p2_jobs = """SHOW BUILD INDEX WHERE TableName =
"test_cloud_build_index_on_partition" AND PartitionName = "p2";"""
+ def p2_job_count = sql(show_p2_jobs).size()
+
+ // Each partition holds three rows and one match, so a built index filters
two rows.
+ sql "BUILD INDEX ON test_cloud_build_index_on_partition PARTITION (p1)"
+ wait_for_last_build_index_finish("test_cloud_build_index_on_partition",
timeout)
+ assertEquals(p2_job_count, sql(show_p2_jobs).size())
+ check_inverted_index_filter_rows(p1_query, 2)
+ check_inverted_index_filter_rows(p2_query, 0)
+
+ sql "BUILD INDEX ON test_cloud_build_index_on_partition PARTITION (p2)"
+ wait_for_last_build_index_finish("test_cloud_build_index_on_partition",
timeout)
+ check_inverted_index_filter_rows(p1_query, 2)
+ check_inverted_index_filter_rows(p2_query, 2)
+}
diff --git
a/regression-test/suites/inverted_index_p0/index_change/test_drop_index_on_partition.groovy
b/regression-test/suites/inverted_index_p0/index_change/test_drop_index_on_partition.groovy
index e75392a3f15..9d9e534e8d9 100644
---
a/regression-test/suites/inverted_index_p0/index_change/test_drop_index_on_partition.groovy
+++
b/regression-test/suites/inverted_index_p0/index_change/test_drop_index_on_partition.groovy
@@ -51,6 +51,37 @@ suite("test_drop_index_on_partition", "inverted_index") {
assertTrue(useTime <= OpTimeout,
"wait_for_build_index_on_partition_finish timeout")
}
+ // Cloud mode stores one rowset schema per schema version, so it cannot
drop an index from only
+ // some partitions and rejects the statement before creating any job.
+ if (isCloudMode()) {
+ sql "DROP TABLE IF EXISTS test_drop_idx_on_partition_cloud"
+ sql """
+ CREATE TABLE test_drop_idx_on_partition_cloud (
+ k1 int NOT NULL,
+ v1 varchar(50),
+ INDEX idx_v1 (v1) USING INVERTED
+ )
+ DUPLICATE KEY(`k1`)
+ PARTITION BY RANGE(`k1`) (
+ PARTITION p1 VALUES LESS THAN (100),
+ PARTITION p2 VALUES LESS THAN (200)
+ )
+ DISTRIBUTED BY HASH(`k1`) BUCKETS 1
+ """
+ // SHOW BUILD INDEX also lists jobs of earlier tables with this name,
so compare counts.
+ def cloud_job_count =
get_build_index_job_count("test_drop_idx_on_partition_cloud")
+ test {
+ sql "DROP INDEX idx_v1 ON test_drop_idx_on_partition_cloud
PARTITION (p1)"
+ exception "DROP INDEX ON PARTITION is not supported in cloud mode"
+ }
+ test {
+ sql "ALTER TABLE test_drop_idx_on_partition_cloud DROP INDEX
idx_v1 PARTITION (p1)"
+ exception "DROP INDEX ON PARTITION is not supported in cloud mode"
+ }
+ assertEquals(cloud_job_count,
get_build_index_job_count("test_drop_idx_on_partition_cloud"))
+ return
+ }
+
// case 1: basic DROP INDEX ON PARTITION with job count verification
def tableName1 = "test_drop_idx_on_partition_basic"
sql "DROP TABLE IF EXISTS ${tableName1}"
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]