zhiqiang-hhhh commented on code in PR #59827:
URL: https://github.com/apache/doris/pull/59827#discussion_r2761952365


##########
be/src/olap/tablet.cpp:
##########
@@ -1298,11 +1302,134 @@ std::vector<RowsetSharedPtr> 
Tablet::pick_candidate_rowsets_to_build_inverted_in
             return false;
         };
 
+        // Check if the specified indexes are actually built (exist in files)
+        // Returns true only if ALL required indexes exist in files for ALL 
segments
+        auto are_indexes_built_in_files = [&](const RowsetSharedPtr& rowset) 
-> bool {
+            const auto& tablet_schema = rowset->tablet_schema();
+            auto storage_format = 
tablet_schema->get_inverted_index_storage_format();
+
+            // Collect index metadata that needs to be checked
+            std::vector<const TabletIndex*> indexes_to_check;
+            for (const auto& index : tablet_schema->indexes()) {
+                if ((index->index_type() == IndexType::INVERTED ||
+                     index->index_type() == IndexType::ANN) &&
+                    alter_index_uids.count(index->index_id()) > 0) {
+                    indexes_to_check.push_back(index.get());
+                }
+            }
+
+            if (indexes_to_check.empty()) {
+                return false;
+            }
+
+            // Check each segment
+            for (int seg_id = 0; seg_id < rowset->num_segments(); seg_id++) {
+                auto idx_file_info = 
rowset->rowset_meta()->inverted_index_file_info(seg_id);
+
+                // === Fast path: V2+ format check index_size in metadata 
without opening file ===
+                if (storage_format >= InvertedIndexStorageFormatPB::V2) {
+                    if (!idx_file_info.has_index_size() || 
idx_file_info.index_size() == 0) {

Review Comment:
   可能需要检查每个index而不是直接看idx文件的size。Ann 索引在某个 segment 上可能会不构建索引



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