mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-04 13:32:13 +00:00
Update evaluateConstantExpression
This commit is contained in:
parent
15182772cc
commit
c084ce52bf
@ -362,7 +362,6 @@ 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)
|
||||
@ -394,6 +393,7 @@ std::optional<Blocks> evaluateExpressionOverConstantCondition(const ASTPtr & nod
|
||||
for (const auto & conjunct : dnf)
|
||||
{
|
||||
Block block;
|
||||
bool always_false = false;
|
||||
|
||||
for (const auto & elem : conjunct)
|
||||
{
|
||||
@ -412,23 +412,16 @@ 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 (!always_false_map.contains(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;
|
||||
}
|
||||
}
|
||||
always_false = prev_value != curr_value;
|
||||
if (always_false)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (always_false)
|
||||
continue;
|
||||
|
||||
// Block should contain all required columns from `target_expr`
|
||||
if (!has_required_columns(block))
|
||||
{
|
||||
@ -452,11 +445,6 @@ 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>())
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user