2015-06-22 21:26:03 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-01-10 19:01:41 +00:00
|
|
|
#include <Core/NamesAndTypes.h>
|
2021-06-28 11:42:21 +00:00
|
|
|
#include <Core/NamesAndAliases.h>
|
2022-01-10 19:01:41 +00:00
|
|
|
#include <Core/Settings.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/SystemLog.h>
|
2020-05-20 20:16:32 +00:00
|
|
|
#include <Interpreters/ClientInfo.h>
|
2021-11-08 18:56:09 +00:00
|
|
|
#include <Interpreters/TransactionVersionMetadata.h>
|
2023-02-01 02:31:31 +00:00
|
|
|
#include <Parsers/IAST.h>
|
2015-06-22 21:26:03 +00:00
|
|
|
|
2022-08-02 10:45:06 +00:00
|
|
|
|
2018-06-14 13:03:23 +00:00
|
|
|
namespace ProfileEvents
|
|
|
|
{
|
|
|
|
class Counters;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-22 21:26:03 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2016-12-06 20:55:13 +00:00
|
|
|
/** Allows to log information about queries execution:
|
|
|
|
* - info about start of query execution;
|
|
|
|
* - performance metrics (are set at the end of query execution);
|
|
|
|
* - info about errors of query execution.
|
2015-06-22 21:26:03 +00:00
|
|
|
*/
|
|
|
|
|
2016-12-06 20:55:13 +00:00
|
|
|
/// A struct which will be inserted as row into query_log table
|
2015-06-22 21:26:03 +00:00
|
|
|
struct QueryLogElement
|
|
|
|
{
|
2020-04-04 21:07:00 +00:00
|
|
|
using Type = QueryLogElementType;
|
2015-06-22 21:26:03 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Type type = QUERY_START;
|
2015-06-22 21:26:03 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Depending on the type of query and type of stage, not all the fields may be filled.
|
2015-06-22 21:26:03 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
time_t event_time{};
|
2020-11-03 13:59:17 +00:00
|
|
|
Decimal64 event_time_microseconds{};
|
2017-04-01 07:20:54 +00:00
|
|
|
time_t query_start_time{};
|
2020-11-03 13:59:17 +00:00
|
|
|
Decimal64 query_start_time_microseconds{};
|
2017-04-01 07:20:54 +00:00
|
|
|
UInt64 query_duration_ms{};
|
2015-06-22 21:26:03 +00:00
|
|
|
|
2020-01-22 13:58:36 +00:00
|
|
|
/// The data fetched from DB to execute the query
|
2017-04-01 07:20:54 +00:00
|
|
|
UInt64 read_rows{};
|
|
|
|
UInt64 read_bytes{};
|
2015-06-22 21:26:03 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// The data written to DB
|
|
|
|
UInt64 written_rows{};
|
|
|
|
UInt64 written_bytes{};
|
2016-12-06 20:55:13 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// The data sent to the client
|
|
|
|
UInt64 result_rows{};
|
|
|
|
UInt64 result_bytes{};
|
2015-06-22 21:26:03 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
UInt64 memory_usage{};
|
2015-07-01 05:18:54 +00:00
|
|
|
|
2020-07-22 04:00:16 +00:00
|
|
|
String current_database;
|
2017-04-01 07:20:54 +00:00
|
|
|
String query;
|
2021-08-07 06:26:08 +00:00
|
|
|
String formatted_query;
|
2020-12-15 19:29:25 +00:00
|
|
|
UInt64 normalized_query_hash{};
|
2020-12-02 12:08:03 +00:00
|
|
|
|
2023-02-01 02:31:31 +00:00
|
|
|
IAST::QueryKind query_kind;
|
2020-12-02 12:08:03 +00:00
|
|
|
std::set<String> query_databases;
|
|
|
|
std::set<String> query_tables;
|
|
|
|
std::set<String> query_columns;
|
2021-02-10 14:12:49 +00:00
|
|
|
std::set<String> query_projections;
|
2021-06-24 16:54:04 +00:00
|
|
|
std::set<String> query_views;
|
2015-06-22 21:26:03 +00:00
|
|
|
|
2021-01-21 21:15:11 +00:00
|
|
|
std::unordered_set<String> used_aggregate_functions;
|
2021-01-23 12:07:37 +00:00
|
|
|
std::unordered_set<String> used_aggregate_function_combinators;
|
|
|
|
std::unordered_set<String> used_database_engines;
|
|
|
|
std::unordered_set<String> used_data_type_families;
|
2021-01-21 21:15:11 +00:00
|
|
|
std::unordered_set<String> used_dictionaries;
|
|
|
|
std::unordered_set<String> used_formats;
|
|
|
|
std::unordered_set<String> used_functions;
|
|
|
|
std::unordered_set<String> used_storages;
|
|
|
|
std::unordered_set<String> used_table_functions;
|
2022-10-21 16:13:36 +00:00
|
|
|
std::set<String> used_row_policies;
|
2021-01-20 10:54:11 +00:00
|
|
|
|
2020-01-22 13:52:26 +00:00
|
|
|
Int32 exception_code{}; // because ErrorCodes are int
|
2017-04-01 07:20:54 +00:00
|
|
|
String exception;
|
|
|
|
String stack_trace;
|
2023-01-17 19:04:25 +00:00
|
|
|
std::string_view exception_format_string{};
|
2015-06-29 21:35:35 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ClientInfo client_info;
|
2015-06-22 21:26:03 +00:00
|
|
|
|
2020-12-28 02:38:16 +00:00
|
|
|
String log_comment;
|
|
|
|
|
2020-02-02 20:01:13 +00:00
|
|
|
std::vector<UInt64> thread_ids;
|
2021-10-11 15:56:23 +00:00
|
|
|
std::shared_ptr<ProfileEvents::Counters::Snapshot> profile_counters;
|
2018-05-17 16:01:41 +00:00
|
|
|
std::shared_ptr<Settings> query_settings;
|
|
|
|
|
2021-03-31 17:55:04 +00:00
|
|
|
TransactionID tid;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
static std::string name() { return "QueryLog"; }
|
2015-06-22 21:26:03 +00:00
|
|
|
|
2021-06-28 11:42:21 +00:00
|
|
|
static NamesAndTypesList getNamesAndTypes();
|
|
|
|
static NamesAndAliases getNamesAndAliases();
|
2020-05-21 20:15:18 +00:00
|
|
|
void appendToBlock(MutableColumns & columns) const;
|
2022-04-17 21:49:39 +00:00
|
|
|
static const char * getCustomColumnList() { return nullptr; }
|
2018-05-31 15:54:08 +00:00
|
|
|
|
|
|
|
static void appendClientInfo(const ClientInfo & client_info, MutableColumns & columns, size_t & i);
|
2016-10-27 17:48:12 +00:00
|
|
|
};
|
2015-06-26 19:23:25 +00:00
|
|
|
|
2015-06-22 21:26:03 +00:00
|
|
|
|
2016-10-27 17:48:12 +00:00
|
|
|
/// Instead of typedef - to allow forward declaration.
|
|
|
|
class QueryLog : public SystemLog<QueryLogElement>
|
2015-06-22 21:26:03 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
using SystemLog<QueryLogElement>::SystemLog;
|
2015-06-22 21:26:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|