2019-01-20 17:49:53 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-10-07 14:18:18 +00:00
|
|
|
#include <Core/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>
|
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
|
2020-06-01 12:02:36 +00:00
|
|
|
static IndexDescription getIndexFromAST(const ASTPtr & definition_ast, const ColumnsDescription & columns, const Context & 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);
|
2020-06-19 10:53:20 +00:00
|
|
|
|
|
|
|
/// Recalculate index with new columns because index expression may change
|
|
|
|
/// if something change in columns.
|
|
|
|
void recalculateWithNewColumns(const ColumnsDescription & new_columns, const Context & context);
|
2020-05-28 13:03:18 +00:00
|
|
|
};
|
|
|
|
|
2020-06-01 16:22:33 +00:00
|
|
|
/// All secondary indices in storage
|
2020-05-28 13:09:03 +00:00
|
|
|
struct IndicesDescription : public std::vector<IndexDescription>
|
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
|
2020-05-28 13:03:18 +00:00
|
|
|
static IndicesDescription parse(const String & str, const ColumnsDescription & columns, const Context & context);
|
2020-06-01 19:58:11 +00:00
|
|
|
|
|
|
|
/// Return common expression for all stored indices
|
|
|
|
ExpressionActionsPtr getSingleExpressionForIndices(const ColumnsDescription & columns, const Context & context) const;
|
2020-05-28 13:03:18 +00:00
|
|
|
};
|
2019-01-20 17:49:53 +00:00
|
|
|
|
2019-01-26 06:26:49 +00:00
|
|
|
}
|