airborne12 opened a new pull request, #69442:
URL: https://github.com/apache/doris/pull/69442

   ### What problem does this PR solve?
   
   Issue Number: None
   
   Related PR: #68674
   
   Problem Summary:
   
   `ALTER TABLE ... DROP INDEX idx PARTITION (p)` only submits partition scoped 
index jobs and keeps the index in the table metadata. When it is combined with 
other clauses in one statement, part of the statement is silently not executed 
or the index files are deleted on the wrong partitions:
   
   ```sql
   -- returns success, vi is still INT: the partition scoped index job path 
ignores every other clause
   ALTER TABLE t MODIFY COLUMN vi BIGINT NULL, DROP INDEX idx_v1 PARTITION (p1);
   -- returns success, x is not added
   ALTER TABLE t ADD COLUMN x INT, DROP INDEX idx_v1 PARTITION (p1);
   -- the full-table drop selects the light index path, which deletes idx_v1 on 
every partition
   -- while the table metadata still lists idx_v1
   ALTER TABLE t DROP INDEX idx_v1 PARTITION (p1), DROP INDEX idx_v2;
   -- the partitions of both clauses are merged and every job carries both 
indexes,
   -- so idx_v1 and idx_v2 are deleted on p1 and p2
   ALTER TABLE t DROP INDEX idx_v1 PARTITION (p1), DROP INDEX idx_v2 PARTITION 
(p2);
   ```
   
   Root cause: `SchemaChangeHandler#process` records a partition scoped drop 
with `buildIndexChange`, whose dispatch branch only calls 
`buildOrDeleteTableInvertedIndices` and ignores the other clauses; the light 
index path does not carry the partition targets; and 
`buildOrDeleteTableInvertedIndices` matches every partition of any clause and 
gives each job all altered indexes. `BUILD INDEX` is a standalone statement, so 
`DROP INDEX ... PARTITION` is the only way to mix partition scoped index jobs 
with other clauses.
   
   Fix: `process()` rejects a statement that contains `DROP INDEX ... 
PARTITION` together with any other clause, before any clause is processed, with 
`DROP INDEX on partitions can not be combined with other clauses in one ALTER 
statement, please run them in separate statements.` The check only looks at the 
clause types, so it runs before the clause loop and a rejected statement leaves 
the table unchanged. A partition scoped drop alone keeps its behavior.
   
   ### Release note
   
   `DROP INDEX ... PARTITION` combined with other clauses in one ALTER TABLE 
statement is now rejected instead of silently skipping the other clauses or 
dropping the index on the wrong partitions; run them in separate statements.
   
   ### Check List (For Author)
   
   - Test <!-- At least one of them must be included. -->
       - [ ] Regression test
       - [x] Unit Test
       - [ ] Manual test (add detailed scripts or steps below)
       - [ ] No need to test or manual test. Explain why:
           - [ ] This is a refactor/code format and no logic has been changed.
           - [ ] Previous test can cover this change.
           - [ ] No code files have been changed.
           - [ ] Other reason <!-- Add your reason?  -->
   
     `SchemaChangeHandlerTest#testDropIndexOnPartitionsMustBeTheOnlyClause` 
runs the four statements above, checks each is rejected and the column type, 
columns, index list, schema version and index change jobs are unchanged, then 
checks a partition scoped drop alone still submits its job. The test fails 
without the change.
   
   - Behavior changed:
       - [ ] No.
       - [x] Yes. <!-- Explain the behavior change -->
         `DROP INDEX ... PARTITION` has to be the only clause of its ALTER 
TABLE statement.
   
   - Does this need documentation?
       - [x] No.
       - [ ] Yes. <!-- Add document PR link here. eg: 
https://github.com/apache/doris-website/pull/1214 -->
   
   ### Check List (For Reviewer who merge this PR)
   
   - [ ] Confirm the release note
   - [ ] Confirm test cases
   - [ ] Confirm document
   - [ ] Add branch pick label <!-- Add branch pick label that this PR should 
merge into -->
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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]

Reply via email to