diff --git a/src/Common/ThreadStatus.h b/src/Common/ThreadStatus.h index d22f6e1574b..97ddda1ea30 100644 --- a/src/Common/ThreadStatus.h +++ b/src/Common/ThreadStatus.h @@ -165,7 +165,7 @@ protected: std::function fatal_error_callback; /// It is used to avoid enabling the query profiler when you have multiple ThreadStatus in the same thread - bool query_profiled_enabled = true; + bool query_profiler_enabled = true; /// Requires access to query_id. friend class MemoryTrackerThreadSwitcher; @@ -207,7 +207,8 @@ public: void disableProfiling() { - query_profiled_enabled = false; + assert(!query_profiler_real && !query_profiler_cpu); + query_profiler_enabled = false; } /// Starts new query and create new thread group for it, current thread becomes master thread of the query diff --git a/src/Interpreters/ThreadStatusExt.cpp b/src/Interpreters/ThreadStatusExt.cpp index e796c2b85a1..fc6aa15a1e8 100644 --- a/src/Interpreters/ThreadStatusExt.cpp +++ b/src/Interpreters/ThreadStatusExt.cpp @@ -310,7 +310,7 @@ void ThreadStatus::resetPerformanceCountersLastUsage() void ThreadStatus::initQueryProfiler() { - if (!query_profiled_enabled) + if (!query_profiler_enabled) return; /// query profilers are useless without trace collector @@ -326,11 +326,11 @@ void ThreadStatus::initQueryProfiler() { if (settings.query_profiler_real_time_period_ns > 0) query_profiler_real = std::make_unique(thread_id, - /* period */ static_cast(settings.query_profiler_real_time_period_ns)); + /* period= */ static_cast(settings.query_profiler_real_time_period_ns)); if (settings.query_profiler_cpu_time_period_ns > 0) query_profiler_cpu = std::make_unique(thread_id, - /* period */ static_cast(settings.query_profiler_cpu_time_period_ns)); + /* period= */ static_cast(settings.query_profiler_cpu_time_period_ns)); } catch (...) { diff --git a/tests/queries/0_stateless/02125_query_views_log.reference b/tests/queries/0_stateless/02125_query_views_log.reference new file mode 100644 index 00000000000..3ae4af9b4d0 --- /dev/null +++ b/tests/queries/0_stateless/02125_query_views_log.reference @@ -0,0 +1,24 @@ +-- { echo } +select view_name, read_rows, read_bytes, written_rows, written_bytes from system.query_views_log where startsWith(view_name, currentDatabase() || '.mv') order by view_name format Vertical; +Row 1: +────── +view_name: default.mv1 +read_rows: 1000000 +read_bytes: 4000000 +written_rows: 1000000 +written_bytes: 4000000 + +Row 2: +────── +view_name: default.mv2 +read_rows: 1000000 +read_bytes: 4000000 +written_rows: 1000000 +written_bytes: 4000000 +select read_rows, read_bytes, written_rows, written_bytes from system.query_log where type = 'QueryFinish' and query_kind = 'Insert' and current_database = currentDatabase() format Vertical; +Row 1: +────── +read_rows: 1000000 +read_bytes: 8000000 +written_rows: 3000000 +written_bytes: 12000000 diff --git a/tests/queries/0_stateless/02125_query_views_log.sql b/tests/queries/0_stateless/02125_query_views_log.sql new file mode 100644 index 00000000000..d2d19b76a1f --- /dev/null +++ b/tests/queries/0_stateless/02125_query_views_log.sql @@ -0,0 +1,16 @@ +drop table if exists src; +drop table if exists dst; +drop table if exists mv1; +drop table if exists mv2; + +create table src (key Int) engine=Null(); +create table dst (key Int) engine=Null(); +create materialized view mv1 to dst as select * from src; +create materialized view mv2 to dst as select * from src; + +insert into src select * from numbers(1e6) settings log_queries=1, max_untracked_memory=0, parallel_view_processing=1; +system flush logs; + +-- { echo } +select view_name, read_rows, read_bytes, written_rows, written_bytes from system.query_views_log where startsWith(view_name, currentDatabase() || '.mv') order by view_name format Vertical; +select read_rows, read_bytes, written_rows, written_bytes from system.query_log where type = 'QueryFinish' and query_kind = 'Insert' and current_database = currentDatabase() format Vertical;