Apply patch from @azat

This commit is contained in:
Alexey Milovidov 2021-08-10 00:48:44 +03:00
parent 664d492dff
commit 4b4cd59ea7

View File

@ -18,6 +18,7 @@
#include <Interpreters/FunctionNameNormalizer.h>
#include <Interpreters/ReplaceQueryParameterVisitor.h>
#include <Poco/Util/AbstractConfiguration.h>
#include <unordered_map>
namespace DB
{
@ -339,6 +340,7 @@ std::optional<Blocks> evaluateExpressionOverConstantCondition(const ASTPtr & nod
if (const auto * fn = node->as<ASTFunction>())
{
std::unordered_map<std::string, bool> always_false_map;
const auto dnf = analyzeFunction(fn, target_expr, limit);
if (dnf.empty() || !limit)
@ -388,8 +390,19 @@ std::optional<Blocks> evaluateExpressionOverConstantCondition(const ASTPtr & nod
Field prev_value = assert_cast<const ColumnConst &>(*prev.column).getField();
Field curr_value = assert_cast<const ColumnConst &>(*elem.column).getField();
if (prev_value != curr_value)
return Blocks{};
if (!always_false_map.count(elem.name))
{
always_false_map[elem.name] = prev_value != curr_value;
}
else
{
auto & always_false = always_false_map[elem.name];
/// If at least one of conjunct is not always false, we should preserve this.
if (always_false)
{
always_false = prev_value != curr_value;
}
}
}
}
}
@ -417,6 +430,11 @@ std::optional<Blocks> evaluateExpressionOverConstantCondition(const ASTPtr & nod
return {};
}
}
bool any_always_false = std::any_of(always_false_map.begin(), always_false_map.end(), [](const auto & v) { return v.second; });
if (any_always_false)
return Blocks{};
}
else if (const auto * literal = node->as<ASTLiteral>())
{