| 430 | } |
| 431 | |
| 432 | QueryLogElement logQueryStart( |
| 433 | const std::chrono::time_point<std::chrono::system_clock> & query_start_time, |
| 434 | const ContextMutablePtr & context, |
| 435 | const String & query_for_logging, |
| 436 | UInt64 normalized_query_hash, |
| 437 | const ASTPtr & query_ast, |
| 438 | const QueryPipeline & pipeline, |
| 439 | const IInterpreter * interpreter, |
| 440 | bool internal, |
| 441 | const String & query_database, |
| 442 | const String & query_table, |
| 443 | bool async_insert) |
| 444 | { |
| 445 | const Settings & settings = context->getSettingsRef(); |
| 446 | |
| 447 | QueryLogElement elem; |
| 448 | |
| 449 | elem.type = QueryLogElementType::QUERY_START; |
| 450 | elem.event_time = timeInSeconds(query_start_time); |
| 451 | elem.event_time_microseconds = timeInMicroseconds(query_start_time); |
| 452 | elem.query_start_time = timeInSeconds(query_start_time); |
| 453 | elem.query_start_time_microseconds = timeInMicroseconds(query_start_time); |
| 454 | |
| 455 | elem.current_database = context->getCurrentDatabase(); |
| 456 | elem.query = query_for_logging; |
| 457 | if (query_ast && settings[Setting::log_formatted_queries]) |
| 458 | elem.formatted_query = query_ast->formatWithSecretsOneLine(); |
| 459 | elem.normalized_query_hash = normalized_query_hash; |
| 460 | elem.query_kind = query_ast ? query_ast->getQueryKind() : IAST::QueryKind::Select; |
| 461 | |
| 462 | elem.client_info = context->getClientInfo(); |
| 463 | |
| 464 | elem.is_internal = internal; |
| 465 | |
| 466 | if (auto txn = context->getCurrentTransaction()) |
| 467 | elem.tid = txn->tid; |
| 468 | |
| 469 | bool log_queries = settings[Setting::log_queries]; |
| 470 | |
| 471 | auto query_log = context->getQueryLog(); |
| 472 | if (!query_log) |
| 473 | return elem; |
| 474 | |
| 475 | /// Log into system table start of query execution, if need. |
| 476 | if (log_queries) |
| 477 | { |
| 478 | /// This check is not obvious, but without it 01220_scalar_optimization_in_alter fails. |
| 479 | if (pipeline.initialized()) |
| 480 | { |
| 481 | const auto & info = context->getQueryAccessInfo(); |
| 482 | std::lock_guard lock(info.mutex); |
| 483 | elem.query_databases = info.databases; |
| 484 | elem.query_tables = info.tables; |
| 485 | elem.query_columns = info.columns; |
| 486 | elem.query_partitions = info.partitions; |
| 487 | elem.query_projections = info.projections; |
| 488 | elem.query_views = info.views; |
| 489 | elem.used_row_policies = info.row_policies; |
no test coverage detected