Merge pull request #56232 from evillique/fix-startup-crash

Fix a crash during table loading on startup
This commit is contained in:
Nikolay Degterinsky 2023-11-03 23:28:16 +01:00 committed by GitHub
commit 35d785592b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -78,16 +78,19 @@ static auto getQueryInterpreter(const ASTSubquery & subquery, ExecuteScalarSubqu
subquery_settings.extremes = false;
subquery_context->setSettings(subquery_settings);
/// When execute `INSERT INTO t WITH ... SELECT ...`, it may lead to `Unknown columns`
/// exception with this settings enabled(https://github.com/ClickHouse/ClickHouse/issues/52494).
subquery_context->getQueryContext()->setSetting("use_structure_from_insertion_table_in_table_functions", false);
if (!data.only_analyze && subquery_context->hasQueryContext())
if (subquery_context->hasQueryContext())
{
/// Save current cached scalars in the context before analyzing the query
/// This is specially helpful when analyzing CTE scalars
auto context = subquery_context->getQueryContext();
for (const auto & it : data.scalars)
context->addScalar(it.first, it.second);
/// When execute `INSERT INTO t WITH ... SELECT ...`, it may lead to `Unknown columns`
/// exception with this settings enabled(https://github.com/ClickHouse/ClickHouse/issues/52494).
subquery_context->getQueryContext()->setSetting("use_structure_from_insertion_table_in_table_functions", false);
if (!data.only_analyze)
{
/// Save current cached scalars in the context before analyzing the query
/// This is specially helpful when analyzing CTE scalars
auto context = subquery_context->getQueryContext();
for (const auto & it : data.scalars)
context->addScalar(it.first, it.second);
}
}
ASTPtr subquery_select = subquery.children.at(0);