Skip to content

Commit b822e54

Browse files
committed
improve performance of countif
1 parent c8cb101 commit b822e54

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/Analyzer/Passes/RewriteAggregateFunctionWithIfPass.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,9 @@ class RewriteAggregateFunctionWithIfVisitor : public InDepthQueryTreeVisitorWith
7272

7373
QueryTreeNodes new_arguments{2};
7474

75-
/// We need to preserve the output type from if()
76-
if (if_arguments_nodes[1]->getResultType()->getName() != if_node->getResultType()->getName())
77-
{
78-
/// For count, adding an extra cast is too heavy for the benefit.
79-
if (lower_name == "count")
80-
return;
81-
75+
/// We need to preserve the output type from if(). Notice that the return type of count() is the same either way
76+
if (if_arguments_nodes[1]->getResultType()->getName() != if_node->getResultType()->getName() && lower_name != "count")
8277
new_arguments[0] = createCastFunction(std::move(if_arguments_nodes[1]), if_node->getResultType(), getContext());
83-
}
8478
else
8579
new_arguments[0] = std::move(if_arguments_nodes[1]);
8680

@@ -105,14 +99,9 @@ class RewriteAggregateFunctionWithIfVisitor : public InDepthQueryTreeVisitorWith
10599

106100
QueryTreeNodes new_arguments{2};
107101

108-
if (if_arguments_nodes[2]->getResultType()->getName() != if_node->getResultType()->getName())
109-
{
110-
/// For count, adding an extra cast is too heavy for the benefit.
111-
if (lower_name == "count")
112-
return;
113-
102+
/// We need to preserve the output type from if(). Notice that the return type of count() is the same either way
103+
if (if_arguments_nodes[2]->getResultType()->getName() != if_node->getResultType()->getName() && lower_name != "count")
114104
new_arguments[0] = createCastFunction(std::move(if_arguments_nodes[2]), if_node->getResultType(), getContext());
115-
}
116105
else
117106
new_arguments[0] = std::move(if_arguments_nodes[2]);
118107

0 commit comments

Comments
 (0)