mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
Disable logical expression optimizer for expression with aliases. Never use it with optimize_min_equality_disjunction_chain_length=0
This commit is contained in:
parent
6a086ab926
commit
aaecc233b2
@ -119,7 +119,7 @@ void LogicalExpressionsOptimizer::collectDisjunctiveEqualityChains()
|
||||
bool found_chain = false;
|
||||
|
||||
auto * function = to_node->as<ASTFunction>();
|
||||
if (function && function->name == "or" && function->children.size() == 1)
|
||||
if (function && function->alias.empty() && function->name == "or" && function->children.size() == 1)
|
||||
{
|
||||
const auto * expression_list = function->children[0]->as<ASTExpressionList>();
|
||||
if (expression_list)
|
||||
@ -128,14 +128,14 @@ void LogicalExpressionsOptimizer::collectDisjunctiveEqualityChains()
|
||||
for (const auto & child : expression_list->children)
|
||||
{
|
||||
auto * equals = child->as<ASTFunction>();
|
||||
if (equals && equals->name == "equals" && equals->children.size() == 1)
|
||||
if (equals && equals->alias.empty() && equals->name == "equals" && equals->children.size() == 1)
|
||||
{
|
||||
const auto * equals_expression_list = equals->children[0]->as<ASTExpressionList>();
|
||||
if (equals_expression_list && equals_expression_list->children.size() == 2)
|
||||
{
|
||||
/// Equality expr = xN.
|
||||
const auto * literal = equals_expression_list->children[1]->as<ASTLiteral>();
|
||||
if (literal)
|
||||
if (literal && literal->alias.empty())
|
||||
{
|
||||
auto expr_lhs = equals_expression_list->children[0]->getTreeHash();
|
||||
OrWithExpression or_with_expression{function, expr_lhs, function->tryGetAlias()};
|
||||
@ -230,6 +230,9 @@ bool LogicalExpressionsOptimizer::mayOptimizeDisjunctiveEqualityChain(const Disj
|
||||
const auto & equalities = chain.second;
|
||||
const auto & equality_functions = equalities.functions;
|
||||
|
||||
if (settings.optimize_min_equality_disjunction_chain_length == 0)
|
||||
return false;
|
||||
|
||||
/// For LowCardinality column, the dict is usually smaller and the index is relatively large.
|
||||
/// In most cases, merging OR-chain as IN is better than converting each LowCardinality into full column individually.
|
||||
/// For non-LowCardinality, we need to eliminate too short chains.
|
||||
|
@ -0,0 +1 @@
|
||||
0
|
@ -0,0 +1,2 @@
|
||||
create table test_local (id UInt32, path LowCardinality(String)) engine = MergeTree order by id;
|
||||
WITH ((position(path, '/a') > 0) AND (NOT (position(path, 'a') > 0))) OR (path = '/b') OR (path = '/b/') as alias1 SELECT max(alias1) FROM remote('127.0.0.{1,2}', currentDatabase(), test_local) WHERE (id = 299386662);
|
Loading…
Reference in New Issue
Block a user