@@ -964,7 +964,11 @@ bool InsertDependenciesBuilder::observePath(const DependencyPath & path)
964964 select_contexts[root_view] = select_context;
965965 insert_contexts[root_view] = insert_context;
966966 input_headers[root_view] = init_header;
967- thread_groups[root_view] = CurrentThread::getGroup ();
967+ // / For background tasks (i.e. Buffer flush) there may not be any group
968+ if (auto thread_group = CurrentThread::getGroup ())
969+ thread_groups[root_view] = thread_group;
970+ else
971+ thread_groups[root_view] = ThreadGroup::createForMaterializedView (init_context);
968972 views_error_registry->init (root_view);
969973 dependent_views[root_view] = {};
970974 };
@@ -990,7 +994,7 @@ bool InsertDependenciesBuilder::observePath(const DependencyPath & path)
990994
991995 inner_tables[current] = materialized_view->getTargetTableId ();
992996 source_tables[current] = parent;
993- thread_groups[current] = ThreadGroup::createForMaterializedView ();
997+ thread_groups[current] = ThreadGroup::createForMaterializedView (init_context );
994998 view_types[current] = QueryViewsLogElement::ViewType::MATERIALIZED;
995999 views_error_registry->init (current);
9961000
@@ -1019,7 +1023,7 @@ bool InsertDependenciesBuilder::observePath(const DependencyPath & path)
10191023 inner_tables[current] = current;
10201024 select_queries[current] = live_view->getInnerQuery ();
10211025 input_headers[current] = output_headers.at (path.parent (2 ));
1022- thread_groups[current] = ThreadGroup::createForMaterializedView ();
1026+ thread_groups[current] = ThreadGroup::createForMaterializedView (init_context );
10231027 view_types[current] = QueryViewsLogElement::ViewType::LIVE;
10241028 views_error_registry->init (current);
10251029
@@ -1051,7 +1055,7 @@ bool InsertDependenciesBuilder::observePath(const DependencyPath & path)
10511055 inner_tables[current] = current;
10521056 select_queries[current] = window_view->getMergeableQuery ();
10531057 input_headers[current] = output_headers.at (path.parent (2 ));
1054- thread_groups[current] = ThreadGroup::createForMaterializedView ();
1058+ thread_groups[current] = ThreadGroup::createForMaterializedView (init_context );
10551059 view_types[current] = QueryViewsLogElement::ViewType::WINDOW;
10561060 views_error_registry->init (current);
10571061
0 commit comments