ClickHouse/dbms/Storages/MergeTree/MergeTreeIndexSet.h

121 lines
3.2 KiB
C++
Raw Normal View History

2019-01-26 13:12:13 +00:00
#pragma once
#include <Storages/MergeTree/MergeTreeIndices.h>
#include <Storages/MergeTree/MergeTreeData.h>
2019-03-09 14:03:41 +00:00
#include <Interpreters/SetVariants.h>
2019-01-27 18:02:15 +00:00
2019-01-26 13:12:13 +00:00
#include <memory>
2019-01-29 17:26:45 +00:00
#include <set>
2019-01-26 13:12:13 +00:00
namespace DB
{
2019-06-19 15:30:48 +00:00
class MergeTreeIndexSet;
2019-01-26 13:12:13 +00:00
2019-06-19 15:30:48 +00:00
struct MergeTreeIndexGranuleSet : public IMergeTreeIndexGranule
2019-01-26 13:12:13 +00:00
{
2019-08-03 11:02:40 +00:00
explicit MergeTreeIndexGranuleSet(const MergeTreeIndexSet & index_);
MergeTreeIndexGranuleSet(const MergeTreeIndexSet & index_, MutableColumns && columns_);
2019-01-26 13:12:13 +00:00
void serializeBinary(WriteBuffer & ostr) const override;
void deserializeBinary(ReadBuffer & istr) override;
2019-03-08 19:52:21 +00:00
size_t size() const { return block.rows(); }
2019-01-27 18:02:15 +00:00
bool empty() const override { return !size(); }
2019-01-26 13:12:13 +00:00
2019-06-19 15:30:48 +00:00
~MergeTreeIndexGranuleSet() override = default;
2019-01-26 13:12:13 +00:00
2019-06-19 15:30:48 +00:00
const MergeTreeIndexSet & index;
2019-03-08 19:52:21 +00:00
Block block;
};
2019-06-19 15:30:48 +00:00
struct MergeTreeIndexAggregatorSet : IMergeTreeIndexAggregator
2019-03-08 19:52:21 +00:00
{
2019-06-19 15:30:48 +00:00
explicit MergeTreeIndexAggregatorSet(const MergeTreeIndexSet & index);
~MergeTreeIndexAggregatorSet() override = default;
2019-03-08 19:52:21 +00:00
2019-03-09 14:03:41 +00:00
size_t size() const { return data.getTotalRowCount(); }
2019-03-08 19:52:21 +00:00
bool empty() const override { return !size(); }
2019-03-09 14:03:41 +00:00
2019-03-08 19:52:21 +00:00
MergeTreeIndexGranulePtr getGranuleAndReset() override;
2019-03-09 14:03:41 +00:00
void update(const Block & block, size_t * pos, size_t limit) override;
2019-01-26 13:12:13 +00:00
2019-03-09 14:03:41 +00:00
private:
/// return true if has new data
template <typename Method>
bool buildFilter(
Method & method,
2019-03-09 15:26:52 +00:00
const ColumnRawPtrs & column_ptrs,
2019-03-09 14:03:41 +00:00
IColumn::Filter & filter,
size_t pos,
size_t limit,
ClearableSetVariants & variants) const;
2019-01-26 13:12:13 +00:00
2019-06-19 15:30:48 +00:00
const MergeTreeIndexSet & index;
2019-03-09 14:03:41 +00:00
ClearableSetVariants data;
Sizes key_sizes;
MutableColumns columns;
2019-01-26 13:12:13 +00:00
};
2019-01-27 18:23:08 +00:00
2019-06-19 15:30:48 +00:00
class MergeTreeIndexConditionSet : public IMergeTreeIndexCondition
2019-01-26 13:12:13 +00:00
{
public:
2019-06-19 15:30:48 +00:00
MergeTreeIndexConditionSet(
2019-01-26 13:12:13 +00:00
const SelectQueryInfo & query,
const Context & context,
2019-06-19 15:30:48 +00:00
const MergeTreeIndexSet & index);
2019-01-26 13:12:13 +00:00
bool alwaysUnknownOrTrue() const override;
bool mayBeTrueOnGranule(MergeTreeIndexGranulePtr idx_granule) const override;
2019-06-19 15:30:48 +00:00
~MergeTreeIndexConditionSet() override = default;
2019-01-26 13:12:13 +00:00
private:
2019-01-29 13:13:18 +00:00
void traverseAST(ASTPtr & node) const;
bool atomFromAST(ASTPtr & node) const;
2020-03-18 00:57:00 +00:00
static bool operatorFromAST(ASTPtr & node);
2019-01-27 20:24:33 +00:00
bool checkASTUseless(const ASTPtr & node, bool atomic = false) const;
2019-01-29 16:53:44 +00:00
2019-06-19 15:30:48 +00:00
const MergeTreeIndexSet & index;
2019-01-27 20:24:33 +00:00
2019-01-29 16:53:44 +00:00
bool useless;
2019-01-29 17:26:45 +00:00
std::set<String> key_columns;
2019-01-28 08:15:13 +00:00
ASTPtr expression_ast;
2019-01-27 20:24:33 +00:00
ExpressionActionsPtr actions;
2019-01-26 13:12:13 +00:00
};
2019-06-19 15:30:48 +00:00
class MergeTreeIndexSet : public IMergeTreeIndex
2019-01-26 13:12:13 +00:00
{
public:
2019-06-19 15:30:48 +00:00
MergeTreeIndexSet(
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_,
size_t max_rows_)
2019-02-06 07:49:18 +00:00
: IMergeTreeIndex(std::move(name_), std::move(expr_), columns_, data_types_, header_, granularity_), max_rows(max_rows_) {}
2019-01-26 13:12:13 +00:00
2019-06-19 15:30:48 +00:00
~MergeTreeIndexSet() override = default;
2019-01-26 13:12:13 +00:00
MergeTreeIndexGranulePtr createIndexGranule() const override;
2019-03-08 19:52:21 +00:00
MergeTreeIndexAggregatorPtr createIndexAggregator() const override;
2019-01-26 13:12:13 +00:00
2019-06-19 15:30:48 +00:00
MergeTreeIndexConditionPtr createIndexCondition(
2019-01-26 13:12:13 +00:00
const SelectQueryInfo & query, const Context & context) const override;
2019-02-25 08:43:19 +00:00
bool mayBenefitFromIndexForIn(const ASTPtr & node) const override;
2019-01-26 15:45:38 +00:00
size_t max_rows = 0;
2019-01-26 13:12:13 +00:00
};
2019-01-29 17:28:13 +00:00
}