Commit df345a2
authored
refactor query graph and enable profiling for a connection (#140)
The idea of this PR is to make this tool a bit more useful (and visually
appealing). I think generally it is good to have some better profiling
tools to explore queries.
**EDIT**: Initially it was only about the query graph visuals, but I
decided to expose the profiling functions enabled in the C++ API
(similar to what the Go client does with the C API).
To use the tool:
1. Build this branch (see
https://duckdb.org/docs/stable/dev/building/python)
2. Run the following in DuckDB
```sql
PRAGMA enable_profiling = 'json';
PRAGMA profiling_output = './tmp/profile.json';
SELECT ... FROM ...;
```
3. Run the script (I do it with uv):
```bash
uv run -m duckdb.query_graph --profile_input profile.json
```
If you want to use the profiling within the client:
```python
import duckdb
from duckdb.query_graph import ProfilingInfo
con = duckdb.connect()
con.enable_profiling()
con.execute("select 42").fetchall() #or some other eager operation
profiling_info = ProfilingInfo(con)
# then the options are
profiling_info.to_json()
profiling_info.to_pydict()
profiling_info.to_html()
# optionally
con.disable_profiling()
```
It is also possible to just provide the profiling info as a file:
```python
# we create profiling info from a file instead of binding it to a connection
profiling_info = ProfilingInfo(from_file = 'profile.json')
# then the stuff
profiling_info.to_html(output_file='profile.html')
```
Which should yield something like the following screenshot:
<img width="1023" height="814" alt="Screenshot 2026-01-09 at 11 09 21"
src="https://github.com/user-attachments/assets/44de8776-18b2-4320-8c90-4b9cfec40cd1"
/>
<img width="993" height="701" alt="Screenshot 2026-01-09 at 11 09 44"
src="https://github.com/user-attachments/assets/d17ffc91-0354-4ed1-824c-b44018be1a74"
/>
<img width="208" height="568" alt="Screenshot 2026-01-09 at 11 10 05"
src="https://github.com/user-attachments/assets/307f5558-9a6e-4c31-b290-a90a84283014"
/>11 files changed
Lines changed: 726 additions & 245 deletions
File tree
- _duckdb-stubs
- duckdb
- query_graph
- scripts
- src/duckdb_py
- include/duckdb_python/pyconnection
- tests/fast
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| 50 | + | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
| 93 | + | |
92 | 94 | | |
93 | 95 | | |
94 | 96 | | |
| |||
109 | 111 | | |
110 | 112 | | |
111 | 113 | | |
| 114 | + | |
112 | 115 | | |
113 | 116 | | |
114 | 117 | | |
| |||
313 | 316 | | |
314 | 317 | | |
315 | 318 | | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
316 | 322 | | |
317 | 323 | | |
318 | 324 | | |
| |||
1250 | 1256 | | |
1251 | 1257 | | |
1252 | 1258 | | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
1253 | 1262 | | |
1254 | 1263 | | |
1255 | 1264 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
| 91 | + | |
90 | 92 | | |
91 | 93 | | |
92 | 94 | | |
| |||
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
| 112 | + | |
110 | 113 | | |
111 | 114 | | |
112 | 115 | | |
| |||
310 | 313 | | |
311 | 314 | | |
312 | 315 | | |
| 316 | + | |
313 | 317 | | |
314 | 318 | | |
315 | 319 | | |
| 320 | + | |
316 | 321 | | |
317 | 322 | | |
318 | 323 | | |
| |||
333 | 338 | | |
334 | 339 | | |
335 | 340 | | |
| 341 | + | |
336 | 342 | | |
337 | 343 | | |
338 | 344 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
0 commit comments