Backport #63930 to 24.3: Fix analyzer: there's turtles all the way down...

This commit is contained in:
robot-clickhouse 2024-05-17 04:06:22 +00:00
parent 32ef90ed66
commit e5a2bdfa04
3 changed files with 29 additions and 2 deletions

View File

@ -5604,9 +5604,13 @@ ProjectionNames QueryAnalyzer::resolveFunction(QueryTreeNodePtr & node, Identifi
/// Replace storage with values storage of insertion block
if (StoragePtr storage = scope.context->getViewSource())
{
if (auto * query_node = in_second_argument->as<QueryNode>())
QueryTreeNodePtr table_expression;
/// Process possibly nested sub-selects
for (auto * query_node = in_second_argument->as<QueryNode>(); query_node; query_node = table_expression->as<QueryNode>())
table_expression = extractLeftTableExpression(query_node->getJoinTree());
if (table_expression)
{
auto table_expression = extractLeftTableExpression(query_node->getJoinTree());
if (auto * query_table_node = table_expression->as<TableNode>())
{
if (query_table_node->getStorageID().getFullNameNotQuoted() == storage->getStorageID().getFullNameNotQuoted())

View File

@ -0,0 +1,4 @@
0
1
0
1

View File

@ -0,0 +1,19 @@
-- https://github.com/ClickHouse/ClickHouse/issues/63833
SET allow_experimental_analyzer = 1;
create table Example (id Int32) engine = MergeTree ORDER BY id;
INSERT INTO Example SELECT number AS id FROM numbers(2);
create table Null engine=Null as Example ;
--create table Null engine=MergeTree order by id as Example ;
create materialized view Transform to Example as
select * from Null
join ( select * FROM Example
WHERE id IN (SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT * FROM Null)))))
) as old
using id;
INSERT INTO Null SELECT number AS id FROM numbers(2);
select * from Example; -- should return 4 rows