diff --git a/src/Analyzer/Passes/ConvertInToEqualPass.cpp b/src/Analyzer/Passes/ConvertInToEqualPass.cpp index ce2cec9f9ed..45b8a91f7ad 100644 --- a/src/Analyzer/Passes/ConvertInToEqualPass.cpp +++ b/src/Analyzer/Passes/ConvertInToEqualPass.cpp @@ -32,9 +32,12 @@ public: auto * constant_node = args[1]->as(); if (!column_node || !constant_node) return ; + // IN multiple values is not supported if (constant_node->getValue().getType() == Field::Types::Which::Tuple) - return; - + return ; + // x IN null not equivalent to x = null + if (constant_node->hasSourceExpression() || constant_node->getValue().isNull()) + return ; auto equal_resolver = createInternalFunctionEqualOverloadResolver(); auto equal = std::make_shared("equals"); QueryTreeNodes arguments{column_node->clone(), constant_node->clone()}; diff --git a/tests/queries/0_stateless/03013_optimize_in_to_equal.reference b/tests/queries/0_stateless/03013_optimize_in_to_equal.reference index f55a7b76eaf..9ef4de0f607 100644 --- a/tests/queries/0_stateless/03013_optimize_in_to_equal.reference +++ b/tests/queries/0_stateless/03013_optimize_in_to_equal.reference @@ -1,5 +1,11 @@ a 1 ------------------- +0 +0 +0 +0 +0 +------------------- QUERY id: 0 PROJECTION COLUMNS x String diff --git a/tests/queries/0_stateless/03013_optimize_in_to_equal.sql b/tests/queries/0_stateless/03013_optimize_in_to_equal.sql index 9d80825ceb4..e4dba3a0aa2 100644 --- a/tests/queries/0_stateless/03013_optimize_in_to_equal.sql +++ b/tests/queries/0_stateless/03013_optimize_in_to_equal.sql @@ -5,6 +5,8 @@ INSERT INTO test VALUES ('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5); select * from test where x in ('a') SETTINGS allow_experimental_analyzer = 1; select '-------------------'; +select x in Null from test; +select '-------------------'; explain query tree select * from test where x in ('a') SETTINGS allow_experimental_analyzer = 1; select '-------------------'; -explain query tree select * from test where x in ('a','b') SETTINGS allow_experimental_analyzer = 1; \ No newline at end of file +explain query tree select * from test where x in ('a','b') SETTINGS allow_experimental_analyzer = 1;