mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 16:12:01 +00:00
Slightly better (preparation) [#CLICKHOUSE-3]
This commit is contained in:
parent
df11490b2a
commit
e5682e81f7
@ -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<const ASTFunction *> 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<Range> KeyCondition::applyMonotonicFunctionsChainToRange(
|
||||
Range key_range,
|
||||
RPNElement::MonotonicFunctionsChain & functions,
|
||||
MonotonicFunctionsChain & functions,
|
||||
DataTypePtr current_type
|
||||
)
|
||||
{
|
||||
|
@ -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<FunctionBasePtr>;
|
||||
|
||||
|
||||
static Block getBlockWithConstants(
|
||||
const ASTPtr & query, const Context & context, const NamesAndTypesList & all_columns);
|
||||
|
||||
static std::optional<Range> 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<MergeTreeSetIndex>;
|
||||
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<FunctionBasePtr>;
|
||||
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<std::string, bool(*)(RPNElement & out, const Field & value, const ASTPtr & node)>;
|
||||
static const AtomMap atom_map;
|
||||
|
||||
static std::optional<Range> applyMonotonicFunctionsChainToRange(
|
||||
Range key_range,
|
||||
RPNElement::MonotonicFunctionsChain & functions,
|
||||
DataTypePtr current_type);
|
||||
|
||||
private:
|
||||
using RPN = std::vector<RPNElement>;
|
||||
using ColumnIndices = std::map<String, size_t>;
|
||||
|
||||
using AtomMap = std::unordered_map<std::string, bool(*)(RPNElement & out, const Field & value, const ASTPtr & node)>;
|
||||
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user