MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / addStatusInfoToQueryLogElement

Function addStatusInfoToQueryLogElement

src/Interpreters/executeQuery.cpp:352–420  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

350}
351
352static void
353addStatusInfoToQueryLogElement(QueryLogElement & element, const QueryStatusInfo & info, const ASTPtr query_ast, const ContextPtr context_ptr, std::chrono::system_clock::time_point time)
354{
355 UInt64 elapsed_microseconds = info.elapsed_microseconds;
356 element.event_time = timeInSeconds(time);
357 element.event_time_microseconds = timeInMicroseconds(time);
358 element.query_duration_ms = elapsed_microseconds / 1000;
359
360 ProfileEvents::increment(ProfileEvents::QueryTimeMicroseconds, elapsed_microseconds);
361 if (!query_ast || query_ast->as<ASTSelectQuery>() || query_ast->as<ASTSelectWithUnionQuery>())
362 {
363 ProfileEvents::increment(ProfileEvents::SelectQueryTimeMicroseconds, elapsed_microseconds);
364 }
365 else if (query_ast->as<ASTInsertQuery>())
366 {
367 ProfileEvents::increment(ProfileEvents::InsertQueryTimeMicroseconds, elapsed_microseconds);
368 }
369 else
370 {
371 ProfileEvents::increment(ProfileEvents::OtherQueryTimeMicroseconds, elapsed_microseconds);
372 }
373
374 element.read_rows = info.read_rows;
375 element.read_bytes = info.read_bytes;
376
377 element.written_rows = info.written_rows;
378 element.written_bytes = info.written_bytes;
379
380 element.memory_usage = info.peak_memory_usage > 0 ? info.peak_memory_usage : 0;
381
382 element.thread_ids = info.thread_ids;
383 element.peak_threads_usage = info.peak_threads_usage;
384 element.profile_counters = info.profile_counters;
385
386 /// We need to refresh the access info since dependent views might have added extra information, either during
387 /// creation of the view (PushingToViews chain) or while executing its internal SELECT
388 const auto & access_info = context_ptr->getQueryAccessInfo();
389 {
390 std::lock_guard lock(access_info.mutex);
391 element.query_databases.insert(access_info.databases.begin(), access_info.databases.end());
392 element.query_tables.insert(access_info.tables.begin(), access_info.tables.end());
393 element.query_columns.insert(access_info.columns.begin(), access_info.columns.end());
394 element.query_partitions.insert(access_info.partitions.begin(), access_info.partitions.end());
395 element.query_projections.insert(access_info.projections.begin(), access_info.projections.end());
396 element.query_views.insert(access_info.views.begin(), access_info.views.end());
397 element.used_row_policies.insert(access_info.row_policies.begin(), access_info.row_policies.end());
398 }
399
400 /// We copy QueryFactoriesInfo for thread-safety, because it is possible that query context can be modified by some processor even
401 /// after query is finished
402 const auto & factories_info(context_ptr->getQueryFactoriesInfo());
403 {
404 std::lock_guard lock(factories_info.mutex);
405 element.used_aggregate_functions = factories_info.aggregate_functions;
406 element.used_aggregate_function_combinators = factories_info.aggregate_function_combinators;
407 element.used_database_engines = factories_info.database_engines;
408 element.used_data_type_families = factories_info.data_type_families;
409 element.used_dictionaries = factories_info.dictionaries;

Callers 3

logQueryFinishImplFunction · 0.85
logQueryExceptionFunction · 0.85
logExceptionBeforeStartFunction · 0.85

Calls 8

timeInSecondsFunction · 0.85
getAsyncReadCountersMethod · 0.80
timeInMicrosecondsFunction · 0.50
incrementFunction · 0.50
insertMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected