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

Function logExceptionBeforeStart

src/Interpreters/executeQuery.cpp:863–994  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

861}
862
863void logExceptionBeforeStart(
864 const String & query_for_logging,
865 UInt64 normalized_query_hash,
866 ContextPtr context,
867 ASTPtr ast,
868 const std::shared_ptr<OpenTelemetry::SpanHolder> & query_span,
869 UInt64 elapsed_milliseconds,
870 bool internal)
871{
872 auto query_end_time = std::chrono::system_clock::now();
873
874 /// Exception before the query execution.
875 if (auto quota = context->getQuota())
876 quota->used(QuotaType::ERRORS, 1, /* check_exceeded = */ false);
877
878 const Settings & settings = context->getSettingsRef();
879
880 const auto & client_info = context->getClientInfo();
881
882 /// Log the start of query execution into the table if necessary.
883 QueryLogElement elem;
884
885 elem.type = QueryLogElementType::EXCEPTION_BEFORE_START;
886 elem.event_time = timeInSeconds(query_end_time);
887 elem.event_time_microseconds = timeInMicroseconds(query_end_time);
888 elem.query_start_time = client_info.initial_query_start_time;
889 elem.query_start_time_microseconds = client_info.initial_query_start_time_microseconds;
890 elem.query_duration_ms = elapsed_milliseconds;
891
892 elem.current_database = context->getCurrentDatabase();
893 elem.query = query_for_logging;
894 elem.normalized_query_hash = normalized_query_hash;
895
896 // Log query_kind if ast is valid
897 if (ast)
898 {
899 elem.query_kind = ast->getQueryKind();
900 if (settings[Setting::log_formatted_queries])
901 elem.formatted_query = ast->formatWithSecretsOneLine();
902 }
903
904 addPrivilegesInfoToQueryLogElement(elem, context);
905
906 // We don't calculate databases, tables and columns when the query isn't able to start
907
908 elem.exception_code = getCurrentExceptionCode();
909 auto exception_message = getCurrentExceptionMessageAndPattern(/* with_stacktrace */ false);
910 elem.exception = std::move(exception_message.text);
911 elem.exception_format_string = exception_message.format_string;
912 elem.exception_format_string_args = exception_message.format_string_args;
913
914 elem.client_info = context->getClientInfo();
915
916 elem.log_comment = settings[Setting::log_comment];
917 if (elem.log_comment.size() > settings[Setting::max_query_size])
918 elem.log_comment.resize(settings[Setting::max_query_size]);
919
920 if (auto txn = context->getCurrentTransaction())

Callers 4

dropTempTableMethod · 0.85
executeQueryImplFunction · 0.85
processDataMethod · 0.85

Tested by

no test coverage detected