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 d47d7eb4dd1 [fix](inverted index) Reject DROP INDEX ON PARTITION for 
indexes on VARIANT columns (#71122)
d47d7eb4dd1 is described below

commit d47d7eb4dd1d2a0e3a59473a85b5cc46f3212755
Author: Jack <[email protected]>
AuthorDate: Wed Dec 2 09:07:03 2026 +0800

    [fix](inverted index) Reject DROP INDEX ON PARTITION for indexes on VARIANT 
columns (#71122)
    
    ### Background
    
    `DROP INDEX <index> ON <table> PARTITION (...)`, and its `ALTER TABLE
    ... DROP INDEX ... PARTITION` form, deletes the files of an inverted
    index on the named partitions and keeps the index in the table schema.
    The FE creates one index change job per partition. On each tablet, the
    BE `IndexBuilder` finds the index in each rowset's schema through the
    column that the job names, rewrites the rowset without it, and the job
    then reports FINISHED. An inverted index on a VARIANT column is written
    for the column's subcolumns (paths), not for the root column.
    
    ### What problem does this PR solve?
    
    Issue Number: None
    Related PR: #62181 (introduced DROP INDEX ON PARTITION), #70357 (same
    feature on branch-4.1), #70352 (branch-4.2 backport where the bug was
    reported), #71041 (rejects the statement in cloud mode; touches the same
    regression suite)
    PR Type: Bugfix
    
    Problem Summary:
    
    On a shared-nothing cluster, DROP INDEX ON PARTITION on an inverted
    index of a VARIANT column, including a `field_pattern` index, is
    accepted and its job reaches FINISHED, but the index stays on the
    partition: the BE rewrites each rowset and copies every index file
    unchanged. This PR rejects the statement for indexes on VARIANT columns,
    as BUILD INDEX already does.
    
    ```sql
    CREATE TABLE t (k INT NOT NULL, v VARIANT, s STRING,
      INDEX idx_v (v) USING INVERTED, INDEX idx_s (s) USING INVERTED)
    DUPLICATE KEY(k)
    PARTITION BY RANGE(k) (PARTITION p1 VALUES LESS THAN (3000), PARTITION p2 
VALUES LESS THAN (MAXVALUE))
    DISTRIBUTED BY HASH(k) BUCKETS 1 PROPERTIES ("replication_num" = "1");
    -- load rows with v = {"a": "tag<n % 10>", "b": <n>} and s = 'tag<n % 10>'
    DROP INDEX idx_v ON t PARTITION (p1);
    SET enable_match_without_inverted_index = false;
    SELECT count(*) FROM t PARTITION (p1) WHERE cast(v['a'] AS STRING) MATCH 
'tag3';
    ```
    
    | | Before the fix | With the fix |
    |---|---|---|
    | `DROP INDEX idx_v ON t PARTITION (p1)` | Accepted, job `FINISHED`; the
    p1 rowset keeps `idx_v` in its schema and its `.idx` file stays 13411
    bytes; the MATCH on p1 still returns `300` | `DROP INDEX ON PARTITION is
    not supported for index idx_v on VARIANT column v` |
    | `DROP INDEX idx_s ON t PARTITION (p1)` (STRING control) | Job
    `FINISHED`; `.idx` 13411 -> 9865 bytes; a MATCH on `s` in p1 fails with
    `match_any not support execute_match` | Not changed |
    
    ### Details
    
    - **Frequency:** Always, for DROP INDEX ON PARTITION on an inverted
    index of a VARIANT column in shared-nothing mode.
    - **Root cause:** The FE accepts the statement for every inverted index.
    `IndexBuilder::update_inverted_index_info()` looks up the indexes to
    drop with `TabletSchema::inverted_indexs(column)` for the column named
    in the job, and for a root VARIANT column that function returns only
    VARIANT values indexes. With nothing found, the rowset is rewritten with
    every index file copied and the job finishes.
    - **Why existing tests missed it:** Unit tests: the partition drop tests
    in `IndexChangeJobTest` (`testDropIndexOnPartition*`) use a table
    without VARIANT columns and check only what the FE accepts. Regression:
    `inverted_index_p0/index_change/test_drop_index_on_partition` drops
    indexes on `varchar` and `string` columns only, and checks the job state
    and `SHOW INDEX`, not whether a partition still uses the index.
    `variant_p0/v2/with_index/test_variant_values_index_rejected_state` (S9)
    does run the partition drop on a path index and a `field_pattern` index
    of a VARIANT column, but it expected the drop to succeed, checked only
    that a job was created, and queried the partition with
    `enable_match_without_inverted_index=true`, so it passed while the index
    stayed.
    - **Fix:** `SchemaChangeHandler` rejects the partition drop when a
    column of the index is VARIANT, beside the other checks of that path and
    in line with the BUILD INDEX check on VARIANT columns. Making the BE
    drop the subcolumn indexes would change the rowset rewrite for V2 and
    SNII index files and is left out; DROP INDEX on the whole table still
    removes these indexes.
    - **Behavior change:** Both statement forms now fail for an inverted
    index of a VARIANT column, also with IF EXISTS when the index exists.
    - **Other paths and branches:** BUILD INDEX already rejects VARIANT
    columns, and VARIANT values indexes were already rejected with their own
    message. Cloud mode: #71041 rejects every partition drop; until it is
    merged, this check applies there too. `branch-4.1` has the bug since
    #70357; on `branch-4.2` the feature arrives with #70352, which will
    carry this fix.
    
    ### Testing
    
    -
    
