mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 17:41:59 +00:00
Merge pull request #50857 from ClickHouse/fix-analyzer-mv-scalars
Fix analyzer - insertion from select with subquery referencing insertion table should process only insertion block.
This commit is contained in:
commit
3096edf3ef
@ -1952,7 +1952,7 @@ void QueryAnalyzer::evaluateScalarSubqueryIfNeeded(QueryTreeNodePtr & node, Iden
|
|||||||
subquery_context->setSetting("use_structure_from_insertion_table_in_table_functions", false);
|
subquery_context->setSetting("use_structure_from_insertion_table_in_table_functions", false);
|
||||||
|
|
||||||
auto options = SelectQueryOptions(QueryProcessingStage::Complete, scope.subquery_depth, true /*is_subquery*/);
|
auto options = SelectQueryOptions(QueryProcessingStage::Complete, scope.subquery_depth, true /*is_subquery*/);
|
||||||
auto interpreter = std::make_unique<InterpreterSelectQueryAnalyzer>(node->toAST(), subquery_context, options);
|
auto interpreter = std::make_unique<InterpreterSelectQueryAnalyzer>(node->toAST(), subquery_context, subquery_context->getViewSource(), options);
|
||||||
|
|
||||||
auto io = interpreter->execute();
|
auto io = interpreter->execute();
|
||||||
|
|
||||||
@ -4896,6 +4896,25 @@ ProjectionNames QueryAnalyzer::resolveFunction(QueryTreeNodePtr & node, Identifi
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/// Replace storage with values storage of insertion block
|
||||||
|
if (StoragePtr storage = scope.context->getViewSource())
|
||||||
|
{
|
||||||
|
if (auto * query_node = in_second_argument->as<QueryNode>())
|
||||||
|
{
|
||||||
|
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())
|
||||||
|
{
|
||||||
|
auto replacement_table_expression = std::make_shared<TableNode>(storage, scope.context);
|
||||||
|
if (std::optional<TableExpressionModifiers> table_expression_modifiers = query_table_node->getTableExpressionModifiers())
|
||||||
|
replacement_table_expression->setTableExpressionModifiers(*table_expression_modifiers);
|
||||||
|
in_second_argument = in_second_argument->cloneAndReplace(table_expression, std::move(replacement_table_expression));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
resolveExpressionNode(in_second_argument, scope, false /*allow_lambda_expression*/, true /*allow_table_expression*/);
|
resolveExpressionNode(in_second_argument, scope, false /*allow_lambda_expression*/, true /*allow_table_expression*/);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,6 +109,10 @@ void replaceStorageInQueryTree(QueryTreeNodePtr & query_tree, const ContextPtr &
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Don't replace storage if table name differs
|
||||||
|
if (auto * table_node = table_expression_to_replace->as<TableNode>(); table_node && table_node->getStorageID().getFullNameNotQuoted() != storage->getStorageID().getFullNameNotQuoted())
|
||||||
|
return;
|
||||||
|
|
||||||
auto replacement_table_expression = std::make_shared<TableNode>(storage, context);
|
auto replacement_table_expression = std::make_shared<TableNode>(storage, context);
|
||||||
std::optional<TableExpressionModifiers> table_expression_modifiers;
|
std::optional<TableExpressionModifiers> table_expression_modifiers;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user