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

   ### Background
   
   A heavy schema change on BE either rewrites every row into new segments 
("directly") or, when only metadata differs, links the old segment files into 
the new tablet ("linked"). `SchemaChangeJob::parse_request` picks linked unless 
a column needs an expression, a delete predicate exists, the row store changes, 
a rowset is remote, or `variant_util::has_schema_index_diff` reports an index 
difference on a column. Index files are written when a segment is written, so a 
linked segment keeps exactly the indexes it had.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: #54276 (added ANN indexes), #71130 (rejects the affected BUILD 
IMMEDIATE cases until this lands)
   PR Type: Bugfix
   
   Problem Summary:
   
   `has_schema_index_diff` compares bloom filter flags and inverted indexes 
only. When a heavy schema change adds an ANN index and nothing else forces a 
rewrite, for example `ALTER TABLE t ADD COLUMN x INT, ADD INDEX idx_ann 
(embedding) USING ANN ...` with `enable_light_index_change = false`, BE links 
the old segments: the job finishes and the new tablet schema lists the ANN 
index, but the existing segments have no ANN index file. ANN queries on that 
data fall back to brute force, and a later `BUILD INDEX` skips those rowsets 
because their schema already lists the index. This PR makes 
`has_schema_index_diff` also report an added, dropped or changed ANN index, so 
such a schema change rewrites the segments.
   
   ### Details
   
   - **Frequency:** Always, for a local (shared-nothing) heavy schema change 
whose only index change is an ANN index and whose rowsets are all local, 
without delete predicates or column conversions. Light index changes and `BUILD 
INDEX` are not affected. Not observed in production; found by code review of 
#71130.
   - **Root cause:** `variant_util::has_schema_index_diff` compares 
`is_bf_column` and `TabletSchema::inverted_indexs` of the old and new column, 
but not `TabletSchema::ann_index`, so `SchemaChangeJob::parse_request` treats 
an ANN index change as metadata-only and chooses the linked schema change.
   - **Why existing tests missed it:** BE unit tests: 
`SchemaUtilTest.TestHasSchemaIndexDiff` covers only a bloom filter and inverted 
index difference; no test compares ANN indexes. Regression suites: 
`ann_index_p0` adds ANN indexes at table creation or with light ADD INDEX plus 
`BUILD INDEX`, never through a heavy schema change, and its build tests check 
that jobs finish, not that existing data uses the index.
   - **Fix:** compare the ANN index of the two columns the same way as inverted 
indexes (`ann_index` and `is_same_except_id`), so adding, dropping or changing 
one forces a rewrite. `parse_request` is the only caller of the comparison, so 
every heavy schema change that touches an ANN index rewrites the segments.
   - **Behavior change:** a heavy schema change that adds, drops or changes an 
ANN index rewrites the segments instead of linking them, so it takes as long as 
other rewriting schema changes and the result has the ANN index for existing 
data.
   - **Other paths and branches:** cloud mode rewrites anyway because cloud 
rowsets are remote. The same comparison without ANN is on branch-4.0 
(`be/src/vec/common/schema_util.cpp`), branch-4.1 and branch-4.2 
(`be/src/exec/common/variant_util.cpp`); branch-3.1 has no ANN index.
   
   ### Testing
   
   - New BE UT `SchemaUtilTest.TestHasSchemaIndexDiffAnnIndex`: adding, 
dropping and changing (metric type) an ANN index must count as an index 
difference, and identical schemas must not. Without the fix it fails on the 
three difference cases (`has_schema_index_diff` returns false); with the fix it 
passes.
   - `run-be-ut.sh --filter='SchemaUtilTest.*:*SchemaChange*'`: 63 tests pass 
locally.
   - `build-support/check-format.sh` passes; clang-tidy reports nothing on the 
changed lines.
   
   ### Release note
   
   A schema change that adds an ANN index through the heavy schema change path 
now builds the index for existing data instead of leaving it unindexed.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: No
   - Pre-submission status: Ready
   
   ### AI Disclosure
   
   - Tool: Claude Code (Claude Opus 5.5)
   - Generated: code, test, this description
   - Human review: pending author review
   


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