diff --git a/src/Interpreters/evaluateConstantExpression.cpp b/src/Interpreters/evaluateConstantExpression.cpp index 42e96bae07b..db19c000cfd 100644 --- a/src/Interpreters/evaluateConstantExpression.cpp +++ b/src/Interpreters/evaluateConstantExpression.cpp @@ -290,8 +290,6 @@ std::optional evaluateExpressionOverConstantCondition(const ASTPtr & nod { Blocks result; - // TODO: `node` may be always-false literal. - if (const auto * fn = node->as()) { const auto dnf = analyzeFunction(fn, target_expr); @@ -350,6 +348,14 @@ std::optional evaluateExpressionOverConstantCondition(const ASTPtr & nod } } } + else if (const auto * literal = node->as()) + { + // Check if it's always true or false. + if (literal->value.getType() == Field::Types::UInt64 && literal->value.get() == 0) + return {result}; + else + return {}; + } return {result}; } diff --git a/tests/queries/0_stateless/01755_shard_pruning_with_literal.reference b/tests/queries/0_stateless/01755_shard_pruning_with_literal.reference new file mode 100644 index 00000000000..6ed281c757a --- /dev/null +++ b/tests/queries/0_stateless/01755_shard_pruning_with_literal.reference @@ -0,0 +1,2 @@ +1 +1 diff --git a/tests/queries/0_stateless/01755_shard_pruning_with_literal.sql b/tests/queries/0_stateless/01755_shard_pruning_with_literal.sql new file mode 100644 index 00000000000..0e93d76573c --- /dev/null +++ b/tests/queries/0_stateless/01755_shard_pruning_with_literal.sql @@ -0,0 +1,14 @@ +set optimize_skip_unused_shards=1; + +drop table if exists data_01755; +drop table if exists dist_01755; + +create table data_01755 (i Int) Engine=Memory; +create table dist_01755 as data_01755 Engine=Distributed(test_cluster_two_shards, currentDatabase(), data_01755, i); + +insert into data_01755 values (1); + +select * from dist_01755 where 1 settings enable_early_constant_folding = 0; + +drop table if exists data_01755; +drop table if exists dist_01755;