Backport #66400 to 24.6: Do not check parent scope for group_by_use_nulls outside of subquery.

This commit is contained in:
robot-clickhouse 2024-07-16 17:07:39 +00:00
parent 293a9a0c6c
commit 75a04c87e6
3 changed files with 90 additions and 0 deletions

View File

@ -3823,6 +3823,10 @@ ProjectionNames QueryAnalyzer::resolveExpressionNode(QueryTreeNodePtr & node, Id
node->convertToNullable();
break;
}
/// Check parent scopes until find current query scope.
if (scope_ptr->scope_node->getNodeType() == QueryTreeNodeType::QUERY)
break;
}
}

View File

@ -264,3 +264,44 @@ SETTINGS group_by_use_nulls = 1, max_bytes_before_external_sort=10;
9 \N 9
\N 0 20
\N 1 25
CREATE TABLE test
ENGINE = ReplacingMergeTree
PRIMARY KEY id
AS SELECT number AS id FROM numbers(100);
SELECT id
FROM test
GROUP BY id
WITH CUBE
HAVING id IN (
SELECT id
FROM test
)
FORMAT `NUll`
SETTINGS allow_experimental_analyzer = 1, group_by_use_nulls = true;
SELECT id
FROM test
FINAL
GROUP BY id
WITH CUBE
HAVING id IN (
SELECT DISTINCT id
FROM test
FINAL
)
FORMAT `NUll`
SETTINGS allow_experimental_analyzer = 1, group_by_use_nulls = true;
SELECT id
FROM test
FINAL
GROUP BY
GROUPING SETS ((id))
ORDER BY
id IN (
SELECT DISTINCT id
FROM test
FINAL
LIMIT 4
) ASC
LIMIT 256 BY id
FORMAT `NUll`
SETTINGS allow_experimental_analyzer = 1, group_by_use_nulls=true;

View File

@ -83,3 +83,48 @@ GROUP BY
)
ORDER BY 1, tuple(val)
SETTINGS group_by_use_nulls = 1, max_bytes_before_external_sort=10;
CREATE TABLE test
ENGINE = ReplacingMergeTree
PRIMARY KEY id
AS SELECT number AS id FROM numbers(100);
SELECT id
FROM test
GROUP BY id
WITH CUBE
HAVING id IN (
SELECT id
FROM test
)
FORMAT `NUll`
SETTINGS allow_experimental_analyzer = 1, group_by_use_nulls = true;
SELECT id
FROM test
FINAL
GROUP BY id
WITH CUBE
HAVING id IN (
SELECT DISTINCT id
FROM test
FINAL
)
FORMAT `NUll`
SETTINGS allow_experimental_analyzer = 1, group_by_use_nulls = true;
SELECT id
FROM test
FINAL
GROUP BY
GROUPING SETS ((id))
ORDER BY
id IN (
SELECT DISTINCT id
FROM test
FINAL
LIMIT 4
) ASC
LIMIT 256 BY id
FORMAT `NUll`
SETTINGS allow_experimental_analyzer = 1, group_by_use_nulls=true;