Add setting optimize_short_circuit_function_evaluation

This commit is contained in:
Pavel Kruglov 2021-08-13 14:48:32 +03:00
parent fc59c98676
commit 36bea6abb4
7 changed files with 13 additions and 11 deletions

View File

@ -94,9 +94,6 @@ size_t extractMaskNumericImpl(
size_t index;
if constexpr (column_is_short)
{
if (data_index >= data.size())
throw Exception("Amount of ones in the mask doesn't equal short column size", ErrorCodes::LOGICAL_ERROR);
index = data_index;
++data_index;
}

View File

@ -492,6 +492,7 @@ class IColumn;
\
M(UInt64, function_range_max_elements_in_block, 500000000, "Maximum number of values generated by function 'range' per block of data (sum of array sizes for every row in a block, see also 'max_block_size' and 'min_insert_block_size_rows'). It is a safety threshold.", 0) \
M(Bool, use_short_circuit_function_evaluation, true, "Enable short-circuit function evaluation", 0) \
M(Bool, optimize_short_circuit_function_evaluation, true, "Enable lazy execution only for heavy functions or for functions that can throw", 0) \
\
/** Experimental functions */ \
M(Bool, allow_experimental_funnel_functions, false, "Enable experimental functions for funnel analysis.", 0) \

View File

@ -957,7 +957,8 @@ public:
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & arguments) const override
{
return (IsOperation<Op>::div_int || IsOperation<Op>::modulo) && !arguments[1].is_const;
return ((IsOperation<Op>::div_int || IsOperation<Op>::modulo) && !arguments[1].is_const)
|| (IsOperation<Op>::div_floating && (isDecimal(arguments[0].type) || isDecimal(arguments[1].type)));
}
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override

View File

@ -61,8 +61,6 @@ struct IsOperation
plus || minus || multiply ||
div_floating || div_int || div_int_or_zero ||
least || greatest;
static constexpr bool can_throw = div_int || modulo;
};
}

View File

@ -47,7 +47,7 @@ namespace ErrorCodes
ExpressionActions::~ExpressionActions() = default;
static std::unordered_set<const ActionsDAG::Node *> processShortCircuitFunctions(const ActionsDAG & actions_dag);
static std::unordered_set<const ActionsDAG::Node *> processShortCircuitFunctions(const ActionsDAG & actions_dag, bool optimize_short_circuit_function_evaluation);
ExpressionActions::ExpressionActions(ActionsDAGPtr actions_dag_, const ExpressionActionsSettings & settings_)
: settings(settings_)
@ -57,7 +57,7 @@ ExpressionActions::ExpressionActions(ActionsDAGPtr actions_dag_, const Expressio
/// It's important to determine lazy executed nodes before compiling expressions.
std::unordered_set<const ActionsDAG::Node *> lazy_executed_nodes;
if (settings.use_short_circuit_function_evaluation)
lazy_executed_nodes = processShortCircuitFunctions(*actions_dag);
lazy_executed_nodes = processShortCircuitFunctions(*actions_dag, settings.optimize_short_circuit_function_evaluation);
#if USE_EMBEDDED_COMPILER
if (settings.can_compile_expressions && settings.compile_expressions == CompileExpressions::yes)
@ -278,7 +278,7 @@ static bool findLazyExecutedNodes(
return has_lazy_node;
}
static std::unordered_set<const ActionsDAG::Node *> processShortCircuitFunctions(const ActionsDAG & actions_dag)
static std::unordered_set<const ActionsDAG::Node *> processShortCircuitFunctions(const ActionsDAG & actions_dag, bool optimize_short_circuit_function_evaluation)
{
const auto & nodes = actions_dag.getNodes();
@ -302,10 +302,13 @@ static std::unordered_set<const ActionsDAG::Node *> processShortCircuitFunctions
for (const auto & [node, settings] : short_circuit_nodes)
{
/// Recursively find nodes that should be lazy executed.
findLazyExecutedNodes(node->children, lazy_execution_infos, settings.force_enable_lazy_execution, lazy_executed_nodes);
findLazyExecutedNodes(
node->children,
lazy_execution_infos,
settings.force_enable_lazy_execution || !optimize_short_circuit_function_evaluation,
lazy_executed_nodes);
}
return lazy_executed_nodes;
}
void ExpressionActions::linearizeActions(const std::unordered_set<const ActionsDAG::Node *> & lazy_executed_nodes)

View File

@ -15,6 +15,7 @@ ExpressionActionsSettings ExpressionActionsSettings::fromSettings(const Settings
settings.max_temporary_non_const_columns = from.max_temporary_non_const_columns;
settings.compile_expressions = compile_expressions;
settings.use_short_circuit_function_evaluation = from.use_short_circuit_function_evaluation;
settings.optimize_short_circuit_function_evaluation = from.optimize_short_circuit_function_evaluation;
return settings;
}

View File

@ -26,6 +26,7 @@ struct ExpressionActionsSettings
CompileExpressions compile_expressions = CompileExpressions::no;
bool use_short_circuit_function_evaluation = false;
bool optimize_short_circuit_function_evaluation = false;
static ExpressionActionsSettings fromSettings(const Settings & from, CompileExpressions compile_expressions = CompileExpressions::no);
static ExpressionActionsSettings fromContext(ContextPtr from, CompileExpressions compile_expressions = CompileExpressions::no);