From e5682e81f707363b6b6cfce323d61b2deb9a107e Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 4 Jun 2018 20:01:00 +0300 Subject: [PATCH] Slightly better (preparation) [#CLICKHOUSE-3] --- dbms/src/Storages/MergeTree/KeyCondition.cpp | 6 +-- dbms/src/Storages/MergeTree/KeyCondition.h | 43 +++++++++++--------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/dbms/src/Storages/MergeTree/KeyCondition.cpp b/dbms/src/Storages/MergeTree/KeyCondition.cpp index bc618f8d655..3b9f5cfdafa 100644 --- a/dbms/src/Storages/MergeTree/KeyCondition.cpp +++ b/dbms/src/Storages/MergeTree/KeyCondition.cpp @@ -535,7 +535,7 @@ bool KeyCondition::isKeyPossiblyWrappedByMonotonicFunctions( const Context & context, size_t & out_key_column_num, DataTypePtr & out_key_res_column_type, - RPNElement::MonotonicFunctionsChain & out_functions_chain) + MonotonicFunctionsChain & out_functions_chain) { std::vector chain_not_tested_for_monotonicity; DataTypePtr key_column_type; @@ -637,7 +637,7 @@ bool KeyCondition::atomFromAST(const ASTPtr & node, const Context & context, Blo DataTypePtr key_expr_type; /// Type of expression containing key column size_t key_arg_pos; /// Position of argument with key column (non-const argument) size_t key_column_num; /// Number of a key column (inside sort_descr array) - RPNElement::MonotonicFunctionsChain chain; + MonotonicFunctionsChain chain; bool is_set_const = false; bool is_constant_transformed = false; @@ -934,7 +934,7 @@ bool KeyCondition::mayBeTrueInRange( std::optional KeyCondition::applyMonotonicFunctionsChainToRange( Range key_range, - RPNElement::MonotonicFunctionsChain & functions, + MonotonicFunctionsChain & functions, DataTypePtr current_type ) { diff --git a/dbms/src/Storages/MergeTree/KeyCondition.h b/dbms/src/Storages/MergeTree/KeyCondition.h index c7d55b0a575..311dffd863a 100644 --- a/dbms/src/Storages/MergeTree/KeyCondition.h +++ b/dbms/src/Storages/MergeTree/KeyCondition.h @@ -257,6 +257,22 @@ public: String toString() const; + /** A chain of possibly monotone functions. + * If the key column is wrapped in functions that can be monotonous in some value ranges + * (for example: -toFloat64(toDayOfWeek(date))), then here the functions will be located: toDayOfWeek, toFloat64, negate. + */ + using MonotonicFunctionsChain = std::vector; + + + static Block getBlockWithConstants( + const ASTPtr & query, const Context & context, const NamesAndTypesList & all_columns); + + static std::optional applyMonotonicFunctionsChainToRange( + Range key_range, + MonotonicFunctionsChain & functions, + DataTypePtr current_type); + +private: /// The expression is stored as Reverse Polish Notation. struct RPNElement { @@ -289,35 +305,24 @@ public: /// For FUNCTION_IN_RANGE and FUNCTION_NOT_IN_RANGE. Range range; - size_t key_column; + size_t key_column = 0; /// For FUNCTION_IN_SET, FUNCTION_NOT_IN_SET ASTPtr in_function; using MergeTreeSetIndexPtr = std::shared_ptr; MergeTreeSetIndexPtr set_index; - /** A chain of possibly monotone functions. - * If the key column is wrapped in functions that can be monotonous in some value ranges - * (for example: -toFloat64(toDayOfWeek(date))), then here the functions will be located: toDayOfWeek, toFloat64, negate. - */ - using MonotonicFunctionsChain = std::vector; mutable MonotonicFunctionsChain monotonic_functions_chain; /// The function execution does not violate the constancy. }; - static Block getBlockWithConstants( - const ASTPtr & query, const Context & context, const NamesAndTypesList & all_columns); - - using AtomMap = std::unordered_map; - static const AtomMap atom_map; - - static std::optional applyMonotonicFunctionsChainToRange( - Range key_range, - RPNElement::MonotonicFunctionsChain & functions, - DataTypePtr current_type); - -private: using RPN = std::vector; using ColumnIndices = std::map; + using AtomMap = std::unordered_map; + +public: + static const AtomMap atom_map; +private: + bool mayBeTrueInRange( size_t used_key_size, const Field * left_key, @@ -342,7 +347,7 @@ private: const Context & context, size_t & out_key_column_num, DataTypePtr & out_key_res_column_type, - RPNElement::MonotonicFunctionsChain & out_functions_chain); + MonotonicFunctionsChain & out_functions_chain); bool isKeyPossiblyWrappedByMonotonicFunctionsImpl( const ASTPtr & node,