airborne12 opened a new pull request, #71041:
URL: https://github.com/apache/doris/pull/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.
   
   ### Release note
   
   In cloud mode, `DROP INDEX ... ON PARTITION` and `ALTER TABLE ... DROP INDEX 
... PARTITION` now fail with "DROP INDEX ON PARTITION is not supported in cloud 
mode". Before, they reported success but kept the index on the named 
partitions. Drop the index from the whole table instead.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: No. The DROP INDEX page in 
apache/doris-website does not document the ON PARTITION form; when it does, it 
should state the cloud-mode limitation.
   - Pre-submission status: Partially verified: the shared-nothing part of 
test_drop_index_on_partition was not rerun locally (unchanged by this PR; CI P0 
runs it)
   
   ### AI Disclosure
   
   - Tool: Claude Code (Claude Opus 5.5)
   - Generated: code, tests, this description
   - Human review: not stated
   - Prompts: The author asked the agent to watch #70352 and to check whether 
the review finding that a cloud partition drop finishes without deleting the 
index was reproduced; after the reproduction and an explanation of why cloud 
mode cannot drop an index per partition, the author chose to reject the 
statement in cloud mode on master first, and asked to add a cloud regression 
case for `BUILD INDEX ... PARTITION` in the same PR.
   


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