Merge pull request #66948 from ClickHouse/backport/24.5/66655

Backport #66655 to 24.5: Allow scalar subquery in the first argument of IN with new analyzer.
This commit is contained in:
Dmitry Novik 2024-07-30 18:36:11 +02:00 committed by GitHub
commit 737b736765
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 4 deletions

View File

@ -5736,6 +5736,17 @@ ProjectionNames QueryAnalyzer::resolveFunction(QueryTreeNodePtr & node, Identifi
resolveExpressionNode(in_second_argument, scope, false /*allow_lambda_expression*/, true /*allow_table_expression*/);
}
/// Edge case when the first argument of IN is scalar subquery.
auto & in_first_argument = function_in_arguments_nodes[0];
auto first_argument_type = in_first_argument->getNodeType();
if (first_argument_type == QueryTreeNodeType::QUERY || first_argument_type == QueryTreeNodeType::UNION)
{
IdentifierResolveScope subquery_scope(in_first_argument, &scope /*parent_scope*/);
subquery_scope.subquery_depth = scope.subquery_depth + 1;
evaluateScalarSubqueryIfNeeded(in_first_argument, subquery_scope);
}
}
/// Initialize function argument columns

View File

@ -12,3 +12,6 @@
1
1
0
1
1
1

View File

@ -17,7 +17,11 @@ SELECT 1 IN [1, 2];
SELECT (1, 1) IN [(1, 1), (1, 2)];
SELECT (1, 1) IN [(1, 2), (1, 2)];
SELECT (1, 2) IN 1; -- { serverError 43 }
SELECT (1, 2) IN [1]; -- { serverError 124 }
SELECT (1, 2) IN (((1, 2), (1, 2)), ((1, 2), (1, 2))); -- { serverError 43 }
SELECT (1, 2) IN [((1, 2), (1, 2)), ((1, 2), (1, 2))]; -- { serverError 43 }
SELECT (1, 2) IN 1; -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
SELECT (1, 2) IN [1]; -- { serverError INCORRECT_ELEMENT_OF_SET }
SELECT (1, 2) IN (((1, 2), (1, 2)), ((1, 2), (1, 2))); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
SELECT (1, 2) IN [((1, 2), (1, 2)), ((1, 2), (1, 2))]; -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
select (select 1) in (1);
select in(untuple(((1), (1))));
select in(untuple(((select 1), (1))));