ClickHouse/src/Storages/MergeTree/MergeTreeIndexSet.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

159 lines
4.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
struct MergeTreeIndexGranuleSet final : 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, MergeTreeIndexVersion version) override;
2019-01-26 13:12:13 +00:00
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;
};
struct MergeTreeIndexAggregatorSet final : 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
class MergeTreeIndexConditionSet final : 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_,
2022-12-09 17:15:39 +00:00
const Block & index_sample_block,
2020-05-27 18:38:34 +00:00
size_t max_rows_,
2022-12-09 17:15:39 +00:00
const SelectQueryInfo & query_info,
ContextPtr 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:
2022-12-09 17:15:39 +00:00
const ActionsDAG::Node & traverseDAG(const ActionsDAG::Node & node,
ActionsDAGPtr & result_dag,
const ContextPtr & context,
std::unordered_map<const ActionsDAG::Node *, const ActionsDAG::Node *> & node_to_result_node) const;
const ActionsDAG::Node * atomFromDAG(const ActionsDAG::Node & node,
ActionsDAGPtr & result_dag,
const ContextPtr & context) const;
const ActionsDAG::Node * operatorFromDAG(const ActionsDAG::Node & node,
ActionsDAGPtr & result_dag,
const ContextPtr & context,
std::unordered_map<const ActionsDAG::Node *, const ActionsDAG::Node *> & node_to_result_node) const;
bool checkDAGUseless(const ActionsDAG::Node & node, const ContextPtr & context, bool atomic = false) const;
2019-01-29 13:13:18 +00:00
void traverseAST(ASTPtr & node) const;
2022-12-09 17:15:39 +00:00
2019-01-29 13:13:18 +00:00
bool atomFromAST(ASTPtr & node) const;
2022-12-09 17:15:39 +00:00
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;
2019-01-27 20:24:33 +00:00
2022-12-09 17:15:39 +00:00
bool isUseless() const
{
return actions == nullptr;
}
std::unordered_set<String> key_columns;
2019-01-27 20:24:33 +00:00
ExpressionActionsPtr actions;
2019-01-26 13:12:13 +00:00
};
class MergeTreeIndexSet final : 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(
const SelectQueryInfo & query, ContextPtr context) const override;
2019-01-26 13:12:13 +00:00
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
}