add explain visualizer - #1279
Conversation
|
tbh I have no idea whats the best way to write tests for it ? |
Codecov Report
@@ Coverage Diff @@
## master #1279 +/- ##
==========================================
- Coverage 83.80% 78.25% -5.56%
==========================================
Files 21 23 +2
Lines 2594 2888 +294
==========================================
+ Hits 2174 2260 +86
- Misses 420 628 +208
Continue to review full report at Codecov.
|
|
The explain plan looks gorgeous. 😄 I'm still playing around with it, haven't had a chance to look through the code yet. Looks like some of the colors you've used from click aren't available in the older versions of click. So we should consider requiring a modern version of click in setup.py. |
|
@dkuku Instead of binding the explain mode to F5 key can we detect an EXPLAIN query and automatically display the results using ExplainVisualizer? |
|
@amjith we can but you need to pass some params to the explain query and when these are missing it may crash due to missing fields or the format (it needs json). I was tinking more of having an easy way to show the explain for your current query. I think its more useful than having a way to switch between vim/emacs mode with a shortcut because you use one or the other? |
|
Hey @dkuku, sorry it's been forever since you submitted this PR, but I think it's good to merge. Would you be able to rebase it on top of main and resolve the conflicts? |
|
Hi @j-bennet I merged master into this branch. |
|
Merged. Nice work! 🍫 |
In pgexecute.run(), the control flow was `if explain_mode: prepend EXPLAIN prefix / elif pgspecial: <detect+run special>`. Because it was if/elif, when explain mode (F5) was ON the pgspecial branch never ran, so \q, \d, exit, named queries, \i, \autocommit, \G, etc. were turned into `EXPLAIN (...) <command>` and shipped to the server as invalid SQL. The user could not even quit -- typing \q gave `syntax error at or near "\"`, which is especially painful after an idle-timeout reconnect (the reconnect retries the command and it errors again). Fix: detect special commands FIRST (drop the `elif`, make it `if pgspecial:`), and apply the EXPLAIN prefix ONLY to genuine SQL, right before execute_normal_sql(). Special commands now keep working while explain mode is on. Side effects: \G is now stripped correctly under explain mode, and the restrict-mode meta-command guard (CVE-2025-8714) stays authoritative instead of being bypassed by turning on F5. This is an UPSTREAM bug (dbcli/pgcli, present since the explain visualizer was added in dbcli#1279); candidate for an upstream PR. Tests: 4 new @dbtest in test_pgexecute.py (special not wrapped, describe runs as special, normal SQL still wrapped, \G stripped). 3 of them fail on the old code, all pass on the fix. Full suite 2969 passed (no DB) / all green with DB; ruff + mypy clean. Bump 4.5.6 -> 4.5.7.
Description
adds a formatter for explain analyze output
based on https://github.com/dkuku/pyev
Checklist
changelog.rst.AUTHORSfile (or it's already there).pip install pre-commit && pre-commit install), and ranblackon my code.