1 | #pragma once |
2 | |
3 | #include <Interpreters/SystemLog.h> |
4 | |
5 | |
6 | namespace ProfileEvents |
7 | { |
8 | class Counters; |
9 | } |
10 | |
11 | |
12 | namespace DB |
13 | { |
14 | |
15 | |
16 | /** Allows to log information about queries execution: |
17 | * - info about start of query execution; |
18 | * - performance metrics (are set at the end of query execution); |
19 | * - info about errors of query execution. |
20 | */ |
21 | |
22 | /// A struct which will be inserted as row into query_log table |
23 | struct QueryLogElement |
24 | { |
25 | enum Type : UInt8 // Make it signed for compatibility with DataTypeEnum8 |
26 | { |
27 | QUERY_START = 1, |
28 | QUERY_FINISH = 2, |
29 | EXCEPTION_BEFORE_START = 3, |
30 | EXCEPTION_WHILE_PROCESSING = 4, |
31 | }; |
32 | |
33 | Type type = QUERY_START; |
34 | |
35 | /// Depending on the type of query and type of stage, not all the fields may be filled. |
36 | |
37 | time_t event_time{}; |
38 | time_t query_start_time{}; |
39 | UInt64 query_duration_ms{}; |
40 | |
41 | /// The data fetched from DB to execute the query |
42 | UInt64 read_rows{}; |
43 | UInt64 read_bytes{}; |
44 | |
45 | /// The data written to DB |
46 | UInt64 written_rows{}; |
47 | UInt64 written_bytes{}; |
48 | |
49 | /// The data sent to the client |
50 | UInt64 result_rows{}; |
51 | UInt64 result_bytes{}; |
52 | |
53 | UInt64 memory_usage{}; |
54 | |
55 | String query; |
56 | |
57 | String exception; |
58 | String stack_trace; |
59 | |
60 | ClientInfo client_info; |
61 | |
62 | std::vector<UInt32> thread_numbers; |
63 | std::vector<UInt32> os_thread_ids; |
64 | std::shared_ptr<ProfileEvents::Counters> profile_counters; |
65 | std::shared_ptr<Settings> query_settings; |
66 | |
67 | static std::string name() { return "QueryLog" ; } |
68 | |
69 | static Block createBlock(); |
70 | void appendToBlock(Block & block) const; |
71 | |
72 | static void appendClientInfo(const ClientInfo & client_info, MutableColumns & columns, size_t & i); |
73 | }; |
74 | |
75 | |
76 | /// Instead of typedef - to allow forward declaration. |
77 | class QueryLog : public SystemLog<QueryLogElement> |
78 | { |
79 | using SystemLog<QueryLogElement>::SystemLog; |
80 | }; |
81 | |
82 | } |
83 | |