2019-05-31 04:03:46 +00:00
|
|
|
#include "StorageSystemPartsColumns.h"
|
|
|
|
|
2017-12-04 15:44:31 +00:00
|
|
|
#include <Common/escapeForFileName.h>
|
|
|
|
#include <Columns/ColumnString.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
|
|
|
#include <DataTypes/DataTypeDateTime.h>
|
|
|
|
#include <DataTypes/DataTypeDate.h>
|
|
|
|
#include <DataStreams/OneBlockInputStream.h>
|
|
|
|
#include <Storages/VirtualColumnUtils.h>
|
|
|
|
#include <Databases/IDatabase.h>
|
2017-12-04 15:53:18 +00:00
|
|
|
#include <Parsers/queryToString.h>
|
2017-12-04 15:44:31 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2019-08-03 11:02:40 +00:00
|
|
|
StorageSystemPartsColumns::StorageSystemPartsColumns(const std::string & name_)
|
|
|
|
: StorageSystemPartsBase(name_,
|
2018-03-26 14:18:04 +00:00
|
|
|
{
|
|
|
|
{"partition", std::make_shared<DataTypeString>()},
|
|
|
|
{"name", std::make_shared<DataTypeString>()},
|
2020-01-13 16:40:24 +00:00
|
|
|
{"part_type", std::make_shared<DataTypeString>()},
|
2018-03-26 14:18:04 +00:00
|
|
|
{"active", std::make_shared<DataTypeUInt8>()},
|
|
|
|
{"marks", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"rows", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"bytes_on_disk", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"data_compressed_bytes", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"data_uncompressed_bytes", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"marks_bytes", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"modification_time", std::make_shared<DataTypeDateTime>()},
|
|
|
|
{"remove_time", std::make_shared<DataTypeDateTime>()},
|
|
|
|
{"refcount", std::make_shared<DataTypeUInt32>()},
|
|
|
|
{"min_date", std::make_shared<DataTypeDate>()},
|
|
|
|
{"max_date", std::make_shared<DataTypeDate>()},
|
2018-06-13 15:47:40 +00:00
|
|
|
{"partition_id", std::make_shared<DataTypeString>()},
|
2018-03-26 14:18:04 +00:00
|
|
|
{"min_block_number", std::make_shared<DataTypeInt64>()},
|
|
|
|
{"max_block_number", std::make_shared<DataTypeInt64>()},
|
|
|
|
{"level", std::make_shared<DataTypeUInt32>()},
|
2018-06-13 15:47:40 +00:00
|
|
|
{"data_version", std::make_shared<DataTypeUInt64>()},
|
2018-03-26 14:18:04 +00:00
|
|
|
{"primary_key_bytes_in_memory", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"primary_key_bytes_in_memory_allocated", std::make_shared<DataTypeUInt64>()},
|
|
|
|
|
|
|
|
{"database", std::make_shared<DataTypeString>()},
|
|
|
|
{"table", std::make_shared<DataTypeString>()},
|
|
|
|
{"engine", std::make_shared<DataTypeString>()},
|
2019-08-01 10:29:14 +00:00
|
|
|
{"disk_name", std::make_shared<DataTypeString>()},
|
2018-03-26 14:18:04 +00:00
|
|
|
{"path", std::make_shared<DataTypeString>()},
|
|
|
|
|
|
|
|
{"column", std::make_shared<DataTypeString>()},
|
2019-07-04 18:27:14 +00:00
|
|
|
{"type", std::make_shared<DataTypeString>()},
|
|
|
|
{"default_kind", std::make_shared<DataTypeString>()},
|
|
|
|
{"default_expression", std::make_shared<DataTypeString>()},
|
|
|
|
{"column_bytes_on_disk", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"column_data_compressed_bytes", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"column_data_uncompressed_bytes", std::make_shared<DataTypeUInt64>()},
|
2019-07-05 15:32:55 +00:00
|
|
|
{"column_marks_bytes", std::make_shared<DataTypeUInt64>()}
|
2018-03-26 14:18:04 +00:00
|
|
|
}
|
|
|
|
)
|
2017-12-04 15:44:31 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-08-03 11:02:40 +00:00
|
|
|
void StorageSystemPartsColumns::processNextStorage(MutableColumns & columns_, const StoragesInfo & info, bool has_state_column)
|
2017-12-04 15:44:31 +00:00
|
|
|
{
|
2017-12-12 15:54:03 +00:00
|
|
|
/// Prepare information about columns in storage.
|
|
|
|
struct ColumnInfo
|
2017-12-04 15:44:31 +00:00
|
|
|
{
|
2017-12-12 15:54:03 +00:00
|
|
|
String default_kind;
|
|
|
|
String default_expression;
|
|
|
|
};
|
2017-12-04 15:44:31 +00:00
|
|
|
|
2017-12-12 15:54:03 +00:00
|
|
|
std::unordered_map<String, ColumnInfo> columns_info;
|
2019-03-14 15:20:51 +00:00
|
|
|
for (const auto & column : info.storage->getColumns())
|
2017-12-04 15:44:31 +00:00
|
|
|
{
|
2017-12-12 15:54:03 +00:00
|
|
|
ColumnInfo column_info;
|
2019-03-14 15:20:51 +00:00
|
|
|
if (column.default_desc.expression)
|
2017-12-04 15:53:18 +00:00
|
|
|
{
|
2019-03-14 15:20:51 +00:00
|
|
|
column_info.default_kind = toString(column.default_desc.kind);
|
|
|
|
column_info.default_expression = queryToString(column.default_desc.expression);
|
2017-12-04 15:53:18 +00:00
|
|
|
}
|
|
|
|
|
2017-12-12 15:54:03 +00:00
|
|
|
columns_info[column.name] = column_info;
|
2017-12-04 15:44:31 +00:00
|
|
|
}
|
|
|
|
|
2017-12-12 15:54:03 +00:00
|
|
|
/// Go through the list of parts.
|
2019-05-20 16:24:36 +00:00
|
|
|
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)
|
2017-12-04 15:44:31 +00:00
|
|
|
{
|
2019-05-20 16:24:36 +00:00
|
|
|
const auto & part = all_parts[part_number];
|
|
|
|
auto part_state = all_parts_state[part_number];
|
2018-03-26 14:18:04 +00:00
|
|
|
auto columns_size = part->getTotalColumnsSize();
|
2017-12-04 15:44:31 +00:00
|
|
|
|
2017-12-12 15:54:03 +00:00
|
|
|
/// For convenience, in returned refcount, don't add references that was due to local variables in this method: all_parts, active_parts.
|
|
|
|
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();
|
2017-12-04 15:44:31 +00:00
|
|
|
|
2020-02-23 01:04:59 +00:00
|
|
|
using State = IMergeTreeDataPart::State;
|
2017-12-04 15:44:31 +00:00
|
|
|
|
2020-01-16 16:15:01 +00:00
|
|
|
for (const auto & column : part->getColumns())
|
2019-07-04 18:27:14 +00:00
|
|
|
|
2017-12-04 15:53:18 +00:00
|
|
|
{
|
2017-12-12 15:54:03 +00:00
|
|
|
size_t j = 0;
|
2017-12-04 15:53:18 +00:00
|
|
|
{
|
2017-12-12 15:54:03 +00:00
|
|
|
WriteBufferFromOwnString out;
|
2018-10-09 18:32:44 +00:00
|
|
|
part->partition.serializeText(*info.data, out, format_settings);
|
2019-08-03 11:02:40 +00:00
|
|
|
columns_[j++]->insert(out.str());
|
2017-12-04 15:53:18 +00:00
|
|
|
}
|
2019-08-03 11:02:40 +00:00
|
|
|
columns_[j++]->insert(part->name);
|
2020-01-13 16:40:24 +00:00
|
|
|
columns_[j++]->insert(part->getTypeName());
|
2019-08-03 11:02:40 +00:00
|
|
|
columns_[j++]->insert(part_state == State::Committed);
|
|
|
|
columns_[j++]->insert(part->getMarksCount());
|
|
|
|
|
|
|
|
columns_[j++]->insert(part->rows_count);
|
2020-03-23 13:32:02 +00:00
|
|
|
columns_[j++]->insert(part->getBytesOnDisk());
|
2019-08-03 11:02:40 +00:00
|
|
|
columns_[j++]->insert(columns_size.data_compressed);
|
|
|
|
columns_[j++]->insert(columns_size.data_uncompressed);
|
|
|
|
columns_[j++]->insert(columns_size.marks);
|
|
|
|
columns_[j++]->insert(UInt64(part->modification_time));
|
|
|
|
columns_[j++]->insert(UInt64(part->remove_time.load(std::memory_order_relaxed)));
|
|
|
|
|
|
|
|
columns_[j++]->insert(UInt64(use_count));
|
|
|
|
|
|
|
|
columns_[j++]->insert(min_date);
|
|
|
|
columns_[j++]->insert(max_date);
|
|
|
|
columns_[j++]->insert(part->info.partition_id);
|
|
|
|
columns_[j++]->insert(part->info.min_block);
|
|
|
|
columns_[j++]->insert(part->info.max_block);
|
|
|
|
columns_[j++]->insert(part->info.level);
|
|
|
|
columns_[j++]->insert(UInt64(part->info.getDataVersion()));
|
|
|
|
columns_[j++]->insert(index_size_in_bytes);
|
|
|
|
columns_[j++]->insert(index_size_in_allocated_bytes);
|
|
|
|
|
|
|
|
columns_[j++]->insert(info.database);
|
|
|
|
columns_[j++]->insert(info.table);
|
|
|
|
columns_[j++]->insert(info.engine);
|
2019-08-14 09:46:30 +00:00
|
|
|
columns_[j++]->insert(part->disk->getName());
|
2019-08-03 11:02:40 +00:00
|
|
|
columns_[j++]->insert(part->getFullPath());
|
2019-08-14 09:46:30 +00:00
|
|
|
|
2019-08-03 11:02:40 +00:00
|
|
|
columns_[j++]->insert(column.name);
|
|
|
|
columns_[j++]->insert(column.type->getName());
|
2017-12-12 15:54:03 +00:00
|
|
|
|
|
|
|
auto column_info_it = columns_info.find(column.name);
|
|
|
|
if (column_info_it != columns_info.end())
|
2017-12-04 15:44:31 +00:00
|
|
|
{
|
2019-08-03 11:02:40 +00:00
|
|
|
columns_[j++]->insert(column_info_it->second.default_kind);
|
|
|
|
columns_[j++]->insert(column_info_it->second.default_expression);
|
2017-12-12 15:54:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-03 11:02:40 +00:00
|
|
|
columns_[j++]->insertDefault();
|
|
|
|
columns_[j++]->insertDefault();
|
2017-12-12 15:54:03 +00:00
|
|
|
}
|
2017-12-04 15:44:31 +00:00
|
|
|
|
2019-07-16 17:13:12 +00:00
|
|
|
ColumnSize column_size = part->getColumnSize(column.name, *column.type);
|
2019-08-03 11:02:40 +00:00
|
|
|
columns_[j++]->insert(column_size.data_compressed + column_size.marks);
|
|
|
|
columns_[j++]->insert(column_size.data_compressed);
|
|
|
|
columns_[j++]->insert(column_size.data_uncompressed);
|
|
|
|
columns_[j++]->insert(column_size.marks);
|
2017-12-04 15:44:31 +00:00
|
|
|
|
2017-12-12 15:54:03 +00:00
|
|
|
if (has_state_column)
|
2019-08-03 11:02:40 +00:00
|
|
|
columns_[j++]->insert(part->stateString());
|
2017-12-04 15:44:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|