diff --git a/dbms/src/Storages/System/StorageSystemParts.cpp b/dbms/src/Storages/System/StorageSystemParts.cpp index 903e3882345..7beb39ff57a 100644 --- a/dbms/src/Storages/System/StorageSystemParts.cpp +++ b/dbms/src/Storages/System/StorageSystemParts.cpp @@ -242,17 +242,7 @@ BlockInputStreams StorageSystemParts::read( block.getByPosition(i++).column->insert(part->name); block.getByPosition(i++).column->insert(static_cast(part_state == State::Committed)); block.getByPosition(i++).column->insert(static_cast(part->marks_count)); - - size_t marks_size = 0; - for (const NameAndTypePair & it : part->columns) - { - String name = escapeForFileName(it.name); - auto checksum = part->checksums.files.find(name + ".mrk"); - if (checksum != part->checksums.files.end()) - marks_size += checksum->second.file_size; - } - block.getByPosition(i++).column->insert(static_cast(marks_size)); - + block.getByPosition(i++).column->insert(static_cast(part->getTotalMrkSizeInBytes())); block.getByPosition(i++).column->insert(static_cast(part->rows_count)); block.getByPosition(i++).column->insert(static_cast(part->size_in_bytes)); block.getByPosition(i++).column->insert(static_cast(part->modification_time)); diff --git a/dbms/src/Storages/System/StorageSystemPartsColumns.cpp b/dbms/src/Storages/System/StorageSystemPartsColumns.cpp index d246116465c..ec81ff3a2e4 100644 --- a/dbms/src/Storages/System/StorageSystemPartsColumns.cpp +++ b/dbms/src/Storages/System/StorageSystemPartsColumns.cpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace DB { @@ -23,7 +24,7 @@ StorageSystemPartsColumns::StorageSystemPartsColumns(const std::string & name_) {"name", std::make_shared()}, {"active", std::make_shared()}, {"marks", std::make_shared()}, - {"marks_size", std::make_shared()}, + {"marks_bytes_in_block", std::make_shared()}, {"rows", std::make_shared()}, {"bytes", std::make_shared()}, {"modification_time", std::make_shared()}, @@ -39,7 +40,14 @@ StorageSystemPartsColumns::StorageSystemPartsColumns(const std::string & name_) {"database", std::make_shared()}, {"table", std::make_shared()}, - {"engine", std::make_shared()} + {"engine", std::make_shared()}, + {"column", std::make_shared()}, + { "type", std::make_shared() }, + { "default_kind", std::make_shared() }, + { "default_expression", std::make_shared() }, + { "data_compressed_bytes", std::make_shared() }, + { "data_uncompressed_bytes", std::make_shared() }, + { "marks_bytes_in_column", std::make_shared() }, } { } @@ -96,6 +104,7 @@ BlockInputStreams StorageSystemPartsColumns::read( database_column = block_to_filter.getByName("database").column; size_t rows = database_column->size(); + IColumn::Offsets_t offsets(rows); ColumnPtr table_column = std::make_shared(); ColumnPtr engine_column = std::make_shared(); ColumnPtr active_column = std::make_shared(); @@ -105,6 +114,7 @@ BlockInputStreams StorageSystemPartsColumns::read( String database_name = (*database_column)[i].get(); const DatabasePtr database = databases.at(database_name); + offsets[i] = i ? offsets[i - 1] : 0; for (auto iterator = database->getIterator(context); iterator->isValid(); iterator->next()) { String table_name = iterator->name(); @@ -118,15 +128,23 @@ BlockInputStreams StorageSystemPartsColumns::read( storages[std::make_pair(database_name, iterator->name())] = storage; /// Add all combinations of flag 'active'. - for (auto active : {0, 1}) + for (UInt64 active : {0, 1}) { table_column->insert(table_name); engine_column->insert(engine_name); active_column->insert(active); } + + offsets[i] += 2; } } + for (size_t i = 0; i < block_to_filter.columns(); ++i) + { + ColumnPtr & column = block_to_filter.safeGetByPosition(i).column; + column = column->replicate(offsets); + } + block_to_filter.insert(ColumnWithTypeAndName(table_column, std::make_shared(), "table")); block_to_filter.insert(ColumnWithTypeAndName(engine_column, std::make_shared(), "engine")); block_to_filter.insert(ColumnWithTypeAndName(active_column, std::make_shared(), "active")); @@ -216,6 +234,30 @@ BlockInputStreams StorageSystemPartsColumns::read( else all_parts = data->getDataPartsVector({State::Committed}, &all_parts_state); + struct ColumnInfo + { + String default_kind; + String default_expression; + }; + + NamesAndTypesList columns = storage->getColumnsList(); + columns.insert(std::end(columns), std::begin(storage->alias_columns), std::end(storage->alias_columns)); + column_defaults = storage->column_defaults; + std::unordered_map columns_info; + + for (const auto & column : columns) + { + ColumnInfo column_info; + + const auto it = column_defaults.find(column.name); + if (it != std::end(column_defaults)) + { + column_info.default_kind = toString(it->second.type); + column_info.default_expression = queryToString(it->second.expression); + } + + columns_info[column.name] = column_info; + } /// Finally, we'll go through the list of parts. for (size_t part_number = 0; part_number < all_parts.size(); ++part_number) @@ -223,39 +265,67 @@ BlockInputStreams StorageSystemPartsColumns::read( const auto & part = all_parts[part_number]; auto part_state = all_parts_state[part_number]; - size_t j = 0; - { - WriteBufferFromOwnString out; - part->partition.serializeTextQuoted(*data, out); - block.getByPosition(j++).column->insert(out.str()); - } - block.getByPosition(j++).column->insert(part->name); - block.getByPosition(j++).column->insert(static_cast(part_state == State::Committed)); - block.getByPosition(j++).column->insert(static_cast(part->marks_count)); - block.getByPosition(j++).column->insert(static_cast(part->getTotalMrkSizeInBytes())); - - block.getByPosition(j++).column->insert(static_cast(part->rows_count)); - block.getByPosition(j++).column->insert(static_cast(part->size_in_bytes)); - block.getByPosition(j++).column->insert(static_cast(part->modification_time)); - block.getByPosition(j++).column->insert(static_cast(part->remove_time)); - + auto total_mrk_size_in_bytes = part->getTotalMrkSizeInBytes(); /// For convenience, in returned refcount, don't add references that was due to local variables in this method: all_parts, active_parts. - block.getByPosition(j++).column->insert(static_cast(part.use_count() - 1)); + auto use_count = part.use_count() - 1; + auto min_date = part->getMinDate(); + auto max_date = part->getMaxDate(); + auto index_size_in_bytes = part->getIndexSizeInBytes(); + auto index_size_in_allocated_bytes = part->getIndexSizeInAllocatedBytes(); - block.getByPosition(j++).column->insert(static_cast(part->getMinDate())); - block.getByPosition(j++).column->insert(static_cast(part->getMaxDate())); - block.getByPosition(j++).column->insert(part->info.min_block); - block.getByPosition(j++).column->insert(part->info.max_block); - block.getByPosition(j++).column->insert(static_cast(part->info.level)); - block.getByPosition(j++).column->insert(static_cast(part->getIndexSizeInBytes())); - block.getByPosition(j++).column->insert(static_cast(part->getIndexSizeInAllocatedBytes())); + for (const auto & column : part->columns) + { + size_t j = 0; + { + WriteBufferFromOwnString out; + part->partition.serializeTextQuoted(*data, out); + block.getByPosition(j++).column->insert(out.str()); + } + block.getByPosition(j++).column->insert(part->name); + block.getByPosition(j++).column->insert(static_cast(part_state == State::Committed)); + block.getByPosition(j++).column->insert(static_cast(part->marks_count)); + block.getByPosition(j++).column->insert(static_cast(total_mrk_size_in_bytes)); - block.getByPosition(j++).column->insert(database); - block.getByPosition(j++).column->insert(table); - block.getByPosition(j++).column->insert(engine); + block.getByPosition(j++).column->insert(static_cast(part->rows_count)); + block.getByPosition(j++).column->insert(static_cast(part->size_in_bytes)); + block.getByPosition(j++).column->insert(static_cast(part->modification_time)); + block.getByPosition(j++).column->insert(static_cast(part->remove_time)); - if (has_state_column) - block.getByPosition(j++).column->insert(part->stateString()); + block.getByPosition(j++).column->insert(static_cast(use_count)); + + block.getByPosition(j++).column->insert(static_cast(min_date)); + block.getByPosition(j++).column->insert(static_cast(max_date)); + block.getByPosition(j++).column->insert(part->info.min_block); + block.getByPosition(j++).column->insert(part->info.max_block); + block.getByPosition(j++).column->insert(static_cast(part->info.level)); + block.getByPosition(j++).column->insert(static_cast(index_size_in_bytes)); + block.getByPosition(j++).column->insert(static_cast(index_size_in_allocated_bytes)); + + block.getByPosition(j++).column->insert(database); + block.getByPosition(j++).column->insert(table); + block.getByPosition(j++).column->insert(engine); + block.getByPosition(j++).column->insert(column.name); + block.getByPosition(j++).column->insert(column.type->getName()); + + auto column_info_it = columns_info.find(column.name); + if (column_info_it != columns_info.end()) + { + block.getByPosition(j++).column->insert(column_info_it->second.default_kind); + block.getByPosition(j++).column->insert(column_info_it->second.default_expression); + } + else + { + block.getByPosition(j++).column->insertDefault(); + block.getByPosition(j++).column->insertDefault(); + } + + block.getByPosition(j++).column->insert(part->getColumnCompressedSize(column.name)); + block.getByPosition(j++).column->insert(part->getColumnUncompressedSize(column.name)); + block.getByPosition(j++).column->insert(part->getColumnMrkSize(column.name)); + + if (has_state_column) + block.getByPosition(j++).column->insert(part->stateString()); + } } }