slightly better

This commit is contained in:
Anton Popov 2024-07-01 15:31:32 +00:00
parent db0beabb1c
commit e439921d37
3 changed files with 10 additions and 1 deletions

View File

@ -375,6 +375,12 @@ void IMergeTreeDataPart::unloadIndex()
index_loaded = false;
}
bool IMergeTreeDataPart::isIndexLoaded() const
{
std::scoped_lock lock(index_mutex);
return index_loaded;
}
void IMergeTreeDataPart::setName(const String & new_name)
{
mutable_name = new_name;

View File

@ -369,6 +369,7 @@ public:
void setIndex(const Columns & cols_);
void setIndex(Columns && cols_);
void unloadIndex();
bool isIndexLoaded() const;
/// For data in RAM ('index')
UInt64 getIndexSizeInBytes() const;

View File

@ -8622,7 +8622,9 @@ size_t MergeTreeData::unloadPrimaryKeysOfOutdatedParts()
for (const auto & part : parts_range)
{
/// Outdated part may be hold by SELECT query and still needs the index.
if (part.unique())
/// This check requires lock of index_mutex but if outdated part is unique then there is no
/// contention on it, so it's relatively cheap and it's ok to check under a global parts lock.
if (part.unique() && part->isIndexLoaded())
parts_to_unload_index.push_back(part);
}
}