Created
August 9, 2021 20:48
-
-
Save azat/77537536e39612979bfa60881f740570 to your computer and use it in GitHub Desktop.
[PATCH] Fix always false check in evaluateConstantExpression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 111f1566e13efd03c4b72b2325b2254284d17fe8 Mon Sep 17 00:00:00 2001 | |
From: Azat Khuzhin <a3at.mail@gmail.com> | |
Date: Mon, 9 Aug 2021 23:23:39 +0300 | |
Subject: [PATCH] Fix always false check in evaluateConstantExpression | |
--- | |
.../evaluateConstantExpression.cpp | 22 +++++++++++++++++-- | |
1 file changed, 20 insertions(+), 2 deletions(-) | |
diff --git a/src/Interpreters/evaluateConstantExpression.cpp b/src/Interpreters/evaluateConstantExpression.cpp | |
index 6a2e559a07..5ce68bab68 100644 | |
--- a/src/Interpreters/evaluateConstantExpression.cpp | |
+++ b/src/Interpreters/evaluateConstantExpression.cpp | |
@@ -18,6 +18,7 @@ | |
#include <Interpreters/FunctionNameNormalizer.h> | |
#include <Interpreters/ReplaceQueryParameterVisitor.h> | |
#include <Poco/Util/AbstractConfiguration.h> | |
+#include <unordered_map> | |
namespace | |
{ | |
@@ -368,6 +369,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) | |
@@ -420,8 +422,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; | |
+ } | |
+ } | |
} | |
} | |
} | |
@@ -449,6 +462,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>()) | |
{ | |
-- | |
2.32.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment