2019-01-08 17:27:44 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-17 12:11:36 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeIndices.h>
|
2019-01-08 17:27:44 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeData.h>
|
|
|
|
#include <Storages/MergeTree/KeyCondition.h>
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-04-01 02:37:19 +00:00
|
|
|
struct MergeTreeIndexGranuleMinMax final : public IMergeTreeIndexGranule
|
2019-01-08 17:27:44 +00:00
|
|
|
{
|
2020-05-28 12:37:05 +00:00
|
|
|
MergeTreeIndexGranuleMinMax(const String & index_name_, const Block & index_sample_block_);
|
|
|
|
MergeTreeIndexGranuleMinMax(
|
|
|
|
const String & index_name_,
|
|
|
|
const Block & index_sample_block_,
|
|
|
|
std::vector<Range> && hyperrectangle_);
|
|
|
|
|
2019-06-19 15:30:48 +00:00
|
|
|
~MergeTreeIndexGranuleMinMax() override = default;
|
2019-01-08 17:27:44 +00:00
|
|
|
|
|
|
|
void serializeBinary(WriteBuffer & ostr) const override;
|
2021-08-05 18:09:17 +00:00
|
|
|
void deserializeBinary(ReadBuffer & istr, MergeTreeIndexVersion version) override;
|
2019-01-09 14:15:23 +00:00
|
|
|
|
2020-03-10 14:56:55 +00:00
|
|
|
bool empty() const override { return hyperrectangle.empty(); }
|
2019-01-08 17:27:44 +00:00
|
|
|
|
2020-05-28 12:37:05 +00:00
|
|
|
String index_name;
|
2020-05-27 18:38:34 +00:00
|
|
|
Block index_sample_block;
|
2020-03-10 14:56:55 +00:00
|
|
|
std::vector<Range> hyperrectangle;
|
2019-03-08 19:52:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-04-01 02:37:19 +00:00
|
|
|
struct MergeTreeIndexAggregatorMinMax final : IMergeTreeIndexAggregator
|
2019-03-08 19:52:21 +00:00
|
|
|
{
|
2020-05-28 12:37:05 +00:00
|
|
|
MergeTreeIndexAggregatorMinMax(const String & index_name_, const Block & index_sample_block);
|
2019-06-19 15:30:48 +00:00
|
|
|
~MergeTreeIndexAggregatorMinMax() override = default;
|
2019-03-08 19:52:21 +00:00
|
|
|
|
2020-03-10 14:56:55 +00:00
|
|
|
bool empty() const override { return hyperrectangle.empty(); }
|
2019-03-08 19:52:21 +00:00
|
|
|
MergeTreeIndexGranulePtr getGranuleAndReset() override;
|
|
|
|
void update(const Block & block, size_t * pos, size_t limit) override;
|
2019-01-08 17:27:44 +00:00
|
|
|
|
2020-05-28 12:37:05 +00:00
|
|
|
String index_name;
|
2020-05-27 18:38:34 +00:00
|
|
|
Block index_sample_block;
|
2020-03-10 14:56:55 +00:00
|
|
|
std::vector<Range> hyperrectangle;
|
2019-01-08 17:27:44 +00:00
|
|
|
};
|
|
|
|
|
2019-01-27 18:23:08 +00:00
|
|
|
|
2021-04-01 02:37:19 +00:00
|
|
|
class MergeTreeIndexConditionMinMax final : public IMergeTreeIndexCondition
|
2019-01-08 17:27:44 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-06-19 15:30:48 +00:00
|
|
|
MergeTreeIndexConditionMinMax(
|
2020-05-28 13:09:03 +00:00
|
|
|
const IndexDescription & index,
|
2022-11-17 18:44:26 +00:00
|
|
|
const SelectQueryInfo & query_info,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context);
|
2019-01-08 17:27:44 +00:00
|
|
|
|
|
|
|
bool alwaysUnknownOrTrue() const override;
|
|
|
|
|
|
|
|
bool mayBeTrueOnGranule(MergeTreeIndexGranulePtr idx_granule) const override;
|
|
|
|
|
2019-06-19 15:30:48 +00:00
|
|
|
~MergeTreeIndexConditionMinMax() override = default;
|
2019-01-08 17:27:44 +00:00
|
|
|
private:
|
2020-05-27 18:38:34 +00:00
|
|
|
DataTypes index_data_types;
|
2019-01-08 17:27:44 +00:00
|
|
|
KeyCondition condition;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-06-19 15:30:48 +00:00
|
|
|
class MergeTreeIndexMinMax : public IMergeTreeIndex
|
2019-01-08 17:27:44 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-03-13 12:23:51 +00:00
|
|
|
explicit MergeTreeIndexMinMax(const IndexDescription & index_)
|
2020-05-27 18:38:34 +00:00
|
|
|
: IMergeTreeIndex(index_)
|
|
|
|
{}
|
2019-01-08 17:27:44 +00:00
|
|
|
|
2019-06-19 15:30:48 +00:00
|
|
|
~MergeTreeIndexMinMax() override = default;
|
2019-01-08 17:27:44 +00:00
|
|
|
|
|
|
|
MergeTreeIndexGranulePtr createIndexGranule() const override;
|
2019-03-08 19:52:21 +00:00
|
|
|
MergeTreeIndexAggregatorPtr createIndexAggregator() const override;
|
2019-01-08 17:27:44 +00:00
|
|
|
|
2019-06-19 15:30:48 +00:00
|
|
|
MergeTreeIndexConditionPtr createIndexCondition(
|
2021-04-10 23:33:54 +00:00
|
|
|
const SelectQueryInfo & query, ContextPtr context) const override;
|
2019-01-08 17:27:44 +00:00
|
|
|
|
2019-02-25 08:43:19 +00:00
|
|
|
bool mayBenefitFromIndexForIn(const ASTPtr & node) const override;
|
2021-08-05 18:09:17 +00:00
|
|
|
|
|
|
|
const char* getSerializedFileExtension() const override { return ".idx2"; }
|
2022-10-23 03:29:26 +00:00
|
|
|
MergeTreeIndexFormat getDeserializedFormat(const IDataPartStorage & data_part_storage, const std::string & path_prefix) const override; /// NOLINT
|
2019-01-08 17:27:44 +00:00
|
|
|
};
|
|
|
|
|
2019-01-29 20:00:12 +00:00
|
|
|
}
|