`SchemaChangeHandlerTest#testDropIndexOnPartitionRejectsVariantColumnIndexes`
    (new): on a partitioned table with a root VARIANT index, a
    `field_pattern` index and a STRING index, checks that the two VARIANT
    partition drops are rejected without creating an index change job, and
    that the STRING one is accepted. On master without the fix it failed
    with `Expected java.lang.Exception to be thrown, but nothing was
    thrown`. With the fix, `SchemaChangeHandlerTest`, `IndexChangeJobTest`,
    `CloudIndexTest`, `VariantValuesIndexChangeTest` and
    `CloudSchemaChangeHandlerTest` pass locally.
    - `test_drop_index_on_partition` case 11 (new), run locally against a
    shared-nothing docker cluster: with the master FE it fails with `Expect
    exception msg contains 'DROP INDEX ON PARTITION is not supported for
    index idx_v on VARIANT column v', but meet 'null'`; with the fixed FE
    both statements fail with the new message and the whole suite passes.
    - `test_variant_values_index_rejected_state` S9 (updated): it now
    expects both partition drops to be rejected, checks that the table and
    job state do not change, and queries p1 with
    `enable_match_without_inverted_index=false`, so p1 must keep the index.
    Its `.out` file does not change. With the fixed FE, the old S9 failed as
    on CI (`DROP INDEX ON PARTITION is not supported for index path_idx on
    VARIANT column v`), and the updated suite passes on the same
    shared-nothing docker cluster.
    - The reproduction above ran on a shared-nothing docker cluster built
    from master of 2026-11-25.
