Skip to content

Commit d329f2b

Browse files
revert to resolution on secondary
1 parent 0848762 commit d329f2b

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

src/Interpreters/InterpreterCreateQuery.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,12 +1107,10 @@ void InterpreterCreateQuery::validateMaterializedViewColumnsAndEngine(const ASTC
11071107
{
11081108
if (getContext()->getSettingsRef()[Setting::allow_experimental_analyzer])
11091109
{
1110-
/*
1110+
/// We should treat SELECT as an initial query in order to properly analyze it.
11111111
auto context = Context::createCopy(getContext());
11121112
context->setQueryKindInitial();
1113-
input_block = InterpreterSelectQueryAnalyzer::getSampleBlock(create.select->clone(), context, SelectQueryOptions().ignoreASTOptimizations());
1114-
*/
1115-
input_block = InterpreterSelectQueryAnalyzer::getSampleBlock(create.select->clone(), getContext());
1113+
input_block = InterpreterSelectQueryAnalyzer::getSampleBlock(create.select->clone(), context, SelectQueryOptions{}.createView());
11161114
}
11171115
else
11181116
{
@@ -2315,13 +2313,6 @@ void InterpreterCreateQuery::prepareOnClusterQuery(ASTCreateQuery & create, Cont
23152313

23162314
BlockIO InterpreterCreateQuery::executeQueryOnCluster(ASTCreateQuery & create)
23172315
{
2318-
/// Rewrite SELECT query to resolve and qualify all expressions
2319-
if (create.select)
2320-
create.set(
2321-
create.select,
2322-
InterpreterSelectQueryAnalyzer(create.select->clone(), getContext(), SelectQueryOptions{}.analyze()).getQueryTree()->toAST()
2323-
);
2324-
23252316
prepareOnClusterQuery(create, getContext(), create.cluster);
23262317
DDLQueryOnClusterParams params;
23272318
params.access_to_check = getRequiredAccess();

src/Interpreters/InterpreterSelectQueryAnalyzer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ static QueryTreeNodePtr buildQueryTreeAndRunPasses(const ASTPtr & query,
158158
/// We should not apply any query tree level optimizations on shards
159159
/// because it can lead to a changed header.
160160
if (select_query_options.ignore_ast_optimizations
161+
|| select_query_options.is_create_view
161162
|| context->getClientInfo().query_kind == ClientInfo::QueryKind::SECONDARY_QUERY)
162163
query_tree_pass_manager.runOnlyResolve(query_tree);
163164
else

src/Interpreters/SelectQueryOptions.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct SelectQueryOptions
4545
bool is_create_parameterized_view = false;
4646
/// Bypass setting constraints for some internal queries such as projection ASTs.
4747
bool ignore_setting_constraints = false;
48+
bool is_create_view = false; /// this select is a part of CREATE [MATERIALIZED] VIEW query
4849

4950
/// Bypass access check for select query.
5051
/// This allows to skip double access check in some specific cases (e.g. insert into table with materialized view)
@@ -84,6 +85,12 @@ struct SelectQueryOptions
8485
return out;
8586
}
8687

88+
SelectQueryOptions & createView(bool value = true)
89+
{
90+
is_create_view = value;
91+
return *this;
92+
}
93+
8794
SelectQueryOptions createParameterizedView() const
8895
{
8996
SelectQueryOptions out = *this;

0 commit comments

Comments
 (0)