diff --git a/dbms/src/Interpreters/LogicalExpressionsOptimizer.cpp b/dbms/src/Interpreters/LogicalExpressionsOptimizer.cpp index b53a25909ce..1ac667fb209 100644 --- a/dbms/src/Interpreters/LogicalExpressionsOptimizer.cpp +++ b/dbms/src/Interpreters/LogicalExpressionsOptimizer.cpp @@ -197,7 +197,8 @@ void LogicalExpressionsOptimizer::addInExpression(const DisjunctiveEqualityChain value_list->children.push_back(operands[1]); } - /// Отсортировать литералы. + /// Отсортировать литералы, чтобы они были указаны в одном и том же порядке в выражении IN. + /// Иначе они указывались бы в порядке адресов ASTLiteral, который недетерминирован. std::sort(value_list->children.begin(), value_list->children.end(), [](const DB::ASTPtr & lhs, const DB::ASTPtr & rhs) { const auto val_lhs = static_cast(&*lhs); diff --git a/dbms/tests/queries/0_stateless/00234_disjunctive_equality_chains_optimization.reference b/dbms/tests/queries/0_stateless/00234_disjunctive_equality_chains_optimization.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/dbms/tests/queries/0_stateless/00234_disjunctive_equality_chains_optimization.sql b/dbms/tests/queries/0_stateless/00234_disjunctive_equality_chains_optimization.sql new file mode 100644 index 00000000000..10a25cfeea0 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00234_disjunctive_equality_chains_optimization.sql @@ -0,0 +1,4 @@ +CREATE TABLE IF NOT EXISTS test.foo(id UInt64) Engine=Memory; +INSERT INTO test.foo(id) VALUES (0),(4),(1),(1),(3),(1),(1),(2),(2),(2),(1),(2),(3),(2),(1),(1),(2),(1),(1),(1),(3),(1),(2),(2),(1),(1),(3),(1),(2),(1),(1),(3),(2),(1),(1),(4),(0); +SELECT sum(id = 3 OR id = 1 OR id = 2) AS x, sum(id = 3 OR id = 1 OR id = 2) AS x FROM test.foo; +DROP TABLE test.foo;