2015-06-22 21:26:03 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/SystemLog.h>
|
2015-06-22 21:26:03 +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
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
QUERY_START = 1,
|
|
|
|
QUERY_FINISH = 2,
|
|
|
|
EXCEPTION_BEFORE_START = 3,
|
|
|
|
EXCEPTION_WHILE_PROCESSING = 4,
|
|
|
|
};
|
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{};
|
|
|
|
time_t query_start_time{};
|
|
|
|
UInt64 query_duration_ms{};
|
2015-06-22 21:26:03 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// The data fetched from DB to execute the query
|
|
|
|
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
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String query;
|
2015-06-22 21:26:03 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String exception;
|
|
|
|
String stack_trace;
|
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
|
|
|
|
2018-05-17 16:01:41 +00:00
|
|
|
std::vector<UInt32> thread_numbers;
|
2019-08-31 21:47:15 +00:00
|
|
|
std::vector<UInt32> os_thread_ids;
|
2018-05-17 16:01:41 +00:00
|
|
|
std::shared_ptr<ProfileEvents::Counters> profile_counters;
|
|
|
|
std::shared_ptr<Settings> query_settings;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
static std::string name() { return "QueryLog"; }
|
2015-06-22 21:26:03 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
static Block createBlock();
|
|
|
|
void appendToBlock(Block & block) const;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|