This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new b66ffe9eb5f branch-4.1: [fix](inverted index) Backport partition DROP
INDEX fixes #71043 #71122 (#71046)
b66ffe9eb5f is described below
commit b66ffe9eb5fce53047e1e9b1b61121e2c813f215
Author: Jack <[email protected]>
AuthorDate: Sat Dec 5 21:57:35 2026 +0800
branch-4.1: [fix](inverted index) Backport partition DROP INDEX fixes
#71043 #71122 (#71046)
### What problem does this PR solve?
Issue Number: None
Related PR: #71043 and #71122 (master fixes, open; this backport follows
any change they get in review), #70357 (brought partition DROP INDEX and
the light DROP pre-check to branch-4.1), #70352 (branch-4.2 backport
whose review found both bugs)
Problem Summary:
Backport two partition DROP INDEX fixes to `branch-4.1`, one commit per
source PR:
| Source | Change | Pick |
|---|---|---|
| #71043 | BUILD INDEX and DROP INDEX on partitions, and the whole-table
light DROP INDEX pre-check, found an unfinished index change job by the
partition name stored in the job. `RENAME PARTITION` is allowed while
such jobs run, so a statement on the new name missed the conflict: a
DROP could run while a BUILD of the same index was pending, and the
BUILD restored the index afterwards. The checks now match jobs by
partition ID. | 43de3f60fd5, adapted |
| #71122 | DROP INDEX ON PARTITION on an inverted index of a VARIANT
column, including a `field_pattern` index, was accepted and its job
reached FINISHED, but the BE finds no index under a VARIANT root column,
so nothing was deleted. The FE now rejects it, as BUILD INDEX already
does for VARIANT columns. | a9f18452698, adapted |
Hunk audit for #71043 (commit 5c5d807d234):
| File | Source hunk | Result |
|---|---|---|
| `IndexChangeJob.java` | `@@ -202,6 +202,10 @@ public class
IndexChangeJob implements Writable {` | Ported |
| `SchemaChangeHandler.java` | `@@ -3975,7 +3975,7 @@ public class
SchemaChangeHandler extends AlterHandler {` | Ported |
| `SchemaChangeHandler.java` | `@@ -4041,29 +4041,32 @@ public class
SchemaChangeHandler extends AlterHandler {` | Adapted: kept this
branch's light DROP pre-check, which has no add-and-drop or cluster
checks; only the partition matching changes |
| `SchemaChangeHandler.java` | (this branch only) partition DROP
pre-check | Adapted: passes the selected partitions as IDs |
| `SchemaChangeHandlerTest.java` | `@@ -1403,7 +1403,9 @@ public class
SchemaChangeHandlerTest extends TestWithFeService {` | N-A:
`testDropIndexRejectedByIndexChangeJobKeepsMetadata` does not exist on
this branch |
| `SchemaChangeHandlerTest.java` | `@@ -1493,6 +1495,7 @@ public class
SchemaChangeHandlerTest extends TestWithFeService {` | Ported to this
branch's `testDropIndexRejectedByPendingBuildOfSameIndex` |
| `SchemaChangeHandlerTest.java` | `@@ -1516,6 +1519,54 @@ public class
SchemaChangeHandlerTest extends TestWithFeService {` | Adapted: the
partition DROP is rejected by this branch's pre-check, so the test
expects "has an unfinished index change job" for both statements |
Hunk audit for #71122 (commit df392dc3de0):
| File | Source hunk | Result |
|---|---|---|
| `SchemaChangeHandler.java` | `@@ -2664,6 +2664,15 @@ public class
SchemaChangeHandler extends AlterHandler {` | Adapted: same check; the
comment says the BE finds no index under a VARIANT root column, because
this branch has no VARIANT values indexes (on master the BE finds only
values indexes there) |
| `SchemaChangeHandlerTest.java` | `@@ -265,6 +265,32 @@ public class
SchemaChangeHandlerTest extends TestWithFeService {` | Adapted: placed
after `expectException`, since the values index tests it follows on
master do not exist here; `List.of` became `Lists.newArrayList` for this
branch's Java 8 source level |
| `test_drop_index_on_partition.groovy` | `@@ -270,4 +270,34 @@
suite("test_drop_index_on_partition", "inverted_index") {` | Ported as
case 11 |
### Release note
Fix BUILD INDEX and DROP INDEX on partitions missing a conflict with an
unfinished index change job when the partition was renamed after the job
was created.
DROP INDEX ... ON PARTITION now fails with "DROP INDEX ON PARTITION is
not supported for index <index> on VARIANT column <column>" for inverted
indexes on VARIANT columns. Before, it reported success but kept the
index on the named partitions. Drop the index from the whole table
instead.
### Check List (For Author)
- Test
- [x] Regression test
- [x] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test.
Run locally on this branch with both picks: `./run-fe-ut.sh --run
org.apache.doris.alter.SchemaChangeHandlerTest,org.apache.doris.alter.IndexChangeJobTest,org.apache.doris.alter.CloudIndexTest,org.apache.doris.cloud.alter.CloudSchemaChangeHandlerTest,org.apache.doris.catalog.IndexTest`
passed (32, 18, 5, 12 and 2 tests), including the new
`testIndexChangeConflictFollowsRenamedPartition` and
`testDropIndexOnPartitionRejectsVariantColumnIndexes`. Both tests failed
on master without their fixes (#71043, #71122).
#71043 has no regression case: holding an index change job unfinished in
a real cluster needs a delay hook that does not exist, so a SQL case
would depend on timing. Case 11 of `test_drop_index_on_partition` (from
#71122) was run against a local shared-nothing cluster on master only:
it failed without the fix and passed with it; this branch's CI runs it.
- Behavior changed:
- [ ] No.
- [x] Yes. Partition DROP of an index on a VARIANT column is now
rejected (it used to report success and keep the index).
- Does this need documentation?
- [x] No.
- [ ] Yes.
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../org/apache/doris/alter/IndexChangeJob.java | 4 ++
.../apache/doris/alter/SchemaChangeHandler.java | 34 +++++++---
.../doris/alter/SchemaChangeHandlerTest.java | 75 ++++++++++++++++++++++
.../test_drop_index_on_partition.groovy | 30 +++++++++
4 files changed, 133 insertions(+), 10 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/alter/IndexChangeJob.java
b/fe/fe-core/src/main/java/org/apache/doris/alter/IndexChangeJob.java
index facb618b372..78097ad3b98 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/alter/IndexChangeJob.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/alter/IndexChangeJob.java
@@ -202,6 +202,10 @@ public class IndexChangeJob implements Writable {
return tableName;
}
+ public long getPartitionId() {
+ return partitionId;
+ }
+
public String getPartitionName() {
return partitionName;
}
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 4d238e871c9..02b31bfdc4c 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
@@ -2212,6 +2212,15 @@ public class SchemaChangeHandler extends AlterHandler {
throw new DdlException(
"Only inverted index supports DROP INDEX
ON PARTITION");
}
+ // For a VARIANT column the BE finds no index under
the root column, so a partition drop
+ // of its index 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");
@@ -2227,8 +2236,11 @@ public class SchemaChangeHandler extends AlterHandler {
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), specifiedPartitions);
+ ImmutableList.of(found),
specifiedPartitionIds);
alterIndexes.add(found);
indexOnPartitions.put(found.getIndexId(),
specifiedPartitions);
@@ -3455,7 +3467,7 @@ public class SchemaChangeHandler extends AlterHandler {
}
if (hasIndexChangeJobOnPartition(originIndexId,
db.getId(), olapTable.getId(),
- partitionName, alterIndexes)) {
+ partitionId, alterIndexes)) {
throw new DdlException("partition " + partitionName +
" has been built specified index."
+ " please check your build
stmt.");
}
@@ -3510,27 +3522,29 @@ public class SchemaChangeHandler extends AlterHandler {
if (droppedIndexes.isEmpty()) {
return;
}
- checkNoIndexChangeJobOnPartitions(db, olapTable, droppedIndexes,
olapTable.getPartitionNames());
+ checkNoIndexChangeJobOnPartitions(db, olapTable, droppedIndexes, new
HashSet<>(olapTable.getPartitionIds()));
}
+ // Jobs are matched by partition ID because a partition can be renamed
while its job is unfinished.
private void checkNoIndexChangeJobOnPartitions(Database db, OlapTable
olapTable, List<Index> alterIndexes,
- Set<String> partitionNames) throws DdlException {
+ Set<Long> partitionIds) throws DdlException {
for (IndexChangeJob indexChangeJob :
ImmutableList.copyOf(indexChangeJobs.values())) {
- if (partitionNames.contains(indexChangeJob.getPartitionName())
+ if (partitionIds.contains(indexChangeJob.getPartitionId())
&& isConflictingIndexChangeJob(indexChangeJob,
olapTable.getBaseIndexId(), db.getId(),
olapTable.getId(), alterIndexes)) {
- throw new DdlException("partition " +
indexChangeJob.getPartitionName() + " of table "
- + olapTable.getName() + " has an unfinished index
change job, please retry after it finishes.");
+ throw new DdlException("partition " +
olapTable.getPartition(indexChangeJob.getPartitionId()).getName()
+ + " of table " + olapTable.getName()
+ + " has an unfinished index change job, please retry
after it finishes.");
}
}
}
+ // Jobs are matched by partition ID because a partition can be renamed
while its job is unfinished.
public boolean hasIndexChangeJobOnPartition(
- long originIndexId, long dbId, long tableId, String partitionName,
- List<Index> alterIndexes) {
+ long originIndexId, long dbId, long tableId, long partitionId,
List<Index> alterIndexes) {
// TODO: this is temporary methods
for (IndexChangeJob indexChangeJob :
ImmutableList.copyOf(indexChangeJobs.values())) {
- if (indexChangeJob.getPartitionName().equals(partitionName)
+ if (indexChangeJob.getPartitionId() == partitionId
&& isConflictingIndexChangeJob(indexChangeJob,
originIndexId, dbId, tableId, alterIndexes)) {
return true;
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/alter/SchemaChangeHandlerTest.java
b/fe/fe-core/src/test/java/org/apache/doris/alter/SchemaChangeHandlerTest.java
index c9afc5f5d07..d44ef5b7ea8 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/alter/SchemaChangeHandlerTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/alter/SchemaChangeHandlerTest.java
@@ -170,6 +170,32 @@ public class SchemaChangeHandlerTest extends
TestWithFeService {
}
}
+ @Test
+ public void testDropIndexOnPartitionRejectsVariantColumnIndexes() throws
Exception {
+ createTable("CREATE TABLE test.variant_partition_drop (id INT, v
VARIANT<MATCH_NAME 'a':STRING>, s STRING, "
+ + "INDEX v_idx(v) USING INVERTED, "
+ + "INDEX a_idx(v) USING INVERTED
PROPERTIES('field_pattern'='a', 'parser'='english'), "
+ + "INDEX s_idx(s) USING INVERTED) "
+ + "DUPLICATE KEY(id) PARTITION BY RANGE(id) "
+ + "(PARTITION p1 VALUES LESS THAN (10), PARTITION p2 VALUES
LESS THAN (MAXVALUE)) "
+ + "DISTRIBUTED BY HASH(id) BUCKETS 1
PROPERTIES('replication_num'='1')");
+ OlapTable table = (OlapTable)
Env.getCurrentInternalCatalog().getDbOrMetaException("test")
+ .getTableOrMetaException("variant_partition_drop",
Table.TableType.OLAP);
+ for (String indexName : Lists.newArrayList("v_idx", "a_idx")) {
+ Exception error = Assertions.assertThrows(Exception.class, () ->
executeNereidsSql(
+ "DROP INDEX " + indexName + " ON
test.variant_partition_drop PARTITION (p1)"));
+ Assertions.assertTrue(error.getMessage().contains("DROP INDEX ON
PARTITION is not supported for index "
+ + indexName + " on VARIANT column v"), error.getMessage());
+ }
+
Assertions.assertTrue(Env.getCurrentEnv().getSchemaChangeHandler().getIndexChangeJobs().values().stream()
+ .noneMatch(job -> job.getTableId() == table.getId()));
+ // An index on a non-VARIANT column of the same table can still be
dropped from a partition.
+ executeNereidsSql("DROP INDEX s_idx ON test.variant_partition_drop
PARTITION (p1)");
+
Assertions.assertTrue(Env.getCurrentEnv().getSchemaChangeHandler().getIndexChangeJobs().values().stream()
+ .anyMatch(job -> job.getTableId() == table.getId()));
+ Assertions.assertEquals(3, table.getIndexes().size());
+ }
+
// In this test we should cover this following cases:
// Positive Test Case
// 3.1 add sub-column
@@ -931,6 +957,54 @@ public class SchemaChangeHandlerTest extends
TestWithFeService {
}
}
+ @Test
+ public void testIndexChangeConflictFollowsRenamedPartition() throws
Exception {
+ String tableName = "sc_index_change_renamed_partition";
+ dropTable("test." + tableName, false);
+ createTable("CREATE TABLE test." + tableName + " (\n"
+ + "k1 INT,\n"
+ + "v1 STRING,\n"
+ + "INDEX idx_v1 (v1) USING INVERTED\n"
+ + ") ENGINE=OLAP\n"
+ + "DUPLICATE KEY(k1)\n"
+ + "PARTITION BY RANGE(k1) (PARTITION p1 VALUES LESS THAN
(\"10\"),"
+ + " PARTITION p2 VALUES LESS THAN (\"20\"))\n"
+ + "DISTRIBUTED BY HASH(k1) BUCKETS 1\n"
+ + "PROPERTIES ('replication_num' = '1', 'light_schema_change'
= 'true');");
+
+ Database db =
Env.getCurrentInternalCatalog().getDbOrMetaException("test");
+ OlapTable tbl = (OlapTable) db.getTableOrMetaException(tableName,
Table.TableType.OLAP);
+ SchemaChangeHandler handler =
Env.getCurrentEnv().getSchemaChangeHandler();
+ Index index = tbl.getIndexes().stream()
+ .filter(idx -> idx.getIndexName().equals("idx_v1"))
+ .findFirst().get();
+
+ // An unfinished BUILD INDEX idx_v1 on p1 keeps the partition name it
was created with.
+ long jobId = Env.getCurrentEnv().getNextId();
+ IndexChangeJob job = new IndexChangeJob(jobId, db.getId(),
tbl.getId(), tbl.getName(), 1000L, 0,
+ Lists.newArrayList(), Lists.newArrayList());
+ job.setOriginIndexId(tbl.getBaseIndexId());
+ job.setPartitionId(tbl.getPartition("p1").getId());
+ job.setPartitionName("p1");
+ job.setAlterInvertedIndexInfo(false, Lists.newArrayList(index));
+ handler.getIndexChangeJobs().put(jobId, job);
+ try {
+ alterTable("ALTER TABLE test." + tableName + " RENAME PARTITION p1
p1_renamed", connectContext);
+ String[][] clauseAndError = {
+ {"DROP INDEX idx_v1 PARTITION (p1_renamed)", "has an
unfinished index change job"},
+ {"DROP INDEX idx_v1", "has an unfinished index change
job"}};
+ for (String[] ce : clauseAndError) {
+ String sql = "ALTER TABLE test." + tableName + " " + ce[0];
+ Exception e = Assertions.assertThrows(Exception.class, () ->
alterTable(sql, connectContext));
+ Assertions.assertTrue(e.getMessage().contains(ce[1]),
e.getMessage());
+ Assertions.assertTrue(e.getMessage().contains("p1_renamed"),
e.getMessage());
+ }
+ Assertions.assertTrue(tbl.getIndexes().stream().anyMatch(idx ->
idx.getIndexName().equals("idx_v1")));
+ } finally {
+ handler.getIndexChangeJobs().remove(jobId);
+ }
+ }
+
@Test
public void testDropIndexOnPartitionsMustBeTheOnlyClause() throws
Exception {
String tableName = "sc_drop_index_on_partitions_alone";
@@ -1008,6 +1082,7 @@ public class SchemaChangeHandlerTest extends
TestWithFeService {
IndexChangeJob job = new IndexChangeJob(jobId, db.getId(),
tbl.getId(), tbl.getName(), 1000L, 0,
Lists.newArrayList(), Lists.newArrayList());
job.setOriginIndexId(tbl.getBaseIndexId());
+ job.setPartitionId(tbl.getPartition("p1").getId());
job.setPartitionName("p1");
job.setAlterInvertedIndexInfo(false, Lists.newArrayList(index));
handler.getIndexChangeJobs().put(jobId, job);
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 6fe9b2deca4..e2d57f8ebf9 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
@@ -297,4 +297,34 @@ suite("test_drop_index_on_partition", "inverted_index") {
sql """set enable_fallback_on_missing_inverted_index = true"""
def result4 = sql """SELECT * FROM ${tableName5} ORDER BY k1"""
assertEquals(2, result4.size())
+
+ // case 11: error - indexes on a VARIANT column, including field_pattern
indexes
+ sql "DROP TABLE IF EXISTS test_drop_idx_on_partition_variant"
+ sql """
+ CREATE TABLE IF NOT EXISTS test_drop_idx_on_partition_variant (
+ k1 int NOT NULL,
+ v variant<MATCH_NAME 'a':string>,
+ INDEX idx_v (v) USING INVERTED,
+ INDEX idx_a (v) USING INVERTED PROPERTIES("field_pattern" = "a",
"parser" = "english")
+ )
+ 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
+ properties("replication_num" = "1");
+ """
+ sql """INSERT INTO test_drop_idx_on_partition_variant VALUES
+ (10, '{"a": "hello world", "b": "x"}'), (110, '{"a": "doris", "b":
"y"}')"""
+ def variant_job_count =
get_build_index_job_count("test_drop_idx_on_partition_variant")
+ test {
+ sql "DROP INDEX idx_v ON test_drop_idx_on_partition_variant PARTITION
(p1)"
+ exception "DROP INDEX ON PARTITION is not supported for index idx_v on
VARIANT column v"
+ }
+ test {
+ sql "ALTER TABLE test_drop_idx_on_partition_variant DROP INDEX idx_a
PARTITION (p1)"
+ exception "DROP INDEX ON PARTITION is not supported for index idx_a on
VARIANT column v"
+ }
+ assertEquals(variant_job_count,
get_build_index_job_count("test_drop_idx_on_partition_variant"))
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]