Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExpressionJIT fix short-circuit with alias #29574

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Interpreters/ExpressionJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,16 @@ static bool isCompilableConstant(const ActionsDAG::Node & node)
return node.column && isColumnConst(*node.column) && canBeNativeType(*node.result_type);
}

static const ActionsDAG::Node * removeAliasIfNecessary(const ActionsDAG::Node * node)
{
const ActionsDAG::Node * node_no_alias = node;

while (node_no_alias->type == ActionsDAG::ActionType::ALIAS)
node_no_alias = node_no_alias->children[0];

return node_no_alias;
}

static bool isCompilableFunction(const ActionsDAG::Node & node, const std::unordered_set<const ActionsDAG::Node *> & lazy_executed_nodes)
{
if (node.type != ActionsDAG::ActionType::FUNCTION)
Expand All @@ -336,7 +346,9 @@ static bool isCompilableFunction(const ActionsDAG::Node & node, const std::unord
{
for (const auto & child : node.children)
{
if (lazy_executed_nodes.contains(child))
const ActionsDAG::Node * child_no_alias = removeAliasIfNecessary(child);

if (lazy_executed_nodes.contains(child_no_alias))
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
12 changes: 12 additions & 0 deletions tests/queries/0_stateless/02036_jit_short_circuit.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SET compile_expressions = 1;
SET min_count_to_compile_expression = 0;
SET short_circuit_function_evaluation='enable';

DROP TABLE IF EXISTS test_table;
CREATE TABLE test_table (message String) ENGINE=TinyLog;

INSERT INTO test_table VALUES ('Test');

SELECT if(action = 'bonus', sport_amount, 0) * 100 FROM (SELECT message AS action, cast(message, 'Float64') AS sport_amount FROM test_table);

DROP TABLE test_table;