ClickHouse/src/Storages/MergeTree/MergeTreeIndexSet.h

140 lines
3.4 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
{
2020-05-27 18:38:34 +00:00
explicit MergeTreeIndexGranuleSet(
const String & index_name_,
const Block & index_sample_block_,
size_t max_rows_);
MergeTreeIndexGranuleSet(
const String & index_name_,
const Block & index_sample_block_,
size_t max_rows_,
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
2020-05-27 18:38:34 +00:00
String index_name;
size_t max_rows;
Block index_sample_block;
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
{
2020-05-27 18:38:34 +00:00
explicit MergeTreeIndexAggregatorSet(
const String & index_name_,
const Block & index_sample_block_,
size_t max_rows_);
2019-06-19 15:30:48 +00:00
~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
2020-05-27 18:38:34 +00:00
String index_name;
size_t max_rows;
Block index_sample_block;
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(
2020-05-27 18:38:34 +00:00
const String & index_name_,
const Block & index_sample_block_,
size_t max_rows_,
const SelectQueryInfo & query,
const Context & context);
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
2020-05-27 18:38:34 +00:00
String index_name;
size_t max_rows;
Block index_sample_block;
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(
2020-05-28 13:09:03 +00:00
const IndexDescription & index_,
2019-02-05 16:43:52 +00:00
size_t max_rows_)
2020-05-27 18:38:34 +00:00
: IMergeTreeIndex(index_)
, 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
}