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 6a1da3db536 [fix](fe) Reject BUILD INDEX and DROP INDEX ... PARTITION 
when light index change is disabled (#71128)
6a1da3db536 is described below

commit 6a1da3db536dc2b2a4b0e6ed5b18952c9182fda1
Author: Jack <[email protected]>
AuthorDate: Wed Dec 2 09:07:35 2026 +0800

    [fix](fe) Reject BUILD INDEX and DROP INDEX ... PARTITION when light index 
change is disabled (#71128)
    
    ### Background
    
    `BUILD INDEX idx ON t [PARTITION (...)]` builds an index for data
    written before the index was added, and `ALTER TABLE t DROP INDEX idx
    PARTITION (...)` deletes the index files of some partitions. Both
    statements run only as index change jobs: `SchemaChangeHandler.process`
    hands them to `buildOrDeleteTableInvertedIndices`, which creates one
    `IndexChangeJob` per partition. The master-only FE config
    `enable_light_index_change` (default `true`) switches the light index
    change machinery on and off.
    
    ### What problem does this PR solve?
    
    Issue Number: None
    Related PR: #32143 (introduced the silent branch)
    PR Type: Bugfix
    
    Problem Summary:
    
    With `enable_light_index_change = false`, `BUILD INDEX` and `DROP INDEX
    ... PARTITION` return OK but create no index change job, so nothing is
    built or dropped and the user gets no sign of it. This PR makes both
    statements fail with an error that names the config.
    
    ```sql
    ADMIN SET FRONTEND CONFIG ("enable_light_index_change" = "false");
    BUILD INDEX idx_v1 ON t;
    -- before: Query OK, no job in SHOW BUILD INDEX, nothing built
    -- after:  ERROR ... BUILD INDEX and DROP INDEX ... PARTITION require 
enable_light_index_change=true
    ```
    
    ### Details
    
    - **Frequency:** Always, when `enable_light_index_change` is `false` and
    a user runs `BUILD INDEX` or `DROP INDEX ... PARTITION`. The config
    defaults to `true`, so only clusters that turned it off are affected.
    - **Root cause:** in `SchemaChangeHandler.process`, the
    `buildIndexChange` branch calls `buildOrDeleteTableInvertedIndices` only
    inside `if (Config.enable_light_index_change)` and has no else branch.
    When the config is off, the statement falls through and returns
    normally.
    - **Why existing tests missed it:** FE unit tests:
    `SchemaChangeHandlerTest`, `IndexChangeJobTest` and `CloudIndexTest` run
    `BUILD INDEX` and `DROP INDEX ... PARTITION` only with the config at its
    default `true`; the only test that turns it off
    (`VariantValuesIndexChangeTest`) checks ADD of a VARIANT values index.
    Regression suites: the `inverted_index_p0/index_change` and
    `cloud_build_index` suites never change this FE config.
    - **Fix:** reject the statement in the same branch with a `DdlException`
    when the config is off. `BuildIndexOp` and a partition scoped `DROP
    INDEX` change no table metadata before this point, and a partition
    scoped `DROP INDEX` must be the only clause of its statement, so a
    rejected statement leaves the table unchanged.
    - **Behavior change:** with `enable_light_index_change = false`, `BUILD
    INDEX` and `DROP INDEX ... PARTITION` return an error instead of OK.
    Nothing changes while the config is `true`, its default.
    - **Other paths and branches:** the other users of the config already
    fall back correctly: ADD INDEX and full-table DROP INDEX take the heavy
    schema change path when it is off, and the light DROP INDEX pre-check
    returns early. The same silent branch is on branch-3.1, branch-4.0,
    branch-4.1 and branch-4.2; on branch-4.1 and later it also covers `DROP
    INDEX ... PARTITION`, which #62181 added.
    
    ### Testing
    
    - New FE UT
    
`SchemaChangeHandlerTest#testIndexJobStatementsRejectedWhenLightIndexChangeDisabled`:
    with the config off, `BUILD INDEX`, `BUILD INDEX ... PARTITION` and
    `DROP INDEX ... PARTITION` must throw, and no index change job is
    created. Without the fix it fails with `Expected java.lang.Exception to
    be thrown, but nothing was thrown` on `BUILD INDEX`; with the fix it
    passes.
    - `SchemaChangeHandlerTest`, `IndexChangeJobTest`, `CloudIndexTest` and
    `VariantValuesIndexChangeTest`: 86 tests, all pass locally.
    - `build.sh --fe`: build succeeds with 0 checkstyle violations.
---
 .../apache/doris/alter/SchemaChangeHandler.java    |  9 ++++--
 .../doris/alter/SchemaChangeHandlerTest.java       | 35 ++++++++++++++++++++++
 2 files changed, 41 insertions(+), 3 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 e953b6fc01e..98fe43598c2 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
@@ -2753,10 +2753,13 @@ public class SchemaChangeHandler extends AlterHandler {
                 if (alterIndexes.isEmpty()) {
                     throw new DdlException("Altered index is empty. please 
check your alter stmt.");
                 }
-                if (Config.enable_light_index_change) {
-                    buildOrDeleteTableInvertedIndices(db, olapTable, 
indexSchemaMap,
-                            alterIndexes, indexOnPartitions, isDropIndex);
+                // BUILD INDEX and DROP INDEX ... PARTITION run only as index 
change jobs.
+                if (!Config.enable_light_index_change) {
+                    throw new DdlException("BUILD INDEX and DROP INDEX ... 
PARTITION require"
+                            + " enable_light_index_change=true");
                 }
+                buildOrDeleteTableInvertedIndices(db, olapTable, 
indexSchemaMap,
+                        alterIndexes, indexOnPartitions, isDropIndex);
             } else {
                 createJob(rawSql, db.getId(), olapTable, indexSchemaMap, 
propertyMap, newIndexes, sequenceMapping);
             }
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 5a0fde5c589..c0ab10671d9 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
@@ -1592,6 +1592,41 @@ public class SchemaChangeHandlerTest extends 
TestWithFeService {
                 
tbl.getIndexes().stream().map(Index::getIndexName).collect(Collectors.toList()));
     }
 
+    @Test
+    public void testIndexJobStatementsRejectedWhenLightIndexChangeDisabled() 
throws Exception {
+        String tableName = "sc_index_job_light_change_off";
+        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');");
+
+        SchemaChangeHandler handler = 
Env.getCurrentEnv().getSchemaChangeHandler();
+        int indexChangeJobCount = handler.getIndexChangeJobs().size();
+        boolean enableLightIndexChange = Config.enable_light_index_change;
+        Config.enable_light_index_change = false;
+        try {
+            // These statements only run as index change jobs, so they must 
fail instead of returning OK.
+            for (String sql : Lists.newArrayList(
+                    "BUILD INDEX idx_v1 ON test." + tableName,
+                    "BUILD INDEX idx_v1 ON test." + tableName + " PARTITION 
(p1)",
+                    "ALTER TABLE test." + tableName + " DROP INDEX idx_v1 
PARTITION (p1)")) {
+                Exception e = Assertions.assertThrows(Exception.class, () -> 
executeNereidsSql(sql), sql);
+                Assertions.assertTrue(e.getMessage().contains("require 
enable_light_index_change=true"),
+                        e.getMessage());
+            }
+        } finally {
+            Config.enable_light_index_change = enableLightIndexChange;
+        }
+        Assertions.assertEquals(indexChangeJobCount, 
handler.getIndexChangeJobs().size());
+    }
+
     @Test
     public void testLightIndexChangeWithHeavyWorkRunsHeavySchemaChange() 
throws Exception {
         String tableName = "sc_light_index_with_heavy_work";


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

Reply via email to