#include "StorageSystemParts.h" #include #include #include #include #include #include #include #include #include #include #include #include namespace DB { StorageSystemParts::StorageSystemParts(const StorageID & table_id_) : StorageSystemPartsBase(table_id_, { {"partition", std::make_shared()}, {"name", std::make_shared()}, {"uuid", std::make_shared()}, {"part_type", std::make_shared()}, {"active", std::make_shared()}, {"marks", std::make_shared()}, {"rows", std::make_shared()}, {"bytes_on_disk", std::make_shared()}, {"data_compressed_bytes", std::make_shared()}, {"data_uncompressed_bytes", std::make_shared()}, {"marks_bytes", std::make_shared()}, {"modification_time", std::make_shared()}, {"remove_time", std::make_shared()}, {"refcount", std::make_shared()}, {"min_date", std::make_shared()}, {"max_date", std::make_shared()}, {"min_time", std::make_shared()}, {"max_time", std::make_shared()}, {"partition_id", std::make_shared()}, {"min_block_number", std::make_shared()}, {"max_block_number", std::make_shared()}, {"level", std::make_shared()}, {"data_version", std::make_shared()}, {"primary_key_bytes_in_memory", std::make_shared()}, {"primary_key_bytes_in_memory_allocated", std::make_shared()}, {"is_frozen", std::make_shared()}, {"database", std::make_shared()}, {"table", std::make_shared()}, {"engine", std::make_shared()}, {"disk_name", std::make_shared()}, {"path", std::make_shared()}, {"hash_of_all_files", std::make_shared()}, {"hash_of_uncompressed_files", std::make_shared()}, {"uncompressed_hash_of_compressed_files", std::make_shared()}, {"delete_ttl_info_min", std::make_shared()}, {"delete_ttl_info_max", std::make_shared()}, {"move_ttl_info.expression", std::make_shared(std::make_shared())}, {"move_ttl_info.min", std::make_shared(std::make_shared())}, {"move_ttl_info.max", std::make_shared(std::make_shared())}, {"default_compression_codec", std::make_shared()}, {"recompression_ttl_info.expression", std::make_shared(std::make_shared())}, {"recompression_ttl_info.min", std::make_shared(std::make_shared())}, {"recompression_ttl_info.max", std::make_shared(std::make_shared())}, {"group_by_ttl_info.expression", std::make_shared(std::make_shared())}, {"group_by_ttl_info.min", std::make_shared(std::make_shared())}, {"group_by_ttl_info.max", std::make_shared(std::make_shared())} } ) { } void StorageSystemParts::processNextStorage(MutableColumns & columns_, const StoragesInfo & info, bool has_state_column) { using State = IMergeTreeDataPart::State; MergeTreeData::DataPartStateVector all_parts_state; MergeTreeData::DataPartsVector all_parts; all_parts = info.getParts(all_parts_state, has_state_column); for (size_t part_number = 0; part_number < all_parts.size(); ++part_number) { const auto & part = all_parts[part_number]; auto part_state = all_parts_state[part_number]; ColumnSize columns_size = part->getTotalColumnsSize(); size_t i = 0; { WriteBufferFromOwnString out; part->partition.serializeText(*info.data, out, format_settings); columns_[i++]->insert(out.str()); } columns_[i++]->insert(part->name); columns_[i++]->insert(part->uuid); columns_[i++]->insert(part->getTypeName()); columns_[i++]->insert(part_state == State::Committed); columns_[i++]->insert(part->getMarksCount()); columns_[i++]->insert(part->rows_count); columns_[i++]->insert(part->getBytesOnDisk()); columns_[i++]->insert(columns_size.data_compressed); columns_[i++]->insert(columns_size.data_uncompressed); columns_[i++]->insert(columns_size.marks); columns_[i++]->insert(static_cast(part->modification_time)); time_t remove_time = part->remove_time.load(std::memory_order_relaxed); columns_[i++]->insert(static_cast(remove_time == std::numeric_limits::max() ? 0 : remove_time)); /// For convenience, in returned refcount, don't add references that was due to local variables in this method: all_parts, active_parts. columns_[i++]->insert(static_cast(part.use_count() - 1)); columns_[i++]->insert(part->getMinDate()); columns_[i++]->insert(part->getMaxDate()); columns_[i++]->insert(static_cast(part->getMinTime())); columns_[i++]->insert(static_cast(part->getMaxTime())); columns_[i++]->insert(part->info.partition_id); columns_[i++]->insert(part->info.min_block); columns_[i++]->insert(part->info.max_block); columns_[i++]->insert(part->info.level); columns_[i++]->insert(static_cast(part->info.getDataVersion())); columns_[i++]->insert(part->getIndexSizeInBytes()); columns_[i++]->insert(part->getIndexSizeInAllocatedBytes()); columns_[i++]->insert(part->is_frozen.load(std::memory_order_relaxed)); columns_[i++]->insert(info.database); columns_[i++]->insert(info.table); columns_[i++]->insert(info.engine); if (part->isStoredOnDisk()) { columns_[i++]->insert(part->volume->getDisk()->getName()); columns_[i++]->insert(part->getFullPath()); } else { columns_[i++]->insertDefault(); columns_[i++]->insertDefault(); } MinimalisticDataPartChecksums helper; helper.computeTotalChecksums(part->checksums); auto checksum = helper.hash_of_all_files; columns_[i++]->insert(getHexUIntLowercase(checksum.first) + getHexUIntLowercase(checksum.second)); checksum = helper.hash_of_uncompressed_files; columns_[i++]->insert(getHexUIntLowercase(checksum.first) + getHexUIntLowercase(checksum.second)); checksum = helper.uncompressed_hash_of_compressed_files; columns_[i++]->insert(getHexUIntLowercase(checksum.first) + getHexUIntLowercase(checksum.second)); /// delete_ttl_info { columns_[i++]->insert(static_cast(part->ttl_infos.table_ttl.min)); columns_[i++]->insert(static_cast(part->ttl_infos.table_ttl.max)); } auto add_ttl_info_map = [&](const TTLInfoMap & ttl_info_map) { Array expression_array; Array min_array; Array max_array; expression_array.reserve(ttl_info_map.size()); min_array.reserve(ttl_info_map.size()); max_array.reserve(ttl_info_map.size()); for (const auto & [expression, ttl_info] : ttl_info_map) { expression_array.emplace_back(expression); min_array.push_back(static_cast(ttl_info.min)); max_array.push_back(static_cast(ttl_info.max)); } columns_[i++]->insert(expression_array); columns_[i++]->insert(min_array); columns_[i++]->insert(max_array); }; add_ttl_info_map(part->ttl_infos.moves_ttl); columns_[i++]->insert(queryToString(part->default_codec->getCodecDesc())); add_ttl_info_map(part->ttl_infos.recompression_ttl); add_ttl_info_map(part->ttl_infos.group_by_ttl); /// _state column should be the latest. if (has_state_column) columns_[i++]->insert(part->stateString()); } } }