@@ -69,7 +69,6 @@ class ThreadGroup
6969 ThreadGroup ();
7070 using FatalErrorCallback = std::function<void ()>;
7171 explicit ThreadGroup (ContextPtr query_context_, FatalErrorCallback fatal_error_callback_ = {});
72- explicit ThreadGroup (ThreadGroupPtr parent);
7372
7473 // / The first thread created this thread group
7574 const UInt64 master_thread_id;
@@ -80,7 +79,7 @@ class ThreadGroup
8079
8180 const FatalErrorCallback fatal_error_callback;
8281
83- MemorySpillScheduler::Ptr memory_spill_scheduler;
82+ MemorySpillScheduler memory_spill_scheduler;
8483 ProfileEvents::Counters performance_counters{VariableContext::Process};
8584 MemoryTracker memory_tracker{VariableContext::Process};
8685
@@ -119,14 +118,11 @@ class ThreadGroup
119118
120119 static ThreadGroupPtr createForBackgroundProcess (ContextPtr storage_context);
121120
122- static ThreadGroupPtr createForMaterializedView ();
123-
124121 std::vector<UInt64> getInvolvedThreadIds () const ;
125122 size_t getPeakThreadsUsage () const ;
126- UInt64 getThreadsTotalElapsedMs () const ;
127123
128124 void linkThread (UInt64 thread_id);
129- void unlinkThread (UInt64 elapsed_thread_counter_ms );
125+ void unlinkThread ();
130126
131127private:
132128 mutable std::mutex mutex;
@@ -142,8 +138,6 @@ class ThreadGroup
142138
143139 // / Peak threads count in the group
144140 size_t peak_threads_usage TSA_GUARDED_BY (mutex) = 0;
145-
146- UInt64 elapsed_total_threads_counter_ms TSA_GUARDED_BY (mutex) = 0;
147141};
148142
149143/* *
@@ -246,13 +240,10 @@ class ThreadStatus : public boost::noncopyable
246240 UInt64 microseconds () const ;
247241 UInt64 seconds () const ;
248242
249- UInt64 elapsedMilliseconds () const ;
250- UInt64 elapsedMilliseconds (const TimePoint & current) const ;
251-
252243 std::chrono::time_point<std::chrono::system_clock> point;
253244 };
254245
255- TimePoint thread_attach_time {};
246+ TimePoint query_start_time {};
256247
257248 // CPU and Real time query profilers
258249 std::unique_ptr<QueryProfilerReal> query_profiler_real;
@@ -264,6 +255,9 @@ class ThreadStatus : public boost::noncopyable
264255 Stopwatch stopwatch{CLOCK_MONOTONIC_COARSE};
265256 UInt64 last_performance_counters_update_time = 0 ;
266257
258+ // / See setInternalThread()
259+ bool internal_thread = false ;
260+
267261 // / This is helpful for cut linking dependencies for clickhouse_common_io
268262 using Deleter = std::function<void ()>;
269263 Deleter deleter;
@@ -283,6 +277,22 @@ class ThreadStatus : public boost::noncopyable
283277 ContextPtr getQueryContext () const ;
284278 ContextPtr getGlobalContext () const ;
285279
280+ // / "Internal" ThreadStatus is used for materialized views for separate
281+ // / tracking into system.query_views_log
282+ // /
283+ // / You can have multiple internal threads, but only one non-internal with
284+ // / the same thread_id.
285+ // /
286+ // / "Internal" thread:
287+ // / - cannot have query profiler
288+ // / since the running (main query) thread should already have one
289+ // / - should not try to obtain latest counter on detach
290+ // / because detaching of such threads will be done from a different
291+ // / thread_id, and some counters are not available (i.e. getrusage()),
292+ // / but anyway they are accounted correctly in the main ThreadStatus of a
293+ // / query.
294+ void setInternalThread ();
295+
286296 // / Attaches slave thread to existing thread group
287297 void attachToGroup (const ThreadGroupPtr & thread_group_, bool check_detached = true );
288298
0 commit comments