2019-06-19 10:07:56 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <optional>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2020-01-14 13:23:51 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeDataPartType.h>
|
2020-02-27 16:47:40 +00:00
|
|
|
#include <Disks/IDisk.h>
|
2022-04-07 17:44:49 +00:00
|
|
|
#include <Storages/MergeTree/IDataPartStorage.h>
|
2019-06-19 10:07:56 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2019-06-19 14:46:06 +00:00
|
|
|
|
|
|
|
class MergeTreeData;
|
2019-10-11 15:37:16 +00:00
|
|
|
|
2022-09-05 05:26:58 +00:00
|
|
|
|
|
|
|
/** Various types of mark files are stored in files with various extensions:
|
|
|
|
* .mrk, .mrk2, .mrk3, .cmrk, .cmrk2, .cmrk3.
|
2022-09-06 16:24:06 +00:00
|
|
|
* This helper allows to obtain mark type from file extension and vice versa.
|
2022-09-05 05:26:58 +00:00
|
|
|
*/
|
|
|
|
struct MarkType
|
|
|
|
{
|
|
|
|
MarkType(std::string_view extension);
|
|
|
|
MarkType(bool adaptive_, bool compressed_, MergeTreeDataPartType::Value part_type_);
|
|
|
|
|
|
|
|
static bool isMarkFileExtension(std::string_view extension);
|
|
|
|
std::string getFileExtension() const;
|
|
|
|
|
|
|
|
bool adaptive = false;
|
|
|
|
bool compressed = false;
|
|
|
|
MergeTreeDataPartType::Value part_type = MergeTreeDataPartType::Unknown;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-06-19 10:07:56 +00:00
|
|
|
/// Meta information about index granularity
|
|
|
|
struct MergeTreeIndexGranularityInfo
|
|
|
|
{
|
|
|
|
public:
|
2022-09-05 05:26:58 +00:00
|
|
|
MarkType mark_type;
|
2019-06-19 10:07:56 +00:00
|
|
|
|
|
|
|
/// Fixed size in rows of one granule if index_granularity_bytes is zero
|
2019-11-21 16:10:22 +00:00
|
|
|
size_t fixed_index_granularity = 0;
|
2019-06-19 10:07:56 +00:00
|
|
|
|
|
|
|
/// Approximate bytes size of one granule
|
2019-11-21 16:10:22 +00:00
|
|
|
size_t index_granularity_bytes = 0;
|
|
|
|
|
2020-01-14 13:23:51 +00:00
|
|
|
MergeTreeIndexGranularityInfo(const MergeTreeData & storage, MergeTreeDataPartType type_);
|
2019-11-21 16:10:22 +00:00
|
|
|
|
2022-09-06 15:41:39 +00:00
|
|
|
MergeTreeIndexGranularityInfo(const MergeTreeData & storage, MarkType mark_type_);
|
|
|
|
|
2022-09-05 16:55:00 +00:00
|
|
|
MergeTreeIndexGranularityInfo(MergeTreeDataPartType type_, bool is_adaptive_, size_t index_granularity_, size_t index_granularity_bytes_);
|
|
|
|
|
2022-10-23 03:29:26 +00:00
|
|
|
void changeGranularityIfRequired(const IDataPartStorage & data_part_storage);
|
2019-06-19 10:07:56 +00:00
|
|
|
|
2019-10-11 15:37:16 +00:00
|
|
|
String getMarksFilePath(const String & path_prefix) const
|
2019-06-19 10:07:56 +00:00
|
|
|
{
|
2022-09-05 05:26:58 +00:00
|
|
|
return path_prefix + mark_type.getFileExtension();
|
2019-06-19 10:07:56 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 13:23:51 +00:00
|
|
|
size_t getMarkSizeInBytes(size_t columns_num = 1) const;
|
|
|
|
|
2023-01-25 17:34:09 +00:00
|
|
|
static std::optional<MarkType> getMarksTypeFromFilesystem(const IDataPartStorage & data_part_storage);
|
2019-06-19 10:07:56 +00:00
|
|
|
};
|
|
|
|
|
2020-01-14 13:23:51 +00:00
|
|
|
constexpr inline auto getNonAdaptiveMrkSizeWide() { return sizeof(UInt64) * 2; }
|
|
|
|
constexpr inline auto getAdaptiveMrkSizeWide() { return sizeof(UInt64) * 3; }
|
2020-02-03 12:08:40 +00:00
|
|
|
inline size_t getAdaptiveMrkSizeCompact(size_t columns_num);
|
2019-06-19 10:07:56 +00:00
|
|
|
|
|
|
|
}
|