diff --git a/be/src/olap/compaction.cpp b/be/src/olap/compaction.cpp index 4e9297983a5185..7e349609eefbef 100644 --- a/be/src/olap/compaction.cpp +++ b/be/src/olap/compaction.cpp @@ -427,6 +427,21 @@ bool CompactionMixin::handle_ordered_data_compaction() { return false; } + // Skip ordered data compaction if any rowset has inverted/ann index. + for (auto& rowset : _input_rowsets) { + const auto& meta = rowset->rowset_meta(); + const auto& schema = meta->tablet_schema(); + if (!schema) { + // RowsetMeta should always carry a valid schema in production, but unit tests and + // some auxiliary paths may build rowsets with an empty schema. Ordered data compaction + // must be conservative here to avoid undefined behavior. + return false; + } + if (schema->has_inverted_index() || schema->has_ann_index()) { + return false; + } + } + // If some rowsets has idx files and some rowsets has not, we can not do link file compaction. // Since the output rowset will be broken.