---
 .../apache/doris/alter/SchemaChangeHandler.java    |  9 +++++++
 .../doris/alter/SchemaChangeHandlerTest.java       | 26 +++++++++++++++++++
 .../test_drop_index_on_partition.groovy            | 30 ++++++++++++++++++++++
 ...test_variant_values_index_rejected_state.groovy | 25 +++++++++---------
 4 files changed, 78 insertions(+), 12 deletions(-)

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 9fa871636d0..e953b6fc01e 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
@@ -2664,6 +2664,15 @@ public class SchemaChangeHandler extends AlterHandler {
                             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");
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 9c9650432e9..5a0fde5c589 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
@@ -265,6 +265,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 : List.of("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());
+    }
+
     @Test
     public void testWithChangelogSchemaChangeNoHistoricalValue() throws 
Exception {
         String tableName = "changelog_no_hist";
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 9d9e534e8d9..923d66f7161 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
@@ -301,4 +301,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"))
 }
diff --git 
a/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_rejected_state.groovy
 
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_rejected_state.groovy
index c6ff5eea0bd..0edba67f0b9 100644
--- 
a/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_rejected_state.groovy
+++ 
b/regression-test/suites/variant_p0/v2/with_index/test_variant_values_index_rejected_state.groovy
@@ -69,7 +69,8 @@ suite("test_variant_values_index_rejected_state", 
"p0,nonConcurrent") {
         quickTest("rejected_${i}_template", "SELECT id FROM vvi_rejected_state 
WHERE v['tagA'] MATCH_ANY 'alpha' ORDER BY id", true)
     }
     qt_final_values "SELECT id,aux,v FROM vvi_rejected_state ORDER BY id"
-    // S9: partition DROP keeps the table binding; it only rewrites the chosen 
partition.
+    // S9: every partition keeps the table's indexes. Cloud mode cannot move a 
partition off SNII, and
+    // DROP INDEX ON PARTITION is rejected for path and field_pattern indexes 
on VARIANT.
     if (isCloudMode()) {
         for (String format : ["V2","V3"]) {
             def before = state()
@@ -82,23 +83,23 @@ suite("test_variant_values_index_rejected_state", 
"p0,nonConcurrent") {
     }
     sql "ALTER TABLE vvi_rejected_state ADD PARTITION p2 VALUES LESS THAN(200)"
     sql """INSERT INTO vvi_rejected_state 
VALUES(101,101,parse_to_variant('{"s":"hello world","tagB":"beta"}'))"""
-    def retainedDDL = sql("SHOW CREATE TABLE vvi_rejected_state")
-    def retainedIndexes = sql("SHOW INDEX FROM vvi_rejected_state")
     for (String index : ["path_idx","tag_idx"]) {
-        def beforeJobs = sql_return_maparray("SHOW BUILD INDEX WHERE 
TableName='vvi_rejected_state'")
-        sql "DROP INDEX ${index} ON vvi_rejected_state PARTITION(p1)"
-        wait_for_last_build_index_finish("vvi_rejected_state",180000)
-        def jobs = sql_return_maparray("SHOW BUILD INDEX WHERE 
TableName='vvi_rejected_state'")
-        assertTrue(jobs.size() > beforeJobs.size())
-        assertEquals(retainedDDL,sql("SHOW CREATE TABLE vvi_rejected_state"))
-        assertEquals(retainedIndexes,sql("SHOW INDEX FROM vvi_rejected_state"))
+        // Cloud mode rejects every partition drop, with its own message.
+        String expected = isCloudMode() ? "DROP INDEX ON PARTITION is not 
supported"
+                : "DROP INDEX ON PARTITION is not supported for index ${index} 
on VARIANT column v"
+        def before = state()
+        test {
+            sql "DROP INDEX ${index} ON vvi_rejected_state PARTITION(p1)"
+            exception expected
+        }
+        assertEquals(before,state())
         quickTest("${index}_partition_root", "SELECT id FROM 
vvi_rejected_state WHERE v MATCH_ALL 'hello world' ORDER BY id", true)
         quickTest("${index}_other_partition_path", "SELECT id FROM 
vvi_rejected_state PARTITION(p2) WHERE v['s'] MATCH_PHRASE 'hello world' ORDER 
BY id", true)
         quickTest("${index}_other_partition_template", "SELECT id FROM 
vvi_rejected_state PARTITION(p2) WHERE v['tagB'] MATCH_ANY 'beta' ORDER BY id", 
true)
-        sql "SET enable_match_without_inverted_index=true"
+        // p1 is the partition named in the rejected DROP. 
enable_match_without_inverted_index stays false,
+        // so these MATCHes need p1 to keep the index.
         quickTest("${index}_dropped_partition_path", "SELECT id FROM 
vvi_rejected_state PARTITION(p1) WHERE v['s'] MATCH_ANY 'hello' ORDER BY id", 
true)
         quickTest("${index}_dropped_partition_template", "SELECT id FROM 
vvi_rejected_state PARTITION(p1) WHERE v['tagA'] MATCH_ANY 'alpha' ORDER BY 
id", true)
-        sql "SET enable_match_without_inverted_index=false"
     }
 
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to