Debian Codegraph @

doc/source/reference/command/output_trace_log.md

raw symbols SCIP
1 # Output trace log
2
3 ## Summary
4
5 ```{versionadded} 13.0.9
6
7 ```
8
9 ```{note}
10
11 This is an experimental feature. Currently, this feature is still not stable.
12
13 This feature requires {doc}`/reference/command/command_version` 3 or later.
14 ```
15
16 Trace log is similar information to PostgreSQL's [`EXPLAIN (ANALYZE,
17 VERBOSE)`](https://www.postgresql.org/docs/current/sql-explain.html)
18 information. It includes the followings:
19
20 - What was executed?
21 - Which index was used?
22 - How long did the operation take?
23 - What value was used internal?
24 - ...
25
26 Trace log contents may be insufficient for now because this feature is
27 still experimental. If you want more information, please report it to
28 [the GitHub
29 issue](https://github.com/groonga/groonga/issues/new?labels=Feature&template=feature_request.yml)
30 with your use case.
31
32 ## Usage
33
34 You can get trace log by specifying `yes` as `output_trace_log`. You
35 also need to specify `3` as {doc}`/reference/command/command_version`.
36
37 Command line style:
38
39 ```text
40 select ... --output_trace_log yes --command_version 3
41 ```
42
43 URI style:
44
45 ```text
46 /d/select?...&output_trace_log=yes&command_version=3
47 ```
48
49 ## Format
50
51 Trace log is available only when you use JSON or Apache Arrow
52 {doc}`/reference/command/output_format`. If you don't specify output
53 format, JSON is used by default.
54
55 ### JSON
56
57 You can specify JSON output format explicitly like the followings:
58
59 Command line style:
60
61 ```text
62 select ... --output_trace_log yes --command_version 3 --output_type json
63 ```
64
65 URI style:
66
67 ```text
68 /d/select.json?...&output_trace_log=yes&command_version=3
69 ```
70
71 or
72
73 ```text
74 /d/select?...&output_trace_log=yes&command_version=3&output_type=json
75 ```
76
77 Here is an output structure for JSON output format:
78
79 ```json
80 {
81 "header": {},
82 "trace_log": {
83 "columns": [
84 {"name": "depth"},
85 {"name": "sequence"},
86 {"name": "name"},
87 {"name": "value"},
88 {"name": "elapsed_time"}
89 ],
90 "logs": [
91 [1, 0, "ii.select.input", "Hello", 100],
92 [2, 0, "ii.select.exact.n_hits", 2, 200],
93 [1, 1, "ii.select.n_hits", 2, 210]
94 ],
95 ],
96 "body": []
97 }
98 ```
99
100 If `output_trace_log` is `yes`, `"trace_log": {...}` is added. It has
101 2 key-value pairs:
102
103 ```{list-table}
104 :header-rows: 1
105
106 * - Key
107 - Description
108 * - `columns`
109 - An array of column metadata for each trace log entry
110 * - `logs`
111 - An array of trace log entries
112 ```
113
114 Each `columns` element has the following key-value pairs:
115
116 ```{list-table}
117 :header-rows: 1
118
119 * - Key
120 - Description
121 * - `name`
122 - The name of column
123 ```
124
125 Each `logs` element has the following elements:
126
127 ```{list-table}
128 :header-rows: 1
129
130 * - Index
131 - Name
132 - Description
133 * - 0
134 - `depth`
135 - The execution level.
136
137 Multiple trace logs may be outputted for one execution level. If there are
138 multiple trace logs for one execution level, `sequence` is incremented for
139 each trace logs in the same execution level.
140 * - 1
141 - `sequence`
142 - The sequence number in the same execution level.
143
144 If this is `0`, it shows that new execution level is started.
145 * - 2
146 - `name`
147 - The name of this trace log.
148 * - 3
149 - `value`
150 - The value of this trace log.
151
152 The value type must be one of the followings:
153 * Integer
154 * String
155 * - 4
156 - `elapsed_time`
157 - The elapsed time since the command is started. Unit is nano second.
158 ```
159
160 `logs` is a flat array but it may be able to format as a tree like
161 PostgreSQL's `EXPLAIN (ANALYZE, VERBOSE)` output based on `depth` and
162 `sequence`. Groonga may have an option to do it in the future or we
163 may provide a tool for it.
164
165 Example:
166
167 ```{literalinclude} ../../../../test/command/suite/select/fuzzy/output_trace_log/json.expected
168 :language: json
169 :start-after: select
170 ```
171
172 ### Apache Arrow
173
174 You can specify Apache Arrow output format explicitly like the
175 followings:
176
177 Command line style:
178
179 ```text
180 select ... --output_trace_log yes --command_version 3 --output_type apache-arrow
181 ```
182
183 URI style:
184
185 ```text
186 /d/select.arrows?...&output_trace_log=yes&command_version=3
187 ```
188
189 or
190
191 ```text
192 /d/select?...&output_trace_log=yes&command_version=3&output_type=apache-arrow
193 ```
194
195 Here is an output structure for Apache Arrow output format:
196
197 ```text
198 ----
199 Apache Arrow record batch (stream format)
200 Metadata:
201 GROONGA:data_type: metadata
202 ----
203 ----
204 Apache Arrow record batch (stream format)
205 Metadata:
206 GROONGA:data_type: trace_log
207 Schema:
208 depth: uint16
209 sequence: uint16
210 name: string
211 value: dense_union<0: uint32=0, 1: string=1>
212 elapsed_time: uint64
213 ----
214 Apache Arrow record batch (stream format)
215 Metadata:
216 GROONGA:n_hits: N
217 ----
218 ```
219
220 The second record batch is a trace log. You can check
221 `GROONGA:data_type` metadata to detect a record batch for trace log.
222
223 Here is descriptions of each column of the record batch:
224
225 ```{list-table}
226 :header-rows: 1
227
228 * - Name
229 - Description
230 * - `depth`
231 - The execution level.
232
233 Multiple trace logs may be outputted for one execution level. If there are
234 multiple trace logs for one execution level, `sequence` is incremented for
235 each trace logs in the same execution level.
236 * - `sequence`
237 - The sequence number in the same execution level.
238
239 If this is `0`, it shows that new execution level is started.
240 * - `name`
241 - The name of this trace log.
242 * - `value`
243 - The value of this trace log.
244
245 The value type must be one of the followings:
246 * Integer
247 * String
248 * - `elapsed_time`
249 - The elapsed time since the command is started. Unit is nano second.
250 ```
251
252 Example:
253
254 ```{literalinclude} ../../../../test/command/suite/select/fuzzy/output_trace_log/apache_arrow.expected
255 :language: none
256 :start-at: depth
257 :end-before: ====
258 ```