ClickHouse/src/Storages/MergeTree/MergeTreeIndexMinMax.h

89 lines
2.5 KiB
C++
Raw Normal View History

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
{
2019-06-19 15:30:48 +00:00
class MergeTreeIndexMinMax;
2019-01-08 17:27:44 +00:00
2019-01-27 18:23:08 +00:00
2019-06-19 15:30:48 +00:00
struct MergeTreeIndexGranuleMinMax : public IMergeTreeIndexGranule
2019-01-08 17:27:44 +00:00
{
2019-08-03 11:02:40 +00:00
explicit MergeTreeIndexGranuleMinMax(const MergeTreeIndexMinMax & index_);
2020-03-10 14:56:55 +00:00
MergeTreeIndexGranuleMinMax(const MergeTreeIndexMinMax & index_, 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;
void deserializeBinary(ReadBuffer & istr) 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
2019-06-19 15:30:48 +00:00
const MergeTreeIndexMinMax & index;
2020-03-10 14:56:55 +00:00
std::vector<Range> hyperrectangle;
2019-03-08 19:52:21 +00:00
};
2019-06-19 15:30:48 +00:00
struct MergeTreeIndexAggregatorMinMax : IMergeTreeIndexAggregator
2019-03-08 19:52:21 +00:00
{
2019-06-19 15:30:48 +00:00
explicit MergeTreeIndexAggregatorMinMax(const MergeTreeIndexMinMax & index);
~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
2019-06-19 15:30:48 +00:00
const MergeTreeIndexMinMax & index;
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
2019-06-19 15:30:48 +00:00
class MergeTreeIndexConditionMinMax : public IMergeTreeIndexCondition
2019-01-08 17:27:44 +00:00
{
public:
2019-06-19 15:30:48 +00:00
MergeTreeIndexConditionMinMax(
2019-01-09 17:05:52 +00:00
const SelectQueryInfo & query,
const Context & context,
2019-06-19 15:30:48 +00:00
const MergeTreeIndexMinMax & index);
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:
2019-06-19 15:30:48 +00:00
const MergeTreeIndexMinMax & index;
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:
2019-06-19 15:30:48 +00:00
MergeTreeIndexMinMax(
2019-02-05 16:43:52 +00:00
String name_,
ExpressionActionsPtr expr_,
const Names & columns_,
const DataTypes & data_types_,
const Block & header_,
size_t granularity_)
2019-02-06 07:49:18 +00:00
: IMergeTreeIndex(name_, expr_, columns_, data_types_, header_, granularity_) {}
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(
2019-01-09 17:05:52 +00:00
const SelectQueryInfo & query, const Context & 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;
2019-01-08 17:27:44 +00:00
};
}