ClickHouse/src/Storages/IndicesDescription.h

81 lines
2.4 KiB
C++
Raw Normal View History

2019-01-20 17:49:53 +00:00
#pragma once
2021-10-02 07:13:14 +00:00
#include <base/types.h>
2019-01-20 17:49:53 +00:00
2019-10-07 14:18:18 +00:00
#include <memory>
#include <vector>
2020-05-28 13:03:18 +00:00
#include <Core/Field.h>
#include <Interpreters/ExpressionActions.h>
#include <Parsers/IAST_fwd.h>
#include <Storages/ColumnsDescription.h>
#include <Common/NamePrompter.h>
2019-01-20 17:49:53 +00:00
namespace DB
{
2020-06-01 10:48:52 +00:00
/// Description of non-primary index for Storage
2020-05-28 13:09:03 +00:00
struct IndexDescription
2020-05-28 13:03:18 +00:00
{
2020-06-01 10:48:52 +00:00
/// Definition AST of index
2020-05-28 13:03:18 +00:00
ASTPtr definition_ast;
2020-06-01 10:48:52 +00:00
/// List of expressions for index calculation
2020-05-28 13:03:18 +00:00
ASTPtr expression_list_ast;
2020-06-01 10:48:52 +00:00
/// Index name
2020-05-28 13:03:18 +00:00
String name;
2020-06-01 10:48:52 +00:00
/// Index type (minmax, set, bloom filter, etc.)
2020-05-28 13:03:18 +00:00
String type;
2020-06-01 10:48:52 +00:00
/// Prepared expressions for index calculations
2020-05-28 13:03:18 +00:00
ExpressionActionsPtr expression;
2020-06-01 10:48:52 +00:00
/// Index arguments, for example probability for bloom filter
2020-05-28 13:03:18 +00:00
FieldVector arguments;
2020-06-01 10:48:52 +00:00
/// Names of index columns (not to be confused with required columns)
2020-05-28 13:03:18 +00:00
Names column_names;
2020-06-01 10:48:52 +00:00
/// Data types of index columns
2020-05-28 13:03:18 +00:00
DataTypes data_types;
2020-07-10 08:13:21 +00:00
/// Sample block with index columns. (NOTE: columns in block are empty, but not nullptr)
2020-05-28 13:03:18 +00:00
Block sample_block;
2020-06-01 10:48:52 +00:00
/// Index granularity, make sense for skip indices
2020-05-28 13:03:18 +00:00
size_t granularity;
2020-06-01 10:48:52 +00:00
/// Parse index from definition AST
static IndexDescription getIndexFromAST(const ASTPtr & definition_ast, const ColumnsDescription & columns, ContextPtr context);
2020-06-05 17:29:40 +00:00
IndexDescription() = default;
/// We need custom copy constructors because we don't want
/// unintentionaly share AST variables and modify them.
IndexDescription(const IndexDescription & other);
IndexDescription & operator=(const IndexDescription & other);
/// Recalculate index with new columns because index expression may change
/// if something change in columns.
void recalculateWithNewColumns(const ColumnsDescription & new_columns, ContextPtr context);
2020-05-28 13:03:18 +00:00
};
2020-06-01 16:22:33 +00:00
/// All secondary indices in storage
struct IndicesDescription : public std::vector<IndexDescription>, IHints<1, IndicesDescription>
2020-05-28 13:03:18 +00:00
{
2020-06-01 10:48:52 +00:00
/// Index with name exists
2020-05-28 13:03:18 +00:00
bool has(const String & name) const;
2020-06-01 10:48:52 +00:00
/// Convert description to string
2020-05-28 13:03:18 +00:00
String toString() const;
2020-06-01 10:48:52 +00:00
/// Parse description from string
static IndicesDescription parse(const String & str, const ColumnsDescription & columns, ContextPtr context);
2020-06-01 19:58:11 +00:00
/// Return common expression for all stored indices
ExpressionActionsPtr getSingleExpressionForIndices(const ColumnsDescription & columns, ContextPtr context) const;
Names getAllRegisteredNames() const override;
2020-05-28 13:03:18 +00:00
};
2019-01-20 17:49:53 +00:00
2019-01-26 06:26:49 +00:00
}