diff --git a/src/DataStreams/PushingToViewsBlockOutputStream.cpp b/src/DataStreams/PushingToViewsBlockOutputStream.cpp index a79cc61bd2d..4bf6fb7e1e9 100644 --- a/src/DataStreams/PushingToViewsBlockOutputStream.cpp +++ b/src/DataStreams/PushingToViewsBlockOutputStream.cpp @@ -93,6 +93,10 @@ PushingToViewsBlockOutputStream::PushingToViewsBlockOutputStream( views.emplace_back(ViewInfo{std::move(query), database_table, std::move(out)}); } + /// Remove calculated scalar subquery results, because they can be calculated for real, not substituted tables. + if (views_context->hasQueryContext()) + views_context->getQueryContext().dropScalars(); + /// Do not push to destination table if the flag is set if (!no_destination) { diff --git a/src/Interpreters/Context.cpp b/src/Interpreters/Context.cpp index f5651a1ab77..912fdeb4fbc 100644 --- a/src/Interpreters/Context.cpp +++ b/src/Interpreters/Context.cpp @@ -885,6 +885,12 @@ bool Context::hasScalar(const String & name) const } +void Context::dropScalars() +{ + scalars.clear(); +} + + StoragePtr Context::executeTableFunction(const ASTPtr & table_expression) { /// Slightly suboptimal. diff --git a/src/Interpreters/Context.h b/src/Interpreters/Context.h index 0d2b3cdb5af..d2448e78440 100644 --- a/src/Interpreters/Context.h +++ b/src/Interpreters/Context.h @@ -330,6 +330,7 @@ public: const Block & getScalar(const String & name) const; void addScalar(const String & name, const Block & block); bool hasScalar(const String & name) const; + void dropScalars(); StoragePtr executeTableFunction(const ASTPtr & table_expression);