Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add column primary_key_size to system.parts #51496

Merged
merged 19 commits into from Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/en/operations/system-tables/parts.md
Expand Up @@ -39,6 +39,8 @@ Columns:

- `data_uncompressed_bytes` ([UInt64](../../sql-reference/data-types/int-uint.md)) – Total size of uncompressed data in the data part. All the auxiliary files (for example, files with marks) are not included.

- `primary_key_size` ([UInt64](../../sql-reference/data-types/int-uint.md)) – The amount of memory (in bytes) used by primary key values in the primary.idx/cidx file on disk.

- `marks_bytes` ([UInt64](../../sql-reference/data-types/int-uint.md)) – The size of the file with marks.

- `secondary_indices_compressed_bytes` ([UInt64](../../sql-reference/data-types/int-uint.md)) – Total size of compressed data for secondary indices in the data part. All the auxiliary files (for example, files with marks) are not included.
Expand Down
17 changes: 17 additions & 0 deletions src/Storages/MergeTree/IMergeTreeDataPart.cpp
@@ -1,5 +1,6 @@
#include "IMergeTreeDataPart.h"
#include "Storages/MergeTree/IDataPartStorage.h"
#include "base/types.h"
yariks5s marked this conversation as resolved.
Show resolved Hide resolved

#include <optional>
#include <boost/algorithm/string/join.hpp>
Expand Down Expand Up @@ -1803,6 +1804,22 @@ MutableDataPartStoragePtr IMergeTreeDataPart::makeCloneOnDisk(const DiskPtr & di
return getDataPartStorage().clonePart(path_to_clone, getDataPartStorage().getPartDirectory(), disk, storage.log);
}

UInt64 IMergeTreeDataPart::getIndexSizeFromFile() const
{
auto metadata_snapshot = storage.getInMemoryMetadataPtr();
if (parent_part)
metadata_snapshot = metadata_snapshot->projections.get(name).metadata;
const auto & pk = metadata_snapshot->getPrimaryKey();
if (!pk.column_names.empty())
{
String file = "primary" + getIndexExtension(false);
if (checksums.files.contains("primary" + getIndexExtension(true)))
file = "primary" + getIndexExtension(true);
return getFileSizeOrZero(file);
}
return 0;
}

void IMergeTreeDataPart::checkConsistencyBase() const
{
auto metadata_snapshot = storage.getInMemoryMetadataPtr();
Expand Down
1 change: 1 addition & 0 deletions src/Storages/MergeTree/IMergeTreeDataPart.h
Expand Up @@ -346,6 +346,7 @@ class IMergeTreeDataPart : public std::enable_shared_from_this<IMergeTreeDataPar
UInt64 getIndexSizeInBytes() const;
UInt64 getIndexSizeInAllocatedBytes() const;
UInt64 getMarksCount() const;
UInt64 getIndexSizeFromFile() const;

UInt64 getBytesOnDisk() const { return bytes_on_disk; }
void setBytesOnDisk(UInt64 bytes_on_disk_) { bytes_on_disk = bytes_on_disk_; }
Expand Down
3 changes: 3 additions & 0 deletions src/Storages/System/StorageSystemParts.cpp
Expand Up @@ -57,6 +57,7 @@ StorageSystemParts::StorageSystemParts(const StorageID & table_id_)
{"bytes_on_disk", std::make_shared<DataTypeUInt64>()},
{"data_compressed_bytes", std::make_shared<DataTypeUInt64>()},
{"data_uncompressed_bytes", std::make_shared<DataTypeUInt64>()},
{"primary_key_size", std::make_shared<DataTypeUInt64>()},
{"marks_bytes", std::make_shared<DataTypeUInt64>()},
{"secondary_indices_compressed_bytes", std::make_shared<DataTypeUInt64>()},
{"secondary_indices_uncompressed_bytes", std::make_shared<DataTypeUInt64>()},
Expand Down Expand Up @@ -168,6 +169,8 @@ void StorageSystemParts::processNextStorage(
columns[res_index++]->insert(columns_size.data_compressed);
if (columns_mask[src_index++])
columns[res_index++]->insert(columns_size.data_uncompressed);
if (columns_mask[src_index++])
columns[res_index++]->insert(part->getIndexSizeFromFile());
if (columns_mask[src_index++])
columns[res_index++]->insert(columns_size.marks);
if (columns_mask[src_index++])
Expand Down
Expand Up @@ -466,6 +466,7 @@ CREATE TABLE system.parts
`bytes_on_disk` UInt64,
`data_compressed_bytes` UInt64,
`data_uncompressed_bytes` UInt64,
`primary_key_size` UInt64,
`marks_bytes` UInt64,
`secondary_indices_compressed_bytes` UInt64,
`secondary_indices_uncompressed_bytes` UInt64,
Expand Down